/* =============================================================================
   FOLAPLAY DASHBOARD — stylesheet
   -----------------------------------------------------------------------------
   Colour tokens (--series-1, --surface, --ink, …) are injected on :root by
   views/layout.php from config.php [11] PALETTE. Nothing here hardcodes a data
   colour: elements read the tokens, so light/dark and rebranding happen in one
   place.

   Sections
     1. Reset & base
     2. Layout shell (sidebar, topbar, content)
     3. Buttons, icons, form controls
     4. Hero figure & stat tiles
     5. Meters, legends, swatches
     6. Panels & tables
     7. Filters, pagination, states
     8. Responsive
   ========================================================================== */

/* -------------------------------------------------- 1. Reset & base ------ */

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

:root {
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 250px;
    --gap: 18px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -16px rgba(0, 0, 0, .18);
    --t: 140ms ease;
}

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--plane);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

code {
    font-family: var(--mono);
    font-size: .85em;
    padding: .1em .38em;
    border-radius: 5px;
    background: color-mix(in oklab, var(--ink) 7%, var(--surface));
}

.muted { color: var(--ink-2); }
.small { font-size: .82rem; }
.mono  { font-family: var(--mono); font-size: .86rem; }
.num   { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 100;
    background: var(--surface); padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
    outline: 2px solid var(--series-1);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --------------------------------------------- 2. Layout shell ----------- */

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 18px 14px;
    background: var(--surface);
    border-right: 1px solid var(--grid);
    z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-mark {
    display: grid; place-items: center;
    width: 34px; height: 34px; flex: none;
    border-radius: 9px;
    background: var(--series-1);
    color: #fff; font-weight: 700; font-size: 1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: .95rem; }
.brand-text small { font-size: .74rem; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: .9rem; font-weight: 500;
    color: var(--ink-2);
    transition: background var(--t), color var(--t);
}
.nav-item:hover { background: color-mix(in oklab, var(--ink) 5%, var(--surface)); color: var(--ink); }
.nav-item.is-active {
    background: color-mix(in oklab, var(--series-1) 12%, var(--surface));
    color: var(--series-1);
    font-weight: 600;
}
.nav-item .icon { flex: none; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sidebar-note {
    font-size: .72rem; line-height: 1.45; color: var(--muted);
    padding: 0 12px;
}

.main-wrap {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    padding: 0 22px;
    height: 58px;
    background: color-mix(in oklab, var(--plane) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--grid);
}
.page-title { font-size: 1rem; font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; }
.menu-toggle { display: none; }

.content {
    flex: 1;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    max-width: 1400px;
    width: 100%;
}

.footer {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding: 18px 22px 26px;
    font-size: .76rem; color: var(--muted);
}
.footer .dot { opacity: .5; }

.scrim {
    display: none;
    position: fixed; inset: 0; z-index: 35;
    background: rgba(0, 0, 0, .45);
}

/* ------------------------------------- 3. Buttons, icons, controls ------- */

.icon { width: 18px; height: 18px; }
.state-icon { width: 34px; height: 34px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit; font-size: .875rem; font-weight: 550;
    cursor: pointer;
    transition: background var(--t), border-color var(--t), color var(--t);
}
.btn-primary { background: var(--series-1); color: #fff; }
.btn-primary:hover { background: color-mix(in oklab, var(--series-1) 86%, #000); }
.btn-ghost {
    background: transparent; color: var(--ink-2);
    border-color: var(--grid);
}
.btn-ghost:hover { background: color-mix(in oklab, var(--ink) 5%, var(--surface)); color: var(--ink); }
.btn-block { width: 100%; }

.icon-btn {
    display: grid; place-items: center;
    width: 34px; height: 34px;
    border: 1px solid var(--grid);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    transition: background var(--t), color var(--t);
}
.icon-btn:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 5%, var(--surface)); }

/* Theme toggle shows exactly one glyph. */
[data-toggle-theme] .icon-moon { display: none; }
:root[data-theme="dark"] [data-toggle-theme] .icon-sun { display: none; }
:root[data-theme="dark"] [data-toggle-theme] .icon-moon { display: block; }

/* Every text-like input must be listed, or it falls back to the browser's own
   widget and stops matching the rest of the form. */
input[type="search"],
input[type="number"],
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="date"],
select {
    font: inherit; font-size: .875rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--grid);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    min-width: 0;
}
select { cursor: pointer; padding-right: 30px; appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

/* --------------------------------- 4. Hero figure & stat tiles ----------- */

/* Flex items default to min-width:auto and refuse to shrink below their
   max-content width, which pushes the page into horizontal scroll on narrow
   screens. Every flex row that can hold long text opts out explicitly. */
.page-intro, .result-bar, .meter-head, .tile-label, .legend li, .panel-head {
    min-width: 0;
}
.page-intro > *, .result-bar > *, .meter-head > *, .panel-head > * { min-width: 0; }

.page-intro {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px 16px; flex-wrap: wrap;
}
.page-intro > div { flex: 1 1 280px; }
.page-intro p { margin-top: 4px; font-size: .875rem; overflow-wrap: anywhere; }
.stamp {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: .78rem; color: var(--muted);
    padding: 6px 11px;
    border: 1px solid var(--grid);
    border-radius: 999px;
}
.stamp .icon { width: 14px; height: 14px; }

.hero {
    background: var(--surface);
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px;
}
.hero-label {
    font-size: .8rem; font-weight: 600; letter-spacing: .02em;
    text-transform: uppercase; color: var(--muted);
}
.hero-value {
    font-size: clamp(2.6rem, 6vw, 3.4rem);
    font-weight: 680;
    line-height: 1.05;
    letter-spacing: -.03em;
    margin: 6px 0 2px;
}
.hero-hint { font-size: .85rem; color: var(--ink-2); }

.hero-split {
    display: flex; gap: 2px;      /* 2px surface gap between fills */
    height: 12px; margin-top: 18px;
}
.hero-split .seg {
    background: var(--hue);
    border-radius: 3px;
}

.tile-group { display: flex; flex-direction: column; gap: 9px; }
.tile-group-title {
    display: flex; align-items: center; gap: 8px;
    font-size: .78rem; font-weight: 600;
    letter-spacing: .05em; text-transform: uppercase;
    color: var(--muted);
    padding-left: 2px;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.tiles-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

@media (max-width: 1080px) { .tiles, .tiles-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px)  { .tiles, .tiles-3 { grid-template-columns: 1fr; } }

.tile-meter.is-soft > span { background: color-mix(in oklab, var(--hue, var(--series-1)) var(--soft-mix), var(--surface)); }

.tile {
    display: flex; flex-direction: column; gap: 3px;
    padding: 15px 17px;
    background: var(--surface);
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color var(--t), transform var(--t);
}
.tile.is-link:hover {
    border-color: color-mix(in oklab, var(--hue, var(--series-1)) 55%, var(--grid));
    transform: translateY(-1px);
}
.tile.is-current {
    border-color: var(--hue, var(--series-1));
    box-shadow: var(--shadow), inset 0 0 0 1px var(--hue, var(--series-1));
}
.tile-label {
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
    font-size: .8rem; font-weight: 550; color: var(--ink-2);
}
.tile-value {
    font-size: 1.7rem; font-weight: 660; letter-spacing: -.02em; line-height: 1.15;
}
.tile-hint { font-size: .76rem; color: var(--muted); }

.tile-meter {
    display: block;
    height: 4px; margin: 6px 0 4px;
    border-radius: 999px;
    background: color-mix(in oklab, var(--hue, var(--series-1)) 16%, var(--surface));
    overflow: hidden;
}
.tile-meter > span {
    display: block; height: 100%;
    border-radius: 999px;
    background: var(--hue, var(--series-1));
}

/* ---------------------------- 5. Meters, legends, swatches --------------- */

.swatch {
    width: 10px; height: 10px; flex: none;
    border-radius: 3px;
    background: var(--hue, var(--series-1));
    display: inline-block;
}
.swatch-soft { background: color-mix(in oklab, var(--hue, var(--series-1)) var(--soft-mix), var(--surface)); }

.meters { display: grid; gap: 22px; }
.meter-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; font-size: .9rem; }
.meter-head .muted { margin-left: auto; font-size: .8rem; }

.meter-track {
    display: flex; gap: 2px;      /* 2px surface gap between fills */
    height: 14px; margin: 9px 0 10px;
}
.meter-track .seg { border-radius: 4px; }
.seg-paid { background: var(--hue); }
.seg-non  { background: color-mix(in oklab, var(--hue) var(--soft-mix), var(--surface)); }

.legend {
    display: flex; flex-wrap: wrap; gap: 8px 22px;
    margin: 0; padding: 12px 0 0; list-style: none;
    font-size: .82rem; color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.legend strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* -------------------------------------------- 6. Panels & tables --------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--grid);
}
.panel-head h3 { display: flex; align-items: center; gap: 9px; }
.panel-head h3 .icon { color: var(--muted); }
.panel-head > .muted { margin-left: auto; }
.panel-body { padding: 18px; }

.table-scroll { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .855rem;
}
.table th, .table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--grid);
    white-space: nowrap;
}
.table thead th {
    position: sticky; top: 0;
    background: var(--surface);
    font-size: .75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted);
    z-index: 1;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in oklab, var(--ink) 3.5%, var(--surface)); }
