/* ---------------------------------------------------------------------------
   Electronic Construction Permitting System — stylesheet

   One file, no build step, no external requests. The Bangla face is bundled
   in assets/fonts so no page contacts a third party.

   Colour is defined once as semantic tokens and redefined for dark mode.
   --brand drives every accent shade below, so one value produces a coherent
   ramp in both light and dark rather than a single flat colour that works in
   one.
--------------------------------------------------------------------------- */

:root {
    /* Fixed for now: no setting sets this yet. A later slice may let the
       administrator choose it, constrained to a six-digit hex first. */
    --brand: #1a5cff;

    --bg: #f1f4f8;
    --surface: #ffffff;
    --surface-sunken: #f6f8fb;
    --border: #e4e8ee;
    --border-strong: #cbd2dc;

    /* The sidebar is chrome, not content. Giving it its own ground — rather
       than the same white as every panel — is what stops the page reading as
       one flat sheet with lines drawn on it. */
    --chrome: #f7f9fc;

    --text: #0f151d;
    --text-muted: #57616f;
    --text-faint: #838d9a;

    --accent: var(--brand);
    --accent-hover: color-mix(in srgb, var(--brand) 86%, #000);
    --accent-soft: color-mix(in srgb, var(--brand) 10%, transparent);
    --accent-line: color-mix(in srgb, var(--brand) 32%, transparent);
    --on-accent: #ffffff;

    /* The header bar: navy in both themes (see .topbar). */
    --header-from: #0f2a4a;
    --header-to: #1b3f6b;
    --on-header: #ffffff;
    --on-header-muted: rgb(255 255 255 / 0.72);
    --header-h: 4rem;

    --ok: #0f6b45;
    --ok-soft: #e6f4ec;
    --warn: #8a5300;
    --warn-soft: #fdf3e3;
    --danger: #b3261e;
    --danger-soft: #fdeceb;

    --r-sm: 6px;
    --r: 10px;
    --r-lg: 14px;
    --r-full: 999px;

    --shadow-sm: 0 1px 2px rgb(15 21 29 / 0.06);
    --shadow: 0 1px 3px rgb(15 21 29 / 0.08), 0 8px 24px -12px rgb(15 21 29 / 0.12);

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --tap: 44px;
    --ease: cubic-bezier(0.2, 0, 0, 1);

    color-scheme: light;
}

/* The same dark values are applied by two different conditions: no explicit
   choice on a dark device, and an explicit dark choice anywhere. A token
   defined only inside the media query could never be overridden by the
   toggle, which is the whole point of having one. Keep these two lists in
   step — a value changed in one and not the other is a bug nobody sees
   until they flip the switch. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1117;
        --surface: #161b22;
        --surface-sunken: #11161d;
        --border: #262d38;
        --border-strong: #3a4451;
        --chrome: #12171f;
        --header-from: #0b1f38;
        --header-to: #16335a;

        --text: #e7ecf2;
        --text-muted: #9aa5b3;
        --text-faint: #6e7986;

        /* Mixing toward white rather than black: darkening an accent on a dark
           surface reduces contrast instead of signalling interaction. */
        --accent-hover: color-mix(in srgb, var(--brand) 82%, #fff);
        --accent-soft: color-mix(in srgb, var(--brand) 18%, transparent);
        --accent-line: color-mix(in srgb, var(--brand) 45%, transparent);

        --ok: #57d69b;
        --ok-soft: #10281e;
        --warn: #e0aa5a;
        --warn-soft: #2a2013;
        --danger: #f2837a;
        --danger-soft: #2c1614;

        --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
        --shadow: 0 1px 3px rgb(0 0 0 / 0.5), 0 10px 28px -14px rgb(0 0 0 / 0.7);

        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-sunken: #11161d;
    --border: #262d38;
    --border-strong: #3a4451;
    --chrome: #12171f;
    --header-from: #0b1f38;
    --header-to: #16335a;

    --text: #e7ecf2;
    --text-muted: #9aa5b3;
    --text-faint: #6e7986;

    /* Mixing toward white rather than black: darkening an accent on a dark
       surface reduces contrast instead of signalling interaction. */
    --accent-hover: color-mix(in srgb, var(--brand) 82%, #fff);
    --accent-soft: color-mix(in srgb, var(--brand) 18%, transparent);
    --accent-line: color-mix(in srgb, var(--brand) 45%, transparent);

    --ok: #57d69b;
    --ok-soft: #10281e;
    --warn: #e0aa5a;
    --warn-soft: #2a2013;
    --danger: #f2837a;
    --danger-soft: #2c1614;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow: 0 1px 3px rgb(0 0 0 / 0.5), 0 10px 28px -14px rgb(0 0 0 / 0.7);

    color-scheme: dark;
}

:root[data-theme="light"] {
    color-scheme: light;
}

/* --- base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.011em; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.125rem; font-weight: 620; margin-bottom: 0.5rem; }
p { margin: 0 0 0.75rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

.hint {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0.25rem 0 1.25rem;
}

.mono {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}

/* Anything that can take focus shows it. Removing these rings is the single
   most common way a keyboard user loses their place on a page. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* --- page frame ---------------------------------------------------------- */

/* 90% of the window at every width, with no maximum (slice 6): the wider the
   screen, the more of it the lists use. The side padding sits inside that
   90% (box-sizing: border-box above), so the gutter is kept. */
.site-main {
    width: 90%;
    margin: clamp(1.25rem, 4vw, 2rem) auto;
    padding: 0 clamp(1rem, 4vw, 1.5rem);
}

.site-footer {
    margin: 2.5rem auto;
    padding: 0 clamp(1rem, 4vw, 1.5rem) max(1rem, env(safe-area-inset-bottom));
    color: var(--text-faint);
    font-size: 0.8125rem;
}

/* --- surfaces ------------------------------------------------------------ */

/* Panels sit on the page rather than being drawn onto it: a soft two-layer
   shadow and a near-invisible hairline, instead of a hard 1px box. The
   difference between "a card" and "a rectangle with a border" is almost
   entirely this. */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: clamp(1.125rem, 3vw, 1.5rem);
    box-shadow: 0 1px 2px rgb(15 21 29 / 0.04), 0 6px 16px -8px rgb(15 21 29 / 0.10);
}
/* The deeper shadow belongs to dark mode only. This used to sit outside the
   media query, where :root:not([data-theme="light"]) also matched every light
   screen that had made no explicit choice. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .panel {
        box-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 20px -10px rgb(0 0 0 / 0.5);
    }
}
:root[data-theme="dark"] .panel {
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 20px -10px rgb(0 0 0 / 0.5);
}
/* A table fills its panel edge to edge; the padding belongs to the cells. */
.panel.flush { padding: 0.5rem 1.125rem 0.25rem; }
.panel + .panel { margin-top: 1.25rem; }
.panel.narrow { max-width: 27rem; margin-inline: auto; margin-block: clamp(1.5rem, 6vw, 3rem); }

/* --- buttons ------------------------------------------------------------- */

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--tap);
    padding: 0 1.125rem;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 560;
    color: var(--on-accent);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--r);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 140ms var(--ease), border-color 140ms var(--ease),
                transform 90ms var(--ease);
}
button:hover, .button:hover { background: var(--accent-hover); color: var(--on-accent); }
/* Scale rather than translate: it gives press feedback without nudging
   neighbouring content around. */
