:root {
  --bg: #070b16;
  --bg-grad: radial-gradient(1200px 600px at 20% -10%, rgba(56,189,248,0.10), transparent 60%), radial-gradient(900px 500px at 110% 10%, rgba(129,140,248,0.10), transparent 60%), #070b16;
  --surface: #0f172a;
  --surface-2: #141e36;
  --surface-3: #1a2640;
  --border: rgba(148,163,184,0.12);
  --border-strong: rgba(148,163,184,0.22);
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #8496b3;
  --faint: #54647e;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --accent-grad: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
  --good: #22c55e;
  --good-2: rgba(34,197,94,0.12);
  --warn: #f59e0b;
  --warn-2: rgba(245,158,11,0.12);
  --bad: #ef4444;
  --bad-2: rgba(239,68,68,0.12);
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.25);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; min-height: 100%; background: var(--bg); }
body { font-family: var(--font); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; background: var(--bg-grad); background-attachment: fixed; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

/* ============ Sign-in splash ============ */
.splash { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; gap: 40px; }
.splash-card { background: linear-gradient(165deg, rgba(20,30,54,0.9), rgba(15,23,42,0.9)); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: 44px 40px; width: 100%; max-width: 440px; box-shadow: var(--shadow), 0 0 0 1px rgba(56,189,248,0.06) inset; backdrop-filter: blur(10px); }
.splash-logo { width: 48px; height: 48px; margin-bottom: 18px; display: block; }
.splash-card h1 { font-size: 34px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.02em; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.splash-tag { color: var(--text-secondary); margin-bottom: 26px; font-size: 15px; }
.splash-features { list-style: none; padding: 0; margin: 0 0 28px; }
.splash-features li { display: flex; align-items: center; gap: 10px; padding: 8px 0; color: var(--text-secondary); font-size: 14px; }
.splash-features .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; box-shadow: 0 0 10px var(--accent); }
.splash-fine { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }
.splash-footer { color: var(--muted); font-size: 13px; text-align: center; }
.splash-footer a { color: var(--text-secondary); transition: color 0.15s; }
.splash-footer a:hover { color: var(--accent); }

/* ============ App shell ============ */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
@media (max-width: 860px) { .app { grid-template-columns: 1fr; } }

/* ============ Sidebar ============ */
.sidebar { background: linear-gradient(180deg, rgba(15,23,42,0.65), rgba(7,11,22,0.75)); border-right: 1px solid var(--border); padding: 22px 16px 18px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
@media (max-width: 860px) { .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--border); } }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 6px; }
.sidebar-brand img { width: 32px; height: 32px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }

