/* ===================== Design tokens ===================== */
:root {
  --ink: #10161F; --paper: #F5F6FA; --surface: #FFFFFF; --surface-2: #FBFBFD; --border: #E1E5EC;
  --muted: #5B6478; --muted-2: #828BA0;
  --blueprint: #1B4B91; --blueprint-ink: #153B72; --blueprint-soft: #E8EEF9; --blueprint-soft-ink: #1B4B91;
  --brass: #8A6415; --brass-soft: #F4ECD8;
  --good: #166534; --good-soft: #DFF3E4;
  --warn: #8A5A0A; --warn-soft: #FBEDD3;
  --bad: #96201C; --bad-soft: #FBE4E2;
  --neutral: #475569; --neutral-soft: #EDF0F4;
  --sidebar-bg: #0E1B33; --sidebar-ink: #C7D0E3; --sidebar-ink-dim: #7C89A8; --sidebar-active: #16274A; --sidebar-border: #1C2C4C;
  --shadow: 0 1px 2px rgba(16,22,31,.04), 0 8px 24px -12px rgba(16,22,31,.12);
  --radius: 10px;
  --pico-font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  background: var(--paper); color: var(--ink);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px; line-height: 1.5;
}
h1, h2, h3, h4, .serif { font-family: 'Source Serif 4', ui-serif, Georgia, serif; }
.mono, code, .fit-score, .co-sub.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
svg.icon { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -3px; }

