/* Expense Report — a clean, slate-and-blue dashboard look. Colours are tokens so light and dark themes share every rule. */
:root {
  color-scheme: light;
  --page: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #8592a6;
  --grid: #e9edf3;
  --axis: #cbd3df;
  --border: #e3e8ef;
  --border-strong: #cfd7e3;
  --hover: rgba(15, 23, 42, 0.035);
  --accent: #2a78d6;
  --accent-hover: #2167bd;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --nav: #0f1d3a;
  --nav-2: #1b2c52;
  --nav-ink: #ffffff;
  --nav-muted: rgba(255, 255, 255, 0.66);
  --good: #0a7a3c;
  --bad: #c62f3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s-other: #a8a69e;
  /* The same series colours as r, g, b (for tinted table cells), plus more hues for smaller categories. */
  --h1: 42, 120, 214; --h2: 235, 104, 52; --h3: 27, 175, 122; --h4: 237, 161, 0; --h5: 232, 123, 164; --h6: 0, 131, 0; --h7: 74, 58, 167;
  --h8: 0, 150, 170; --h9: 160, 105, 60; --h10: 205, 55, 85; --h11: 125, 140, 25; --h12: 70, 170, 230; --h13: 150, 80, 200; --h14: 95, 115, 145;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --radius: 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13.5px;
  font-feature-settings: "cv11", "ss01";
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b1120;
    --surface: #131b2e;
    --surface-2: #18223a;
    --ink: #f1f5f9;
    --ink-2: #b6c2d4;
    --muted: #7c8aa3;
    --grid: #222d45;
    --axis: #34405a;
    --border: #232f49;
    --border-strong: #33415f;
    --hover: rgba(255, 255, 255, 0.04);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-wash: rgba(57, 135, 229, 0.18);
    --nav: #070c18;
    --nav-2: #141d33;
    --good: #2fbf6b;
    --bad: #f0707a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #6b6a65;
    --h1: 57, 135, 229; --h2: 217, 89, 38; --h3: 25, 158, 112; --h4: 201, 133, 0; --h5: 213, 81, 129; --h6: 0, 131, 0; --h7: 144, 133, 233;
    --h8: 0, 175, 195; --h9: 190, 130, 80; --h10: 230, 85, 110; --h11: 160, 175, 40; --h12: 95, 185, 240; --h13: 180, 120, 230; --h14: 130, 150, 180;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); -webkit-font-smoothing: antialiased; overflow: hidden; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
.num, td.amt, th.amt { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ico { width: 15px; height: 15px; flex: none; }

/* ---------- header ---------- */
.topbar {
  flex: none; display: flex; align-items: center; gap: 28px; padding: 0 28px; height: 60px;
  background: linear-gradient(180deg, var(--nav-2), var(--nav)); color: var(--nav-ink);
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #4f9bf0, #1f5fb8); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }
.brand-mark svg { width: 16px; height: 16px; }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name small { font-size: 11px; font-weight: 500; color: var(--nav-muted); letter-spacing: 0; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs button {
  border: 0; background: transparent; padding: 0 14px; cursor: pointer; color: var(--nav-muted); font-weight: 500; height: 100%;
  position: relative; transition: color 0.15s;
}
.tabs button:hover { color: var(--nav-ink); }
.tabs button.active { color: var(--nav-ink); font-weight: 600; }
.tabs button.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: #5aa2f2; }
.spacer { flex: 1; }
.topbar .btn { height: 36px; padding: 0 14px; }
.topbar .btn.ghost { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.18); color: var(--nav-ink); }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, 0.16); }
.topbar .btn:disabled { opacity: 0.45; }

