/* Kaleo CRM. Near-black chrome, gold accent, white cards. No inline styles anywhere: classes only. */

:root {
  --ink: #0B0F14;
  --ink-2: #141A22;
  --ink-3: #1E2630;
  --gold: #F5C542;
  --gold-ink: #6B4E00;
  --paper: #F4F6F8;
  --card: #FFFFFF;
  --text: #16202B;
  --muted: #5C6B7A;
  --line: #DDE3EA;
  --blue: #1D5FD0;
  --green: #17794A;
  --amber: #9A6200;
  --red: #B3261E;
  --red-bg: #FDECEA;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 15, 20, .06), 0 8px 24px rgba(11, 15, 20, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7em; }
a { color: var(--blue); }
a:hover { text-decoration-thickness: 2px; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #F7F9FB;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0 0 12px;
  max-height: 340px;
  overflow: auto;
}

[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--gold); color: #111; padding: 10px 14px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

:focus-visible {
  outline: 3px solid #7AA7F0;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- shell ---------- */
.app {
  display: grid;
  grid-template-columns: 216px 1fr;
  grid-template-rows: 56px auto 1fr;
  grid-template-areas:
    "top top"
    "side banner"
    "side view";
  min-height: 100vh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--ink);
  color: #E8EDF3;
  border-bottom: 1px solid #000;
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--gold); color: #1A1400; font-weight: 800; font-size: 15px;
}
.brand-text { font-size: 15px; letter-spacing: .01em; }
.brand-dim { color: #9FB0C2; font-weight: 500; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.who { color: #AFC0D0; font-size: 13px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.agent-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: #C8D4E0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #7F8C99; display: inline-block; }
.dot.is-ok { background: #3BC56B; box-shadow: 0 0 0 3px rgba(59, 197, 107, .18); }
.dot.is-bad { background: #E2574C; box-shadow: 0 0 0 3px rgba(226, 87, 76, .18); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .02em; white-space: nowrap;
}
.badge-local { background: #2B3644; color: var(--gold); border: 1px solid #3A4757; }

.sidebar {
  grid-area: side;
  background: var(--ink);
  color: #C9D5E1;
  padding: 14px 10px 24px;
  border-right: 1px solid #000;
}
.nav-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: #C9D5E1; text-decoration: none; font-size: 14px; border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--ink-3); color: #fff; border-left-color: var(--gold); font-weight: 600; }
.sidebar-note { margin: 0; padding: 10px 12px; font-size: 12px; color: #8C9BAA; line-height: 1.5; border-top: 1px solid #1C242E; }

.nav-toggle {
  display: none;
  width: 36px; height: 32px; border-radius: 8px;
  background: var(--ink-2); border: 1px solid #2B3644; cursor: pointer;
}
.nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after {
  display: block; width: 16px; height: 2px; margin: 0 auto; background: #DDE6EF; border-radius: 2px; position: relative;
}
.nav-toggle-bars::before, .nav-toggle-bars::after { content: ""; position: absolute; left: 0; }
.nav-toggle-bars::before { top: -5px; }
.nav-toggle-bars::after { top: 5px; }

.banner {
  grid-area: banner;
  margin: 14px 22px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--red-bg);
  border: 1px solid #F3B6B0;
  border-left: 4px solid var(--red);
  color: #7A1B15;
  font-size: 14px;
}

.view { grid-area: view; padding: 20px 22px 56px; min-width: 0; }
.view:focus { outline: none; }

/* ---------- primitives ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin: 0 0 16px;
}
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-sub { color: var(--muted); font-size: 13px; margin: -2px 0 12px; }

.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1 1 auto; }

.section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 4px 0 10px; }
.section-head h2 { margin: 0; font-size: 1.05rem; }

.alert-banner {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  background: var(--red-bg); color: #7A1B15; border: 1px solid #F3B6B0;
  border-left: 4px solid var(--red);
  border-radius: var(--radius); padding: 11px 14px; margin: 0 0 16px; font-size: 13.5px;
}

.grid { display: grid; gap: 14px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-tight { gap: 6px; }
.stack { display: grid; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nums { font-variant-numeric: tabular-nums; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }
.pre-line { white-space: pre-line; }
.divider { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

.btn {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: #F2F5F8; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #1B232D; }
.btn-gold { background: var(--gold); border-color: #E0B02D; color: #211900; }
.btn-gold:hover { background: #F7CE5E; }
.btn-ghost { background: transparent; border-color: #3A4757; color: #E8EDF3; }
.btn-ghost:hover { background: var(--ink-2); }
.btn-danger { color: var(--red); border-color: #EBC6C2; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { font-size: 12.5px; padding: 4px 9px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; padding: 10px 14px; font-size: 15px; }

.field { display: grid; gap: 4px; margin-bottom: 12px; align-content: start; }
.grid > * { align-self: start; }
.field > label { font-size: 13px; font-weight: 600; color: #2C3947; }
.field .hint { font-size: 12px; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid #C9D3DD;
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 88px; }
input:disabled, select:disabled, textarea:disabled { background: #F1F4F7; color: #7A8794; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--ink); }
input[type="number"] { max-width: 170px; }

.form-error { color: var(--red); font-size: 13px; margin: 0 0 10px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin: 0; min-width: 132px; }
.filters .field-grow { flex: 1 1 240px; }
.filters .check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; padding-bottom: 7px; }

/* ---------- dashboard ---------- */
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 13px 14px; }
.kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 12px; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.chart { width: 100%; height: auto; max-height: 210px; display: block; }
.pipeline-svg { width: 100%; height: 34px; display: block; }
.pipeline-svg g { cursor: pointer; }
.chart-axis { stroke: #D8DFE7; stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 10px; font-family: var(--font); }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; background: #FAFBFC; position: sticky; top: 0; z-index: 1;
}
table.data tbody tr:hover { background: #FAFCFE; }
table.data tr.is-clickable { cursor: pointer; }
table.data tr.is-clickable:focus-visible { outline: 3px solid #7AA7F0; outline-offset: -3px; }
table.data td.nums { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-strong { font-weight: 600; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap;
  border: 1px solid transparent;
}
.pill-new { background: #E8F0FE; color: #1A4FA0; border-color: #C7DAFB; }
.pill-contacted { background: #FFF4D6; color: var(--gold-ink); border-color: #F3DFA4; }
.pill-engaged { background: #E7F6EC; color: var(--green); border-color: #C2E6CF; }
.pill-skool-free { background: #EFE8FD; color: #5A2FB0; border-color: #D8C9FA; }
.pill-pro { background: var(--gold); color: #2A2000; border-color: #DDB12F; }
.pill-lost { background: #EFF2F5; color: #5E6B78; border-color: #DCE2E8; }
.pill-test { background: #FDECEA; color: var(--red); border-color: #F2C3BE; }
.pill-ok { background: #E7F6EC; color: var(--green); border-color: #C2E6CF; }
.pill-warn { background: #FFF4D6; color: var(--amber); border-color: #F3DFA4; }
.pill-bad { background: var(--red-bg); color: var(--red); border-color: #F2C3BE; }
.pill-neutral { background: #EFF2F5; color: #4D5A67; border-color: #DCE2E8; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #EFF3F7; border: 1px solid #DCE3EA; color: #3C4A57;
  border-radius: 999px; padding: 1px 8px; font-size: 12px; max-width: 100%;
}
.chip-x {
  border: 0; background: transparent; cursor: pointer; font: inherit; line-height: 1;
  color: #6B7885; padding: 0 1px; border-radius: 50%;
}
.chip-x:hover { color: var(--red); }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- lead detail ---------- */
.lead-head { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.lead-name { font-size: 1.4rem; font-weight: 700; margin: 0 0 2px; }
.lead-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 5px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 200px 1fr; gap: 12px; font-size: 13.5px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.timeline li:last-child { border-bottom: 0; padding-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.timeline li > span { color: var(--muted); font-size: 12.5px; white-space: normal; }
.overdue { color: var(--red); font-weight: 650; }
.done-task { color: var(--muted); text-decoration: line-through; }

.draft { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #FCFDFE; }
.draft.is-closed { background: #F7F9FB; }
.draft-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.draft-body { white-space: pre-wrap; font-size: 13.5px; color: #2A3742; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; }

/* ---------- settings ---------- */
.setting-grid { display: grid; grid-template-columns: minmax(190px, 260px) 1fr; gap: 14px; align-items: start; }
.setting-grid .field { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 42px; height: 24px; border-radius: 999px; background: #C9D3DD; position: relative;
  transition: background .15s ease; flex: none;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s ease;
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid #7AA7F0; outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .45; cursor: not-allowed; }
.lock { font-size: 12px; color: var(--muted); }
.locked-card { border-left: 4px solid #C9D3DD; }

.list-rows { display: grid; gap: 8px; }
.list-row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.list-row .grow { flex: 1 1 220px; }
.list-row .narrow { flex: 0 0 84px; }
.list-row .rule-field { flex: 0 0 150px; }
.check-grid { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.check-inline { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; }

/* ---------- misc ---------- */
.alert-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .msg { flex: 1 1 auto; }
.empty { padding: 22px 10px; text-align: center; color: var(--muted); font-size: 14px; }
.loading { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 14px; }
.skeleton {
  height: 12px; border-radius: 6px; margin: 8px 0;
  background: linear-gradient(90deg, #EDF1F5 25%, #F7F9FB 37%, #EDF1F5 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton.w-40 { width: 40%; }
.skeleton.w-70 { width: 70%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .switch-track, .switch-track::after { transition: none; }
}

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); }
.toast {
  background: var(--ink); color: #F2F6FA; border-radius: 10px; padding: 11px 13px; font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(11, 15, 20, .3); border-left: 4px solid #7AA7F0;
}
.toast-error { border-left-color: #E2574C; }
.toast-ok { border-left-color: #3BC56B; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); }
.login-card { width: min(400px, 100%); padding: 26px 24px; margin: 0; }
.login-title { font-size: 1.4rem; margin-bottom: 2px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .who { display: none; }
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto auto 1fr;
    grid-template-areas:
      "top"
      "side"
      "banner"
      "view";
  }
  .nav-toggle { display: inline-grid; place-items: center; }
  .sidebar { display: none; padding: 6px 10px 10px; border-right: 0; border-bottom: 1px solid #000; }
  .sidebar.is-open { display: block; }
  .nav-list { grid-auto-flow: row; margin-bottom: 8px; }
  .sidebar-note { display: none; }
  .banner { margin: 10px 12px 0; }
  .view { padding: 14px 12px 48px; }
  .brand-text { font-size: 14px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .kpi-value { font-size: 22px; }
  .setting-grid { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }

  /* tables become cards */
  table.data { display: block; }
  table.data thead { display: none; }
  table.data tbody, table.data tr, table.data td { display: block; width: auto; }
  table.data tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  table.data td {
    border: 0;
    padding: 3px 0;
    display: grid;
    grid-template-columns: 108px 1fr;
    gap: 8px;
    align-items: baseline;
    word-break: break-word;
  }
  table.data td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 700;
  }
  table.data td:empty { display: none; }
  table.data td[data-label=""]::before { content: none; }
  table.data td.cell-actions { grid-template-columns: 1fr; }
  .cell-sub { display: inline; }
}

@media (prefers-color-scheme: dark) {
  html { color-scheme: light; }
}
