/* InvoiceHub dashboard.
   Self-contained: system fonts, no webfont, no CDN, no script. The page renders with the network
   cut, which is the point - a dashboard that needs a third party to be legible is a dashboard that
   is illegible on the day you need it. */

:root {
    color-scheme: light dark;

    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-sunken: #eceef2;
    --bg-hover: #f0f2f5;
    --border: #dde1e7;
    --border-strong: #c4cad3;

    --text: #16191d;
    --text-muted: #5c6470;
    --text-faint: #858d99;

    --accent: #2f5bd7;
    --accent-hover: #2449b3;
    --accent-contrast: #ffffff;
    --accent-soft: #e8eefc;

    --good: #1c7a4a;
    --good-soft: #e3f4ea;
    --info: #1f6a90;
    --info-soft: #e2f0f7;
    --warn: #8a5a00;
    --warn-soft: #fdf1d8;
    --bad: #b3261e;
    --bad-soft: #fbe6e4;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 4px 12px rgba(16, 20, 28, .05);
    --shadow-loud: 0 2px 6px rgba(179, 38, 30, .16);

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

    --page-max: 1180px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101318;
        --bg-raised: #171b22;
        --bg-sunken: #1d222b;
        --bg-hover: #1f242d;
        --border: #2a303a;
        --border-strong: #3a4250;

        --text: #e7eaef;
        --text-muted: #a2abba;
        --text-faint: #7c8695;

        --accent: #7fa2ff;
        --accent-hover: #9ab6ff;
        --accent-contrast: #0d1118;
        --accent-soft: #1b2740;

        --good: #6cd39b;
        --good-soft: #14301f;
        --info: #7fc6e8;
        --info-soft: #122a35;
        --warn: #e8bd68;
        --warn-soft: #34260c;
        --bad: #ff8f84;
        --bad-soft: #391714;

        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
        --shadow-loud: 0 2px 10px rgba(255, 143, 132, .18);
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    letter-spacing: -.01em;
}

h1 { font-size: 1.55rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 620; }

p { margin: 0; }

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--bg-raised);
    padding: .6rem 1rem;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 20;
}

.skip-link:focus {
    left: 0;
}

/* ---------- chrome ---------- */

.topbar {
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 58px;
    display: flex;
    align-items: center;
    gap: 1.75rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: var(--text);
    font-size: 1.02rem;
    letter-spacing: -.015em;
}

.brand:hover { text-decoration: none; }

.brand-mark {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--accent), var(--info));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

.brand-text strong { font-weight: 680; }

.nav {
    display: flex;
    gap: .35rem;
    margin-right: auto;
}

.nav-link {
    color: var(--text-muted);
    padding: .38rem .7rem;
    border-radius: var(--radius-sm);
    font-weight: 520;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-link.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.tenant {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .8rem;
}

.tenant-label {
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-size: .68rem;
}

.tenant-code {
    font-family: var(--font-mono);
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .18rem .45rem;
    color: var(--text-muted);
}

.tenant-code--missing {
    color: var(--bad);
    border-color: var(--bad);
    background: var(--bad-soft);
}

.page {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

.footer {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 1.25rem 1.5rem 2rem;
    color: var(--text-faint);
    font-size: .8rem;
    display: flex;
    gap: .5rem;
}

.footer-sep { opacity: .5; }

/* ---------- headers ---------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-sub {
    margin-top: .4rem;
    color: var(--text-muted);
    font-size: .9rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.page-sub-text { color: var(--text-faint); }

.breadcrumb {
    display: flex;
    gap: .5rem;
    align-items: center;
    font-size: .85rem;
    color: var(--text-faint);
    margin-bottom: 1.1rem;
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-raised);
    color: var(--text);
    font: inherit;
    font-size: .875rem;
    font-weight: 540;
    cursor: pointer;
    white-space: nowrap;
}

.button:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

.button--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.button--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.button--quiet {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}

.button--danger {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--bad);
}

.button--danger:hover {
    background: var(--bad-soft);
    border-color: var(--bad);
}

.button.is-disabled {
    opacity: .45;
    cursor: default;
    pointer-events: none;
}

.link-action {
    font-size: .85rem;
    margin-left: .75rem;
}

.link-action:first-child { margin-left: 0; }

/* ---------- alerts ---------- */

.alert {
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    padding: .7rem .9rem;
    margin-bottom: 1.25rem;
    font-size: .9rem;
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.alert--good { background: var(--good-soft); border-left-color: var(--good); }
.alert--warn { background: var(--warn-soft); border-left-color: var(--warn); }
.alert--bad  { background: var(--bad-soft);  border-left-color: var(--bad); }

/* The one thing on the page that must not be missed. */
.review-banner {
    display: flex;
    gap: .9rem;
    align-items: flex-start;
    background: var(--bad-soft);
    border: 1px solid var(--bad);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-loud);
}

.review-banner h2 {
    color: var(--bad);
    font-size: 1rem;
}

.review-banner p {
    margin-top: .3rem;
    color: var(--text);
    font-size: .9rem;
}

.review-banner-mark {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bad);
    color: var(--bg-raised);
    font-weight: 700;
    font-size: .82rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: .1rem;
}

/* ---------- filters ---------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: .85rem;
    align-items: flex-end;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.field {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    min-width: 8.5rem;
}

.field--grow {
    flex: 1 1 16rem;
    min-width: 12rem;
}

.field--actions {
    flex-direction: row;
    gap: .5rem;
    align-items: center;
}

.field label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-faint);
    font-weight: 600;
}

input[type="search"],
input[type="date"],
input[type="text"],
select {
    font: inherit;
    font-size: .875rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: .45rem .6rem;
    width: 100%;
    min-height: 34px;
}

/* ---------- table ---------- */

.table-wrap {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .89rem;
}

.table th {
    text-align: left;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-faint);
    font-weight: 600;
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sunken);
    white-space: nowrap;
}

