/* ---------------------------------------------------------------------------
 * INVOICES (collections view)
 * Scoped under body.invoices so nothing here reaches another page.
 * Same steel + brass family as the Safe and the dashboard.
 * The age ramp and the paid colour were validated for colourblind separation
 * and lightness in both modes; do not substitute them by eye.
 * ------------------------------------------------------------------------- */

body.invoices {
    --iv-surface:   #ffffff;
    --iv-surface-2: #e9edef;
    --iv-line:      #d5dce0;
    --iv-hairline:  #e7ecee;
    --iv-text:      #121a20;
    --iv-text-2:    #5c6b78;
    --iv-text-3:    #8697a3;
    --iv-brass:     #9a6a1f;
    --iv-brass-dim: #f0e4cd;

    /* the collected portion of an invoice - the validated "money in" step */
    --iv-paid: #2563eb;

    /* ordinal ramp for how late something is - one hue, monotone lightness */
    --iv-age-1: #e5a077;
    --iv-age-2: #d4813f;
    --iv-age-3: #c2410c;
    --iv-age-4: #8a2c08;
    --iv-age-ink-light: #3d1c08;
    --iv-age-ink-dark:  #ffffff;

    /* status - reserved, always paired with a word */
    --iv-critical:    #a3261a;
    --iv-critical-bg: #f9e3e0;
    --iv-warning:     #8a5a08;
    --iv-warning-bg:  #f8ecd6;
    --iv-good:        #17604a;
    --iv-good-bg:     #dff0e8;

    --iv-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --iv-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
    --iv-figure: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
    --iv-r: 3px;
}

body.invoices.theme-dark,
html.dark body.invoices,
body.dark-theme.invoices {
    --iv-surface: #151d23; --iv-surface-2: #1c262d;
    --iv-line: #2a353d; --iv-hairline: #202b32;
    --iv-text: #e7edf1; --iv-text-2: #93a3af; --iv-text-3: #6d7f8c;
    --iv-brass: #cf9f4f; --iv-brass-dim: #33291a;
    --iv-paid: #3b82f6;
    /* dark steps chosen against the dark surface, not flipped */
    --iv-age-1: #8a4a22; --iv-age-2: #b45f2c; --iv-age-3: #e2703a; --iv-age-4: #f2a173;
    --iv-age-ink-light: #ffffff;
    --iv-age-ink-dark:  #2a1408;
    --iv-critical: #f08a7c; --iv-critical-bg: #3a1d18;
    --iv-warning: #d9a441; --iv-warning-bg: #332811;
    --iv-good: #52c49b; --iv-good-bg: #12332a;
}

body.invoices .iv { display: flex; flex-direction: column; gap: 16px; }
body.invoices .iv :focus-visible { outline: 2px solid var(--iv-brass); outline-offset: 2px; }

body.invoices .iv-card {
    background: var(--iv-surface); border: 1px solid var(--iv-line); border-radius: var(--iv-r);
}
body.invoices .iv-card-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 13px 16px; border-bottom: 1px solid var(--iv-line);
}
body.invoices .iv-card-head h2 { font-size: 16.5px; font-weight: 620; margin: 0; color: var(--iv-text); }
body.invoices .iv-card-head .meta { font-size: 14.5px; color: var(--iv-text-3); }

/* ---------- money ---------- */
body.invoices .iv-money { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 12px; }
body.invoices .iv-stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
body.invoices .iv-stat .lbl { font-size: 14.5px; color: var(--iv-text-2); }
body.invoices .iv-stat .fig {
    font-family: var(--iv-figure); font-size: 39px; letter-spacing: -.028em;
    font-variant-numeric: tabular-nums; line-height: 1.05; color: var(--iv-text);
}
body.invoices .iv-stat .fig div + div { font-size: 26px; color: var(--iv-text-2); }
body.invoices .iv-stat .note { font-size: 14.5px; color: var(--iv-text-3); }
body.invoices .iv-stat .note.alert { color: var(--iv-critical); }
body.invoices .iv-stat .note s { opacity: .75; }

/* ---------- who owes you ---------- */
body.invoices .iv-debtor {
    display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
    padding: 9px 16px; border-bottom: 1px solid var(--iv-hairline); text-decoration: none; color: inherit;
}
body.invoices .iv-debtor:last-child { border-bottom: 0; }
body.invoices .iv-debtor:hover { background: var(--iv-surface-2); text-decoration: none; color: inherit; }
body.invoices .iv-debtor .who { font-size: 16px; color: var(--iv-text); }
body.invoices .iv-debtor .who small { display: block; color: var(--iv-text-3); font-size: 14px; }
body.invoices .iv-debtor .amt {
    font-family: var(--iv-mono); font-size: 16px; font-variant-numeric: tabular-nums; color: var(--iv-text);
}

