/* ---------- tokens ---------- */
:root {
  --ink-900: #11161f;
  --ink-700: #2b3442;
  --ink-500: #5a6678;
  --ink-300: #9aa6b6;
  --line: #e3e7ee;
  --line-strong: #cdd4df;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eef2f7;

  --accent: #2f5bea;       /* decisive indigo */
  --accent-700: #1f3fb0;
  --accent-100: #e7edff;

  --ok: #0f9d6a;
  --ok-100: #e1f6ee;
  --warn: #b8791a;
  --warn-100: #fbf0db;
  --bad: #d0453f;
  --bad-100: #fbe6e5;
  --term: #6b4fd6;
  --term-100: #ece7fb;
  --dirty: #fff6e0;
  --dirty-line: #e7c878;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 1px 2px rgba(17, 22, 31, .06), 0 1px 3px rgba(17, 22, 31, .05);
  --shadow-2: 0 6px 24px rgba(17, 22, 31, .12);
  --font: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--ink-900);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  padding: 0 20px;
  background: var(--ink-900);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px; object-fit: cover;
  background: rgba(255, 255, 255, .08);
}
.brand-name { font-weight: 650; letter-spacing: -.01em; }

.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  appearance: none; border: 0; background: transparent;
  color: rgba(255, 255, 255, .68);
  font: inherit; font-weight: 550;
  padding: 7px 13px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s, color .15s;
}
.tab:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.tab.is-active { color: #fff; background: rgba(255, 255, 255, .14); }

.user-chip {
  margin-left: auto; display: flex; flex-direction: column; align-items: flex-end;
  line-height: 1.15;
}
.user-name { font-weight: 600; }
.user-role {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: rgba(255, 255, 255, .55);
}

/* ---------- layout ---------- */
.content { padding: 20px; max-width: 1480px; margin: 0 auto; }
.panel { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.placeholder {
  background: var(--surface); border: 1px dashed var(--line-strong);
  border-radius: var(--radius); padding: 64px; text-align: center; color: var(--ink-500);
}
.placeholder h2 { margin: 0 0 6px; color: var(--ink-700); }

.state-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 40px; text-align: center; color: var(--ink-500);
}
.state-card.inline { box-shadow: none; border: 0; padding: 48px 24px; }
.state-card h2 { margin: 0 0 8px; color: var(--ink-900); }

/* ---------- quarter picker (primary, step 1) ---------- */
.quarter-bar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: var(--ink-900); color: #fff;
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 14px;
}
.quarter-pick { display: flex; align-items: center; gap: 12px; }
.quarter-pick label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: rgba(255, 255, 255, .6);
}
.quarter-pick select {
  height: 42px; min-width: 280px; font-size: 15px; font-weight: 650;
  background: rgba(255, 255, 255, .08); color: #fff;
  border-color: rgba(255, 255, 255, .2);
}
.quarter-pick select:focus { border-color: #5b86ff; box-shadow: 0 0 0 3px rgba(91, 134, 255, .3); }
.quarter-pick select option { color: var(--ink-900); }
.quarter-hint { margin: 0; font-size: 12px; color: rgba(255, 255, 255, .55); }

/* ---------- controls ---------- */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.control { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.control label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-500);
}
.control.search { grid-column: span 2; }
.control.date-range { grid-column: span 2; }
.date-range .range-inputs input { width: 100%; }

/* Falcon lead link */
.lead-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; margin-left: 4px; vertical-align: -3px;
  color: var(--ink-300); border-radius: 5px; text-decoration: none;
  transition: color .15s, background .15s;
}
.lead-link:hover { color: var(--accent); background: var(--accent-100); }
.lead-link svg { width: 13px; height: 13px; }

select, input[type="text"], input[type="search"], input[type="date"] {
  width: 100%; font: inherit; color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px; height: 36px;
  transition: border-color .15s, box-shadow .15s;
}
select { cursor: pointer; }
select:focus, input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-100);
}
.range-inputs { display: flex; align-items: center; gap: 6px; }
.range-inputs input { width: 100%; }
.range-inputs .dash { color: var(--ink-300); }

.clear-btn { align-self: end; height: 36px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); padding: 8px 14px; height: 36px;
  border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-700); }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink-700); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.link { background: transparent; color: var(--accent); border: 0; padding: 8px 6px; }
