:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6; /* Earned / primary */
  --series-2: #eb6834; /* Paid */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --brand: #1f3864;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--series-1); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- Login ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand), #2a5599);
  padding: 20px;
}
.login-card {
  background: var(--surface-1);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--brand); }
.login-card .muted { color: var(--text-secondary); margin: 0 0 20px; font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--gridline); border-radius: 8px; font-size: 15px;
}
.error-text { color: var(--critical); font-size: 13px; margin-top: 10px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--gridline);
  background: #fff; font-size: 14px; font-weight: 600; color: var(--text-primary);
}
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { background: #2166b8; }
.btn-danger { background: #fff; border-color: var(--critical); color: var(--critical); }
.btn-block { width: 100%; margin-top: 4px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------------- App shell ---------------- */
.app-shell { min-height: 100vh; }
.topbar {
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.nav-toggle { background: none; border: none; color: #fff; font-size: 22px; display: none; }

.sidenav {
  position: fixed; top: 49px; left: 0; bottom: 0; width: 210px;
  background: #fff; border-right: 1px solid var(--gridline);
  padding: 14px 10px; overflow-y: auto; z-index: 15;
}
.sidenav a {
  display: block; padding: 10px 12px; margin-bottom: 2px; border-radius: 8px;
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
}
.sidenav a:hover { background: var(--page); }
.sidenav a.active { background: #e8f0fb; color: var(--series-1); font-weight: 700; }
.nav-logout {
  margin-top: 16px; width: 100%; background: none; border: 1px solid var(--gridline);
  border-radius: 8px; padding: 9px; color: var(--critical); font-size: 13px; font-weight: 600;
}

.view-root { margin-left: 210px; padding: 22px 24px 60px; max-width: 1200px; }

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .sidenav {
    transform: translateX(-100%); transition: transform 0.2s ease; width: 230px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  .sidenav.open { transform: translateX(0); }
  .view-root { margin-left: 0; padding: 16px 14px 50px; }
}

/* ---------------- Common view elements ---------------- */
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-header h1 { font-size: 20px; margin: 0; color: var(--brand); }
.view-header p.sub { color: var(--text-secondary); font-size: 13px; margin: 2px 0 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 26px; }
.kpi-tile {
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi-tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.kpi-tile .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-tile.accent-good .value { color: var(--good); }
.kpi-tile.accent-warning .value { color: #b8790d; }
.kpi-tile.accent-critical .value { color: var(--critical); }

.card { background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.card h2 { font-size: 15px; margin: 0 0 14px; color: var(--text-primary); }

/* width: max-content + min-width: 100% lets columns keep their natural
   content width and grow past the container when there are many of them
   (triggering the .table-scroll horizontal scrollbar), instead of being
   forced to cram into 100% width — which is what was crushing the Notes
   column down to ~96px and wrapping a sentence into a 15-line-tall cell. */
table.data-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.3px;
  color: var(--text-secondary); border-bottom: 1px solid var(--gridline); padding: 8px 10px; white-space: nowrap;
}
table.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--gridline); vertical-align: top; max-width: 320px; }
table.data-table tbody tr:hover { background: var(--page); }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-paid { background: #e3f6e3; color: var(--good); }
.badge-unpaid { background: #fde9e6; color: var(--critical); }
.badge-pending { background: #fff3da; color: #b8790d; }
.badge-void { background: #eee; color: var(--text-secondary); text-decoration: line-through; }
.badge-won { background: #e3f6e3; color: var(--good); }
.badge-sent { background: #eaf1fb; color: var(--series-1); }
.badge-lost { background: #eee; color: var(--text-secondary); }

.filters-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters-row select, .filters-row input[type="text"] {
  padding: 7px 10px; border: 1px solid var(--gridline); border-radius: 8px; font-size: 13px;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--gridline); border-radius: 8px; font-size: 14.5px;
  font-family: inherit;
}
.form-grid textarea { resize: vertical; min-height: 60px; }
.form-section-title { font-size: 13px; font-weight: 700; color: var(--brand); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.breakdown-list { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.breakdown-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--gridline); }
.breakdown-list li.total { font-weight: 700; border-bottom: none; padding-top: 10px; }
.breakdown-list .num { font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13.5px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.toast.error { background: var(--critical); }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 14px; }

/* ---------------- Chart ---------------- */
.viz-root { position: relative; }
.viz-legend { display: flex; gap: 18px; margin-bottom: 10px; font-size: 12.5px; color: var(--text-secondary); }
.viz-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-tooltip {
  position: absolute; background: var(--text-primary); color: #fff; padding: 6px 10px; border-radius: 6px;
  font-size: 12px; pointer-events: none; opacity: 0; transition: opacity 0.1s; white-space: nowrap; z-index: 10;
}
.chart-tooltip.show { opacity: 1; }

.status-select { border: none; background: transparent; font-weight: 700; font-size: 12.5px; }

.link-btn { background: none; border: none; color: var(--series-1); font-size: 13px; font-weight: 600; padding: 0; }