button:active, .button:active { transform: scale(0.985); }

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

button.secondary, .button.secondary {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border-strong);
}
button.secondary:hover, .button.secondary:hover {
    background: var(--surface-sunken);
    border-color: var(--text-faint);
    color: var(--text);
}

/* --- forms --------------------------------------------------------------- */

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 560;
    margin: 1.125rem 0 0.375rem;
}

input[type=text], input[type=email], input[type=password],
input[type=url], input[type=number], input[type=search], input[type=file], input[type=date], textarea, select {
    width: 100%;
    min-height: var(--tap);
    padding: 0.625rem 0.75rem;
    font: inherit;
    font-size: 1rem; /* below 16px iOS zooms the page on focus */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }

input[type=file] { padding: 0.5rem; cursor: pointer; }
input[type=color] {
    width: 3.5rem;
    min-height: var(--tap);
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    cursor: pointer;
}

input[type=checkbox] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--accent);
    cursor: pointer;
}

/* --- notices and status -------------------------------------------------- */

.notice {
    padding: 0.75rem 0.875rem;
    border-radius: var(--r);
    border: 1px solid transparent;
    font-size: 0.9375rem;
    margin-bottom: 1.25rem;
}
.notice ul { margin: 0.5rem 0 0; padding-left: 1.125rem; }
.notice.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.notice.ok    { background: var(--ok-soft);     border-color: color-mix(in srgb, var(--ok) 30%, transparent);     color: var(--ok); }
.notice.warn  { background: var(--warn-soft);   border-color: color-mix(in srgb, var(--warn) 30%, transparent);   color: var(--warn); }

/* Status carries a dot as well as a colour, so it still reads for anyone who
   cannot distinguish the two hues. Not drawn by any view yet — kept for
   slice 2's application status pills. */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.1875rem 0.625rem;
    border-radius: var(--r-full);
    font-size: 0.75rem;
    font-weight: 580;
    white-space: nowrap;
}
.tag::before {
    content: "";
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 50%;
    background: currentColor;
}
.tag.live  { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 22%, transparent); }
.tag.draft { background: var(--surface-sunken); color: var(--text-muted); border: 1px solid var(--border-strong); }

/* --- tables -------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 1rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 0.25rem; }
th:last-child, td:last-child { padding-right: 0.25rem; }
th {
    padding-top: 0.5rem;
    padding-bottom: 0.625rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    background: var(--surface);
    border-bottom-color: var(--border);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 120ms var(--ease); }
tbody tr:hover { background: var(--surface-sunken); }

/* The title is what the eye lands on; the filename is provenance, so it sits
   under it at a smaller size rather than competing on the same line. */
td .stack strong { font-weight: 580; letter-spacing: -0.006em; }
td .stack .hint { font-size: 0.8125rem; }

/* Row actions are compact and quiet. Three full-size buttons of identical
   weight per row is most of what made this table read as undesigned: the eye
   had nowhere to land. They shrink, lose their fill, and only the row under
   the cursor shows its borders. Not drawn by any view yet — kept, with the
   td.actions rules below, for slice 2's tables. */
@media (min-width: 768px) {
    td.actions .button, td.actions button {
        min-height: 2rem;
        padding: 0 0.75rem;
        font-size: 0.8125rem;
        font-weight: 520;
        color: var(--text-muted);
        background: transparent;
        /* A faint border always, rather than none until hover: a control that
           is invisible until you happen to point at it is a control most
           people never find, and hover does not exist on a touch screen. */
        border-color: var(--border);
    }
    td.actions .button:hover, td.actions button:hover {
        color: var(--text);
        background: var(--surface-sunken);
        border-color: var(--border-strong);
    }
}

