/*
 * Accessibility corrections to Filament's default control sizing.
 *
 * Filament ships 36px-tall controls with a 14px font. Two problems, both of which the
 * browser harness MEASURES rather than assumes:
 *
 *   1. A 36px control is below the 44px minimum touch target. School staff use
 *      this panel from phones.
 *   2. A 14px input makes iOS Safari zoom the page on focus, which then leaves the form
 *      scrolled sideways - a common reason people give up on a mobile admin entirely.
 *      16px is the threshold, and it is a threshold, not a preference.
 *
 * Plain CSS through FilamentAsset, deliberately NOT a Tailwind theme (ADR-006: no build step).
 *
 * ## Two things to know before editing
 *
 * NEVER wrap these in @layer. Filament's own rules live in `@layer components`, and an
 * unlayered rule beats any layered one regardless of specificity. Inside a layer these
 * would have to out-specify Filament selector by selector.
 *
 * Filament's class names (fi-input, fi-btn, fi-icon-btn, fi-checkbox-input) are its public
 * styling hooks. If an upgrade renames one, the harness fails and names the element - which
 * is the point of measuring. A selector that matches nothing is indistinguishable from a
 * rule that works (`.fi-textarea` once matched nothing: Filament puts `fi-fo-textarea` on the
 * wrapper and no class on the element).
 *
 * Colours here are Filament's own custom properties, never literals: the panel's palette is
 * set in AdminPanelProvider with measured contrast, and DesignTokensOnlyTest scans this
 * directory.
 */

html.fi {
    /*
     * Declared here rather than taken from public/css/tokens.css on purpose: the panel is a
     * separate document and does not load the public stylesheet. Same value, and
     * AdminControlSizingTest asserts the two agree so they cannot drift.
     */
    --panel-touch: 44px;
    --panel-input-size: 1rem;
}

/* --------------------------------------------------------------------------
   Text inputs, selects and textareas.

   The textarea selector is `.fi-fo-textarea textarea`, NOT `.fi-textarea` -
   see the note above about the selector that matched nothing.
   -------------------------------------------------------------------------- */
.fi-input,
.fi-select-input {
    min-height: var(--panel-touch);
    font-size: var(--panel-input-size);
}

/* Textareas grow, so only the font size matters. */
.fi-fo-textarea textarea {
    font-size: var(--panel-input-size);
}

/* --------------------------------------------------------------------------
   Buttons and icon-only controls
   -------------------------------------------------------------------------- */
.fi-btn {
    min-height: var(--panel-touch);
}

.fi-icon-btn {
    min-width: var(--panel-touch);
    min-height: var(--panel-touch);
}

/*
 * Navigation items ship at 40px. Four pixels short, on the control a phone user touches
 * most often.
 */
.fi-sidebar-item-btn {
    min-height: var(--panel-touch);
}

/*
 * The brand link in the topbar, which is the panel's "home" and was 20px tall.
 *
 * `.fi-topbar-start > a` and not a class of its own: Filament renders this anchor with NO
 * class at all, so there is nothing else to hook. Measured, not guessed - the browser
 * harness reported 164x20 at 1280 and named the element, which is the entire reason the
 * measurement is not optional. A logo-based hook such as
 * `a:has(> .fi-logo)` would not match here because this brand is text.
 */
.fi-topbar-start > a {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
}

/*
 * Breadcrumb links, 23px tall and the usual way back up one level on a phone.
 */
.fi-breadcrumbs-item-label {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
    /* A short label ("Staf") is only 31px wide, and width counts for a touch target too. */
    min-width: var(--panel-touch);
}

/*
 * A toggle switch is 24px tall (ADR-060 put six on "Pengaturan Situs"). The button itself
 * grows to 44px with a transparent border above and below; the track is painted inside the
 * border only, so it looks the same and the knob stays centred.
 */
.fi-toggle {
    height: var(--panel-touch);
    /* Filament's 2px transparent border, which spaces the knob, becomes padding. */
    border-width: 10px 0;
    border-color: transparent;
    padding: 2px;
    background-clip: padding-box;
}

