:root {
  --mist: #F3F6F5;
  --panel: #FFFFFF;
  --ink: #16222C;
  --ink-2: #4A5964;
  --ink-3: #7D8B94;
  --line: #DDE4E2;
  --line-2: #EAEFEE;
  --spruce: #1E5F51;
  --spruce-soft: #E3EFEA;
  --brass: #B9832B;
  --brass-soft: #F6ECDA;
  --brick: #A3473A;
  --brick-soft: #F6E4E1;
  /* Stage sequence: pale to deep, then brass for closed */
  --s1: #BFD6CE;
  --s2: #8DB8A9;
  --s3: #5E9784;
  --s4: #2F735F;
  --s5: #B9832B;

  --display: 'Young Serif', Georgia, serif;
  --body: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 34, 44, .06), 0 4px 14px rgba(22, 34, 44, .05);
  --side: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--mist);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--spruce); }
:focus-visible { outline: 2px solid var(--spruce); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  background: var(--ink); color: #C9D3D8;
  padding: 22px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; color: #fff; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--display); font-size: 18px; line-height: 1.1; }
.brand-name small { display: block; font: 500 11px/1.4 var(--mono); color: #8FA0A8; letter-spacing: .06em; text-transform: uppercase; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  color: inherit; text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav a.active svg { color: var(--brass); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side-foot b { color: #fff; font-weight: 600; display: block; }
.link-btn { background: none; border: 0; padding: 0; color: #8FA0A8; cursor: pointer; text-decoration: underline; font-size: 13px; }
.link-btn:hover { color: #fff; }

.main { min-width: 0; padding: 28px 32px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.1; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); font-size: 14px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
  text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--spruce); border-color: var(--spruce); color: #fff; }
.btn.primary:hover { background: #174C41; }
.btn.danger { color: var(--brick); }
.btn.danger:hover { border-color: var(--brick); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.input:focus { outline: none; border-color: var(--spruce); box-shadow: 0 0 0 3px var(--spruce-soft); }
textarea.input { resize: vertical; min-height: 80px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filters .input { width: auto; min-width: 140px; }
.filters .search { flex: 1; min-width: 200px; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.chip.won { background: var(--brass-soft); color: #7A5418; }
.chip.lost { background: var(--brick-soft); color: var(--brick); }
.chip.web { background: var(--spruce-soft); color: var(--spruce); }
.chip.due { background: var(--brick-soft); color: var(--brick); }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--ink-3); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 14px; }
.card h2 small { font-weight: 500; color: var(--ink-3); margin-left: 6px; }

/* ---------- pipeline board ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 14px; align-items: start; overflow-x: auto; padding-bottom: 8px; }
.col { background: #E9EFED; border-radius: var(--radius); min-height: 240px; display: flex; flex-direction: column; }
.col.drop { background: var(--spruce-soft); box-shadow: inset 0 0 0 2px var(--s3); }
.col-head { padding: 12px 12px 10px; border-top: 4px solid var(--stage); border-radius: var(--radius) var(--radius) 0 0; }
.col-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.step-no {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font: 500 11px var(--mono); background: var(--stage); color: #fff;
}
.col-title .count { margin-left: auto; font: 500 12px var(--mono); color: var(--ink-3); }
.col-sub { font: 500 12px var(--mono); color: var(--ink-3); margin-top: 3px; padding-left: 30px; }
.col-hint { font-size: 12px; color: var(--ink-3); padding-left: 30px; }
.col-body { padding: 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.col-empty { font-size: 13px; color: var(--ink-3); text-align: center; padding: 22px 8px; border: 1.5px dashed #C9D4D1; border-radius: 8px; }

.lead-card {
  background: var(--panel); border-radius: 8px; padding: 11px 12px; cursor: pointer;
  border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(22,34,44,.05); text-align: left; width: 100%;
  display: block; color: inherit; text-decoration: none;
}
.lead-card:hover { border-color: var(--ink-3); }
.lead-card.dragging { opacity: .45; }
.lead-card .name { font-weight: 700; font-size: 14px; }
.lead-card .meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lead-card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.lead-card .money { font: 500 13px var(--mono); color: var(--ink); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #F7FAF9; }
table.list td .sub { font-size: 12px; color: var(--ink-3); }
.stage-dot { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.stage-dot::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--stage); }

.empty { text-align: center; padding: 56px 20px; }
.empty h3 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 0 0 6px; }
.empty p { color: var(--ink-3); margin: 0 0 18px; }

/* ---------- lead profile ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); text-decoration: none; font-size: 14px; margin-bottom: 12px; }
.back:hover { color: var(--ink); }
.profile-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.profile-head h1 { font-family: var(--display); font-weight: 400; font-size: 32px; margin: 0; line-height: 1.1; }
.profile-head .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

/* Signature: the stage route */
.route { display: grid; grid-template-columns: repeat(5, 1fr); margin: 22px 0; position: relative; }
.route button {
  border: 0; background: none; cursor: pointer; padding: 0 4px; text-align: left; position: relative;
  display: flex; flex-direction: column; gap: 8px;
}
.route .bar { height: 8px; background: var(--line); border-radius: 0; }
.route button:first-child .bar { border-radius: 4px 0 0 4px; }
.route button:last-child .bar { border-radius: 0 4px 4px 0; }
.route button.reached .bar { background: var(--stage); }
.route .lbl { display: flex; gap: 8px; align-items: baseline; font-size: 13px; font-weight: 600; color: var(--ink-3); }
.route .lbl .mono { font-size: 11px; }
.route button.reached .lbl { color: var(--ink); }
.route button.current .lbl::after { content: 'current'; font: 500 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--stage); margin-left: auto; padding-right: 4px; }
.route button:hover:not(.current) .bar { box-shadow: inset 0 0 0 2px var(--s3); }
.route.lost .bar { background: var(--line) !important; }
.lost-banner { background: var(--brick-soft); color: var(--brick); padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }

.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; align-items: start; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; margin: 0; font-size: 14px; }
.dl dt { color: var(--ink-3); }
.dl dd { margin: 0; word-break: break-word; }
.section + .section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.section h3 { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 12px; }
.notes { white-space: pre-wrap; font-size: 14px; }

.composer { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.composer .types { display: flex; gap: 6px; flex-wrap: wrap; }
.composer .types button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 13px; cursor: pointer; }
.composer .types button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.timeline .ico { width: 28px; height: 28px; border-radius: 50%; background: var(--line-2); display: grid; place-items: center; color: var(--ink-2); }
.timeline .ico svg { width: 14px; height: 14px; }
.timeline li.sys .ico { background: var(--spruce-soft); color: var(--spruce); }
.timeline .what { font-size: 14px; white-space: pre-wrap; }
.timeline .when { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; align-items: center; }
.timeline .when button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 12px; padding: 0; text-decoration: underline; }

/* ---------- analytics ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.kpi .value { font-family: var(--display); font-size: 32px; line-height: 1.15; margin-top: 4px; }
.kpi .foot { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.delta.up { color: var(--spruce); font-weight: 600; }
.delta.down { color: var(--brick); font-weight: 600; }
.kpi.feature { background: var(--ink); color: #fff; border-color: var(--ink); }
.kpi.feature .label, .kpi.feature .foot { color: #A9B7BE; }
.kpi.feature .value { color: #fff; }
.kpi.feature .delta { color: #fff; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 18px; }
.chart-box { position: relative; height: 260px; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 10px; background: var(--line-2); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--spruce); border-radius: 5px; }
.hbar .n { font-family: var(--mono); text-align: right; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.funnel-row .track { height: 26px; display: flex; justify-content: center; }
.funnel-row .fill { height: 100%; background: var(--stage); border-radius: 4px; min-width: 3px; }
.funnel-row .n { font-family: var(--mono); text-align: right; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.no-data { color: var(--ink-3); font-size: 14px; padding: 30px 0; text-align: center; }

/* ---------- settings ---------- */
.settings { display: grid; gap: 18px; max-width: 860px; }
.code {
  background: var(--ink); color: #DDE6EA; padding: 14px; border-radius: 8px; overflow-x: auto;
  font: 12.5px/1.55 var(--mono); white-space: pre; margin: 10px 0 0;
}
.keyline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.keyline code { font-family: var(--mono); background: var(--line-2); padding: 6px 10px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(22, 34, 44, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(22,34,44,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head h2 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 0; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.form-section { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; margin: 8px 0 -2px; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--ink-3); }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.error { color: var(--brick); font-size: 14px; margin: 0; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-art { background: var(--ink); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art h1 { font-family: var(--display); font-weight: 400; font-size: 44px; line-height: 1.08; margin: 0; max-width: 12ch; }
.auth-art p { color: #A9B7BE; max-width: 36ch; }
.auth-route { display: flex; gap: 6px; margin-top: 28px; }
.auth-route span { flex: 1; height: 6px; border-radius: 3px; }
.auth-route-lbl { display: flex; justify-content: space-between; font: 500 11px var(--mono); color: #8FA0A8; margin-top: 8px; text-transform: uppercase; letter-spacing: .05em; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { font-family: var(--display); font-weight: 400; font-size: 26px; margin: 0; }
.auth-form p { margin: 0; color: var(--ink-3); font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 500;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- mobile ---------- */
.mobile-top, .tabbar { display: none; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3, .profile-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 16px 16px 96px; }
  .mobile-top {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--ink); color: #fff;
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-top .brand-name { font-size: 16px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--ink); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #8FA0A8; text-decoration: none; font-size: 11px; font-weight: 600; padding: 4px; }
  .tabbar a.active { color: #fff; }
  .tabbar a.active svg { color: var(--brass); }
  .tabbar svg { width: 20px; height: 20px; }
  .page-head h1 { font-size: 26px; }
  .board { grid-template-columns: repeat(5, 82vw); overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 8px; }
  .col { scroll-snap-align: center; }
  .filters .input { min-width: 0; flex: 1 1 140px; }
  .route { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .route .lbl { flex-direction: column; gap: 0; font-size: 11px; }
  .route button.current .lbl::after { display: none; }
  .dl { grid-template-columns: 110px 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 20px; }
  .auth-art h1 { font-size: 32px; }
  .hide-sm { display: none; }
  .kpi .value { font-size: 26px; }
  .hbar { grid-template-columns: 96px 1fr 36px; }
  .funnel-row { grid-template-columns: 96px 1fr 56px; }
  .modal-bg { padding: 0; place-items: end stretch; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
