:root {
  --navy: #1F3864; --navy-2: #2a4a80; --gold: #BF8F00;
  --bg: #f4f6fa; --card: #ffffff; --line: #e3e8f0;
  --ink: #1c2333; --ink-2: #5a6478; --ink-3: #98a1b3;
  --red: #c0392b; --red-bg: #fdecea; --amber: #b26a00; --amber-bg: #fff4e0;
  --green: #1e7e46; --green-bg: #e7f5ec; --blue-bg: #eaf0fb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08);
}
* { box-sizing: border-box; margin: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--navy-2); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #c9d2e0; border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 56, 100, .35); outline-offset: 0; border-color: var(--navy-2); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 10px 0 3px; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }

/* ---------- layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 210px; background: var(--navy); color: #fff; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.sidebar .brand { font-size: 17px; font-weight: 700; padding: 4px 10px 14px; letter-spacing: .02em; }
.sidebar .brand span { color: #e8c65a; }
.sidebar a.nav { color: #cdd8ec; padding: 9px 10px; border-radius: 7px; font-weight: 500; }
.sidebar a.nav:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar a.nav.active { background: rgba(255,255,255,.16); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 12px; color: #aebad2; padding: 8px 10px; border-top: 1px solid rgba(255,255,255,.15); }
.sidebar .who b { color: #fff; display: block; }
.sidebar .who .role { text-transform: capitalize; color: #e8c65a; }
.sidebar button.linky { background: none; border: none; color: #cdd8ec; padding: 6px 10px; text-align: left; border-radius: 7px; width: 100%; }
.sidebar button.linky:hover { background: rgba(255,255,255,.08); color: #fff; }
main { flex: 1; padding: 24px 28px; max-width: 1280px; }
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead .sub { color: var(--ink-2); font-size: 13px; }
.pagehead .grow { flex: 1; }

/* ---------- cards / tiles ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer; }
.tile .num { font-size: 30px; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.tile.alert .num { color: var(--red); }
.tile.warn .num { color: var(--amber); }
.tile.okay .num { color: var(--navy); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover { background: var(--blue-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-3); padding: 18px; text-align: center; }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.badge.HOT { background: var(--red-bg); color: var(--red); }
.badge.WARM { background: var(--amber-bg); color: var(--amber); }
.badge.COOL { background: #eef1f6; color: var(--ink-2); }
.badge.NONE { background: #f1f1f1; color: var(--ink-3); }
.badge.stage { background: var(--blue-bg); color: var(--navy-2); font-weight: 600; }
.badge.overdue { background: var(--red-bg); color: var(--red); }
.badge.duesoon { background: var(--amber-bg); color: var(--amber); }
.badge.type { background: #f0ebdd; color: #7a6320; font-weight: 600; }
.badge.dir-Inbound { background: var(--green-bg); color: var(--green); }
.badge.dir-Outbound { background: var(--blue-bg); color: var(--navy-2); }

/* ---------- buttons ---------- */
.btn { background: var(--navy); color: #fff; border: none; border-radius: 7px; padding: 8px 16px; font-weight: 600; }
.btn:hover { background: var(--navy-2); }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid #c9d2e0; }
.btn.secondary:hover { background: var(--blue-bg); }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #e4b6b0; }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- forms ---------- */
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0 16px; }
.formgrid .wide { grid-column: 1 / -1; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 14px; margin-top: 6px; }
.checks label { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; color: var(--ink); margin: 0; cursor: pointer; }
.checks input { width: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { max-width: 260px; }
.filters select { width: auto; }

/* ---------- bars (single-hue) ---------- */
.bars .bar-row { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.bars .track { background: #edf0f6; border-radius: 4px; height: 14px; }
.bars .fill { background: var(--navy-2); border-radius: 4px 4px 4px 4px; height: 14px; min-width: 2px; }
.bars .cnt { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- lead detail ---------- */
.score-box { border-left: 4px solid var(--gold); }
.score-box .big { font-size: 34px; font-weight: 800; }
.breakdown li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.breakdown { list-style: none; padding: 0; margin: 8px 0 0; }
.breakdown .pts { font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--navy-2); }
.timeline .meta { font-size: 12px; color: var(--ink-2); margin-bottom: 2px; }
.timeline .meta b { color: var(--ink); }
.timeline .outcome { font-size: 12px; color: var(--green); margin-top: 2px; }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); opacity: 0; transition: opacity .2s; z-index: 50; max-width: 380px; }
.toast.show { opacity: 1; }
.toast.err { background: var(--red); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 9px 14px; font-weight: 600; color: var(--ink-2); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--gold); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.muted { color: var(--ink-2); font-size: 13px; }
.tiny { color: var(--ink-3); font-size: 12px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.searchbox { position: relative; }
.results { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 20px rgba(20,30,60,.15); z-index: 20; max-height: 300px; overflow: auto; }
.results div { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results div:hover { background: var(--blue-bg); }
.results .none { color: var(--ink-3); cursor: default; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(150deg, var(--navy) 0%, #14264a 100%); width: 100%; }
.login-card { background: #fff; border-radius: 14px; padding: 34px 36px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card h1 { color: var(--navy); margin-bottom: 2px; }
.login-card .sub { color: var(--ink-2); font-size: 13px; margin-bottom: 14px; }
.login-card .btn { width: 100%; margin-top: 16px; padding: 10px; }
.login-err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

details.factor-help { margin-top: 8px; font-size: 13px; color: var(--ink-2); }
details.factor-help summary { cursor: pointer; font-weight: 600; }