.subbar {
  flex: none; display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.page-title h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
#page-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.filters { display: flex; gap: 8px; align-items: center; }

select, input[type="text"], input[type="search"] {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 5px 10px; height: 34px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select { padding-right: 28px; -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238592a6' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
select:hover, input[type="text"]:hover, input[type="search"]:hover { border-color: var(--axis); }
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); padding: 0 14px; height: 34px; border-radius: 8px;
  cursor: pointer; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}
.btn:hover { background: var(--surface-2); border-color: var(--axis); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.12); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; overflow: auto; padding: 24px 28px 0; }
.wrap { max-width: 1440px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; min-width: 0; }
.card h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
.site-foot { max-width: 1440px; margin: 28px auto 0; padding: 18px 0 24px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { display: flex; gap: 14px; align-items: flex-start; }
.tile-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.tile-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tone-blue { background: rgba(var(--h1), 0.12); color: rgb(var(--h1)); }
.tone-orange { background: rgba(var(--h2), 0.12); color: rgb(var(--h2)); }
.tone-green { background: rgba(var(--h3), 0.13); color: rgb(var(--h3)); }
.tone-purple { background: rgba(var(--h7), 0.12); color: rgb(var(--h7)); }
.tile .label { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .note { color: var(--ink-2); font-size: 12.5px; margin-top: 3px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; overflow-x: auto; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: inherit; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 14px; color: var(--ink-2); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.col-hit { fill: transparent; cursor: pointer; }
.col-hit:hover { fill: var(--hover); }

.hbars { display: flex; flex-direction: column; gap: 2px; }
.hbar { display: grid; grid-template-columns: 150px minmax(0, 1fr) 96px; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.hbar:hover { background: var(--hover); }
.hbar .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.hbar .track { height: 14px; position: relative; background: var(--surface-2); border-radius: 4px; }
.hbar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }
.hbar .pct { color: var(--muted); font-size: 11px; margin-left: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--grid); }
th { font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--axis); position: sticky; bottom: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; white-space: nowrap; }
.matrix th:first-child { background: var(--surface-2); z-index: 3; }
.matrix thead th, .matrix thead th:first-child { background: var(--accent); color: var(--accent-ink); font-weight: 600; border-bottom: 0; letter-spacing: 0.04em; }
.matrix thead th:first-child { border-top-left-radius: 6px; }
.matrix thead th:last-child { border-top-right-radius: 6px; }
.matrix tfoot td:first-child { background: var(--surface-2); }
.matrix td.cell { cursor: pointer; }
.matrix .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 8px; vertical-align: 0; }
.matrix .pct { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.matrix td.zero { color: var(--muted); }
.matrix td.total { font-weight: 600; border-left: 1px solid var(--grid); }
td.desc { max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.muted, .muted { color: var(--muted); }
td select { height: 26px; padding: 2px 22px 2px 7px; font-size: 12px; max-width: 190px; }
td select.manual { border-color: var(--accent); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { width: 260px; }
.toolbar .count { margin-left: auto; color: var(--ink-2); }

/* ---------- empty state ---------- */
.empty { max-width: 680px; margin: 48px auto; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 40px 44px; }
.empty h1 { font-size: 24px; margin: 0 0 10px; letter-spacing: -0.02em; }
.empty p { color: var(--ink-2); line-height: 1.55; }
.empty .formats { display: flex; justify-content: center; gap: 8px; margin: 18px 0 22px; }
.drop-hint { border: 1.5px dashed var(--border-strong); border-radius: 12px; padding: 34px 20px; margin-top: 20px; color: var(--muted); }

#drop-overlay {
  position: fixed; inset: 0; background: rgba(42, 120, 214, 0.12); border: 3px dashed var(--accent);
  display: none; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; color: var(--accent); z-index: 50; pointer-events: none;
}
body.dragging #drop-overlay { display: flex; }

/* ---------- modal ---------- */
#billing-root .modal-bg { z-index: 60; }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 24px; }
.modal { background: var(--surface); border-radius: 14px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); width: min(1040px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.modal.narrow { width: min(520px, 100%); }
.modal header { padding: 16px 20px 0; }
.modal header h2 { margin: 0; font-size: 16px; }
.modal header .sub { color: var(--muted); margin-top: 3px; word-break: break-all; }
.modal .body { padding: 14px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal footer { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; align-items: center; border-top: 1px solid var(--border); }
.modal footer .left { margin-right: auto; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.field input[type="text"], .field select { width: 100%; }
#statement-balance-card .field { min-width: 0; }
#statement-balance-card .statement-balance-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); }
.warn { background: rgba(250, 178, 25, 0.14); border: 1px solid rgba(250, 178, 25, 0.5); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }
.stats { display: flex; gap: 22px; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.stats div b { display: block; font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stats div { color: var(--ink-2); font-size: 12px; }
.preview { max-height: 340px; }
tr.dup td { color: var(--muted); text-decoration: line-through; }

/* ---------- toast & tooltip ---------- */
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--page);
  border-radius: 10px; padding: 10px 14px; display: none; align-items: center; gap: 10px; z-index: 45; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  max-width: calc(100% - 40px);
}
#toast.show { display: flex; }
#toast input, #toast select { background: var(--page); color: var(--ink); border-color: transparent; height: 28px; }
#toast .btn { height: 28px; border-color: transparent; }
#toast .btn.ghost { background: transparent; color: var(--page); }
#tooltip {
  position: fixed; pointer-events: none; z-index: 60; background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16); border-radius: 8px; padding: 8px 10px; font-size: 12px; display: none; min-width: 160px; max-width: 300px;
}
#tooltip .t-title { font-weight: 600; margin-bottom: 5px; }
#tooltip .t-row { display: flex; align-items: center; gap: 7px; justify-content: space-between; padding: 1px 0; }
#tooltip .t-row span:first-child { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
#tooltip .t-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
#tooltip .t-total { border-top: 1px solid var(--grid); margin-top: 5px; padding-top: 5px; }
#tooltip.pinned { pointer-events: auto; overflow: auto; overscroll-behavior: contain; }
#tooltip.pinned .t-title { padding-right: 38px; min-height: 32px; }
#tooltip .tip-close { position: absolute; top: 2px; right: 2px; width: 36px; height: 36px; border: 0; background: transparent; color: var(--ink); font: 24px/1 system-ui; cursor: pointer; }
#tooltip.pinned .t-total { position: sticky; bottom: -8px; background: var(--surface); padding-bottom: 4px; }

details summary { cursor: pointer; color: var(--ink-2); }
.kw { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 4px 0 10px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#toast span { white-space: nowrap; }

/* category filter */
.select-btn { min-width: 150px; justify-content: space-between; padding-right: 26px; font-weight: 400; position: relative; max-width: 220px; }
.select-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-btn::after { content: ""; position: absolute; right: 9px; top: 50%; width: 10px; height: 6px; margin-top: -3px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23898781' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat; }
.select-btn.active { border-color: var(--accent); background: var(--accent-wash); }
#cat-pop { position: fixed; z-index: 35; display: none; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 10px; }
#cat-pop.show { display: flex; flex-direction: column; overflow: hidden; }
.pop-actions { display: flex; flex-shrink: 0; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--grid); margin-bottom: 6px; }
.pop-list { min-height: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.pop-list .check { flex-shrink: 0; }
.pop-list .check { padding: 4px 6px; border-radius: 6px; }
.pop-list .check:hover { background: var(--hover); }
.pop-name { flex: 1; }
.pop-list .only { visibility: hidden; font-size: 12px; margin-left: 6px; }
.pop-list .check:hover .only { visibility: visible; }
.tabs button, .topbar .btn, .brand { white-space: nowrap; }
@media (max-width: 1180px) { .brand-name small { display: none; } .topbar { gap: 16px; padding: 0 18px; } .subbar, main { padding-left: 18px; padding-right: 18px; } }
.tag.tag-label { background: var(--accent-wash); color: var(--accent); font-weight: 500; margin-left: 4px; }

.pie-layout { display:grid; grid-template-columns:minmax(180px,260px) minmax(0,1fr); align-items:center; gap:24px; }
.pie-chart { display:block; width:100%; max-width:260px; margin:auto; }
.pie-slice { cursor:pointer; }
.pie-slice:hover, .pie-slice:focus { opacity:.8; stroke:var(--ink); stroke-width:2; outline:none; }
.pie-legend { display:grid; gap:4px; min-width:0; }
.pie-key { display:grid; grid-template-columns:10px minmax(0,1fr) auto 48px; align-items:center; gap:8px; border:0; background:none; color:var(--ink); font:inherit; font-size:13px; text-align:left; width:100%; padding:6px 0; }
button.pie-key { cursor:pointer; }
button.pie-key:hover, button.pie-key:focus-visible { background:var(--surface-2); border-radius:6px; }
.pie-key b { font-variant-numeric:tabular-nums; white-space:nowrap; }
.pie-key > .muted { text-align:right; font-variant-numeric:tabular-nums; }
@media(max-width:600px) { .pie-layout { grid-template-columns:1fr; gap:16px; } .pie-chart { max-width:220px; } }