td .mono {
    display: inline-block;
    max-width: 22ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
    vertical-align: bottom;
}
td.actions { width: 1%; }
td.actions .row { flex-wrap: nowrap; justify-content: flex-end; }

/* An application number ("A-000002/2026") or a timestamp reads worse split
   across two lines than a neighbouring column reading slightly narrower —
   the other columns' text can still wrap to make room. Reset for the card
   layout below, where the row is already full width. */
td.nowrap { white-space: nowrap; }

/* Below this width a four-column table cannot be read without scrolling
   sideways, so each row becomes its own card with the header as a label. */
@media (max-width: 767px) {
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    tbody tr {
        display: block;
        padding: 0.875rem 0;
        border-bottom: 1px solid var(--border);
    }
    tbody tr:last-child { border-bottom: 0; }
    tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: 0.3125rem 0;
        border: 0;
    }
    tbody td::before {
        content: attr(data-label);
        flex: none;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-faint);
    }
    tbody td:not([data-label])::before { content: none; }
    tbody td.actions { width: auto; justify-content: flex-end; padding-top: 0.625rem; }
    tbody td.actions .row { flex-wrap: wrap; }
    td .mono { max-width: none; white-space: normal; word-break: break-all; text-align: right; }
    td.nowrap { white-space: normal; }

    /* The first cell is the card's heading, so it reads full width on the left
       rather than as a right-aligned value opposite a redundant label. */
    tbody td:first-child { display: block; padding-bottom: 0.5rem; }
    tbody td:first-child::before { content: none; }
}

/* --- small layout helpers ------------------------------------------------ */

