:root {
  --bg: oklch(97% 0.005 260);
  --surface: oklch(100% 0 0);
  --ink: oklch(22% 0.02 260);
  --muted: oklch(55% 0.02 260);
  --line: oklch(90% 0.01 260);
  --sidebar: oklch(26% 0.03 265);
  --sidebar-ink: oklch(88% 0.02 265);
  --accent: oklch(66% 0.19 35);
  --accent-ink: oklch(99% 0 0);
  --ok: oklch(65% 0.16 150);
  --warn: oklch(72% 0.16 75);
  --lost: oklch(60% 0.02 260);
  --radius: 12px;
  --shadow: 0 1px 2px oklch(0% 0 0 / 0.04), 0 8px 24px oklch(0% 0 0 / 0.06);
  --space: clamp(1rem, 0.6rem + 1.4vw, 2rem);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }
h1 { font-size: clamp(1.4rem, 1rem + 1.4vw, 2rem); margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1.6rem 0 0.6rem; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-ink);
  padding: 1.4rem 1rem; display: flex; flex-direction: column; gap: 1.4rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: -0.03em; display: flex; gap: 0.35rem; align-items: baseline; }
.brand span { color: var(--accent); }
.brand-lg { font-size: 1.8rem; justify-content: center; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar nav a {
  padding: 0.6rem 0.8rem; border-radius: 10px; color: var(--sidebar-ink);
  opacity: 0.8; transition: background 150ms, opacity 150ms;
}
.sidebar nav a:hover { opacity: 1; background: oklch(100% 0 0 / 0.06); }
.sidebar nav a.active { background: var(--accent); color: var(--accent-ink); opacity: 1; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; }
.sidebar-foot .who { color: oklch(78% 0.02 265); }
.sidebar-foot .logout { opacity: 0.7; }
.sidebar-foot .logout:hover { opacity: 1; color: var(--accent); }

.content { padding: var(--space); max-width: 1100px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }

/* ---------- Panels / stats ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); margin-bottom: 1.2rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 800px) { .cols { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 0.3rem; }
.stat.accent { background: linear-gradient(160deg, var(--accent), oklch(58% 0.19 30)); color: var(--accent-ink); border: none; }
.stat-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }
.stat-value { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.stat-value.sm { font-size: 1.4rem; }
.stat-sub { font-size: 0.82rem; opacity: 0.75; }

/* ---------- Funnel ---------- */
.funnel-row { display: grid; grid-template-columns: 180px 1fr 48px; align-items: center; gap: 0.8rem; margin: 0.5rem 0; }
.funnel-name { font-size: 0.9rem; color: var(--muted); }
.funnel-bar { background: var(--bg); border-radius: 8px; height: 22px; overflow: hidden; }
.funnel-fill { height: 100%; background: linear-gradient(90deg, var(--accent), oklch(72% 0.16 55)); border-radius: 8px; transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1); }
.funnel-num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--line); }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
tr.clickable { cursor: pointer; transition: background 120ms; }
tr.clickable:hover { background: var(--bg); }
.row-actions { display: flex; gap: 0.4rem; align-items: center; }
.row-actions form { margin: 0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; border: 1px solid transparent; }
.badge.new { background: oklch(94% 0.05 35); color: oklch(45% 0.16 35); }
.badge.in_work { background: oklch(94% 0.05 75); color: oklch(45% 0.14 75); }
.badge.won { background: oklch(93% 0.07 150); color: oklch(42% 0.14 150); }
.badge.lost { background: var(--bg); color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 0.9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: transform 120ms, box-shadow 120ms, background 120ms; }
.btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.btn.danger { color: oklch(52% 0.19 25); border-color: oklch(85% 0.06 25); }
.btn.danger:hover { background: oklch(96% 0.04 25); }
button.badge { cursor: pointer; }
button.badge.current { outline: 2px solid var(--ink); outline-offset: 1px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; max-width: 720px; }
.form-row { display: grid; grid-template-columns: 160px 1fr; gap: 1rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input, textarea { font: inherit; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
input:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; line-height: 1.5; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; }
.status-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Answers / timeline ---------- */
.answers { display: grid; grid-template-columns: 1fr; gap: 0.2rem; margin: 0; }
.answers dt { font-size: 0.82rem; color: var(--muted); }
.answers dd { margin: 0 0 0.7rem; font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 150px auto 1fr; gap: 0.6rem; padding: 0.4rem 0; border-bottom: 1px dashed var(--line); font-size: 0.85rem; }
.t-type { font-weight: 700; }
.t-time { color: var(--muted); }
.t-payload { color: var(--muted); font-family: ui-monospace, monospace; font-size: 0.78rem; }
.lead-name { font-size: 1.2rem; font-weight: 700; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 2.2rem; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 0.9rem; }
.login-card .muted { text-align: center; margin: -0.4rem 0 0.6rem; }
.login-card button { padding: 0.7rem; border: none; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
.login-card button:hover { filter: brightness(1.05); }
.alert { background: oklch(95% 0.05 25); color: oklch(45% 0.18 25); padding: 0.6rem 0.8rem; border-radius: 10px; font-size: 0.88rem; }
