/* ---------------------------------------------------------------------------
   InvoiceSync — application stylesheet
   Vanilla CSS, no build step, no framework (CLAUDE.md §1).
   --------------------------------------------------------------------------- */

:root {
    --bg:            #f4f6f8;
    --surface:       #ffffff;
    --border:        #dde3ea;
    --text:          #1c2530;
    --text-muted:    #5d6b7a;
    --accent:        #1f6feb;
    --accent-dark:   #1a5cc4;
    --danger:        #b42318;
    --danger-bg:     #fef3f2;
    --success:       #05803e;
    --success-bg:    #ecfdf3;
    --warning:       #b54708;
    --warning-bg:    #fffaeb;
    --sidebar-bg:    #17212e;
    --sidebar-text:  #a9b6c5;
    --radius:        6px;
    --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9em;
    background: #eef1f5;
    padding: .1em .35em;
    border-radius: 3px;
}

/* --- Icons ---------------------------------------------------------------- */

/* Sized in em so a glyph tracks the text it sits beside without a size class
   per context. flex-shrink:0 stops a long label squashing it into an ellipse. */
.icon {
    width: 1.15em;
    height: 1.15em;
    flex: 0 0 auto;
    vertical-align: -.18em;
}

/* --- Shell ---------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 216px;
    flex: 0 0 216px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    text-decoration: none;
}

.brand-logo   { width: 34px; height: 34px; object-fit: contain; flex: 0 0 auto; }
.brand-text   { min-width: 0; }
.brand-name   { display: block; color: #fff; font-size: 15.5px; font-weight: 600; letter-spacing: .2px; }
.brand-vendor { display: block; font-size: 10.5px; color: #6f7f91; }

.nav { padding: 6px 0 14px; }

/* Group headings. Small, quiet, and not clickable — they name a section, they
   are not a destination. */
.nav-group {
    padding: 14px 18px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .9px;
    text-transform: uppercase;
    color: #5b6b7d;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 18px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    border-left: 3px solid transparent;
}