.row { display: flex; gap: 0.625rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.page-head h1 {
    font-size: 1.75rem;
    font-weight: 680;
    letter-spacing: -0.022em;
}
/* A one-line subtitle under the title. It gives the header something to be
   besides a word, and tells the owner the size of what they are looking at
   before they count the rows. */
.page-head .page-sub {
    margin: 0.1875rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}
.page-head > .row { align-items: center; }

.empty {
    text-align: center;
    padding: clamp(2rem, 8vw, 3.5rem) 1rem;
    color: var(--text-muted);
}
.empty h2 { color: var(--text); }

.filter-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filter-bar select { flex: 0 1 12rem; }

/* --- sidebar --------------------------------------------------------------- */

.skip-link {
    position: absolute;
    left: -9999px;
    padding: 0.625rem 1rem;
    background: var(--surface);
    border-radius: var(--r);
    z-index: 60;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 15rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 0.75rem max(1rem, env(safe-area-inset-bottom));
    background: var(--chrome);
    border-right: 1px solid var(--border);
    z-index: 50;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 0.125rem; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6875rem;
    min-height: 2.5rem;
    padding: 0 0.75rem;
    border-radius: var(--r);
    color: var(--text-muted);
    font-size: 0.9375rem;
    font-weight: 520;
    text-decoration: none;
    transition: background 140ms var(--ease), color 140ms var(--ease);
}
.sidebar-nav a:hover { background: var(--surface-sunken); color: var(--text); }

.sidebar-nav a[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 580;
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.has-sidebar .site-main,
.has-sidebar .site-footer { margin-left: 15rem; }

@media (max-width: 899px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 200ms var(--ease);
        box-shadow: var(--shadow);
    }
    .drawer-open .sidebar { transform: none; }

    /* A scrim behind the open drawer. Without it the sidebar sits on top of a
       fully lit page and reads as a rendering fault rather than a panel. It is
       a pseudo-element rather than a real node so it needs no markup and no
       JavaScript: clicks land on <body>, which the outside-click handler in
       sidebar.js already treats as "close". */
    .drawer-open::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 49;
        background: rgb(15 21 29 / 0.45);
    }

    .icon-button {
        min-height: var(--tap);
        padding: 0 0.75rem;
        color: var(--text);
        background: var(--surface);
        border: 1px solid var(--border-strong);
        font-size: 0.875rem;
    }

    .has-sidebar .site-main,
    .has-sidebar .site-footer { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
}

/* --- motion -------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===========================================================================
   ECPS frame — header across the top, folder tree on the left, footer bar.
   Appended after the portal's rules on purpose: later rules win, and the
   portal's full-height fixed sidebar is re-seated below the header here.
=========================================================================== */

@font-face {
    font-family: "Noto Sans Bengali";
    src: url("fonts/NotoSansBengali-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
    unicode-range: U+0980-09FF, U+200C-200D, U+25CC;
}
@font-face {
    font-family: "Noto Sans Bengali";
    src: url("fonts/NotoSansBengali-SemiBold.ttf") format("truetype");
    font-weight: 560 700;
    font-display: swap;
    unicode-range: U+0980-09FF, U+200C-200D, U+25CC;
}

/* unicode-range means the face downloads only when Bangla text is on the
   page; Latin text in a Bangla page keeps the device's own font. */
:lang(bn) {
    font-family: "Noto Sans Bengali", "Nirmala UI", "Kohinoor Bangla", "Bangla Sangam MN", var(--font);
    line-height: 1.7;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* --- header: the navy bar ------------------------------------------------- */

/* The bar is navy in both themes: it is the system's identity rather than a
   surface that follows the page, so everything on it is white or a
   translucent white. */
.topbar {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-height: var(--header-h);
    padding: 0.5rem clamp(1rem, 3vw, 1.5rem);
    padding-top: max(0.5rem, env(safe-area-inset-top));
    background: linear-gradient(100deg, var(--header-from), var(--header-to));
    color: var(--on-header);
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    color: var(--on-header);
    text-decoration: none;
}
.topbar-brand:hover { color: var(--on-header); }
.topbar-emblem {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--r);
    background: rgb(255 255 255 / 0.12);
    border: 1px solid rgb(255 255 255 / 0.2);
}
/* An uploaded logo keeps its own colours, so it sits on a white tile. */
img.topbar-emblem { object-fit: contain; padding: 3px; background: #fff; }
.topbar-names { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.topbar-names strong,
.topbar-names span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-names strong { font-size: 1.0625rem; font-weight: 680; letter-spacing: -0.011em; }
.topbar-names span { font-size: 0.8125rem; color: var(--on-header-muted); }

/* The wireframe's "e-Submission" tab, as a quiet pill on the bar. */
.badge {
    flex: none;
    padding: 0.1875rem 0.625rem;
    border-radius: var(--r-full);
    background: rgb(255 255 255 / 0.14);
    border: 1px solid rgb(255 255 255 / 0.22);
    color: var(--on-header);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 0.375rem; flex: none; }

/* Focus rings on the navy bar are white; inside a menu's white panel they go
   back to the accent colour. */
.topbar a:focus-visible,
.topbar button:focus-visible,
.topbar summary:focus-visible { outline: 2px solid var(--on-header); outline-offset: 2px; border-radius: var(--r); }
.topbar .menu-panel :focus-visible { outline-color: var(--accent); }

/* --- header menus ----------------------------------------------------------- */

/* Each menu is a <details>: it opens and closes with no script. menus.js adds
   closing on an outside click or Escape. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }

.menu-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--tap);
    padding: 0 0.75rem;
    border-radius: var(--r);
    color: var(--on-header);
    font-size: 0.875rem;
    font-weight: 560;
    cursor: pointer;
    user-select: none;
    transition: background 140ms var(--ease);
}
.menu-button:hover,
.menu[open] > .menu-button { background: rgb(255 255 255 / 0.12); }
.menu-chevron { display: inline-flex; opacity: 0.8; transition: transform 140ms var(--ease); }
.menu[open] .menu-chevron { transform: rotate(180deg); }

.avatar {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: #fff;
    color: var(--header-from);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.user-names { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-name {
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 620;
}
.user-role { font-size: 0.75rem; font-weight: 450; color: var(--on-header-muted); }

.menu-panel {
    position: absolute;
    top: calc(100% + 0.375rem);
    right: 0;
    z-index: 60;
    min-width: 13rem;
    max-width: calc(100vw - 2rem);
    padding: 0.375rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
}
.menu-panel form { margin: 0; }
.menu-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.625rem;
    width: 100%;
    min-height: 2.5rem;
    padding: 0 0.75rem;
    border: 0;
    border-radius: var(--r);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.menu-item:hover { background: var(--surface-sunken); color: var(--text); }
.menu-item .icon { flex: none; color: var(--text-muted); }
.menu-item[aria-current="true"] { color: var(--accent); font-weight: 620; }
.menu-check { display: inline-flex; margin-left: auto; }
.menu-check .icon { color: var(--accent); }
.menu-divider { height: 1px; margin: 0.375rem 0.25rem; border: 0; background: var(--border); }

/* The drawer's button, on the right of the bar where a thumb reaches it. */
#menu-button { display: none; }
.icon-button {
    width: var(--tap);
    min-height: var(--tap);
    padding: 0;
    color: var(--on-header);
    background: transparent;
    border: 1px solid rgb(255 255 255 / 0.28);
}
.icon-button:hover { background: rgb(255 255 255 / 0.12); color: var(--on-header); }

/* --- page grid ---------------------------------------------------------- */

body.has-sidebar {
    display: grid;
    grid-template-columns: 16.5rem minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "top top" "side main" "side foot";
    min-height: 100vh;
}
.has-sidebar .topbar { grid-area: top; position: sticky; top: 0; z-index: 40; }
.has-sidebar .sidebar {
    grid-area: side;
    position: sticky;
    inset: auto;
    top: var(--header-h);
    align-self: start;
    width: auto;
    min-height: calc(100vh - var(--header-h));
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 1.25rem 0.875rem;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.has-sidebar .site-main {
    grid-area: main;
    width: 90%;
    margin: clamp(1.25rem, 4vw, 2rem) auto;
}
/* margin: 0 matters: the portal's own .has-sidebar .site-footer rule sets a
   15rem left margin with the same specificity, earlier in the file. */
.has-sidebar .site-footer { grid-area: foot; margin: 0; }

/* Signed out there is no grid; the footer still sits at the bottom. */
body.plain { display: flex; flex-direction: column; min-height: 100vh; }
body.plain .site-main { flex: 1 0 auto; width: 90%; }

/* --- sidebar entries ------------------------------------------------------ */

.folder-tree ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.1875rem; }
/* The My Applications group ends at a hairline, so My Appeals reads as the
   group's sibling, as the wireframe draws it, not as its last entry. */
.nav-group { margin: 0.25rem 0; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.sidebar-nav a,
.sidebar-foot a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    padding: 0 0.875rem;
    border-radius: var(--r);
    color: var(--text-muted);
    font-size: 0.9375rem;
    font-weight: 540;
    text-decoration: none;
    transition: background 140ms var(--ease), color 140ms var(--ease);
}
.sidebar-nav a:hover,
.sidebar-foot a:hover { background: var(--surface-sunken); color: var(--text); }
.sidebar-nav .icon,
.sidebar-foot .icon { flex: none; }
/* The current page: a pale-blue pill with blue text and icon. */
.sidebar-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 640; }
.nav-text { flex: 1 1 auto; min-width: 0; }
.nav-count {
    flex: none;
    min-width: 1.5rem;
    padding: 0 0.4375rem;
    border-radius: var(--r-full);
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.375rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.folder-label {
    display: block;
    margin: 0.75rem 0 0.25rem;
    padding: 0 0.875rem;
    color: var(--text-faint);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
:lang(bn) .folder-label { text-transform: none; letter-spacing: 0; font-size: 0.8125rem; }

.sidebar-foot { margin-top: auto; padding-top: 0.5rem; border-top: 1px solid var(--border); }
/* The drawer's own My Profile link: on a wide screen the account menu has it. */
.has-sidebar .sidebar-foot { display: none; }

/* --- footer bar ----------------------------------------------------------- */

.site-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: none;
    margin: 0;
    padding: 0.75rem clamp(1rem, 3vw, 1.5rem) max(0.75rem, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 0.8125rem;
    text-align: center;
}
/* The bar itself spans the window, so its ground and hairline do; its text
   keeps to the content's 90% frame above it (slice 6). */
.site-footer p { width: 90%; margin: 0; }

/* --- page head ------------------------------------------------------------ */

/* Eyebrow, title, one line of description: the head every main page opens with. */
.page-head .eyebrow {
    margin: 0 0 0.25rem;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
:lang(bn) .page-head .eyebrow { text-transform: none; letter-spacing: 0; font-size: 0.8125rem; }
.page-head h1 { font-size: clamp(1.5rem, 2.6vw, 1.875rem); font-weight: 720; }

/* --- content pieces ------------------------------------------------------- */

.quick-stats { padding: 0; overflow: hidden; }
.quick-stats-head {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1.125rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.quick-stats-head h2 { margin: 0; font-size: 1.0625rem; }
.quick-stats-head .hint { margin: 0; }
.quick-stats-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--r);
    background: var(--accent-soft);
    color: var(--accent);
}
.quick-stats-total {
    margin-left: auto;
    font-size: 2rem;
    font-weight: 750;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.quick-stats-list { list-style: none; margin: 0; padding: 0.375rem 0.5rem; }
.quick-stats-list li + li { border-top: 1px solid var(--border); }
.quick-stats-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 3.25rem;
    padding: 0 0.75rem;
    border-radius: var(--r);
    color: var(--text);
    text-decoration: none;
    transition: background 140ms var(--ease);
}
.quick-stats-row:hover { background: var(--surface-sunken); color: var(--text); }
.quick-stats-row-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    color: var(--text-muted);
}
.quick-stats-label { flex: 1 1 auto; min-width: 0; font-weight: 540; }
.quick-stats-count {
    min-width: 2rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--r-full);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.quick-stats-chevron { display: inline-flex; color: var(--text-faint); }
.quick-stats-note { margin: 0; padding: 0.75rem 1.25rem 1rem; border-top: 1px solid var(--border); }

.empty-icon {
    display: inline-grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 0.75rem;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}

.steps {
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.form-panel { max-width: 42rem; }
.form-actions { margin-top: 1.5rem; }
.field-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); column-gap: 1rem; }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }

/* --- phones and small tablets: the tree becomes a drawer ------------------ */

@media (max-width: 899px) {
    body.has-sidebar {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "top" "main" "foot";
    }
    .has-sidebar .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        /* Not the wide screen's start: a fixed box aligned to the start
           shrinks to its content instead of filling the screen's height. */
        align-self: auto;
        width: min(18rem, 85vw);
        min-height: 0;
        max-height: none;
        z-index: 50;
    }
    #menu-button { display: inline-flex; }
    .topbar-brand { flex: 1 1 auto; }
    /* Hidden from view, not from screen readers: the name and role stay part
       of the button's accessible name even though the bar has no room to
       show them. display:none here used to drop them from that name too,
       leaving "Account menu" with nothing after it. */
    .user-names {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .has-sidebar .sidebar-foot { display: block; }
}

/* A phone: the names truncate, the menus shrink to their icons. */
@media (max-width: 560px) {
    .topbar { gap: 0.5rem; }
    .badge { display: none; }
    .topbar-names span { display: none; }
    .topbar-emblem { width: 2.25rem; height: 2.25rem; }
    .menu-button { gap: 0.375rem; padding: 0 0.5rem; }
    .lang-menu .menu-label,
    .theme-menu .menu-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* ===========================================================================
   Slice 2 — applications: the Drafts and Ready lists, the type chooser and
   the wizard card. Built from the tokens above only, so dark mode follows.
=========================================================================== */

/* The wireframe's big "+ New Applications" button (A2). */
.new-application {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.875rem;
    min-height: 5.5rem;
    margin-bottom: 1.25rem;
    border: 2px dashed var(--accent-line);
    border-radius: var(--r-lg);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.25rem;
    font-weight: 680;
    text-decoration: none;
    transition: border-color 140ms var(--ease);
}
.new-application:hover { border-color: var(--accent); color: var(--accent-hover); }
.new-application-plus {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
}

/* The application's type, as a pill. */
.tag.kind { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
/* A list's dates are read whole: with an actions column beside them they were cut to "15/09/…". */
.decision-dates .mono { max-width: none; overflow: visible; text-overflow: clip; }
/* An appeal waiting for a decision (slice 4). */
.tag.pending { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent); }
/* The record page (slice 5): a rejected application's pill, and its lists of rejections and appeals. */
.tag.rejected { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent); }
.record-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1rem; }
.record-files { padding: 0; margin-top: 0.5rem; }
.record-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.record-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.75rem 0; border-top: 1px solid var(--border); }
.record-list li:first-child { border-top: 0; }
.record-list .appeal-text { flex-basis: 100%; }
/* My Appeals: the grounds and the decision note under the applicant, their line breaks kept. */
.appeal-cell { min-width: 0; }
.appeal-text { margin: 0.375rem 0 0; white-space: pre-line; overflow-wrap: anywhere; }
/* Allow's and Dismiss's panels open under the whole row of buttons: on a phone Allow comes first, at the left edge. */
td.actions .appeal-actions { position: relative; }
td.actions .appeal-actions details.confirm { position: static; }
.confirm-panel label { margin-top: 0.5rem; }
.confirm-panel textarea { min-height: 4rem; margin-bottom: 0.625rem; }