.table td.num, .table th.num { font-variant-numeric: tabular-nums; }
.table .col-index { color: var(--muted); width: 1%; }
.table td .swatch { margin-right: 6px; vertical-align: -1px; }

.table .empty {
    text-align: center; padding: 42px 16px; color: var(--muted); white-space: normal;
}
.table .empty .icon { display: block; margin: 0 auto 10px; width: 26px; height: 26px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .74rem; font-weight: 600;
    border: 1px solid transparent;
}
/* Status reads from text + shape, never colour alone. */
.badge-paid {
    color: var(--good);
    background: color-mix(in oklab, var(--good) 12%, var(--surface));
    border-color: color-mix(in oklab, var(--good) 30%, var(--surface));
}
.badge-non {
    color: var(--ink-2);
    background: color-mix(in oklab, var(--ink) 6%, var(--surface));
    border-color: var(--grid);
}
/* Diagnostics verdicts. Status colour is always paired with its own word. */
.badge-ok {
    color: var(--good);
    background: color-mix(in oklab, var(--good) 12%, var(--surface));
    border-color: color-mix(in oklab, var(--good) 30%, var(--surface));
}
.badge-warn {
    color: var(--ink);
    background: color-mix(in oklab, var(--warning) 20%, var(--surface));
    border-color: color-mix(in oklab, var(--warning) 45%, var(--surface));
}
.badge-fail {
    color: var(--critical);
    background: color-mix(in oklab, var(--critical) 12%, var(--surface));
    border-color: color-mix(in oklab, var(--critical) 34%, var(--surface));
}

