/* Lead Follow-Up CRM — calm, readable, no frameworks */
:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --line: #e3e6e1;
  --line-strong: #cfd4cc;
  --ink: #1b2420;
  --ink-2: #4c5852;
  --ink-3: #7b857f;
  --accent: #0f5d57;
  --accent-ink: #ffffff;
  --accent-soft: #e4f0ee;
  --hot: #c8372d;  --hot-soft: #fbeceb;
  --warm: #c56a0c; --warm-soft: #fcf1e4;
  --cold: #2f6db5; --cold-soft: #e9f0f9;
  --ok: #2f7d46;   --ok-soft: #e7f3ea;
  --late: #9a3a1c; --late-soft: #fbefe9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.boot { padding: 40px; color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand small { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { font-size: 12px; font-weight: 600; min-width: 22px; text-align: center; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.nav .count.late { background: var(--late-soft); border-color: transparent; color: var(--late); }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .grow { flex: 1; }
.btn.menu-btn { display: none; }
.global-search { max-width: 360px; width: 100%; }
.profile { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 5px 10px 5px 5px; border-radius: 999px; cursor: pointer; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.profile-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.1); min-width: 210px; padding: 6px; }
.profile-menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.profile-menu button { width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.profile-menu button:hover { background: var(--surface-2); }
.page { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--hot); }
.btn.ok { color: var(--ok); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.ico { width: 16px; height: 16px; flex: none; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 8px 10px; outline: none; min-height: 38px; }
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
label.field .hint { font-weight: 400; color: var(--ink-3); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); border-right: 1px solid var(--line); display: inline-flex; align-items: center; gap: 6px; }
.seg button:last-child { border-right: 0; }
.seg button.on[data-v=hot] { background: var(--hot-soft); color: var(--hot); }
.seg button.on[data-v=warm] { background: var(--warm-soft); color: var(--warm); }
.seg button.on[data-v=cold] { background: var(--cold-soft); color: var(--cold); }
.seg button.on:not([data-v]) , .seg button.on[data-v=all] { background: var(--accent-soft); color: var(--accent); }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.quick-dates button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.quick-dates button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- chips ---------- */
.temp { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: .03em; padding: 2px 9px 2px 8px; border-radius: 999px; white-space: nowrap; }
.temp::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.temp.hot { color: var(--hot); background: var(--hot-soft); }
.temp.warm { color: var(--warm); background: var(--warm-soft); }
.temp.cold { color: var(--cold); background: var(--cold-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.hot { background: var(--hot); } .dot.warm { background: var(--warm); } .dot.cold { background: var(--cold); }
.status { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.status.converted { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status.payment_pending { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.status.lost, .status.not_interested, .status.do_not_contact { color: var(--ink-3); }
.fu { font-size: 13px; white-space: nowrap; }
.fu.overdue { color: var(--late); font-weight: 650; }
.fu.today { color: var(--accent); font-weight: 650; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 4px; background: var(--surface-2); border: 1px dashed var(--line-strong); color: var(--ink-3); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-b { padding: 14px 16px; }
.stats { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 12px; box-shadow: var(--shadow); color: var(--ink); display: block; }
.stat:hover { border-color: var(--line-strong); text-decoration: none; }
.stat .label { font-size: 12.5px; color: var(--ink-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.late .num { color: var(--late); }
.stat.ok .num { color: var(--ok); }
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-cols .wide { grid-column: span 2; }
.list-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); text-decoration: none; }
.list-row .nm { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-row .meta { font-size: 13px; color: var(--ink-3); grid-column: 1 / -1; }
.list-row .said { font-size: 13.5px; color: var(--ink-2); grid-column: 1 / -1; }
.list-row .next { font-size: 13.5px; grid-column: 1 / -1; }
.label-inline { font-weight: 650; color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-right: 4px; }
.empty { padding: 28px 16px; text-align: center; color: var(--ink-3); }

/* ---------- leads table ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 140px; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.filters .search { flex: 1 1 260px; min-width: 220px; }
.filters .date-range { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-3); }
.filters .date-range input { min-width: 130px; }
.result-line { font-size: 13px; color: var(--ink-3); margin: 0 0 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table.leads { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.leads td.nowrap { white-space: nowrap; }
table.leads th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 9px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
table.leads td { padding: 10px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.leads tr:last-child td { border-bottom: 0; }
table.leads tbody tr { cursor: pointer; }
table.leads tbody tr:hover td { background: var(--surface-2); }
table.leads .nm { font-weight: 650; white-space: nowrap; }
table.leads .sub { font-size: 12.5px; color: var(--ink-3); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 150px; max-width: 220px; color: var(--ink-2); font-size: 13.5px; }
.lead-cards { display: none; }

/* ---------- lead cards (follow-up pages + mobile) ---------- */
.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; border-left: 4px solid var(--line-strong); }
.fcard.hot { border-left-color: var(--hot); } .fcard.warm { border-left-color: var(--warm); } .fcard.cold { border-left-color: var(--cold); }
.fcard .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.fcard .nm { font-weight: 700; font-size: 16px; color: var(--ink); }
.fcard .facts { font-size: 13px; color: var(--ink-3); }
.fcard .block { font-size: 14px; color: var(--ink-2); }
.fcard .actions { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 2px; }
.group-h { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; font-weight: 700; }
.group-h:first-child { margin-top: 0; }

/* ---------- lead detail ---------- */
.lead-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.lead-head .title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lead-head .sub { color: var(--ink-3); margin-top: 4px; font-size: 14px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px; box-shadow: var(--shadow); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
.toolbar select { width: auto; min-height: 34px; padding: 5px 8px; font-size: 14px; }
.handover { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 0; margin-bottom: 16px; overflow: hidden; }
.handover > div { padding: 14px 16px; border-right: 1px solid var(--line); }
.handover > div:last-child { border-right: 0; }
.handover .k { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-bottom: 4px; }
.handover .v { font-size: 14.5px; white-space: pre-wrap; }
.handover .next-box { background: var(--accent-soft); }
.handover .next-box .v.big { font-size: 16px; font-weight: 650; color: var(--ink); }
.handover .quote { border-left: 3px solid var(--line-strong); padding-left: 10px; font-style: normal; }
.handover .item + .item { margin-top: 12px; }
.detail-cols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.latest-summary { font-size: 15.5px; line-height: 1.6; white-space: pre-wrap; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: -4px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 2px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline li.note::after { border-color: var(--ink-3); }
.timeline .when { font-size: 13px; color: var(--ink-3); }
.timeline .when strong { color: var(--ink); font-weight: 650; }
.timeline .body { margin-top: 4px; font-size: 14px; white-space: pre-wrap; }
.timeline .qa { margin-top: 6px; display: grid; gap: 4px; font-size: 13.5px; }
.timeline .qa div { white-space: pre-wrap; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-word; }
.activity { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 360px; overflow-y: auto; }
.activity li { padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.activity li:last-child { border-bottom: 0; }
.activity .t { color: var(--ink-3); font-size: 12px; }
.future { border-style: dashed; background: var(--surface-2); box-shadow: none; }
.summary-grid { display: grid; gap: 10px; }
.summary-grid .k { font-size: 12px; font-weight: 650; color: var(--ink-3); }
.summary-grid .v { font-size: 14px; white-space: pre-wrap; }

/* ---------- reports ---------- */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 70px; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-track { height: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background: var(--accent); opacity: .85; }
.bar-fill.conv { position: absolute; left: 0; top: 0; background: var(--ok); opacity: 1; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-3); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.reports-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.numbers { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.numbers div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.numbers b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.numbers span { font-size: 12.5px; color: var(--ink-3); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 28, 24, .42); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 680px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal.narrow { max-width: 460px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-b { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; position: sticky; bottom: 0; }
.fieldset-t { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-top: 4px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: 14px; }
details.more[open] summary { margin-bottom: 12px; }
.alert { border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.alert.warn { background: var(--late-soft); color: var(--late); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.err { background: var(--hot-soft); color: var(--hot); }
.dup-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; color: var(--ink); }
.key-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; word-break: break-all; font-size: 13px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 200; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--hot); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 16px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1100px) {
  .detail-cols { grid-template-columns: 1fr; }
  .handover { grid-template-columns: 1fr; }
  .handover > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .handover > div:last-child { border-bottom: 0; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .18s; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 50; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .global-search { display: none; }
  .page { padding: 16px 16px 90px; }
  .dash-cols, .reports-grid { grid-template-columns: 1fr; }
  .dash-cols .wide { grid-column: auto; }
  .table-wrap { display: none; }
  .lead-cards { display: grid; gap: 12px; }
  .fcards { grid-template-columns: 1fr; }
  .profile-btn .pname { display: none; }
  .bar-row { grid-template-columns: 110px 1fr 54px; }
  .fab { display: inline-flex !important; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat .num { font-size: 24px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .modal-back { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .filters select, .filters input { flex: 1 1 45%; min-width: 0; }
  .kv { grid-template-columns: 110px 1fr; }
  h1 { font-size: 20px; }
}
.fab { display: none; position: fixed; right: 16px; bottom: 18px; z-index: 30; box-shadow: 0 6px 18px rgba(15,93,87,.35); padding: 11px 18px; border-radius: 999px; }