button.danger { background: var(--danger); color: #fff; }
button.danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); color: #fff; }
/* The Reject card's opening button is red as well: the panel it opens holds the real one. */
.button.danger { background: var(--danger); color: #fff; }
.button.danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); color: #fff; }
/* In a card's foot there is no room below: the panel opens upwards. */
.wizard-actions .confirm-panel { top: auto; bottom: calc(100% + 0.375rem); }

/* Delete asks once more, with no script: a <details> whose panel holds the real button. */
details.confirm { position: relative; }
details.confirm > summary { list-style: none; }
details.confirm > summary::-webkit-details-marker { display: none; }
.confirm-panel {
    position: absolute;
    top: calc(100% + 0.375rem);
    right: 0;
    z-index: 20;
    width: min(18rem, 80vw);
    padding: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    white-space: normal;
    text-align: left;
}
.confirm-panel p { font-size: 0.875rem; }

.plot-info { display: grid; grid-template-columns: auto 1fr; gap: 0.125rem 0.75rem; margin: 0.25rem 0 0; font-size: 0.875rem; }
.plot-info dt { color: var(--text-muted); }
.plot-info dd { margin: 0; overflow-wrap: anywhere; }

/* The wizard: a card with the wireframe's title bar, and its buttons along the foot. */
.wizard { max-width: 52rem; margin-inline: auto; padding: 0; }
.wizard-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.125rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.wizard-head h1 { display: flex; align-items: center; flex-wrap: wrap; gap: 0.625rem; font-size: 1.25rem; }
.wizard-sub { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.875rem; }
.wizard-close {
    flex: none;
    display: grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    border-radius: var(--r);
    color: var(--text-muted);
}
.wizard-close:hover { background: var(--surface-sunken); color: var(--text); }
.wizard-body { padding: 1.25rem; }
.wizard > .notice { margin: 1rem 1.25rem 0; }
.wizard-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.625rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-sunken);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* Choices drawn as tiles: the application type, and the saved logos and signatures. */
.picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}
.picker legend { padding: 0; margin-bottom: 0.625rem; font-size: 0.875rem; font-weight: 600; }
.tile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 4rem;
    margin: 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    background: var(--surface);
    font-size: 0.9375rem;
    font-weight: 540;
    cursor: pointer;
    transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.tile:hover { border-color: var(--text-faint); }