/* ---------- status tabs ---------- */
body.invoices .iv-tabs {
    display: flex; flex-wrap: wrap; border: 1px solid var(--iv-line);
    border-radius: var(--iv-r); overflow: hidden; background: var(--iv-surface);
}
body.invoices .iv-tabs a {
    padding: 9px 15px; font-size: 16px; text-decoration: none; color: var(--iv-text-2);
    border-right: 1px solid var(--iv-line); display: inline-flex; align-items: baseline; gap: 7px;
}
body.invoices .iv-tabs a:last-child { border-right: 0; }
body.invoices .iv-tabs a:hover { background: var(--iv-surface-2); text-decoration: none; }
body.invoices .iv-tabs a.on { background: var(--iv-brass-dim); color: var(--iv-brass); font-weight: 600; }
body.invoices .iv-tabs a .n {
    font-family: var(--iv-mono); font-size: 14px; font-variant-numeric: tabular-nums; opacity: .75;
}

/* ---------- table ---------- */
body.invoices .iv-scroll { overflow-x: auto; }
body.invoices table.iv-table { width: 100%; border-collapse: collapse; min-width: 1020px; margin: 0; }
body.invoices table.iv-table thead th {
    text-align: left; font-size: 13.5px; font-weight: 650; letter-spacing: .1em; text-transform: uppercase;
    color: var(--iv-text-3); padding: 9px 14px; background: var(--iv-surface-2);
    border-bottom: 1px solid var(--iv-line); white-space: nowrap;
}
body.invoices table.iv-table th.num,
body.invoices table.iv-table td.num { text-align: right; }
body.invoices table.iv-table tbody td {
    padding: 11px 14px; border-bottom: 1px solid var(--iv-hairline); border-top: 0;
    vertical-align: middle; color: var(--iv-text);
}
body.invoices table.iv-table tbody tr:last-child td { border-bottom: 0; }
body.invoices table.iv-table tbody tr:hover { background: var(--iv-surface-2); }

body.invoices .iv-ref {
    font-family: var(--iv-mono); font-size: 14.5px; color: var(--iv-text-2);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
body.invoices .iv-client { font-size: 16px; font-weight: 550; }
body.invoices .iv-client a { color: var(--iv-text); text-decoration: none; }
body.invoices .iv-client a:hover { color: var(--iv-brass); }
body.invoices .iv-client small {
    display: block; font-weight: 400; color: var(--iv-text-3);
    font-size: 14px; font-family: var(--iv-mono);
}

/* status pill: colour plus a word, never colour alone */
body.invoices .iv-pill {
    display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; font-weight: 650;
    letter-spacing: .05em; text-transform: uppercase; padding: 3px 8px;
    border-radius: 2px; white-space: nowrap;
}
body.invoices .iv-pill.paid    { background: var(--iv-good-bg);     color: var(--iv-good); }
body.invoices .iv-pill.due     { background: var(--iv-warning-bg);  color: var(--iv-warning); }
body.invoices .iv-pill.overdue { background: var(--iv-critical-bg); color: var(--iv-critical); }
body.invoices .iv-pill.draft   { background: var(--iv-surface-2);   color: var(--iv-text-3); }

/* how late, on the ordinal ramp */
body.invoices .iv-age {
    font-family: var(--iv-mono); font-size: 14px; padding: 2px 7px;
    border-radius: 2px; white-space: nowrap;
}
body.invoices .iv-age.a1 { background: var(--iv-age-1); color: var(--iv-age-ink-light); }
body.invoices .iv-age.a2 { background: var(--iv-age-2); color: var(--iv-age-ink-light); }
body.invoices .iv-age.a3 { background: var(--iv-age-3); color: var(--iv-age-ink-dark); }
body.invoices .iv-age.a4 { background: var(--iv-age-4); color: var(--iv-age-ink-dark); }
body.invoices .iv-age.none { background: transparent; color: var(--iv-text-3); padding-left: 0; }

/* collected against invoiced, so a part-paid invoice cannot look untouched */
body.invoices .iv-prog { min-width: 160px; }
body.invoices .iv-prog .track { height: 5px; background: var(--iv-surface-2); border-radius: 4px; overflow: hidden; }
body.invoices .iv-prog .fill { height: 100%; background: var(--iv-paid); border-radius: 4px; }
body.invoices .iv-prog .cap {
    display: flex; justify-content: space-between; gap: 8px; margin-top: 4px;
    font-family: var(--iv-mono); font-size: 13.5px; color: var(--iv-text-3); font-variant-numeric: tabular-nums;
}

body.invoices table.iv-table td.iv-out {
    font-family: var(--iv-mono); font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
body.invoices table.iv-table td.iv-out .ccy { font-size: 13.5px; color: var(--iv-text-3); }
body.invoices table.iv-table td.iv-face {
    font-family: var(--iv-mono); font-size: 14.5px; color: var(--iv-text-3);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}

body.invoices table.iv-table tfoot td {
    padding: 11px 14px; background: var(--iv-surface-2); border-top: 1px solid var(--iv-line);
    font-family: var(--iv-mono); font-size: 15px; font-variant-numeric: tabular-nums; color: var(--iv-text);
}
body.invoices table.iv-table tfoot .lbl {
    font-family: var(--iv-sans); font-size: 13.5px; letter-spacing: .08em;
    text-transform: uppercase; color: var(--iv-text-3); font-weight: 650;
}

body.invoices .iv-flag { font-size: 14px; color: var(--iv-warning); display: block; margin-top: 3px; }
body.invoices .iv-nothing { padding: 34px 16px; text-align: center; color: var(--iv-text-3); font-size: 16px; }

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