.table td {
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr:hover { background: var(--bg-hover); }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .actions-col { text-align: right; }

.row--review td { background: color-mix(in srgb, var(--warn-soft) 55%, transparent); }

.cell-primary {
    display: block;
    font-weight: 560;
    color: var(--text);
}

.cell-primary:hover { color: var(--accent); }

.cell-secondary {
    display: block;
    color: var(--text-faint);
    font-size: .8rem;
    margin-top: .1rem;
}

/* Same look on a <td>. It cannot reuse .cell-secondary: display:block on a table cell drops it out
   of the row's layout and the column collapses. */
.cell-muted {
    color: var(--text-faint);
    font-size: .8rem;
}

/* ---------- badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: .13rem .5rem;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge--muted { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--border); }
.badge--info  { background: var(--info-soft); color: var(--info); }
.badge--good  { background: var(--good-soft); color: var(--good); }
.badge--warn  { background: var(--warn-soft); color: var(--warn); }
.badge--bad   { background: var(--bad-soft);  color: var(--bad); border-color: var(--bad); }
.badge--outline { background: transparent; color: var(--text-muted); border-color: var(--border-strong); }

/* ---------- paging ---------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
}

.pager-position {
    font-size: .85rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---------- cards and fields ---------- */

.grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

@media (max-width: 900px) {
    .grid { grid-template-columns: minmax(0, 1fr); }
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem 1.3rem;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    margin-bottom: .9rem;
}

.card-empty {
    color: var(--text-muted);
    font-size: .9rem;
}

.fields {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    gap: .1rem 1.5rem;
}

.fields--compact { grid-template-columns: minmax(0, 1fr); }

.fields > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .45rem 0;
    border-bottom: 1px dashed var(--border);
}

.fields dt {
    color: var(--text-muted);
    font-size: .82rem;
    white-space: nowrap;
}

.fields dd {
    margin: 0;
    text-align: right;
    font-size: .9rem;
    min-width: 0;
}

.fields dd.num { font-variant-numeric: tabular-nums; }
.fields dd.mono { font-family: var(--font-mono); font-size: .82rem; }
.fields dd.break { overflow-wrap: anywhere; text-align: right; }
.fields dd.text-bad { color: var(--bad); }

.fields-total {
    grid-column: 1 / -1;
    border-bottom: none;
    border-top: 2px solid var(--border-strong);
    margin-top: .35rem;
    padding-top: .6rem !important;
}

.fields-total dt { font-weight: 650; color: var(--text); font-size: .9rem; }
.fields-total dd { font-weight: 680; font-size: 1.05rem; }

/* ---------- confidence ---------- */

.confidence-value {
    font-size: 1.9rem;
    font-weight: 680;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--good);
}

.confidence--low .confidence-value { color: var(--bad); }

.meter {
    height: 7px;
    border-radius: 999px;
    background: var(--bg-sunken);
    overflow: hidden;
    margin: .6rem 0 .5rem;
}

.meter-fill {
    height: 100%;
    background: var(--good);
    border-radius: 999px;
}

.confidence--low .meter-fill { background: var(--bad); }

.confidence-note {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .9rem;
}

/* ---------- mailboxes ---------- */