.tile input { flex: none; width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--accent); }
.tile:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.tile:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--r);
    background: var(--surface-sunken);
    color: var(--accent);
}
/* A logo or signature keeps its own colours, so it sits on white in both themes. */
.tile-image {
    flex: none;
    width: 4.5rem;
    height: 2.75rem;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}
.tile-text { min-width: 0; overflow-wrap: anywhere; }

/* The wizard's steps: four links, the current one filled in. */
.wizard-steps { padding: 1rem 1.25rem 0; }
.wizard-steps .steps { margin: 0 0 0.625rem; }
.wizard-steps ol {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.wizard-steps a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 560;
    text-decoration: none;
}
.wizard-steps a:hover { background: var(--surface-sunken); color: var(--text); }
.wizard-steps a[aria-current="step"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.wizard-step-number {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--surface-sunken);
    font-size: 0.75rem;
    font-weight: 700;
}
.wizard-steps a[aria-current="step"] .wizard-step-number { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.wizard-ready { margin: 1rem 1.25rem 0; }

.wizard-section { margin: 1.75rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--border); font-size: 1rem; }
.wizard-section.first { margin-top: 0; padding-top: 0; border-top: 0; }
.field-wide { grid-column: 1 / -1; }
.field-error { margin: 0.375rem 0 0; color: var(--danger); font-size: 0.8125rem; font-weight: 560; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }

