/* EasyInvoice Admin — one stylesheet for both pages. */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-alt: #f0f2f5;
    --text: #1b1f24;
    --muted: #5f6b7a;
    --border: #dde2e8;
    --accent: #2f5bd3;
    --accent-text: #ffffff;
    --ok: #1d7a46;
    --ok-bg: #e3f4ea;
    --warn: #8a5a00;
    --warn-bg: #fdf1d8;
    --danger: #b42318;
    --danger-bg: #fde8e6;
    --info-bg: #e6edfb;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --topbar-h: 50px;   /* measured by app.js */
    color-scheme: light;

    /* EasyInvoice's palette names, for its settings form: its
       common/css/tokens.css (loaded with the form) derives the rest
       from these. --text-white is EasyInvoice's "stand-out" text. */
    --bg-card: var(--surface);
    --text-muted: var(--muted);
    --text-white: #14161b;
    --accent-soft: rgba(47, 91, 211, .12);
    --error: var(--danger);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111418;
        --surface: #181c21;
        --surface-alt: #20252c;
        --text: #e6e9ed;
        --muted: #98a2b0;
        --border: #2c333c;
        --accent: #7c9cf5;
        --accent-text: #0b1020;
        --ok: #6fd39b;
        --ok-bg: #12301f;
        --warn: #f3c46b;
        --warn-bg: #352812;
        --danger: #ff8a80;
        --danger-bg: #3a1714;
        --info-bg: #18233d;
        --shadow: none;
        color-scheme: dark;
        --text-white: #ffffff;
        --accent-soft: rgba(124, 156, 245, .18);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre.code { background: var(--surface-alt); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ── Controls ───────────────────────────────────────────────────────── */

/* The bare-element rules — and .btn, .tabs, .tab, whose names the form
   shares — stop at EasyInvoice's settings form (.inv-sf), which styles
   its own; :where() keeps their specificity. */
label:where(:not(.inv-sf *)) { display: block; margin: 0 0 12px; font-weight: 500; }
label > :is(input, select, textarea):where(:not(.inv-sf *)) { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
:is(input, select, textarea):where(:not(.inv-sf *)) {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
}
/* The browser's own select ignores most of the rules above (macOS draws
   a grey native control), so it is redrawn: no native appearance, and a
   chevron made of two gradients — theme-coloured, light and dark, with no
   image the CSP would have to allow. */
select:where(:not(.inv-sf *)) {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 32px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}
select:disabled { cursor: default; opacity: .6; }
:is(input, select, textarea):focus:where(:not(.inv-sf *)), .btn:focus-visible:where(:not(.inv-sf *)) { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea:where(:not(.inv-sf *)) { resize: vertical; min-height: 70px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; margin: 0; }

.btn:where(:not(.inv-sf *)) {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-weight: 500;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover:where(:not(.inv-sf *)) { background: var(--surface-alt); }
.btn:disabled:where(:not(.inv-sf *)) { opacity: .55; cursor: default; }
.btn-primary:where(:not(.inv-sf *)) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:where(:not(.inv-sf *)) { background: var(--accent); filter: brightness(1.08); }
.btn-danger:where(:not(.inv-sf *)) { color: var(--danger); border-color: currentColor; }
.btn-danger:hover:where(:not(.inv-sf *)) { background: var(--danger-bg); }
.btn-small:where(:not(.inv-sf *)) { padding: 4px 10px; font-size: 13px; }
.btn-wide:where(:not(.inv-sf *)) { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 12rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Messages, badges ───────────────────────────────────────────────── */

.msg:empty { display: none; }
.alert { padding: 9px 12px; border-radius: var(--radius); margin: 0 0 12px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-info { background: var(--info-bg); }

.badge {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; background: var(--surface-alt); color: var(--muted);
    white-space: nowrap;
}
.badge-active { background: var(--ok-bg); color: var(--ok); }
.badge-maintenance, .badge-logins_disabled, .badge-pending, .badge-provisioning { background: var(--warn-bg); color: var(--warn); }
.badge-blocked, .badge-missing, .badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-deleted, .badge-purged { background: var(--surface-alt); color: var(--muted); }

.toast {
    position: fixed; right: 16px; bottom: 16px; z-index: 10;
    padding: 10px 14px; border-radius: var(--radius);
    background: var(--text); color: var(--bg); box-shadow: var(--shadow); max-width: 420px;
}

/* ── Sign-in page ───────────────────────────────────────────────────── */

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
    width: 100%; max-width: 380px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 24px; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 18px; }
.step { display: none; }
.step.active { display: block; }
.qr-box { display: flex; justify-content: center; margin: 8px 0; }
.qr-box svg { max-width: 220px; height: auto; border-radius: 6px; }
.code-input { font-size: 20px; letter-spacing: .25em; text-align: center; }
.or { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 14px 0; font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.footer { margin: 16px 0 0; display: flex; justify-content: space-between; }

/* ── App shell ──────────────────────────────────────────────────────── */

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px;
    background: var(--accent); color: var(--accent-text); font-size: 12px; letter-spacing: .02em;
}
.brand-sub { font-weight: 500; color: var(--muted); }

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 24px;
    padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-alt); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-alt); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right a { color: var(--muted); }
@media (max-width: 720px) { .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; } }

.view { max-width: 1200px; margin: 0 auto; padding: 20px; }
@media (max-width: 720px) { .view { padding: 12px; } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.cards > .card { margin-bottom: 0; }
/* A company's settings: EasyInvoice's component brings its own scoped CSS (.inv-sf). */
.settings-host { margin-top: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-alt); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-alt); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.spacer { height: 16px; }
ul.plain { list-style: none; margin: 4px 0 0; padding: 0; }
.error-text { color: var(--danger); }
.cron-fields { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0 12px; }
@media (max-width: 860px) { .cron-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cron-fields .row > input { min-width: 0; }
.cron-status .row { margin-bottom: 4px; }
.cron { border-top: 1px solid var(--border); padding-top: 16px; }
.card > .cron { border-top: 0; padding-top: 0; margin-top: 0; }
.card > form > h3:first-child, .card > .cron > h3:first-child { margin-top: 0; font-size: 18px; }
.stepup { border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(360px, calc(100vw - 32px));
          background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stepup::backdrop { background: rgba(10, 14, 20, .45); }
.stepup h2 { margin-bottom: 4px; }
.spacer-top { margin-top: 14px; }
/* A table is never flush against what follows it. */
.table-wrap { margin-bottom: 16px; }
.card > .table-wrap:last-child, .card > div > .table-wrap:last-child { margin-bottom: 0; }

/* A folding card (<details>): the summary line is the card's header. */
details.fold > summary {
    display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline;
    cursor: pointer; list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '▸'; color: var(--muted); width: 1em; }
details.fold[open] > summary::before { content: '▾'; }
details.fold[open] > summary { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.fold-body { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .fold-body { grid-template-columns: 1fr; } }
.fold-body h3 { margin: 0 0 8px; font-size: 15px; }
/* A message box under a form: spaced from the controls only when it says something. */
.msg:not(:empty) { margin-top: 12px; }
.secret-once { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: var(--radius); word-break: break-all; }
.secret-once code { color: var(--text); }

/* ── Tabs: the list's state filter and a company's sections ─────────── */

.tabs:where(:not(.inv-sf *)) { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab:where(:not(.inv-sf *)) {
    font: inherit; font-weight: 500; color: var(--muted);
    background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0;
    padding: 7px 12px; margin-bottom: -1px; cursor: pointer;
}
.tab:hover:where(:not(.inv-sf *)) { color: var(--text); background: var(--surface-alt); text-decoration: none; }
.tab[aria-current]:where(:not(.inv-sf *)) { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible:where(:not(.inv-sf *)) { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-count:where(:not(.inv-sf *)) {
    display: inline-block; min-width: 1.7em; padding: 0 6px; border-radius: 999px; text-align: center;
    background: var(--surface-alt); font-size: 12px; font-variant-numeric: tabular-nums;
}
.tab[aria-current] .tab-count:where(:not(.inv-sf *)) { background: var(--info-bg); }
.tab-count-error:where(:not(.inv-sf *)) { background: var(--danger-bg); color: var(--danger); }

/* ── The companies list ─────────────────────────────────────────────── */

.head-count { font-size: 14px; font-weight: 500; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar .list-search { flex: 1; min-width: 16rem; }
.toolbar .check { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 1px 2px 1px 10px; border-radius: 999px; background: var(--info-bg); font-size: 12px; }
.chip button { background: none; border: 0; padding: 0 6px; font: inherit; font-size: 14px; color: inherit; cursor: pointer; border-radius: 999px; }
.chip button:hover { background: var(--surface-alt); }

/* No overflow wrapper here: it would take the sticky header off the page's scroll. */
.list-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; }
.list-table th { position: sticky; top: var(--topbar-h); z-index: 2; white-space: nowrap; }
.list-table thead th:first-child { border-top-left-radius: var(--radius); }
.list-table thead th:last-child { border-top-right-radius: var(--radius); }
.list-table.compact td, .list-table.compact th { padding-top: 4px; padding-bottom: 4px; }
.list-table .sub { font-size: 12px; color: var(--muted); }
.list-table .col-actions { width: 1%; text-align: right; }
.th-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
.th-sort:hover, .th-sort.on { color: var(--text); }
.th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Calm active rows; a restriction is what draws the eye. */
.list-table tr.restricted td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.list-table tr.state-blocked td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.list-table tr.row-last { background: var(--surface-alt); }
.list-table tr.row-cursor, .list-table tr.row-cursor:hover { background: var(--info-bg); }
.note {
    display: inline-block; max-width: 22rem; vertical-align: middle;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px;
}
.pager { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.pager select { padding-top: 4px; padding-bottom: 4px; }
/* Narrower: the secondary columns go first; on a phone each row is a small card. */
@media (max-width: 1100px) { .list-table .col-created, .list-table .col-public_id { display: none; } }
@media (max-width: 1200px) { .list-table .col-health { display: none; } }
@media (max-width: 900px) {
    .list-table .col-fina, .list-table .col-updated { display: none; }
    .list-table .note { max-width: 10rem; }
}
@media (max-width: 700px) {
    .list-table thead { display: none; }
    .list-table, .list-table tbody, .list-table tr, .list-table td { display: block; }
    .list-table tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
    .list-table tr:last-child { border-bottom: 0; }
    .list-table td { border: 0; padding: 2px 0; text-align: left; }
    .list-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
    .list-table .col-actions { width: auto; text-align: left; padding-top: 6px; }
    .list-table tr.restricted td:first-child, .list-table tr.state-blocked td:first-child { box-shadow: none; }
    .list-table tr.restricted { box-shadow: inset 3px 0 0 var(--warn); }
    .list-table tr.state-blocked { box-shadow: inset 3px 0 0 var(--danger); }
    .note { max-width: 100%; }
}

/* A small drop-down menu (<details class="menu">). */
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after { content: '▾'; color: var(--muted); font-size: 11px; }
.menu-panel {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 6; min-width: 200px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(16, 24, 40, .15);
}
.menu-panel .check { margin: 0; padding: 6px 8px; white-space: nowrap; }
.menu-item { display: block; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-alt); }

/* ── One company ────────────────────────────────────────────────────── */

.company-head { position: sticky; top: var(--topbar-h); z-index: 4; background: var(--bg); padding: 8px 0; margin-top: -8px; }
.company-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 4px; }
.company-title h1 { margin: 0; }
.company-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: 13px; }
.btn-ghost:where(:not(.inv-sf *)) { border-color: transparent; background: none; padding: 1px 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.btn-ghost:hover:where(:not(.inv-sf *)) { color: var(--text); }
.danger-zone { border-color: var(--danger); margin-top: 16px; }
.danger-zone > h2 { color: var(--danger); }
.danger-zone h3 { font-size: 14px; margin: 0 0 4px; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; margin: 2px 0 12px; }
.block { display: block; }
.settings-bar {
    display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start;
    padding: 12px 16px; border-radius: var(--radius); background: var(--info-bg);
}

/* The state dialog: pick, read what it does, then Apply. */
.dialog {
    border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(560px, calc(100vw - 32px));
    background: var(--surface); color: var(--text); box-shadow: var(--shadow);
    max-height: calc(100vh - 32px); overflow-y: auto;
}
.dialog::backdrop { background: rgba(10, 14, 20, .45); }
.choices { border: 0; padding: 0; margin: 0 0 12px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; margin: 0 0 6px; border: 1px solid var(--border); border-radius: 6px; font-weight: 400; cursor: pointer; }
.choice > input { display: inline-block; width: auto; flex: none; margin: 3px 0 0; }
.choice > span { flex: 1; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--info-bg); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ── Follow-ups, work views, bulk (P1) ──────────────────────────────── */

.views { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -4px 0 10px; }
.views:empty { display: none; }
.pill {
    font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px;
}
.pill:hover { color: var(--text); }
.pill.on { color: var(--text); border-color: var(--accent); background: var(--info-bg); }
.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.selbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.selbar:empty { display: none; }
.selbar strong { font-size: 13px; }
.list-table .col-sel { width: 1%; padding-right: 0; }
.list-table .col-sel input { margin: 0; }
.list-table tr.row-selected, .list-table tr.row-selected:hover { background: var(--info-bg); }
.reason { font-size: 12px; font-weight: 600; color: var(--text); }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.today { color: var(--warn); font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.followup { border-top: 1px solid var(--border); padding: 10px 0; }
.followup:first-child { border-top: 0; padding-top: 0; }
.followup .row { margin-top: 6px; }
.bulk-list { max-height: 180px; overflow-y: auto; }
@media (max-width: 700px) { .list-table .col-sel { display: inline-block; float: right; } }

/* ── Health, saved views (P2) ───────────────────────────────────────── */

.menu-row { display: flex; align-items: center; gap: 2px; }
.menu-row .menu-item { flex: 1; text-decoration: none; }
.menu-row .menu-item[aria-current] { font-weight: 600; }
.menu-x { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 2px 8px; border-radius: 6px; cursor: pointer; }
.menu-x:hover { background: var(--surface-2); color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-form { display: flex; gap: 6px; padding: 2px; }
.menu-form input { flex: 1; min-width: 0; padding: 4px 8px; }
.menu-note { margin: 4px 8px; }
.menu-panel .msg:not(:empty) { margin: 6px 2px 0; }
.menu-panel { min-width: 260px; }
.list-table time { white-space: nowrap; }