/* The avatar dropdown trigger is 32px square, and it is the only route to "sign out". */
.fi-user-menu-trigger {
    min-width: var(--panel-touch);
    min-height: var(--panel-touch);
}

/*
 * Tab buttons, 39px tall: the relation-manager tabs under an applicant's record ("Dokumen",
 * "Nilai") from 768px up; below that Filament renders them as a select, already sized above.
 */
.fi-tabs-item {
    min-height: var(--panel-touch);
}

/* --------------------------------------------------------------------------
   Checkboxes and radios

   The input itself stays small - a 44px checkbox looks broken - so the LABEL
   carries the hit area, which is what WCAG 2.5.5 actually asks for.
   -------------------------------------------------------------------------- */
label:has(> .fi-checkbox-input),
label:has(> .fi-radio-input) {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
}

/*
 * A radio option is one row of a list, so it stays a block-level flex as Filament draws
 * it. The inline-flex above (unlayered, so it beats Filament's layered rule) flowed the
 * options of the first Radio in the panel (Pengaturan Pendaftaran) onto one line at
 * 1280px, with the first label's text running into the second option's circle.
 */
label:has(> .fi-radio-input) {
    display: flex;
}

/*
 * A table's row-selection checkboxes have NO label: Filament puts the bare input in a cell,
 * so the rule above never reaches them and the harness measured 16x16 on /admin/pendaftar
 * (the first table with a bulk action; it shipped in Phase 6 because dev showed no rows).
 * The hit area grows with a transparent border, which IS hit-tested, while the background
 * stays clipped to the original box. Filament's ring is a box-shadow, which would now be
 * drawn around the whole 44px, so it is redrawn as an outline pulled back inside.
 */
.fi-ta-record-checkbox,
.fi-ta-page-checkbox,
.fi-ta-group-checkbox {
    --ta-checkbox-gap: calc((var(--panel-touch) - var(--spacing) * 4) / 2);
    width: var(--panel-touch);
    height: var(--panel-touch);
    margin: calc(var(--ta-checkbox-gap) * -1);
    border: var(--ta-checkbox-gap) solid transparent;
    background-clip: padding-box;
    box-shadow: none;
    outline: 1px solid color-mix(in oklab, var(--gray-950) 10%, transparent);
    outline-offset: calc(var(--ta-checkbox-gap) * -1 - 1px);
}

.fi-ta-record-checkbox:focus-visible,
.fi-ta-page-checkbox:focus-visible,
.fi-ta-group-checkbox:focus-visible {
    outline: 2px solid var(--primary-600);
}

/*
 * The focus ring belongs on the label, because the input it would otherwise sit on is
 * smaller than the thing a keyboard user is actually moving between.
 */