/* ===================== App shell / sidebar ===================== */
.shell { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar {
  width: 248px; flex: none; background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 4px;
  border-right: 1px solid var(--sidebar-border); position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(155deg, var(--blueprint), #0E2E60);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.brand-mark svg { width: 16px; height: 16px; stroke: #DCE7FB; }
.brand-name { display: block; font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 15.5px; color: #fff; line-height: 1.15; }
.brand-sub { display: block; font-size: 10.5px; color: var(--sidebar-ink-dim); letter-spacing: .04em; text-transform: uppercase; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-ink-dim); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; color: var(--sidebar-ink); text-decoration: none;
}
.nav-item svg { color: var(--sidebar-ink-dim); }
.nav-item:hover { background: rgba(255,255,255,.04); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.active svg { color: var(--blueprint-ink); }
.nav-item .count {
  margin-left: auto; font-size: 11px; background: rgba(255,255,255,.08); color: var(--sidebar-ink);
  padding: 1px 7px; border-radius: 999px; font-family: 'IBM Plex Mono', monospace;
}
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--sidebar-border); display: flex; align-items: center; gap: 9px; }
.avatar-sm {
  width: 26px; height: 26px; border-radius: 50%; background: var(--blueprint-soft); color: var(--blueprint-soft-ink);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none;
}
.who-wrap { min-width: 0; flex: 1; }
.sidebar-footer .who { display: block; font-size: 12px; color: var(--sidebar-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer .role { display: block; font-size: 10.5px; color: var(--sidebar-ink-dim); }
.sidebar-footer a { color: var(--sidebar-ink-dim); display: flex; }
.sidebar-toggle { display: none; }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1180px; }
.auth-main { max-width: 440px; margin: 4rem auto; padding: 0 16px; }

/* ===================== Page head / toolbar ===================== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1, .page-head h2 { font-size: 23px; margin: 0 0 4px; font-weight: 600; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; max-width: 60ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pill-btn, .segment-toggle a {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; cursor: pointer;
  text-decoration: none;
}
.pill-btn.on, .segment-toggle a[aria-current="true"] { background: var(--blueprint-soft); border-color: var(--blueprint-soft); color: var(--blueprint-soft-ink); }
input[type="search"], input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="file"], select, textarea {
  font-family: inherit;
}
.search-box {
  display: flex; align-items: center; gap: 7px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; color: var(--muted-2); font-size: 13px;
}
.search-box svg { color: var(--muted-2); }
.search-box input { border: none !important; background: transparent !important; padding: 0 !important; width: 100%; font-size: 13px; }
.search-box input:focus { outline: none; box-shadow: none; }

.filter-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-form .search-box { flex: 1 1 220px; min-width: 180px; padding: 6px 10px; }
.filter-form .search-box input { font-size: 12.5px; }
.filter-form select, .filter-form button {
  width: auto; flex: 0 0 auto; margin: 0; font-size: 12.5px; padding: 6px 10px; line-height: 1.3; height: auto;
}
.filter-form label {
  display: flex; align-items: center; gap: 5px; width: auto; margin: 0; font-size: 12.5px; white-space: nowrap;
}
.filter-form input[type="checkbox"] { width: 15px; height: 15px; margin: 0; }

/* ===================== Buttons ===================== */
.btn, button, input[type="submit"], [role="button"] {
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; font-family: inherit;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn svg, button svg { width: 14px; height: 14px; }
.btn-primary, button:not(.secondary):not(.contrast):not(.btn-ghost), input[type="submit"] {
  background: var(--blueprint); border-color: var(--blueprint); color: #fff;
}
.btn-primary:hover, button:not(.secondary):not(.contrast):not(.btn-ghost):hover { background: var(--blueprint-ink); border-color: var(--blueprint-ink); }
button.secondary, .btn-secondary { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-ghost, button.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.contrast { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ===================== Stat tiles ===================== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.stat .value { font-family: 'IBM Plex Mono', monospace; font-size: 22px; font-weight: 600; }
.stat.accent .value { color: var(--blueprint); }
.stat.warn .value { color: var(--warn); }
.stat.good .value { color: var(--good); }

/* ===================== Cards / panels ===================== */
article, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 22px; padding: 16px 18px;
}
.panel { padding: 0; }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; border-radius: var(--radius) var(--radius) 0 0; }
.panel-head h2, .panel-head h3, .panel-head strong { font-size: 14.5px; font-weight: 600; margin: 0; }
.panel-body { padding: 16px 18px; }
article > header { margin: -16px -18px 16px; padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }

/* ===================== Tables ===================== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2);
  font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
table th a { cursor: pointer; }
table th a:hover { color: var(--blueprint-ink); }
table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover { background: var(--surface-2); }
table.candidates, .table-wrap table {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.table-wrap { overflow-x: auto; margin-bottom: 22px; }
.table-wrap table { margin-bottom: 0; }

.co-cell { display: flex; align-items: center; gap: 10px; }
.co-icon {
  width: 28px; height: 28px; border-radius: 7px; flex: none; display: flex; align-items: center; justify-content: center;
  font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 12.5px; color: #fff; background: var(--blueprint);
}
.co-name { font-weight: 600; }
.co-sub { font-size: 11.5px; color: var(--muted); }
.contact-cell { display: flex; align-items: center; gap: 8px; }
.person-dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--neutral-soft); color: var(--neutral); flex: none;
  display: flex; align-items: center; justify-content: center;
}
.person-dot svg { width: 12px; height: 12px; }
.fit-score { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; }
.fit-score .bar { display: inline-block; width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin-left: 8px; overflow: hidden; }
.fit-score .bar i { display: block; height: 100%; background: var(--blueprint); }

/* ===================== Badges (tinted pills) ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; white-space: nowrap; letter-spacing: .01em; text-transform: none;
}
.badge-new { background: var(--neutral-soft); color: var(--neutral); }
.badge-qualified { background: var(--blueprint-soft); color: var(--blueprint-soft-ink); }
.badge-pursuing { background: var(--blueprint-soft); color: var(--blueprint-soft-ink); }
.badge-rejected { background: var(--bad-soft); color: var(--bad); }
.badge-pitched { background: var(--warn-soft); color: var(--warn); }
.badge-bid_submitted { background: var(--warn-soft); color: var(--warn); }
.badge-won { background: var(--good-soft); color: var(--good); }
.badge-lost { background: var(--neutral-soft); color: var(--muted-2); }
/* generic semantic aliases used directly in some templates */
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge-accent { background: var(--blueprint-soft); color: var(--blueprint-soft-ink); }
.badge-brass { background: var(--brass-soft); color: var(--brass); }
.admin-lock {
  display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 600; color: var(--brass);
  background: var(--brass-soft); padding: 2px 8px; border-radius: 999px;
}
.admin-lock svg { width: 11px; height: 11px; }

/* ===================== Misc existing components (kept, restyled) ===================== */
.error-box { border-left: 4px solid var(--bad); background: var(--bad-soft); color: var(--bad); padding: .75rem 1rem; margin-bottom: 1rem; border-radius: 0 8px 8px 0; }
.segment-toggle ul { display: flex; gap: .5rem; margin-bottom: 1rem; padding-left: 0; list-style: none; }
.score { font-weight: 700; font-size: 1.1rem; }
.evidence-item { border-bottom: 1px solid var(--border); padding: .5rem 0; }
.evidence-item:last-child { border-bottom: none; }
.evidence-source { font-size: .85rem; color: var(--muted); }

.timeline-item { border-left: 2px solid var(--border); padding: 0 0 1rem 1rem; margin-left: .4rem; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--blueprint); }

.status-actions form { display: inline-block; margin-right: .5rem; }
dialog article { max-width: 480px; }
.priority-controls button { padding: .1rem .5rem; font-size: .8rem; }
.masked-key { font-family: 'IBM Plex Mono', monospace; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.detail-grid.even { grid-template-columns: 1fr 1fr; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 48px 24px; color: var(--muted); }
.empty-state svg { width: 40px; height: 40px; color: var(--muted-2); }
.empty-state p { max-width: 40ch; margin: 0; }

.page-context {
  display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin: 4px 0 14px;
}
.page-context .crumb { font-family: 'IBM Plex Mono', monospace; }

/* ===================== Responsive ===================== */
.sidebar-toggle {
  position: fixed; top: 12px; left: 12px; z-index: 20; background: var(--sidebar-bg); color: #fff; border: none;
  border-radius: 8px; padding: 8px; display: none;
}
@media (max-width: 860px) {
  .sidebar-toggle { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; z-index: 15; transform: translateX(-100%);
    transition: transform .18s ease; box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
  }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .main { padding: 64px 16px 40px; max-width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  table.candidates, .table-wrap { display: block; overflow-x: auto; }
}
