:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #9ca3af;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --violet: #7c3aed;
  --violet-soft: #f5f3ff;
  --side-bg: #0f172a;
  --side-text: #cbd5e1;
  --side-active: #1e293b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #161d2d;
    --border: #222b3d;
    --text: #e5e7eb;
    --text-2: #a3acbd;
    --text-3: #6b7589;
    --accent: #60a5fa;
    --accent-soft: #172554;
    --green: #34d399;
    --green-soft: #052e24;
    --amber: #fbbf24;
    --amber-soft: #2d2206;
    --violet: #a78bfa;
    --violet-soft: #241a45;
    --side-bg: #080b12;
    --side-active: #151c2c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--side-bg); color: var(--side-text); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1); font-weight: 700; letter-spacing: .5px;
}
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: #94a3b8; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--side-text); font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-foot { margin-top: auto; padding: 10px 12px; font-size: 12px; }
.side-foot a { color: #94a3b8; }

.main { padding: 28px 36px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* ---- cards & grids ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.card-head h2 { font-size: 14.5px; font-weight: 600; margin: 0; }
.card-head a { font-size: 13px; }
.card-body { padding: 14px 20px 18px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.grid-side { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.stack > * + * { margin-top: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { padding: 18px 20px; }
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 28px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; }
.list-main { min-width: 0; flex: 1; }
.list-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.list-title a { color: var(--text); }
.list-meta { color: var(--text-3); font-size: 12.5px; margin-left: auto; white-space: nowrap; }
.list-text { color: var(--text-2); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 13px;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.checklist { list-style: none; padding: 0; margin: 6px 0 0; }
.checklist li { display: flex; gap: 8px; padding: 3px 0; color: var(--text); }
.checklist li::before { content: ""; width: 14px; height: 14px; border: 1.5px solid var(--text-3); border-radius: 4px; margin-top: 3px; flex: none; }

/* ---- tables ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; height: 38px; min-width: 280px;
}
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; width: 100%; }
.search svg { width: 16px; height: 16px; color: var(--text-3); }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--text-2); font-weight: 500; font-size: 13px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
td { padding: 13px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.cell-person { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.cell-person a { color: var(--text); }
.muted { color: var(--text-3); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- detail page ---- */
.profile { display: flex; gap: 14px; align-items: center; }
.profile h1 { margin: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--text-3); font-size: 13px; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.section-label { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 8px; }
.vehicle { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.vehicle:first-of-type { border-top: 0; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.tl-item { position: relative; padding: 0 0 24px 28px; }
.tl-item::before { content: ""; position: absolute; left: 7px; top: 22px; bottom: 0; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent-soft); border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--accent); }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-head .when { color: var(--text-3); font-size: 12.5px; margin-left: auto; }
.tl-summary { margin: 8px 0 0; }
.callout { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-top: 10px; }
.callout-title { font-size: 12px; font-weight: 600; color: var(--text-2); }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: 13px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }
.transcript { margin-top: 8px; max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.transcript p { margin: 0 0 8px; }
.speaker { font-weight: 600; margin-right: 6px; }
.speaker.lucas, .speaker.assistant { color: var(--accent); }
.speaker.caller { color: var(--violet); }
audio { width: 100%; margin-top: 8px; height: 36px; }

.empty { text-align: center; padding: 42px 20px; color: var(--text-2); }
.empty svg { width: 36px; height: 36px; color: var(--text-3); margin-bottom: 8px; }
.empty h3 { margin: 0 0 4px; font-size: 15px; color: var(--text); }

/* ---- sidebar extras ---- */
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 16px 12px 6px; }
.office-switch { margin: 0 4px 14px; }
.office-switch select {
  width: 100%; background: var(--side-active); color: #e2e8f0; border: 1px solid #334155; border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 13px;
}
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 4px; border-top: 1px solid #1e293b; margin-top: 10px; }
.side-user .avatar { width: 32px; height: 32px; font-size: 12px; background: #1e293b; color: #cbd5e1; }
.side-user-name { color: #fff; font-weight: 600; font-size: 13px; line-height: 1.2; }
.side-user-role { color: #94a3b8; font-size: 11.5px; }
.link-btn { background: none; border: 0; padding: 0; color: #94a3b8; font: inherit; font-size: 12px; cursor: pointer; }
.link-btn:hover { color: #fff; }

/* ---- forms & buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: #dc2626; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea, .inline-input {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
}
.field textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .inline-input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent);
}
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-weight: 500; }
.alert.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert.ok { background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 30%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) { .alert.error { background: #2a0f12; color: #fca5a5; border-color: #4c1d1d; } }
.copy-row { display: flex; gap: 8px; margin-top: 8px; }
.copy-row input { flex: 1; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form textarea { flex: 1; }

/* task rows */
.task { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.task-check {
  width: 20px; height: 20px; border-radius: 6px; border: 1.8px solid var(--text-3); background: transparent;
  flex: none; margin-top: 1px; cursor: pointer; display: grid; place-items: center; color: #fff; padding: 0;
}
.task-check:hover { border-color: var(--accent); }
.task.done .task-check { background: var(--green); border-color: var(--green); }
.task.done .task-text { color: var(--text-3); text-decoration: line-through; }
.task-main { flex: 1; min-width: 0; }
.task-meta { font-size: 12.5px; color: var(--text-3); }

/* popover editors */
.pop { position: relative; }
.pop > summary { list-style: none; }
.pop > summary::before { content: none; }
.pop[open] > .pop-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(420px, 90vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .18);
}

/* ---- sign-in pages ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 32px 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .brand-mark { color: #fff; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; }
.auth-card p.lead { color: var(--text-2); margin: 0 0 20px; }
.auth-card .field { margin-bottom: 14px; }
.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 10px; margin: 14px 0; border: 1px solid var(--border); }
.qr svg { width: 200px; height: 200px; }
.secret { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; text-align: center; letter-spacing: .08em; font-size: 13px; word-break: break-all; }
.code-input { font-size: 22px !important; letter-spacing: .4em; text-align: center; height: 48px !important; }

/* ---- responsive ---- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-side { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .brand-sub, .side-foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a span, .nav-label, .office-switch, .side-user-name, .side-user-role { display: none; }
  .side-user { border: 0; margin: 0 0 0 auto; padding: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 40px; }
  .search { min-width: 0; width: 100%; }
  .list-title { flex-wrap: wrap; row-gap: 2px; }
  .list-meta { order: 3; width: 100%; margin-left: 0; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 22px; }
  th, td { padding: 10px 12px; }
  .hide-sm { display: none; }
}