label:has(> .fi-checkbox-input:focus-visible),
label:has(> .fi-radio-input:focus-visible) {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Inline link actions, which are text and therefore easy to miss
   -------------------------------------------------------------------------- */
.fi-ac-link-action {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
}

/*
 * Filament pins a link's label to the baseline (`.fi-link > .fi-link-label { align-self: baseline }`)
 * so a link inside a sentence lines up with the text. With the touch height above, the link box is
 * taller than its label, so the label stuck to the top while the icon centred: "Ubah" on the staff
 * list sat about 10px above its own icon. Centre the label like the icon.
 */
.fi-ac-link-action > .fi-link-label {
    align-self: center;
}

/* --------------------------------------------------------------------------
   Body text

   Filament's --text-sm appears throughout and is always a font-size. Left
   alone, table cells and helper text render at 14px.
   -------------------------------------------------------------------------- */
html.fi {
    --text-sm: 1rem;
}

/*
 * A sortable column header is a real control and is Filament's own 23px.
 *
 * It had never been styled because nothing in this panel had a sortable column until SPMB's
 * first lookup table arrived - the same "a hook nobody needed yet" gap the header of this
 * file warns about. Found by the browser harness on the first run against the new screen,
 * which is what it is for.
 *
 * min-height rather than padding: the button is inline-flex inside the cell, so padding
 * would push the header row taller than the sort indicator needs.
 */
.fi-ta-header-cell-sort-btn {
    min-height: var(--panel-touch);
}

/*
 * The one documented exception, and it is a NAMED exception with a reason rather than a
 * threshold quietly lowered until the build went green.
 *
 * `.fi-badge-delete-btn` is 24px: a small x inside a tag. WCAG 2.5.8 exempts a control
 * whose function is available through another control of adequate size - here the tag's own
 * row, and the full edit form. The browser harness carries the same path in
 * TARGET_EXCEPTIONS, cross-referenced to this comment.
 */
.fi-badge-delete-btn {
    min-width: 24px;
    min-height: 24px;
}

/* --------------------------------------------------------------------------
   Phase 8c: the three widgets the gelombang form introduced

   All three were found by the browser harness on that screen's first run, at
   all three widths.
   None of them had ever been styled because nothing in this panel had used
   one: the `.fi-input` rule above covers a text input and a NATIVE select,
   and these are custom widgets that render their own controls.
   -------------------------------------------------------------------------- */

/*
 * The non-native Select trigger, reported as 280x36 "Pilih salah satu opsi".
 *
 * `.fi-select-input` above is the NATIVE `<select>`. A searchable Select renders a
 * `<button class="fi-select-input-btn">` instead, and that is a different element with a
 * different class - so the existing rule matched nothing here. This is the first Select
 * this panel has ever measured: `/panel/identitas` is audited as a LIST page, and The hook existed
 * for months with nothing to apply it to.
 */
.fi-select-input-btn {
    min-height: var(--panel-touch);
    font-size: var(--panel-input-size);
}

/*
 * The date and time trigger, reported as 280x36 three times over - one per window field.
 *
 * `native(false)` is deliberate on these (SpmbWindowPicker: the native control ignores
 * ->timezone() and renders in the viewer's own zone), and the custom trigger is an
 * `<input type="text">` carrying its own class rather than `.fi-input`.
 *
 * The font-size matters as much as the height here and for the usual reason: this is a
 * field somebody types a deadline into on a phone, and at 14px iOS Safari zooms on focus
 * and leaves the form scrolled sideways.
 */
.fi-fo-date-time-picker-display-text-input {
    min-height: var(--panel-touch);
    font-size: var(--panel-input-size);
}

/*
 * The rich-text toolbar's buttons, reported as 32x32, eighteen of them per editor.
 *
 * Sized up rather than exempted, which is the choice every other rule in this file makes.
 * 32px clears WCAG 2.5.8's 24px AA floor, so an exemption could have been argued on
 * paper - but this project's rule is 44px because school staff administer these sites from
 * phones, and a formatting toolbar is used on a phone like any other control. The one
 * exemption below (`.fi-badge-delete-btn`) has a real 2.5.8 argument, that its function is
 * reachable through a larger control; bold and italic have no second control, only a
 * keyboard shortcut nobody has on a phone.
 *
 * The cost is honest: the toolbar is taller and wraps to more rows at 360px. That is the
 * trade this project already made for the sidebar, the breadcrumbs and the sort headers.
 */
.fi-fo-rich-editor-tool {
    min-width: var(--panel-touch);
    min-height: var(--panel-touch);
}

/*
 * And the toolbar has to wrap, because the rule above is what broke it.
 *
 * Widening eighteen buttons to 44px made one toolbar GROUP 332px wide, and the harness
 * reported it running to x=382 in a 360px viewport - a horizontal scroll on the page body,
 * which AGENTS.md section 8 forbids outright. The 44px decision and this rule are one
 * change; shipping the first without the second trades an accessibility failure for a
 * layout one.
 *
 * `flex-wrap` on BOTH levels, deliberately. On the toolbar so groups flow onto new rows,
 * and on the group so a single group that is itself wider than the viewport still breaks -
 * without the second rule the formatting group alone (seven buttons, 308px plus gaps) is
 * one Filament release away from overflowing again on its own.
 *
 * Unconditional rather than inside a breakpoint: base styles describe the small screen
 * (section 8), and a toolbar that wraps when it needs to is correct at every width.
 */
.fi-fo-rich-editor-toolbar,
.fi-fo-rich-editor-toolbar-group {
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   The pustaka: the image library's grid, its picker, and the preview.

   Plain hand-written CSS driven by custom properties, because there is no build step
   anywhere (ADR-006) and no custom Filament theme (AGENTS.md section 9). Colours are
   Filament's own custom properties rather than literals, which is what DesignTokensOnlyTest
   scans this directory for.

   Mobile-first throughout: every rule below describes the narrow screen and the one
   breakpoint that exists is a `min-width`. AGENTS.md section 9 forbids `max-width` queries
   outright, because they scale a desktop design down instead of building up.
   -------------------------------------------------------------------------- */

/*
 * One tile. A <figure> with its <figcaption>, so the caption belongs to the image rather
 * than merely sitting under it.
 */
.pustaka-petak {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
}

/*
 * `aspect-ratio` plus `object-fit: contain` rather than a fixed height.
 *
 * Two reasons. A library holds portrait photos and square logos side by side, and a fixed
 * height crops them differently; `contain` shows the whole image, which is the point of a
 * picker. And the box keeps its shape before the image arrives, so a grid of twelve
 * thumbnails does not reflow as they load - the same reason the tile emits width and height.
 */
.pustaka-petak__gambar {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background-color: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
}

/*
 * A private file has no URL at all (ADR-010), so the tile says what the file is instead of
 * showing a broken image. Centred in the same box the image would have occupied, so a mixed
 * grid keeps its rhythm.
 */
.pustaka-petak__tanpa-gambar {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    font-weight: 600;
    color: var(--gray-500);
    background-color: var(--gray-50);
    border: 1px dashed var(--gray-300);
    border-radius: 0.5rem;
}

.pustaka-petak__nama {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--gray-700);

    /*
     * A school's filenames are long and occasionally one word. Without both of these a
     * single name pushes the grid column wider than the viewport, which at 360px is a
     * horizontal scroll on the page body - forbidden outright by AGENTS.md section 8.
     */
    overflow-wrap: anywhere;
    word-break: break-word;
}

/*
 * "Belum ada teks alternatif", said in words.
 *
 * NOT by colour alone (AGENTS.md section 7a). The colour is a second signal for people who
 * can see it; the sentence is the signal, and it is the one that reaches the people the alt
 * text exists for.
 */
.pustaka-petak__peringatan {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--warning-700);
}

