/* ── TOKENS ──────────────────────────────────────────────────────────────────
   Every colour comes from here; the dark blocks restate the palette. */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f9fafb; --surface-3: #f1f3f6;
  --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #16202d; --muted: #5f6b7a; --hint: #97a1ae;
  --accent: #1f3a5f; --accent-hover: #172d4a; --accent-soft: #e8eef6; --accent-text: #1f3a5f;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7;
  --danger: #b91c1c; --danger-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 20px 50px rgba(16,24,40,.18);
  --overlay: rgba(16,24,40,.4);
  --radius: 12px; --radius-sm: 8px;
  --sidebar-w: 240px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1116; --surface: #161a21; --surface-2: #1b2029; --surface-3: #212733;
    --border: #2a303b; --border-strong: #3a4250;
    --text: #e6e9ee; --muted: #9aa4b2; --hint: #6b7482;
    --accent: #4f7fbf; --accent-hover: #6590cb; --accent-soft: #1d2a3c; --accent-text: #9cc0ef;
    --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33280f;
    --danger: #f87171; --danger-bg: #3a1717;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 50px rgba(0,0,0,.6);
    --overlay: rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116; --surface: #161a21; --surface-2: #1b2029; --surface-3: #212733;
  --border: #2a303b; --border-strong: #3a4250;
  --text: #e6e9ee; --muted: #9aa4b2; --hint: #6b7482;
  --accent: #4f7fbf; --accent-hover: #6590cb; --accent-soft: #1d2a3c; --accent-text: #9cc0ef;
  --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33280f;
  --danger: #f87171; --danger-bg: #3a1717;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 50px rgba(0,0,0,.6);
  --overlay: rgba(0,0,0,.6);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--muted); } .hint { color: var(--hint); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ── SHELL ───────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 18px 18px 14px; font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
.nav { padding: 4px 10px; display: flex; flex-direction: column; gap: 1px; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); padding: 14px 10px 6px; display: flex; justify-content: space-between; align-items: center; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; cursor: pointer; text-decoration: none !important; min-width: 0;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-item .ico { width: 18px; text-align: center; flex-shrink: 0; }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.nav-item .count { font-size: 11px; color: var(--hint); }
.nav-item .dot-overdue { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding: 12px 10px; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.me-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px 32px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ── CONTROLS ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: transparent; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-xs { padding: 2px 8px; font-size: 12px; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.search { max-width: 240px; padding: 6px 10px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.fg { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fg.full { grid-column: 1 / -1; }
.fg label, .field-label { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ── CARDS / METRICS ─────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.metric { padding: 16px 18px; }
.metric-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.metric-value { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.metric-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.good { color: var(--ok); }

.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; }
.progress .p-funded { background: #22c55e; }
.progress .p-committed { background: #f59e0b; }

.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.client-card { padding: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, transform .15s; }
.client-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.client-card.archived { opacity: .6; }
.client-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.client-card .name { font-weight: 650; font-size: 15px; }
.stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.stats b { color: var(--text); font-weight: 600; }

.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-accent { background: var(--accent-soft); color: var(--accent-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ── CLIENT HEADER ───────────────────────────────────────────────────────── */
.client-head { padding: 20px 22px; margin-bottom: 18px; }
.client-head .meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 8px; }
.raise { margin-top: 16px; }
.raise-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; gap: 12px; flex-wrap: wrap; }
.raise-labels b { color: var(--text); }
.legend { display: inline-flex; align-items: center; gap: 5px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 500; color: var(--muted); padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

/* ── KANBAN ──────────────────────────────────────────────────────────────── */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--surface-3); border-radius: var(--radius); padding: 10px; min-height: 160px; border: 2px dashed transparent; transition: border-color .12s, background .12s; }
.col.over { border-color: var(--accent); background: var(--accent-soft); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; }
.col-title { font-weight: 600; font-size: 13px; }
.col-count { font-size: 12px; color: var(--hint); }
.col-sum { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-body { display: flex; flex-direction: column; gap: 8px; }
.col-empty { font-size: 12px; color: var(--hint); text-align: center; padding: 14px 0; font-style: italic; }
.icard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.icard:hover { border-color: var(--border-strong); }
.icard.dragging { opacity: .45; }
.icard .name { font-weight: 600; line-height: 1.3; }
.icard .sub { font-size: 12px; color: var(--muted); }
.icard .amts { display: flex; gap: 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.icard .amts b { font-weight: 600; }
.icard .next { font-size: 12px; background: var(--surface-2); border-radius: 6px; padding: 6px 8px; display: flex; gap: 6px; align-items: baseline; }
.icard .foot { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--hint); gap: 8px; }
.initials { display: flex; }
.initials .avatar { width: 22px; height: 22px; font-size: 10px; margin-left: -5px; border: 2px solid var(--surface); }
.initials .avatar:first-child { margin-left: 0; }

/* ── TABLE ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
table.list th.num, table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: var(--surface-2); }
table.list tbody tr:last-child td { border-bottom: 0; }

/* ── FOLLOW-UPS ──────────────────────────────────────────────────────────── */
.fu-list { display: flex; flex-direction: column; }
.fu { display: flex; gap: 12px; align-items: flex-start; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.fu:last-child { border-bottom: 0; }
.fu input[type="checkbox"] { margin-top: 3px; }
.fu .body { flex: 1; min-width: 0; }
.fu .t { font-weight: 500; }
.fu .done .t, .fu.done .t { text-decoration: line-through; color: var(--hint); }
.fu .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.fu-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 18px 6px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.fu-group.overdue { color: var(--danger); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 10px 18px; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .when { font-size: 11px; color: var(--hint); }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; border: 1px solid var(--border); }
.modal.wide { max-width: 820px; }
.modal.narrow { max-width: 420px; }
.modal-head { padding: 18px 22px 0; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 18px; flex: 1; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.stage-picker { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 16px; }
.stage-picker button { border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); padding: 4px 11px; border-radius: 99px; font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.stage-picker button.on { color: #fff; border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 99px; padding: 4px 11px; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.section { margin-top: 20px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input[type="date"] { width: 150px; flex-shrink: 0; }
.actions-box { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 10px; }
.actions-box .fu { padding: 9px 12px; }
.actions-box .fu input[type="date"] { width: 140px; padding: 3px 6px; font-size: 12px; }
.x-btn { border: 0; background: none; color: var(--hint); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; }
.x-btn:hover { color: var(--danger); }

.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); min-width: 190px; padding: 4px; z-index: 20; }
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu-pop button:hover { background: var(--surface-3); }
.menu-pop button.danger { color: var(--danger); }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-weight: 500; max-width: 360px; animation: toast-in .18s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--muted); }
.notice.err { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

/* ── AUTH PAGE ───────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; padding: 32px 28px; }
.auth-card h1 { margin: 16px 0 4px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.auth-card .btn { width: 100%; padding: 10px; margin-top: 6px; }

/* ── NARROW SCREENS ──────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; font-weight: 600; }
  .content { padding: 18px 16px 50px; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-auto-columns: minmax(250px, 80vw); }
  .search { max-width: none; flex: 1; }
  .add-row { flex-wrap: wrap; }
  .add-row input[type="date"] { width: auto; flex: 1; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; max-width: none !important; }
}