/* Step 4's summary and the list of what is still missing. */
.summary { display: grid; grid-template-columns: minmax(8rem, auto) 1fr; gap: 0.5rem 1.25rem; margin: 1rem 0 0; }
.summary dt { color: var(--text-muted); font-size: 0.875rem; }
.summary dd { margin: 0; overflow-wrap: anywhere; }
.summary .is-missing { color: var(--warn); font-weight: 600; }
.summary-files { margin: 0; padding-left: 1.125rem; }
.summary-image { display: inline-flex; align-items: center; gap: 0.625rem; }
.missing a { color: inherit; font-weight: 650; }
.submit-form { display: flex; justify-content: center; margin-top: 1.75rem; }
.submit-big { min-height: 3.5rem; padding: 0 2.25rem; font-size: 1.125rem; }
.submit-hint { text-align: center; }

@media (max-width: 560px) {
    .wizard-steps ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .summary { grid-template-columns: 1fr; gap: 0.125rem; }
    .summary dd { margin-bottom: 0.5rem; }
}

/* Step 2: the drop zones ("Attach a File") and the list of files attached. */
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 1.5rem 1rem;
    border: 2px dashed var(--border-strong);
    border-radius: var(--r-lg);
    background: var(--surface-sunken);
    text-align: center;
    transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.drop-zone.is-dragover { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone.has-error { border-color: var(--danger); }
.drop-zone-plus {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}
.drop-zone strong { font-size: 1.0625rem; }
.drop-zone label { margin: 0.5rem 0 0; }
.drop-zone input[type=file],
.drop-zone input[type=text] { max-width: 24rem; }
.drop-zone .hint { margin: 0; }

.file-list { list-style: none; margin: 0; padding: 0.5rem 1.25rem 0; }
.file-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.file-list .stack { flex: 1 1 12rem; }
.file-list .hint { margin: 0; overflow-wrap: anywhere; }
.file-list form { margin: 0; }
.file-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    color: var(--text-muted);
}
.file-count { margin: 0; padding: 0.5rem 1.25rem 0; }
/* Rename: the Delete-style pop-over, wide enough for a name and its fixed ending. */
.rename-panel { display: grid; gap: 0.5rem; width: min(24rem, calc(100vw - 2.5rem)); }
.rename-panel label { font-weight: 600; font-size: 0.875rem; }
.rename-panel p { margin: 0; }
.rename-field { display: flex; align-items: center; gap: 0.375rem; }
.rename-field input { flex: 1 1 auto; min-width: 0; }
.rename-ext { flex: none; color: var(--text-muted); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.9375rem; }
.rename-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
/* On a phone the buttons wrap, so a pop-over anchored to Rename could hang
   off the screen's edge: there the panel opens in the row, full width. */
@media (max-width: 560px) {
    .file-list details.rename[open] { flex-basis: 100%; }
    .rename-panel { position: static; width: auto; margin-top: 0.5rem; box-shadow: none; }
}

/* Step 3: the link preview, the logo and signature pickers, "+ Add New" and the pad. */
.link-preview { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.375rem; margin: 0; }
.link-preview .hint { margin: 0; }
.link-preview .mono { color: var(--accent); }

/* The document's own signature (slice 7): no tiles to lay out in columns, so
   its fieldset stacks the current image, the file input and the pad. */
.picker.own-signature { display: block; }
.picker.own-signature .summary-image { margin-bottom: 0.75rem; }

.picker-block { margin-top: 1rem; }
.picker-block + .picker-block { margin-top: 1.75rem; }
.picker-block .field-error { margin-top: 0.5rem; }
.add-new { margin-top: 0.75rem; }
.add-new > summary {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--r);
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 600;
    list-style: none;
    cursor: pointer;
}
.add-new > summary::-webkit-details-marker { display: none; }
.add-new > summary:hover { border-color: var(--accent); }
.add-new-panel {
    margin-top: 0.625rem;
    padding: 0.25rem 1rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface-sunken);
}
.add-new-panel > button { margin-top: 1rem; }

/* ===========================================================================
   Slice 3 — stamping: the page the marks are placed on (drawn by pdf.js),
   the marks themselves, and the corner buttons.
=========================================================================== */

.stamp-stage-wrap { margin-top: 1rem; }
.stamp-stage-wrap > .hint { margin-bottom: 0.5rem; }
.stamp-stage {
    position: relative;
    width: 100%;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--r);
    overflow: hidden;
    touch-action: none;
}
.stamp-stage canvas { display: block; }
.stamp-box {
    position: absolute;
    top: 0;
    left: 0;
    border: 2px solid var(--accent);
    border-radius: 2px;
    background-color: rgb(255 255 255 / 0.6);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    box-shadow: 0 0 0 1px rgb(255 255 255 / 0.7), 0 4px 14px -4px rgb(0 0 0 / 0.35);
    cursor: grab;
    touch-action: none;
}
.stamp-box:active { cursor: grabbing; }
/* The page on screen is not one that carries the code. */
.stamp-box-off { opacity: 0.35; border-style: dashed; }
/* Stepping through a letter's pages, and giving one its own place. */
.stamp-page-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.stamp-page-steps { display: inline-flex; align-items: center; gap: 0.625rem; }
.stamp-page-steps button { min-height: 2.5rem; padding: 0 0.875rem; font-size: 0.875rem; }
.stamp-page-steps button:disabled { opacity: 0.45; cursor: default; }
.stamp-page-steps span { font-weight: 600; font-variant-numeric: tabular-nums; }
.stamp-page-nav label.check { margin: 0; }
/* Which mark this is, read from the box's own aria-label ("Signature 2"): eight boxes
   on one plot are told apart by this, since they share a border and often a shape. */