/* --------------------------- 7. Filters, pagination, states -------------- */

.filters {
    display: flex; flex-wrap: wrap; gap: 9px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--grid);
}
.field { position: relative; display: flex; }
.field-search { flex: 1 1 260px; }
.field-search .icon {
    position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
    color: var(--muted); pointer-events: none; width: 16px; height: 16px;
}
.field-search input { width: 100%; padding-left: 34px; }

.result-bar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 11px 18px;
    font-size: .82rem;
    color: var(--ink-2);
    background: color-mix(in oklab, var(--ink) 3%, var(--surface));
    border-bottom: 1px solid var(--grid);
}
.result-bar > .muted { margin-left: auto; }

.pagination {
    display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
    padding: 14px 18px;
    border-top: 1px solid var(--grid);
}
.page-btn {
    display: inline-flex; align-items: center; gap: 4px;
    min-width: 34px; height: 34px;
    padding: 0 10px;
    justify-content: center;
    border: 1px solid var(--grid);
    border-radius: var(--radius-sm);
    font-size: .82rem; font-variant-numeric: tabular-nums;
    color: var(--ink-2);
    transition: background var(--t), color var(--t), border-color var(--t);
}
.page-btn .icon { width: 15px; height: 15px; }
.page-btn:hover { background: color-mix(in oklab, var(--ink) 5%, var(--surface)); color: var(--ink); }
.page-btn.is-current {
    background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600;
}
.page-btn.is-disabled { opacity: .4; pointer-events: none; }
.page-gap { color: var(--muted); padding: 0 2px; }