.nav-icon { width: 16px; height: 16px; opacity: .75; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-item:hover     { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item:hover .nav-icon { opacity: 1; }
.nav-item.is-active { background: rgba(31, 111, 235, .16); border-left-color: var(--accent); color: #fff; }
.nav-item.is-active .nav-icon { opacity: 1; color: var(--accent); }

.main   { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* Title and subtitle share one baseline. The subtitle is the reason: a second
   line of chrome on every page, forever, to say what the page is. */
.page-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 17px;
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: 9px;
    overflow: hidden;
}

.page-subtitle {
    font-size: 12.5px;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-user { display: flex; align-items: center; gap: 6px; }
.user-name   { font-weight: 500; font-size: 13px; margin-right: 4px; }

.content { flex: 1; padding: 18px 20px; }

.footer {
    display: flex;
    justify-content: space-between;
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12.5px;
}

/* --- Panels and tiles ----------------------------------------------------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
    min-width: 0;
}

.panel-form { max-width: 860px; }

.panel-title { margin: 0; font-size: 14.5px; font-weight: 600; }
.panel-text  { margin: 0; color: var(--text-muted); max-width: 68ch; }

/* --- Key/value list ------------------------------------------------------- */

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

/*
 * Label and figure on one row, the figure hard right.
 *
 * The stacked variant put every caption on its own line, so a four-fact block
 * was eight rows tall. This is four.
 */
.kv-inline { grid-template-columns: 1fr auto; gap: 0; }

.kv-inline dt {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.kv-inline dd {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.kv-inline dt:last-of-type, .kv-inline dd:last-of-type { border-bottom: none; }
.kv-inline .icon { color: var(--text-muted); }

/* --- Alerts --------------------------------------------------------------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 10px 13px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    margin-bottom: 14px;
}

.alert .icon { margin-top: .15em; }

.alert-error   { background: var(--danger-bg);  border-color: #fecdca; color: var(--danger); }
.alert-success { background: var(--success-bg); border-color: #abefc6; color: var(--success); }
.alert-warning { background: var(--warning-bg); border-color: #fedf89; color: var(--warning); }

/* --- Forms and buttons ---------------------------------------------------- */

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-weight: 500; margin-bottom: 5px; font-size: 13px; }

.field-input {
    width: 100%;
    padding: 9px 11px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field-input:focus {
    outline: 2px solid rgba(31, 111, 235, .35);
    outline-offset: 0;
    border-color: var(--accent);
}

.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; display: block; }
.field-input.has-error { border-color: #fda29b; }

/* Flex, not inline-block: every button may now carry an icon, and the gap has
   to work whether it does or not. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    font: inherit;
    font-weight: 500;
    line-height: 1.35;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: #fecdca; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* Square, icon only. The label lives in aria-label + title. */
.btn-icon { padding: 7px; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

/* --- Login ---------------------------------------------------------------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: var(--sidebar-bg);
}

.login-card {
    width: 100%;
    max-width: 370px;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
    padding: 30px;
}

.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { margin: 0; font-size: 22px; font-weight: 650; }
.login-brand p  { margin: 3px 0 0; color: var(--text-muted); font-size: 12px; }

.login-logo {
    display: block;
    max-width: 200px;
    max-height: 80px;
    margin: 0 auto 12px;
    object-fit: contain;
}

/* --- Panel head, breadcrumb ----------------------------------------------- */

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

/* Title and its info toggle on one line. */
.panel-heading {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.panel-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/*
 * The collapsed explanation.
 *
 * Absolutely positioned when open, so it costs exactly one 16px glyph of layout
 * until someone asks for it — the whole point of moving the prose off the page.
 */
.panel-info { position: relative; flex: 0 0 auto; }

.panel-info > summary {
    display: flex;
    align-items: center;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    border-radius: 50%;
}

.panel-info > summary::-webkit-details-marker { display: none; }
.panel-info > summary:hover { color: var(--accent); background: #eaf1fd; }
.panel-info[open] > summary { color: var(--accent); background: #eaf1fd; }

.panel-info-body {
    position: absolute;
    top: 26px;
    left: 0;
    z-index: 30;
    width: 400px;
    max-width: 78vw;
    padding: 12px 14px;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .16);
}

.breadcrumb { margin: 0 0 12px; }
.breadcrumb a { display: inline-flex; align-items: center; gap: 5px;
                color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-status { width: auto; }

/* Search box with its glyph inside the field rather than beside it. */
.filter-search-wrap { position: relative; display: flex; min-width: 260px; }
.filter-search { width: 100%; padding-left: 33px; }

.filter-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--text-muted);
    pointer-events: none;
}

.empty-note {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px 13px;
    background: var(--warning-bg);
    border: 1px solid #fedf89;
    border-radius: var(--radius);
    color: var(--warning);
    margin: 0 0 14px;
}

/* --- Table ---------------------------------------------------------------- */

/*
 * The scroll container.
 *
 * On the panel itself this would clip the panel-info popover, which is
 * positioned outside the flow. A dedicated wrapper keeps the two independent.
 */
.table-wrap { width: 100%; overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }

.table th, .table td {
    padding: 9px 11px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

/* Denser rows for list screens — the default padding was tuned for reading
   prose, and these are scanned. */
.table-compact th, .table-compact td { padding: 7px 10px; }

/* Sits flush to the panel edge: no border under the last row, because the
   panel already has one. */
.table-flush { margin: 0 -2px; }
.table-flush tbody tr:last-child td { border-bottom: none; }

.table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    border-bottom-width: 2px;
    white-space: nowrap;
}

.table td a { color: var(--accent); text-decoration: none; font-weight: 500; }
.table td a:hover { text-decoration: underline; }
.table tbody tr:hover { background: #fafbfc; }

/* An inactive row is dimmed, never hidden — soft delete means the record is
   still there and still findable. */
.table tr.is-inactive td { opacity: .55; }

.table .num     { text-align: right; font-variant-numeric: tabular-nums; }
.table .strong  { font-weight: 600; }
.table .actions { text-align: right; white-space: nowrap; }
.table .empty   { text-align: center; color: var(--text-muted); padding: 28px 12px; }

.is-up   { color: var(--danger); }
.is-down { color: var(--success); }

.muted { color: var(--text-muted); font-size: 12.5px; }

.code-chip {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    font-weight: 600;
    background: #eef1f5;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 6px;
}

/* --- Badges --------------------------------------------------------------- */

.badge {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: 10px;
    padding: 2px 9px;
    white-space: nowrap;
}

.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: #f1f3f6;           color: var(--text-muted); }
.badge-info     { background: #eaf1fd;           color: var(--accent); }

/* Unit statuses */
.badge-available   { background: var(--success-bg); color: var(--success); }
.badge-rented      { background: #eaf1fd;           color: var(--accent); }
.badge-maintenance { background: var(--warning-bg); color: var(--warning); }
.badge-retired     { background: #f1f3f6;           color: var(--text-muted); }
.badge-overdue     { background: var(--danger-bg);  color: var(--danger); }

/* Invoice statuses. Named for the state rather than borrowed from the unit
   palette, so a template can print the derived status directly. */
.badge-draft          { background: var(--warning-bg); color: var(--warning); }
.badge-open           { background: #eaf1fd;           color: var(--accent); }
.badge-partially_paid { background: #eaf1fd;           color: var(--accent); }
.badge-paid           { background: var(--success-bg); color: var(--success); }
.badge-voided         { background: #f1f3f6;           color: var(--text-muted); }

/* --- Status strip --------------------------------------------------------- */

.status-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/*
 * Icon, label and figure on ONE line.
 *
 * The stacked variant — big number above a caption — cost three rows of height
 * above every table to carry four short facts, and on a phone the strip pushed
 * the table itself off the first screen entirely.
 */
.stat-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 7px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    cursor: pointer;
    text-align: left;
}

.stat-chip:hover     { background: #fafbfc; }
.stat-chip.is-active { border-color: var(--accent); background: #f5f9ff; }

.stat-icon { width: 16px; height: 16px; color: var(--text-muted); }
.stat-l    { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.stat-n    { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; margin-left: auto; }

/* The dashboard's own strip: same shape, more presence. */
.status-strip-lg .stat-chip { flex: 1 1 190px; padding: 11px 14px; }
.status-strip-lg .stat-n    { font-size: 18px; }

.stat-available   { border-left-color: var(--success); }
.stat-rented      { border-left-color: var(--accent); }
.stat-maintenance { border-left-color: var(--warning); }
.stat-retired     { border-left-color: #b9c2cc; }
.stat-danger      { border-left-color: var(--danger); }
.stat-danger .stat-n { color: var(--danger); }

/* --- Dashboard ------------------------------------------------------------ */

.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    align-items: start;
}

/* Spans the grid — a six-column table inside a half-width panel is unreadable. */
.panel-wide { grid-column: 1 / -1; }

.notice-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius);
}

.notice-text { flex: 1; min-width: 0; }

.notice-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
}

.notice-link:hover  { text-decoration: underline; }
.notice-chevron     { transform: rotate(-90deg); width: 14px; height: 14px; }

.notice-info    { border-left-color: var(--accent); }
.notice-info    > .icon { color: var(--accent); }
.notice-warning { border-left-color: var(--warning); background: var(--warning-bg); }
.notice-warning > .icon { color: var(--warning); }
.notice-danger  { border-left-color: var(--danger); background: var(--danger-bg); }
.notice-danger  > .icon { color: var(--danger); }

.modal-card-wide { max-width: 880px; }

.table tr.is-carried td { background: #fbfcfd; font-style: italic; }

.totals-block {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 2px solid var(--border);
    grid-template-columns: 1fr auto;
}

.totals-block dd.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Report tabs ---------------------------------------------------------- */

.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.tab {
    padding: 9px 16px;
    font: inherit;
    font-weight: 500;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: var(--text-muted);
    cursor: pointer;
}

.tab:hover      { color: var(--text); }
.tab.is-active  { color: var(--accent); border-bottom-color: var(--accent); }

.sub-table { margin: 6px 0 6px 20px; width: calc(100% - 20px); }
.sub-table th, .sub-table td { padding: 6px 10px; font-size: 12.5px; }
.table tfoot th, .table tfoot td { border-top: 2px solid var(--border); padding: 10px 12px; }

/* --- Integrity checks ----------------------------------------------------- */

.check-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.check-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.check-key  { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }
.check-why  { margin: 4px 0 0; max-width: 80ch; }

.check-rows {
    margin: 8px 0 0;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 11.5px;
    max-height: 240px;
    overflow: auto;
}

.line-total {
    padding: 9px 11px;
    font-size: 17px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    padding: 3px 6px;
    margin-left: 2px;
    border-radius: 4px;
    font: inherit;
    font-size: 12.5px;
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    vertical-align: middle;
}

.btn-link .icon { width: 14px; height: 14px; }
.btn-link:hover { background: #eaf1fd; }
.btn-link-danger { color: var(--danger); }
.btn-link-danger:hover { background: var(--danger-bg); }

/* --- Fixed (locked) field -------------------------------------------------- */

/*
 * A value the owner cannot change on this screen, shown as a fact rather than
 * as a select with exactly one option — a one-option dropdown reads as a
 * choice, invites a click, and does nothing.
 */
.field-fixed {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 11px;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
}

.field-fixed-icon { width: 14px; height: 14px; }

/* --- Pager ---------------------------------------------------------------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding-top: 16px;
}

/* --- Modal ---------------------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
    z-index: 50;
}

.modal[hidden] { display: none; }

.modal-card {
    width: 100%;
    max-width: 680px;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .25);
    padding: 24px;
}

/*
 * Owner-selectable widths (Settings → Modules → Modal size).
 *
 * The suffix IS the stored setting value, so SystemConfig::modalCardClass()
 * concatenates rather than translating.
 */
.modal-sm { max-width: 460px; }
.modal-md { max-width: 680px; }
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1180px; }

/*
 * A wider dialog only helps if the form uses the width. Left at two columns,
 * Extra large is just a bigger white rectangle with the same cramped fields.
 */
.modal-sm .form-grid { grid-template-columns: 1fr; }
.modal-sm .form-grid .field-wide { grid-column: auto; }
.modal-xl .form-grid { grid-template-columns: repeat(3, 1fr); }

/* Retained: pages predating the setting still carry it, and it means Large. */
.modal-card-wide { max-width: 900px; }

.modal-title { margin: 0 0 18px; font-size: 17px; font-weight: 600; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .field-wide { grid-column: 1 / -1; }

.field-hint {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
}

textarea.field-input { resize: vertical; font-family: inherit; }

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

.check input { width: 15px; height: 15px; cursor: pointer; }

.field[hidden], [hidden] { display: none !important; }

.kv-wide { grid-template-columns: 180px 1fr; }

/* --- Print ---------------------------------------------------------------- */

@media print {
    .sidebar, .topbar, .footer, .btn { display: none !important; }
    .content { padding: 0; }
    body { background: #fff; }
}

/* --- Navigation progress --------------------------------------------------- */

/*
 * A thin bar while a page is being fetched and swapped.
 *
 * It exists because instant navigation removes the browser's own loading
 * indicator along with the document reload — without this, a slow screen looks
 * like a click that did nothing.
 */
html.is-navigating::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: 100;
    background: var(--accent);
    transform-origin: 0 50%;
    animation: nav-progress 1.4s ease-out;
}

@keyframes nav-progress {
    0%   { transform: scaleX(0); }
    40%  { transform: scaleX(.6); }
    100% { transform: scaleX(.96); }
}

html.is-navigating .content { opacity: .55; }
.content { transition: opacity .1s linear; }

@media (prefers-reduced-motion: reduce) {
    html.is-navigating::before { animation: none; transform: scaleX(1); }
    .content { transition: none; }
}

/* --- Support-session banner ------------------------------------------------ */

/*
 * Quieter than the test-database banner on purpose.
 *
 * That one says "what you are looking at is not your data" and has to interrupt.
 * This one says "you are on the support login" — a standing fact for the whole
 * session, which should be legible at a glance and then stop competing with the
 * work.
 */
.support-banner {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 13px;
    margin-bottom: 14px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-left: 3px solid #4f46e5;
    border-radius: var(--radius);
    color: #3730a3;
    font-size: 12.5px;
}

.support-banner code { background: rgba(55, 48, 163, .1); color: inherit; }

/* --- Test-database banner -------------------------------------------------- */

/*
 * Loud on purpose. This says "the records you are looking at are not your
 * records", which is the one message that must never be mistaken for chrome.
 */
.test-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
    background: repeating-linear-gradient(
        45deg, #fff4ed, #fff4ed 12px, #ffe9dc 12px, #ffe9dc 24px
    );
    border: 2px solid #f97316;
    border-radius: var(--radius);
    color: #9a3412;
}

.test-banner code {
    background: rgba(154, 52, 18, .1);
    color: inherit;
}

/* --- Privilege list (users & roles) --------------------------------------- */

.privilege-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.privilege-list .code-chip { font-size: 11px; }

fieldset.field { border: none; padding: 0; margin-bottom: 14px; }
fieldset.field legend { padding: 0; }
fieldset.field .check { margin-bottom: 6px; }

/* --- Tabs with icons ------------------------------------------------------ */

.tab { display: inline-flex; align-items: center; gap: 6px; }
.tab .icon { width: 15px; height: 15px; }

/* --- Settings screen ------------------------------------------------------ */

.settings-section { padding-top: 14px; }
.settings-section + .settings-section { border-top: 1px solid var(--border); margin-top: 6px; }

.section-title {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .7px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.settings-grid .field-wide { grid-column: 1 / -1; }

/* An on/off setting reads as a statement plus a switch, so the label belongs
   beside the control rather than above it. */
.field-switch { display: block; margin-bottom: 14px; }
.field-switch .check { font-weight: 500; }

.menu-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-top: 8px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.menu-group-label {
    display: block;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.menu-check { margin-bottom: 4px; font-weight: 400; }
.menu-check.is-locked { opacity: .65; cursor: default; }

.locked-block { margin-bottom: 8px; }
.locked-block .code-chip { font-weight: 400; margin-right: 3px; }

/* --- Invoice template editor ---------------------------------------------- */

/* The selected row in the template list, so the editor below is unambiguous
   about which one it is editing. */
.table tr.is-selected td { background: #f5f9ff; box-shadow: inset 3px 0 0 var(--accent); }

.color-field { display: flex; align-items: center; gap: 8px; }

/* The picker is convenient; the text box beside it is how you paste a brand
   hex you were given. Both write the same value. */
.color-swatch {
    width: 38px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    flex: 0 0 auto;
}

.column-picker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.column-row {
    display: grid;
    grid-template-columns: 200px 72px 1fr 1fr;
    align-items: center;
    gap: 10px;
}

.column-row .check { font-weight: 400; }
.column-order { text-align: center; }
.column-source { font-size: 11.5px; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* --- Branding / logo ------------------------------------------------------ */

.logo-manager { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }

.logo-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 220px;
    min-height: 110px;
    padding: 12px;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.logo-preview img { max-width: 100%; max-height: 86px; object-fit: contain; }
.logo-empty { color: var(--text-muted); font-size: 12.5px; }
.logo-form { flex: 1 1 260px; min-width: 0; }
.logo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===========================================================================
   RESPONSIVE
   ---------------------------------------------------------------------------
   Desktop-first: the rules above are the wide layout, and these narrow it.

   Breakpoints are placed where THIS layout actually breaks, not at device
   names — 1080px is where the six-column tables start crowding, 900px is where
   the 232px sidebar costs more than it gives, 620px is where two-column forms
   stop fitting.
   =========================================================================== */

/* --- Nav toggle (hidden until the sidebar goes off-canvas) ----------------- */

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 38px;
    height: 34px;
    padding: 0 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.nav-toggle span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}

.nav-scrim {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .45);
    z-index: 40;
}

.nav-scrim[hidden] { display: none; }

/* --- ≤1180px: tighter chrome, tables may scroll --------------------------- */

@media (max-width: 1180px) {
    .sidebar { width: 196px; flex: 0 0 196px; }
    .content { padding: 16px; }

    /*
     * Wide tables scroll inside their own wrapper rather than forcing the whole
     * page sideways. NOT on .panel: that would clip the panel-info popover,
     * which is positioned outside the flow on purpose.
     */
    .table-wrap { -webkit-overflow-scrolling: touch; }
    .table-wrap > .table { min-width: 680px; }

    /* Except these, which are narrow enough to wrap naturally. */
    .totals-table, .meta-table, .kv { min-width: 0; }
}

/* --- ≤900px: sidebar goes off-canvas -------------------------------------- */

@media (max-width: 900px) {
    .nav-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 250px;
        flex-basis: 250px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .18s ease-out;
        overflow-y: auto;
    }

    .shell.nav-open .sidebar { transform: translateX(0); }

    .main { width: 100%; }

    .topbar { gap: 10px; padding: 10px 14px; }
    .page-title { font-size: 16px; }
    .content { padding: 14px; }

    /* The subtitle is decoration once the title is fighting for room. */
    .page-subtitle { display: none; }

    .panel-head { flex-wrap: wrap; }
    .panel-actions { margin-left: auto; }

    .filters { width: 100%; }
    .filter-search-wrap { min-width: 0; flex: 1 1 100%; }
    .filter-status { flex: 1 1 auto; }

    .settings-grid { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }

    .modal { padding: 20px 12px; }
    /* Every configured size collapses to the viewport once the sidebar is
       off-canvas — below this width the choice has nothing left to express. */
    .modal-card { max-width: none; }
    .modal-xl .form-grid { grid-template-columns: 1fr 1fr; }
}

/* --- ≤620px: phones ------------------------------------------------------- */

@media (max-width: 620px) {
    body { font-size: 13.5px; }

    .topbar-user { gap: 4px; }
    .user-name { display: none; }

    .content { padding: 10px; }
    .panel { padding: 12px; border-radius: 0; margin-left: -10px; margin-right: -10px; }
    .panel-text { max-width: none; }

    /* Single column for anything that was a grid. */
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .field-wide { grid-column: auto; }
    .kv, .kv-wide { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 10px; font-size: 12px; }

    /* kv-inline keeps its two columns — label left, figure right is exactly
       what works in a narrow column, and stacking it would undo the point. */
    .kv-inline, .kv-inline.kv-wide { grid-template-columns: 1fr auto; gap: 0; }
    .kv-inline dt { margin-top: 0; font-size: inherit; }

    /* Chips go full width: label left, figure right, one per row. Two-up put
       four-figure amounts on two lines each. */
    .status-strip { gap: 6px; }
    .stat-chip, .status-strip-lg .stat-chip { flex: 1 1 100%; padding: 8px 11px; }
    .stat-n { font-size: 15px; }

    /* The popover cannot be 400px wide on a 360px screen. */
    .panel-info-body { position: fixed; left: 10px; right: 10px; width: auto; max-width: none; }

    .notice { flex-wrap: wrap; }
    .notice-text { flex: 1 1 100%; }
    .notice-link { margin-left: auto; }

    .filters { flex-direction: column; }
    .filters .field-input { width: 100%; }

    /* Icon-only row actions. The label is in aria-label and title, which is
       why it is a real attribute rather than the visible text alone. */
    .btn-link-label { display: none; }
    .btn-link { padding: 7px; }
    .btn-link .icon { width: 16px; height: 16px; }

    .modal { padding: 0; align-items: stretch; }

    .modal-card {
        border-radius: 0;
        min-height: 100%;
        padding: 16px 12px;
    }

    /* One column on a phone whatever the window is set to. */
    .modal-xl .form-grid { grid-template-columns: 1fr; }

    /* Actions stick to the bottom so Save is reachable without scrolling to
       the end of a long form. */
    .modal-actions {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        padding-bottom: 4px;
        margin-bottom: -4px;
    }

    .modal-actions .btn { flex: 1; text-align: center; }

    .logo-manager { flex-direction: column; }
    .logo-preview { width: 100%; }

    /* Four columns of controls per row does not fit a phone; stack them and
       let the labels carry the meaning. */
    .column-row { grid-template-columns: 1fr 64px; grid-template-areas: "check order" "label label" "src src"; }
    .column-row .check        { grid-area: check; }
    .column-row .column-order { grid-area: order; }
    .column-row .column-label { grid-area: label; }
    .column-row .column-source { grid-area: src; }
    .column-picker { gap: 14px; }

    .pager { flex-wrap: wrap; gap: 8px; }
    .tabs { gap: 0; }
    .tab { padding: 8px 10px; font-size: 12.5px; }
    .tab span { display: none; }   /* icon-only tabs; each carries its own title */

    .check-head { gap: 6px; }
    .check-key { display: none; }
}

/* --- Touch: bigger targets ------------------------------------------------ */

@media (pointer: coarse) {
    .btn         { padding: 10px 16px; }
    .btn-icon    { padding: 9px; }
    .btn-link    { padding: 9px; }
    .nav-item    { padding: 11px 18px; }
    .field-input { padding: 11px; font-size: 16px; }  /* 16px stops iOS zooming on focus */
    .filter-search { padding-left: 34px; }
    .table th, .table td, .table-compact th, .table-compact td { padding: 11px 10px; }
    .panel-info > summary { width: 26px; height: 26px; justify-content: center; }
}

/* --- Respect reduced-motion ----------------------------------------------- */

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