/*
 * The image picker's choices (ADR-058): the whole thumbnail is the label of its radio or
 * checkbox, so the hit area is the image itself, far above 44px. Its layout and colours live
 * in admin-tema.css; only the focus ring, which is an accessibility rule, is here.
 */
.pustaka-pilih__input:focus-visible + .pustaka-pilih__gambar {
    outline: 3px solid var(--primary-600);
    outline-offset: 2px;
}

/*
 * A Select's clear (x) button, which Filament's select JS builds as
 * `.fi-select-input-value-remove-btn`.
 *
 * Filament renders them at 16x16. Measured on the logo picker, which is the panel's first
 * CLEARABLE Select - every other one here is required or has `selectablePlaceholder(false)`,
 * so there was no clear button to be too small until now.
 *
 * Sized up rather than exempted, the same choice every other rule in this file makes. The
 * glyph stays 16px; what grows is the hit area, which is what the rule is about. A 2.5.8
 * exemption could be argued on paper - clearing a Select is also reachable by selecting the
 * placeholder option - but this project's rule is 44px because school staff administer
 * these sites from phones, and "there is another way to do it" is thin comfort when the
 * other way is a dropdown you have to open first.
 */
.fi-select-input-value-remove-btn {
    min-width: var(--panel-touch);
    min-height: var(--panel-touch);

    /*
     * Centred, because growing the box without this leaves the 16px glyph in the top-left
     * corner of a 44px target - which looks like a misalignment bug rather than a bigger
     * button, and puts the visual affordance nowhere near the middle of the hit area.
     */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/*
 * The "Lupa kata sandi?" hint link on the login form is a 25px-tall inline anchor, and it is the
 * only way back into an account. Same treatment as the breadcrumb links above.
 */
.fi-sc-text .fi-link {  /* a hint is rendered as a text component, not a .fi-fo-field-hint */
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
}

/*
 * The dashboard's "setup incomplete" list (ADR-047): each line is a link on a phone, so each
 * gets the 44px touch height. Filament's fi-link is inline and would be ~20px tall.
 */
.admin-daftar-tautan .fi-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
}