.page-jump {
    margin-left: auto;
    display: flex; align-items: center; gap: 7px;
    font-size: .8rem; color: var(--ink-2);
}
.page-jump input { width: 78px; padding: 7px 9px; text-align: center; }

.notice {
    display: flex; gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid;
    font-size: .875rem;
    line-height: 1.5;
}
.notice .icon { flex: none; margin-top: 1px; }
.notice-warn {
    color: var(--ink);
    background: color-mix(in oklab, var(--warning) 14%, var(--surface));
    border-color: color-mix(in oklab, var(--warning) 42%, var(--surface));
}
.notice-ok {
    color: var(--ink);
    background: color-mix(in oklab, var(--good) 10%, var(--surface));
    border-color: color-mix(in oklab, var(--good) 34%, var(--surface));
}
.notice.compact { margin: 14px 18px 0; }

/* Error page: the cause reads as prose, the remedy as a quiet follow-up. */
.error-cause {
    max-width: 62ch;
    font-size: 1rem;
    color: var(--ink);
}
.error-hint {
    max-width: 62ch;
    font-size: .875rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.state {
    display: flex; flex-direction: column; align-items: center; gap: 12px;
    text-align: center;
    padding: 70px 20px;
    color: var(--ink-2);
}
.state .icon { color: var(--muted); }
.state p { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.trace {
    font-family: var(--mono); font-size: .76rem;
    text-align: left; overflow-x: auto;
    max-width: 100%;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: color-mix(in oklab, var(--ink) 6%, var(--surface));
}

/* --------------------------------------- 8. Account, export, login ------- */

.account {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--grid);
    border-radius: var(--radius-sm);
    font-size: .82rem;
    color: var(--ink-2);
    min-width: 0;
}
.account .icon { flex: none; width: 16px; height: 16px; color: var(--muted); }
.account-name {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--ink); font-weight: 550;
}
.account-out { width: 28px; height: 28px; flex: none; border: 0; background: transparent; }
.account-out .icon { width: 15px; height: 15px; }

.btn-export { margin-left: auto; }
.btn-export .icon { width: 16px; height: 16px; }

/* Login / first-run setup — a standalone page, no app shell. */
.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--plane);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.login-title { font-size: 1.3rem; margin-bottom: 5px; }
.login-sub { font-size: .85rem; line-height: 1.5; margin-bottom: 18px; }

.login-form { display: flex; flex-direction: column; gap: 13px; margin-top: 18px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field > span { font-size: .8rem; font-weight: 550; color: var(--ink-2); }
.login-field input { width: 100%; padding: 10px 12px; }
.login-hint { font-size: .76rem; line-height: 1.5; }

.notice.compact-flat { padding: 11px 13px; font-size: .82rem; margin-top: 14px; }

/* ---------------------------------------------- 9. Responsive ------------ */

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--t);
        box-shadow: var(--shadow);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .scrim { display: block; }
    .main-wrap { margin-left: 0; }
    .menu-toggle { display: grid; }
    .content { padding: 16px; }
    .truncate { max-width: 170px; }
    .page-jump { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

@media print {
    .sidebar, .topbar, .filters, .pagination, .footer, .scrim { display: none !important; }
    .main-wrap { margin-left: 0; }
    .panel, .tile, .hero { box-shadow: none; break-inside: avoid; }
}

/* ------------------------------------------- 10. Account management ------ */

.stack-form { display: flex; flex-direction: column; gap: 13px; max-width: 400px; }
.stack-form .btn { align-self: flex-start; }
.stack-form select { width: 100%; }

.inline-form { display: inline; }

.btn-small { padding: 5px 11px; font-size: .8rem; }

a.account-name { text-decoration: none; }
a.account-name:hover { text-decoration: underline; }

.badge + .badge { margin-left: 5px; }
.table td .badge { margin-left: 6px; }