.btn.link:hover { color: var(--accent-700); text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 16px 2px 10px;
}
.result-count { color: var(--ink-500); font-weight: 550; }
.result-count span { color: var(--ink-900); font-weight: 700; }
#selInfo { color: var(--accent); }
.toolbar-right { display: flex; align-items: center; gap: 12px; }
.updated-label { font-size: 12px; color: var(--ink-300); white-space: nowrap; }

/* ---------- bulk bar ---------- */
.bulk-bar {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  background: var(--accent-100);
  border: 1px solid #c5d3ff;
  border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px;
}
.bulk-label { align-self: center; color: var(--accent-700); }
.bulk-label strong { font-size: 16px; }
.bulk-field { display: flex; flex-direction: column; gap: 4px; }
.bulk-field label { font-size: 11px; font-weight: 600; color: var(--ink-500); text-transform: uppercase; letter-spacing: .05em; }
.bulk-field select, .bulk-field input { min-width: 170px; background: #fff; }
.bulk-bar .ghost { background: #fff; }

/* ---------- table ---------- */
.table-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-1);
  max-height: calc(100vh - 320px);
}
.leads-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.leads-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-3);
  color: var(--ink-700); font-weight: 600; text-align: left;
  padding: 10px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
.leads-table tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle;
}
.leads-table tbody tr:hover td { background: var(--surface-2); }
.leads-table tbody tr.is-dirty td { background: var(--dirty); }
.leads-table tbody tr.is-dirty:hover td { background: #fdf0d2; }
.leads-table tbody tr.is-selected td { box-shadow: inset 3px 0 0 var(--accent); }

.col-check { width: 38px; text-align: center; }
.col-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.lead-name { font-weight: 600; color: var(--ink-900); }
.lead-id { font-family: var(--mono); font-size: 12px; color: var(--ink-500); }
.cell-muted { color: var(--ink-300); }
.num { font-variant-numeric: tabular-nums; }

/* status pills */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.pill.none { background: var(--surface-3); color: var(--ink-500); }
.pill.health { background: var(--ok-100); color: var(--ok); }
.pill.term { background: var(--term-100); color: var(--term); }
.pill.both { background: var(--accent-100); color: var(--accent-700); }
.pill.yes { background: var(--ok-100); color: var(--ok); }
.pill.no { background: var(--bad-100); color: var(--bad); }
.pill.na { background: var(--surface-3); color: var(--ink-500); }
.pill.warnish { background: var(--warn-100); color: var(--warn); }

/* editable cells */
.cell-edit select, .cell-edit input { height: 32px; padding: 5px 8px; font-size: 13px; }
.cell-edit select { min-width: 150px; }
.mts-cell { display: flex; align-items: center; gap: 4px; }
.mts-cell .rupee { color: var(--ink-300); font-weight: 600; }
.mts-cell input { width: 120px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- save bar ---------- */
.save-bar {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 60;
  display: flex; align-items: center; gap: 20px;
  background: var(--ink-900); color: #fff;
  padding: 12px 16px 12px 20px; border-radius: 12px;
  box-shadow: var(--shadow-2);
  animation: rise .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.save-msg strong { color: #ffd479; }
.save-actions { display: flex; gap: 8px; }
.save-bar .ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.save-bar .ghost:hover { background: rgba(255,255,255,.1); }
.save-bar .hide-btn { border-color: transparent; color: rgba(255,255,255,.55); padding: 8px 10px; }
.save-bar .hide-btn:hover { background: rgba(255,255,255,.1); color: #fff; }

/* minimized restore chip */
.save-mini {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  display: flex; align-items: center; gap: 7px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--ink-900); color: #fff;
  border: 0; border-radius: 999px; padding: 9px 15px;
  box-shadow: var(--shadow-2); animation: rise .2s ease;
}
.save-mini:hover { background: var(--ink-700); }
.save-mini .dot { width: 8px; height: 8px; border-radius: 50%; background: #ffd479; }
.save-mini strong { color: #ffd479; }
.save-mini kbd {
  font: inherit; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,.15); border-radius: 4px; padding: 1px 6px; margin-left: 2px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  z-index: 70;
  background: var(--ink-700); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-weight: 550;
  box-shadow: var(--shadow-2); animation: rise .2s ease;
  max-width: 90vw;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .brand-name { display: none; }
  .content { padding: 12px; }
  .control.search { grid-column: span 1; }
  .table-wrap { max-height: none; }
  .save-bar { left: 12px; right: 12px; transform: none; bottom: 12px; justify-content: space-between; }
  .save-mini { right: 12px; bottom: 12px; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}