/* Apex - white and blue, with a dark option. Tokens first; dark values are repeated for "auto" and "forced dark". */
:root {
  --bg: #f3f7fb; --panel: #ffffff; --text: #0c2540; --muted: #5b6f86; --line: #dde6f0;
  --brand: #14407a; --brand-d: #0b2a52; --link: #14407a; --accent: #14b8a6; --on-brand: #ffffff;
  --side: #0b2540; --side-text: #c5d3e4; --side-hover: #14335a; --side-line: #1d3a5f;
  --ok: #1a9d6b; --warn: #c97a0a; --bad: #d64545;
  --radius: 12px; --shadow: 0 1px 2px rgba(11,37,64,.05), 0 6px 18px rgba(11,37,64,.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #08121f; --panel: #0f1f33; --text: #e7eff9; --muted: #92a7c0; --line: #1f3550;
  --brand: #2f76c9; --brand-d: #4a8ddc; --link: #7db6f5; --accent: #2dd4bf; --on-brand: #ffffff;
  --side: #060e19; --side-text: #aebfd4; --side-hover: #11233a; --side-line: #1a2e48;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #08121f; --panel: #0f1f33; --text: #e7eff9; --muted: #92a7c0; --line: #1f3550;
    --brand: #2f76c9; --brand-d: #4a8ddc; --link: #7db6f5; --accent: #2dd4bf; --on-brand: #ffffff;
    --side: #060e19; --side-text: #aebfd4; --side-hover: #11233a; --side-line: #1a2e48;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0; }
a { color: var(--link); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .right { text-align: right; } .nowrap { white-space: nowrap; }

/* brand */
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand .word { font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.brand.big svg { width: 44px; height: 44px; } .brand.big .word { font-size: 32px; }
.tagline { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .7; padding: 0 10px 14px; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.sidebar .logo { color: #fff; padding: 4px 10px 2px; }
.sidebar nav { margin-top: 8px; }
.sidebar nav a { display: block; padding: 9px 12px; border-radius: 10px; color: var(--side-text); margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--side-hover); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .me { margin-top: auto; padding: 10px; font-size: 13px; border-top: 1px solid var(--side-line); display: grid; gap: 6px; }
.sidebar .me small { color: #8ea4bf; display: block; }
.sidebar .btn { background: transparent; border-color: var(--side-line); color: var(--side-text); }
.sidebar .btn:hover { border-color: var(--accent); }
.main { padding: 26px 30px 56px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 14px; cursor: pointer; transition: border-color .12s, background .12s; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); } .btn.primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #05231f; font-weight: 600; }
.btn.danger { color: var(--bad); } .btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="file"] { padding: 6px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 280px; } .toolbar select { width: auto; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; } .grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 2px; } .stat .sub { color: var(--muted); font-size: 12px; }
.stat.alert .value { color: var(--bad); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; } tbody tr:hover { background: color-mix(in srgb, var(--brand) 6%, transparent); }
th.sortable { cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 32px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; color: var(--muted); }

/* badges: one colour variable per kind, tinted from the panel so both themes stay readable */
.badge { --c: #4b627d; display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 14%, var(--panel)); color: color-mix(in srgb, var(--c) 80%, var(--text)); }
.badge.new { --c: #2563eb; } .badge.contacted { --c: #0e8aa8; } .badge.test_drive { --c: #c97a0a; } .badge.quote { --c: #7c4dd6; }
.badge.negotiation { --c: #c2305f; } .badge.won, .badge.available, .badge.done, .badge.ok, .badge.sent, .badge.completed { --c: #1a9d6b; }
.badge.lost, .badge.sold, .badge.cancelled, .badge.high, .badge.invalid, .badge.failed { --c: #d64545; }
.badge.medium, .badge.reserved, .badge.open, .badge.duplicate, .badge.queued { --c: #c97a0a; }
.badge.received, .badge.low { --c: #2563eb; }
.overdue { color: var(--bad); font-weight: 600; }

/* pipeline board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: color-mix(in srgb, var(--line) 45%, transparent); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.col.over { outline: 2px dashed var(--accent); }
.col h3 { display: flex; justify-content: space-between; margin-bottom: 8px; }
.lead-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.lead-card .name { font-weight: 600; display: block; }

/* detail */
.detail { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
dl { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; } dt { color: var(--muted); } dd { margin: 0; word-break: break-word; }
.stepper { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.step { padding: 4px 12px; border-radius: 99px; background: var(--line); font-size: 12px; color: var(--muted); }
.step.current { background: var(--brand); color: var(--on-brand); font-weight: 600; } .step.past { background: color-mix(in srgb, var(--brand) 22%, var(--line)); color: var(--text); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline li.stage_change::before { background: var(--warn); } .timeline li.note::before { background: var(--muted); } .timeline li.sms::before { background: var(--accent); }
.timeline .meta { font-size: 12px; color: var(--muted); }

/* sales manager agent */
.agent { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.agent .sec { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 3px; justify-items: start; }
.meter { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter-fill { height: 100%; background: var(--accent); }
.qual-top { display: flex; justify-content: space-between; }
.risks { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 14%, var(--panel)); color: color-mix(in srgb, var(--warn) 70%, var(--text)); }
.msg { margin: 0 0 8px; padding: 8px 12px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 0 8px 8px 0; }
.chat-log { display: grid; gap: 6px; margin-bottom: 8px; max-height: 360px; overflow-y: auto; }
.bubble { padding: 7px 12px; border-radius: 14px; max-width: 92%; white-space: pre-wrap; }
.bubble.user { background: var(--brand); color: var(--on-brand); justify-self: end; border-bottom-right-radius: 4px; }
.bubble.assistant { background: var(--line); border-bottom-left-radius: 4px; }
.chat-form { display: flex; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 11px; font-size: 12px; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--accent); }
.btn.rec { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.proposal { border: 1px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin: 2px 0 6px; display: grid; gap: 8px; background: color-mix(in srgb, var(--accent) 7%, var(--panel)); }
.proposal ul { margin: 4px 0 0; padding-left: 18px; }
.coach-layout { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.coach-chat { position: sticky; top: 16px; }
.coach-item .name { font-weight: 600; font-size: 15px; }
@media (max-width: 960px) { .coach-layout { grid-template-columns: 1fr; } .coach-chat { position: static; order: -1; } }

/* voice help and guided interview */
.voice-help { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin-bottom: 10px; background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.voice-help summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.voice-help-body { font-size: 13px; padding-top: 6px; }
.voice-help-body h3 { margin: 8px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.voice-help-body ol, .voice-help-body ul { margin: 0 0 6px; padding-left: 20px; }
.voice-help-body li { margin-bottom: 3px; } .voice-help-body p { margin: 6px 0; }
.guide-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 8px; border: 1px solid var(--accent); border-radius: 10px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: 400; color: var(--text); font-size: 13px; }
label.inline input[type="checkbox"] { width: auto; }
.bubble.muted { opacity: .75; }

/* text messages */
.sms-thread { display: grid; gap: 6px; max-height: 320px; overflow-y: auto; margin-bottom: 10px; padding-right: 2px; }
.sms-b { padding: 7px 12px; border-radius: 14px; max-width: 86%; white-space: pre-wrap; word-break: break-word; }
.sms-b.out { background: var(--brand); color: var(--on-brand); justify-self: end; border-bottom-right-radius: 4px; }
.sms-b.in { background: var(--line); justify-self: start; border-bottom-left-radius: 4px; }
.sms-b small { display: block; opacity: .75; font-size: 11px; margin-top: 2px; }
.sms-b.failed { outline: 2px solid var(--bad); }
.sms-compose { display: grid; gap: 8px; }
.sms-compose textarea { min-height: 76px; resize: vertical; }
.sms-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.notice { padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 14%, var(--panel)); color: color-mix(in srgb, var(--warn) 70%, var(--text)); font-size: 13px; }
.notice.info { background: color-mix(in srgb, var(--brand) 10%, var(--panel)); color: var(--text); }

/* import */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.import-sum { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.import-list { max-height: 42vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.import-list table { font-size: 13px; } .import-list th, .import-list td { padding: 6px 10px; }
dialog.wide { width: min(860px, 96vw); }
.dlg-body.block { display: block; }

/* dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, 94vw); box-shadow: 0 24px 70px rgba(0,0,0,.4); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(6,16,30,.6); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.dlg-body { padding: 16px 20px; display: grid; gap: 12px; grid-template-columns: 1fr 1fr; max-height: 70vh; overflow: auto; }
.dlg-body .full { grid-column: 1 / -1; }
.dlg-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.field-error { color: var(--bad); font-size: 12px; margin-top: 2px; } .form-error { color: var(--bad); grid-column: 1 / -1; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent), var(--bg); }
.login .card { width: min(400px, 100%); display: grid; gap: 12px; padding: 26px; }
.login .hint { font-size: 12px; color: var(--muted); }
.login .brand { color: var(--text); margin-bottom: 2px; }
.theme-fab { position: fixed; top: 14px; right: 14px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: #0c2540; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; border-left: 4px solid var(--accent); }
.toast.error { background: var(--bad); border-left-color: #fff; }
.bar { height: 8px; border-radius: 4px; background: var(--accent); min-width: 2px; }
.row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 8px; align-items: center; margin-bottom: 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
  .sidebar .logo { padding: 4px 8px; } .tagline { display: none; } .sidebar nav { display: flex; flex-wrap: wrap; margin: 0; }
  .sidebar .me { margin: 0 0 0 auto; border: 0; padding: 4px 8px; grid-auto-flow: column; align-items: center; }
  .main { padding: 16px; } .detail { grid-template-columns: 1fr; } .dlg-body { grid-template-columns: 1fr; }
}
