:root {
  --ink: #16211d;
  --soft: #5b6a64;
  --faint: #8a978f;
  --line: #e2e7e4;
  --surface: #fff;
  --canvas: #f6f8f7;
  --brand: #1f5f4a;
  --brand-soft: #eaf1ee;
  --danger: #b02a37;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

.shell { min-height: 100vh; }
[hidden] { display: none !important; }

/* ── Sign-in gate ────────────────────────────────────────────────────────── */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 1px 2px rgb(22 33 29 / 6%), 0 12px 32px -16px rgb(22 33 29 / 22%);
}

.gate-title { font-size: 24px; margin: 4px 0 8px; letter-spacing: -0.02em; }
.gate-lede { font-size: 14px; line-height: 1.6; color: var(--soft); margin: 0 0 22px; }
.gate-submit { width: 100%; justify-content: center; margin-top: 14px; }

.gate-message {
  margin-top: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  padding: 11px 13px;
  border-radius: 8px;
  display: none;
}

.gate-message[data-kind="ok"] { display: block; background: #d1e7dd; color: #0a3622; }
.gate-message[data-kind="error"] { display: block; background: #f8d7da; color: #58151c; }
.gate-message[data-kind="info"] { display: block; background: var(--brand-soft); color: var(--brand); }

.gate-foot {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--faint);
  line-height: 1.55;
}

/* ── Topbar additions ────────────────────────────────────────────────────── */

.topbar-identity { min-width: 0; }

.user-badge {
  font-size: 12.5px;
  color: var(--faint);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tenant-switcher {
  width: auto;
  min-width: 150px;
  padding: 7px 10px;
  font-size: 13.5px;
}

@media (max-width: 860px) {
  .user-badge { display: none; }
  .topbar { flex-wrap: wrap; }
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 61px;
  z-index: 9;
}

.tab {
  padding: 11px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--soft);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

.tab-count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-left: 4px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
}

.leads-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 28px 80px;
}

/* ── Leads table ─────────────────────────────────────────────────────────── */

.leads-table { width: 100%; border-collapse: collapse; }

.leads-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--line);
}

.leads-table td {
  padding: 11px 10px 11px 0;
  font-size: 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  vertical-align: top;
}

.leads-table tbody tr { cursor: pointer; }
.leads-table tbody tr:hover { background: var(--canvas); }
.leads-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.lead-sub { display: block; font-size: 12px; color: var(--faint); margin-top: 2px; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.pill[data-status="new"]           { background: #e0edff; color: #14417a; }
.pill[data-status="contacted"]     { background: #fff0d6; color: #7a4f0d; }
.pill[data-status="visit_planned"] { background: #ede0ff; color: #4b1a86; }
.pill[data-status="quoted"]        { background: #d9f0ea; color: #10493c; }
.pill[data-status="won"]           { background: #d1e7dd; color: #0a3622; }
.pill[data-status="lost"]          { background: #f1f1f1; color: #5c5c5c; }

.mail-warn { color: var(--danger); font-size: 12px; }

.lead-detail { padding: 16px 0 0; }
.lead-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 18px; font-size: 14px; }
.lead-detail dt { color: var(--soft); }
.lead-detail dd { margin: 0; font-weight: 600; }

.lead-lines { width: 100%; border-collapse: collapse; margin-top: 6px; }
.lead-lines td { padding: 5px 0; font-size: 13px; border-bottom: 1px solid #f0f3f1; }
.lead-lines td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
}

.topbar h1 { font-size: 19px; margin: 2px 0 0; letter-spacing: -0.015em; }
.topbar-actions { display: flex; gap: 9px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 17px; font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 999px; border: 1.5px solid transparent; cursor: pointer;
  transition: background 140ms, border-color 140ms, color 140ms;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, black); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--soft); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); border-color: var(--faint); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 290px;
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 80px;
  align-items: start;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 280px; }
  .sidenav { display: none; }
}

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static !important; }
}

.sidenav { position: sticky; top: 88px; display: grid; gap: 2px; }

.sidenav a {
  padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 500;
  color: var(--soft); text-decoration: none;
}

.sidenav a:hover { background: var(--surface); color: var(--ink); }
.sidenav a[aria-current="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ── Panels ──────────────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  scroll-margin-top: 88px;
}

.panel h2 { font-size: 17px; margin: 0 0 6px; letter-spacing: -0.015em; }
.lede { font-size: 13.5px; line-height: 1.55; color: var(--soft); margin: 0 0 18px; max-width: 62ch; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 620px) { .grid { grid-template-columns: 1fr; } }
.grid .span-2 { grid-column: 1 / -1; }

label.field { display: block; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field-hint { font-size: 12px; color: var(--faint); margin-top: 4px; line-height: 1.45; }

input[type="text"], input[type="number"], input[type="url"], input[type="email"], select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 8px;
  transition: border-color 140ms, box-shadow 140ms;
}

input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 13%, transparent);
}

textarea { resize: vertical; min-height: 96px; line-height: 1.5; font-family: inherit; }

/* ── Price rows ──────────────────────────────────────────────────────────── */

.price-group { margin-bottom: 22px; }

.price-group-head {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--faint); padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}

.price-row {
  display: grid;
  grid-template-columns: 1fr 132px 34px;
  gap: 14px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}

@media (max-width: 620px) {
  .price-row { grid-template-columns: 1fr 110px 34px; gap: 10px; }
}

.price-name { font-size: 14px; font-weight: 500; }
.price-key { font-size: 11.5px; color: var(--faint); font-family: ui-monospace, Menlo, monospace; margin-top: 2px; }
.price-note { font-size: 12px; color: var(--faint); margin-top: 3px; line-height: 1.45; }
.price-row[data-disabled="true"] .price-name,
.price-row[data-disabled="true"] .price-key { opacity: .45; }

.price-input-wrap { position: relative; display: flex; align-items: center; }
.price-input-wrap input { padding-right: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.price-unit { position: absolute; right: 11px; font-size: 12.5px; color: var(--faint); pointer-events: none; }

.toggle { display: grid; place-items: center; }
.toggle input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; }

.changed { border-color: var(--brand) !important; background: color-mix(in srgb, var(--brand) 5%, white); }

/* ── Preview ─────────────────────────────────────────────────────────────── */

.preview { position: sticky; top: 88px; }

.preview-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.preview-label {
  font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--faint);
}

.preview-desc { font-size: 12.5px; color: var(--soft); line-height: 1.5; margin: 8px 0 14px; }

.preview-amount {
  font-size: 28px; font-weight: 700; letter-spacing: -0.025em;
  color: var(--brand); font-variant-numeric: tabular-nums; line-height: 1.1;
}

.preview-caption { font-size: 12px; color: var(--faint); margin-top: 3px; }

.preview-delta { font-size: 12.5px; font-weight: 600; margin-top: 8px; min-height: 18px; }
.preview-delta[data-dir="up"] { color: var(--danger); }
.preview-delta[data-dir="down"] { color: var(--brand); }

.preview-lines {
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line);
  display: grid; gap: 6px; font-size: 12.5px;
}

.preview-line { display: flex; justify-content: space-between; gap: 10px; color: var(--soft); }
.preview-line span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--ink); color: #fff; opacity: 0; pointer-events: none;
  transition: opacity 180ms, transform 180ms;
}

.toast[data-visible="true"] { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[data-kind="error"] { background: var(--danger); }