.stamp-box[data-mark*="_"]::after {
    content: attr(aria-label);
    position: absolute;
    /* Inside the box: a logo's default corner is a few pixels from the stage's top, which clips. */
    top: 2px;
    left: 2px;
    bottom: auto;
    padding: 1px 6px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--r-sm);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
}
.stamp-box:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.stamp-handle {
    position: absolute;
    right: -9px;
    bottom: -9px;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border: 2px solid #fff;
    border-radius: var(--r-sm);
    cursor: nwse-resize;
    box-shadow: var(--shadow-sm);
}

/* Four corners and Custom: two columns on a phone, one row once there is room. */
.snap-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
@media (min-width: 560px) {
    .snap-group { display: flex; flex-wrap: wrap; }
}
.snap-group button { min-height: 2.5rem; padding: 0 0.875rem; font-size: 0.875rem; }

.page-picker { margin: 1.5rem 0 0; padding: 0; border: 0; min-width: 0; }
.page-picker legend { padding: 0; margin-bottom: 0.5rem; font-weight: 600; }
.page-picker .row { gap: 1.25rem; }
.page-picker label.check { margin: 0; }
.page-picker input[type=text] { max-width: 16rem; }
.size-field input { max-width: 8rem; }
.preview-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }
.stamp-mark + .stamp-mark { margin-top: 0.5rem; }
.stamp-mark .summary-image { margin-top: 0.25rem; }
.preview-frame {
    display: block;
    width: 100%;
    height: min(70vh, 40rem);
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface-sunken);
}

/* Monitor Files: a row's buttons stack, as wireframe L3 draws them. */
td.actions .row-actions { display: flex; flex-direction: column; align-items: stretch; gap: 0.375rem; }
td.actions .row-actions form { margin: 0; }
td.actions .row-actions .button, td.actions .row-actions button { width: 100%; }
/* All files: the application's attachments as download links, each label over its file name. */
.file-links { list-style: none; margin: 0; padding: 0.375rem; display: grid; gap: 0.125rem; }
.file-links a {
    display: grid;
    gap: 0.125rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--r);
    color: var(--text);
    text-decoration: none;
    overflow-wrap: anywhere;
}
.file-links a:hover { background: var(--surface-sunken); color: var(--text); }
.file-links strong { font-size: 0.875rem; font-weight: 600; }
.file-links .hint { margin: 0; font-size: 0.8125rem; }
.decision-dates { white-space: nowrap; }
@media (max-width: 767px) {
    td.actions .row-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
    td.actions .row-actions .button, td.actions .row-actions button { width: auto; }
    .decision-dates { white-space: normal; }
}

/* ===========================================================================
   The signature editor (assets/signature-editor.js): a toolbar over a small
   word processor, and a preview of the picture that will be stamped.
   =========================================================================== */
.sig-editor { margin-top: 1rem; }
.sig-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem;
    border: 1px solid var(--border-strong);
    border-bottom: 0;
    border-radius: var(--r) var(--r) 0 0;
    background: var(--surface-sunken);
}
.sig-toolbar select, .sig-toolbar input[type=number] {
    width: auto;
    min-height: 2.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.9375rem;
}
.sig-toolbar input[type=number] { width: 4.5rem; }
.sig-toolbar input[type=color] { width: 2.75rem; min-height: 2.25rem; }
/* The font search: a box over the whole Google Fonts catalogue. Only the matches
   are in the page, at most twenty, and the list floats so the toolbar does not
   change height as they come and go. */
.sig-font { position: relative; }
.sig-toolbar .sig-font-box {
    width: 11rem;
    min-height: 2.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.9375rem;
}
.sig-font-list {
    position: absolute;
    z-index: 30;
    top: calc(100% + 0.25rem);
    left: 0;
    width: 15rem;
    max-width: 80vw;
    max-height: 15rem;
    margin: 0;
    padding: 0.25rem;
    overflow-y: auto;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.sig-font-option {
    padding: 0.3125rem 0.5rem;
    font-size: 0.9375rem;
    border-radius: calc(var(--r) - 2px);
    cursor: pointer;
}
.sig-font-option:hover { background: var(--accent-soft); }
.sig-font-option.on {
    color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.sig-font-none {
    position: absolute;
    z-index: 30;
    top: calc(100% + 0.25rem);
    left: 0;
    width: 15rem;
    max-width: 80vw;
    margin: 0;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
}
/* It is a live region, so it stays in the page with nothing in it and must then take
   up no room: an empty bordered box under the toolbar would read as a fault. */
.sig-font-none:empty { display: none; }
.sig-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: 0 0.5rem;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface);
    border-color: var(--border-strong);
}
.sig-tool:hover { color: var(--text); background: var(--accent-soft); border-color: var(--accent-line); }
.sig-tool[aria-pressed="true"] {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent);
}
/* White in both themes, like the canvas: the signature is stamped on paper.
   Text is set at one CSS pixel per point so the smallest size stays legible; the
   preview canvas below shows what will wrap and be stamped. */
.sig-editable {
    min-height: 9rem;
    max-width: 720px;
    padding: 12px;
    color: #0f151d;
    caret-color: #0f151d;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 0 0 var(--r) var(--r);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    cursor: text;
}
.sig-editable:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}
.sig-count { margin: 0.375rem 0 0.75rem; text-align: right; max-width: 720px; }
.sig-count.over { color: var(--danger); }
.sig-preview {
    display: block;
    width: 100%;
    max-width: 600px;
    height: auto;
    aspect-ratio: 2 / 1;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
}