.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.sidebar-label { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); padding: 0 8px 4px; font-weight: 600; }
.company-switcher { display: flex; flex-direction: column; gap: 3px; }
.company-item { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--text-secondary); font-size: 13.5px; border: 1px solid transparent; transition: background 0.15s, border-color 0.15s, color 0.15s; }
.company-item:hover { background: var(--surface-2); color: var(--text); }
.company-item.active { background: linear-gradient(135deg, rgba(56,189,248,0.12), rgba(129,140,248,0.10)); border-color: rgba(56,189,248,0.35); color: var(--text); }
.company-item .ci-avatar { width: 26px; height: 26px; border-radius: 6px; background: var(--surface-3); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; color: var(--accent); }
.company-item.active .ci-avatar { background: var(--accent-grad); color: #0b111f; }
.company-item .ci-body { flex: 1; min-width: 0; overflow: hidden; }
.company-item .ci-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-item .ci-sub { font-size: 11px; color: var(--muted); margin-top: 1px; display: flex; align-items: center; gap: 4px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 6px var(--good); flex-shrink: 0; }
.sync-dot.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.sync-dot.bad { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.sync-dot.neutral { background: var(--faint); box-shadow: none; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm); color: var(--text-secondary); font-size: 13.5px; font-weight: 500; cursor: pointer; border: 1px solid transparent; }
.nav-item:hover:not(.disabled) { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.nav-item.disabled { opacity: 0.4; cursor: not-allowed; }
.nav-item .ico { display: inline-flex; width: 20px; justify-content: center; color: var(--accent); font-size: 14px; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; }
.user-chip .uc-body { min-width: 0; overflow: hidden; }
.user-chip .uc-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .uc-role { font-size: 11px; color: var(--muted); }

/* ============ Main ============ */
.main { padding: 26px 32px 16px; display: flex; flex-direction: column; gap: 22px; min-width: 0; }
@media (max-width: 560px) { .main { padding: 18px 16px; } }
.main-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.eyebrow { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.main-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.main-sub { color: var(--muted); margin-top: 6px; font-size: 13.5px; }
.main-header-actions { display: flex; align-items: center; gap: 10px; }

/* ============ KPI cards ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr 1fr; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px 16px 14px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent-grad); opacity: 0.7; }
.kpi-label { font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-value.small { font-size: 20px; }
.kpi-delta { margin-top: 6px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }
.kpi-delta.neutral { color: var(--muted); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ============ Cards ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 20px 22px; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.card h3 { font-size: 15px; font-weight: 600; }
.card p.muted { font-size: 12.5px; margin-top: 3px; }
.cards-row { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .cards-row { grid-template-columns: 1fr; } }
.cards-row-3 { grid-template-columns: 1fr 1fr 1fr; margin-top: 16px; }
@media (max-width: 1000px) { .cards-row-3 { grid-template-columns: 1fr; } }
.tile-body { font-size: 13px; line-height: 1.6; }
.card-chart .chart-wrap { height: 280px; position: relative; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ============ Insights ============ */
.insights { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.insights li { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-sm); padding: 11px 14px; color: var(--text-secondary); font-size: 13px; line-height: 1.55; }
.insights li.positive { border-left-color: var(--good); }
.insights li.warning { border-left-color: var(--warn); }

/* ============ Transactions ============ */
.card-txns { padding: 20px 0 0; }
.card-txns .card-header { padding: 0 22px; }
.table-wrap { overflow-x: auto; }
.txn-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.txn-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; padding: 10px 22px; background: transparent; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.txn-table td { padding: 12px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.txn-table tbody tr:last-child td { border-bottom: 0; }
.txn-table tbody tr:hover { background: var(--surface-2); }
.txn-table td.right, .txn-table th.right { text-align: right; font-variant-numeric: tabular-nums; }
.txn-table .desc { display: flex; align-items: center; gap: 10px; }
.txn-table .type-ico { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.txn-table .type-ico.invoice { background: var(--good-2); color: var(--good); }
.txn-table .type-ico.expense { background: var(--bad-2); color: var(--bad); }
.txn-table .amount.pos { color: var(--good); font-weight: 600; }
.txn-table .amount.neg { color: var(--text); font-weight: 500; }
.pad { padding: 30px 22px; text-align: center; }

/* ============ Footer ============ */
.main-footer { margin-top: auto; padding: 18px 4px 8px; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }
.main-footer a { color: var(--text-secondary); transition: color 0.15s; }
.main-footer a:hover { color: var(--accent); }

/* ============ Buttons + chips ============ */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: var(--r-sm); font-size: 13.5px; font-weight: 500; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn-primary { background: var(--accent-grad); color: #0b111f; border: 0; font-weight: 600; transition: filter 0.15s, color 0.15s; }
.btn-primary:hover { filter: brightness(0.88) saturate(1.1); color: #ffffff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { padding: 12px 18px; font-size: 14.5px; width: 100%; justify-content: center; border-radius: 10px; }
.btn.sm, .btn-ghost.sm { padding: 6px 10px; font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip-accent { background: rgba(56,189,248,0.12); color: var(--accent); border-color: rgba(56,189,248,0.3); }
.chip-good { background: var(--good-2); color: var(--good); border-color: rgba(34,197,94,0.3); }
.chip-warn { background: var(--warn-2); color: var(--warn); border-color: rgba(245,158,11,0.3); }
.chip-bad { background: var(--bad-2); color: var(--bad); border-color: rgba(239,68,68,0.3); }
.muted { color: var(--muted); }
.err { color: var(--bad); margin-top: 10px; font-size: 13px; }

/* ============ Skeletons ============ */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============ Modal ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(7,11,22,0.72); backdrop-filter: blur(4px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(56,189,248,0.06) inset; max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { padding: 22px 24px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.modal-header h3 { font-size: 18px; font-weight: 600; margin-top: 4px; }
.modal-header .muted { font-size: 12.5px; margin-top: 6px; }
.modal-body { padding: 20px 24px; flex: 1; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-secondary); margin-bottom: 14px; }
.form-label input, .form-label textarea, .form-label select { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text); font-family: inherit; font-size: 13.5px; box-sizing: border-box; }
.form-label input:focus, .form-label textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,0.15); }
.form-label textarea { min-height: 70px; resize: vertical; }
.claude-note { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }
.validator-note { background: rgba(245,158,11,0.10); border-left: 3px solid var(--warn); padding: 10px 14px; border-radius: 6px; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.validator-note.agree { background: rgba(34,197,94,0.10); border-left-color: var(--good); }
.validator-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; margin-left: 6px; }
.validator-chip.dissent { background: rgba(245,158,11,0.16); color: var(--warn); }
.validator-chip.agree { background: rgba(34,197,94,0.14); color: var(--good); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.18); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,0.28); }

/* Inline-editable queue cells */
.cell-edit { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.cell-edit .cell-text { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-edit .cell-input {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 13px; min-width: 160px; max-width: 260px;
}
.cell-edit .cell-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,0.18); }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  cursor: pointer; padding: 2px 6px; font-size: 13px; line-height: 1; border-radius: 4px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.cell-apply-btn { color: var(--good); }

/* Row checkbox column */
#close-queue-body input.row-select, #queue-select-all { cursor: pointer; transform: scale(1.1); accent-color: var(--accent); }