.mailbox-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
    gap: 1.25rem;
}

.mailbox {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem 1.25rem;
    box-shadow: var(--shadow);
}

.mailbox--alarm {
    border: 2px solid var(--bad);
    background: color-mix(in srgb, var(--bad-soft) 40%, var(--bg-raised));
    box-shadow: var(--shadow-loud);
}

.mailbox-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .6rem 1rem;
    flex-wrap: wrap;
    margin-bottom: .9rem;
}

.mailbox-head > div {
    flex: 1 1 12rem;
    min-width: 0;
}

/* break-word, not anywhere: `anywhere` also shrinks min-content, so a long address is chopped
   mid-word even when the card has room for it. */
.mailbox-address {
    font-size: 1rem;
    overflow-wrap: break-word;
}

.mailbox-provider {
    color: var(--text-faint);
    font-size: .78rem;
    margin-top: .2rem;
}

.mailbox-alarm-text {
    color: var(--bad);
    font-size: .87rem;
    margin-bottom: .9rem;
}

.mailbox-error {
    margin-top: .9rem;
    font-size: .82rem;
    color: var(--text-muted);
    background: var(--bg-sunken);
    border-radius: var(--radius-sm);
    padding: .55rem .7rem;
    overflow-wrap: anywhere;
}

.mailbox-error-label {
    display: block;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-size: .68rem;
    color: var(--text-faint);
    font-weight: 600;
    margin-bottom: .2rem;
}

.mailbox-actions {
    display: flex;
    gap: .6rem;
    margin-top: 1.1rem;
}

/* ---------- empty state ---------- */

.empty {
    background: var(--bg-raised);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .7rem;
}

.empty p {
    color: var(--text-muted);
    max-width: 44ch;
}

/* ---------- browser extension pairing ---------- */

.pair-form {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.pair-form input[type="text"] {
    width: 15rem;
}

.pairing {
    background: var(--bg-raised);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 1.4rem 1.5rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

/* The code is the whole reason for this panel, so it is the largest thing on the page. Monospaced
   and letter-spaced because it is transcribed by hand into another window: 0/O and 1/I have to be
   distinguishable at a glance. */
.pairing-code {
    font-family: var(--font-mono);
    font-size: clamp(1.9rem, 7vw, 3rem);
    font-weight: 650;
    letter-spacing: .12em;
    line-height: 1.15;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: var(--radius-sm);
    padding: .7rem 1rem;
    margin: .9rem 0 .8rem;
    text-align: center;
    overflow-wrap: anywhere;
    user-select: all;
}

.pairing-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem .9rem;
}

.pairing-expiry {
    font-size: .82rem;
    color: var(--text-muted);
}

.pairing-warn {
    margin-top: 1rem;
    font-size: .87rem;
    color: var(--text);
    background: var(--warn-soft);
    border-left: 3px solid var(--warn);
    border-radius: var(--radius-sm);
    padding: .6rem .8rem;
}

.pairing-steps {
    margin: 1rem 0 0;
    padding-left: 1.2rem;
    color: var(--text-muted);
    font-size: .89rem;
    display: grid;
    gap: .25rem;
}

.pairing-note {
    margin-top: .9rem;
    font-size: .82rem;
    color: var(--text-faint);
    max-width: 68ch;
}

@media (max-width: 640px) {
    .topbar-inner { gap: .6rem; padding: 0 .85rem; }
    .brand-text { display: none; }
    .nav { gap: .1rem; }
    .nav-link { padding: .38rem .5rem; }
    .tenant-label { display: none; }
    .tenant-code {
        max-width: 8.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .page { padding: 1.25rem 1rem 2rem; }
    .page-head { flex-direction: column; align-items: stretch; }
    .fields > div { flex-direction: column; gap: .1rem; }
    .fields dd { text-align: left; }
    .pair-form { flex-direction: column; align-items: stretch; }
    .pair-form input[type="text"] { width: 100%; }
}

/* ---------- signed-in account ---------- */

.nav-spacer { margin-right: auto; }

.account {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    font-size: .8rem;
    padding-left: .9rem;
    border-left: 1px solid var(--border);
}

.account-name {
    color: var(--text-muted);
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-signout {
    border: 0;
    background: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
}

.account-signout:hover { text-decoration: underline; }

/* ---------- sign-in and no-access gates ---------- */

.gate {
    max-width: 34rem;
    margin: 2.5rem auto 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (max-width: 640px) {
    .account { padding-left: .5rem; gap: .4rem; }
    .account-name { display: none; }
    .gate { margin-top: 1rem; }
}
