:root {
  --bg: #eef2f1;
  --surface: #ffffff;
  --ink: #14282b;
  --muted: #5a6b6c;
  --line: #d3dcda;
  --field-line: #b9c6c4;
  --header: #0e4a4f;
  --brand: #0e4a4f;
  --btn-ink: #ffffff;
  --accent: #e3a008;
  --ok: #1b7a45;
  --err: #b3261e;
  --warn: #8a6100;
  --radius: 6px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1b1d;
    --surface: #16272a;
    --ink: #e6eeec;
    --muted: #93a5a5;
    --line: #2a3f42;
    --field-line: #3d5659;
    --header: #0b2e31;
    --brand: #7fd1c7;
    --btn-ink: #0b2e31;
    --ok: #6fd39a;
    --err: #ff8a80;
    --warn: #f2c14e;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--brand); }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
.error { color: var(--err); margin: 8px 0 0; }

/* ---- header ---- */
header { background: var(--header); color: #fff; }
.header-inner { max-width: 1040px; margin: 0 auto; padding: 0 16px; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap; }
header h1 { font-size: 16px; font-weight: 600; margin: 0; padding: 16px 0; }
.tabs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.tab { padding: 14px 12px 11px; border-bottom: 3px solid transparent; color: rgba(255, 255, 255, 0.75); text-decoration: none; font-weight: 500; }
.tab:hover { color: #fff; }
.tab.active { color: #fff; font-weight: 600; border-bottom-color: var(--accent); }
.who { color: rgba(255, 255, 255, 0.75); font-size: 13px; padding: 0 0 12px 12px; }
.who .link { color: #fff; }

/* ---- layout ---- */
.page { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.page.narrow { max-width: 640px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; min-width: 0; }
fieldset.card legend { font-weight: 600; padding: 0 4px; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; }

/* ---- controls ---- */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 36px;
  padding: 6px 14px; border: 1px solid var(--brand); border-radius: var(--radius);
  background: var(--brand); color: var(--btn-ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
button.secondary, .button.secondary { background: transparent; color: var(--brand); }
button.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
button.link { background: none; border: none; padding: 0; min-height: 0; color: inherit; text-decoration: underline; font-weight: 500; }
button:disabled { opacity: 0.55; cursor: progress; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--field-line); border-radius: var(--radius); padding: 7px 9px; min-height: 36px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input:not([type="checkbox"]) { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 8px 0; }
.check input { min-height: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.days { display: flex; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); }
.inline-status { font-size: 13px; }
.inline-status .error { margin: 0; }

/* ---- leads ---- */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.subtab { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 500; }
.subtab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { padding: 4px 10px; border: 1px solid var(--field-line); border-radius: 999px; text-decoration: none; color: var(--ink); font-size: 13px; }
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--btn-ink); }
.leads { list-style: none; margin: 0; padding: 0; }
.lead { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.lead-main { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 320px; }
.lead-title { font-weight: 600; overflow-wrap: anywhere; }
.lead-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; margin: 0 0 12px; }
.lead .lead-meta { margin: 0; }
.lead-flags { font-size: 13px; }
.age { font-variant-numeric: tabular-nums; }
.age.late, .due { color: var(--warn); font-weight: 600; }
.assign { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.assign select { max-width: 260px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); }
.status-new { color: var(--warn); border-color: currentColor; }
.status-contacted, .status-follow_up { color: var(--brand); border-color: currentColor; }
.status-converted { color: var(--ok); border-color: currentColor; }
.status-lost { color: var(--muted); }

/* ---- lead detail ---- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 8px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.seg { background: transparent; color: var(--ink); border-color: var(--field-line); font-weight: 500; min-height: 32px; padding: 3px 10px; }
.seg.active { background: var(--brand); color: var(--btn-ink); border-color: var(--brand); font-weight: 600; }
.outcome-extra:not(:empty) { margin-bottom: 10px; }
.notes { white-space: pre-wrap; font: inherit; font-size: 13px; margin: 10px 0 0; max-height: 280px; overflow: auto; }
.messages { margin: 0; padding-left: 20px; }
.messages li { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; overflow-wrap: anywhere; }
.messages .badge { align-self: flex-start; }

/* ---- report ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- login ---- */
.login { margin-top: 24px; }