/*
 * A link written inside a sentence or a helper text (ADR-067: "Baca ketentuan pendaftaran",
 * "Unduh ... (PDF)"), which the browser harness measured at 22px. Here rather than in
 * spmb-portal.css because the same PDF link appears in the staff panel's form helper. The
 * portal's older `.spmb-tautan-berkas` does the same for its own sentences.
 */
.tautan-sentuh {
    display: inline-flex;
    align-items: center;
    min-height: var(--panel-touch);
    min-width: var(--panel-touch);
    text-decoration: underline;
    overflow-wrap: anywhere;
}

/*
 * Grey TEXT contrast, light mode only (ADR-071, found by the harness's contrast check).
 *
 * Filament writes secondary text (section descriptions, helper text, the gray badge, "atau")
 * in gray-500 and empty-value text ("Belum diisi", "Belum dikirim") in gray-400. On white the
 * platform ramp gives 4.2:1 and 2.4:1, below the 4.5:1 body-text minimum.
 *
 * gray-500 is moved most of the way to 600 (about 5.4:1 on white, 4.8:1 on gray-100) for the
 * light theme only. It is NOT changed in PanelPalette because dark mode uses the same shade
 * for placeholders on gray-900, where a darker 500 would fail instead. Mixed from the ramp's
 * own shades, so no new colour literal. Empty-value text and input placeholders are then
 * lifted from 400 to that 500; gray-400 itself stays for icons and borders.
 */
html:not(.dark) {
    --gray-500: color-mix(in oklab, var(--gray-600) 80%, var(--gray-400));
}

html:not(.dark) :is(
    .fi-ta-placeholder,
    .fi-in-entry .fi-in-placeholder,
    .fi-select-input .fi-select-input-placeholder,
    .fi-fo-markdown-editor .fi-fo-markdown-editor-placeholder,
    .fi-fo-modal-table-select .fi-fo-modal-table-select-placeholder
) {
    color: var(--gray-500);
}

html:not(.dark) :is(.fi-input, .fi-fo-textarea textarea, .fi-fo-date-time-picker-display-text-input)::placeholder {
    color: var(--gray-500);
}

/*
 * The "?" guide button and its slide-over (ADR-078). The button keeps the panel's 44px touch
 * target; the topics are accordions, each summary a full-width 44px row.
 */
.panduan-tombol {
    min-width: var(--panel-touch);
    min-height: var(--panel-touch);
}

.panduan-daftar {
    display: grid;
    gap: 0.5rem;
}

.panduan-topik {
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    padding: 0 1rem;
}

.panduan-topik summary {
    display: flex;
    align-items: center;
    min-height: var(--panel-touch);
    cursor: pointer;
    font-weight: 600;
}

.panduan-topik summary:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.panduan-isi {
    padding-bottom: 1rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.panduan-isi :is(ol, ul) {
    margin: 0.5rem 0;
    padding-inline-start: 1.25rem;
}

.panduan-isi ol {
    list-style: decimal;
}

.panduan-isi ul {
    list-style: disc;
}

.panduan-isi li + li {
    margin-top: 0.375rem;
}

.panduan-versi {
    font-size: 0.875rem;
    color: var(--gray-600);
}

html.dark .panduan-topik {
    border-color: var(--gray-700);
}

html.dark .panduan-versi {
    color: var(--gray-400);
}
