:root {
  --bg: #f4f2ee; --panel: #ffffff; --panel-2: #faf9f6; --line: #e6e2da; --text: #1d2430; --muted: #6b7280;
  --ink: #1f2a37; --accent: #c2410c; --accent-soft: #fff1e8; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --wa: #1fa855; --tg: #2a9fd6; --max: #6d4cff;
  --in: #ffffff; --out: #e9f2ff; --bot: #f1ede4;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,20,20,.06), 0 4px 16px rgba(20,20,20,.05);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --panel: #1b1f26; --panel-2: #20252d; --line: #2c323c; --text: #e7e9ee; --muted: #9aa3af;
    --ink: #0f1217; --accent: #fb923c; --accent-soft: #2b2018; --in: #232831; --out: #1d2c42; --bot: #2a2620; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--tg); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-rows: 52px 1fr; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 0 16px; background: var(--ink); color: #f4f2ee; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; }
.nav a { color: #cfd5dd; text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 500; position: relative; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav .badge { position: absolute; top: 1px; right: -2px; }
.topbar .spacer { flex: 1; }
.topbar .me { color: #cfd5dd; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.topbar .me button { background: none; border: 1px solid rgba(255,255,255,.25); color: #e5e7eb; border-radius: 7px; padding: 4px 10px; cursor: pointer; }
.pill-test { background: #b45309; color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 12px; }

.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; font-weight: 700; }

/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr 340px; min-height: 0; }
.col { min-height: 0; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); }
.col:last-child { border-right: none; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.whatsapp { background: var(--wa); } .dot.telegram { background: var(--tg); } .dot.max { background: var(--max); }
.chat-list { overflow-y: auto; flex: 1; }
.chat-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; position: relative; font-size: 15px; }
.avatar.whatsapp { background: var(--wa); } .avatar.telegram { background: var(--tg); } .avatar.max { background: var(--max); }
.ci-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-meta { display: grid; justify-items: end; gap: 4px; font-size: 11.5px; color: var(--muted); }
.ci-sub { font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.ci-sub .acc-t { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.new { background: #fff1e8; color: #c2410c; border-color: #fed7aa; }
.tag.in_progress { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.tag.offer { background: #faf5ff; color: #7e22ce; border-color: #e9d5ff; }
.tag.won { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.tag.lost { background: #f3f4f6; color: #6b7280; }
.tag.bot { background: var(--bot); color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; line-height: 1.5; }

.chat { background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.chat-head .title { font-weight: 700; font-size: 15px; }
.chat-head .sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { display: none; border: none; background: none; font-size: 20px; cursor: pointer; padding: 0 6px 0 0; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 80%); padding: 8px 11px 6px; border-radius: 12px; box-shadow: var(--shadow); line-height: 1.42; white-space: pre-wrap; word-wrap: break-word; position: relative; }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 4px; }
.msg.bot { background: var(--bot); }
.msg.system { align-self: center; background: none; box-shadow: none; color: var(--muted); font-size: 12.5px; padding: 2px; }
.msg .who { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.msg .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; }
.msg .time .st-failed { color: var(--bad); font-weight: 700; }
.msg img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin: 4px 0; cursor: zoom-in; }
.msg .file { display: inline-flex; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 8px; background: rgba(0,0,0,.04); margin: 3px 0; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 2px 10px; border-radius: 999px; margin: 6px 0; border: 1px solid var(--line); }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; max-height: 160px; min-height: 40px; background: var(--panel-2); }
.composer .files { font-size: 12px; color: var(--muted); padding: 0 12px 6px; background: var(--panel); }
.quick { display: flex; gap: 6px; padding: 6px 12px 0; background: var(--panel); overflow-x: auto; scrollbar-width: none; }
.quick button { flex: none; }
.quick button { font-size: 12px; border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 3px 9px; cursor: pointer; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #c9c3b7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.icon { padding: 7px 10px; font-size: 16px; line-height: 1; }
.btn:disabled { opacity: .5; cursor: default; }
select.inp, input.inp, textarea.inp { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--panel-2); }
textarea.inp { resize: vertical; min-height: 60px; }
.switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { width: 34px; height: 20px; appearance: none; background: #cbd5e1; border-radius: 999px; position: relative; cursor: pointer; transition: .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 16px; }

/* ---------- lead panel ---------- */
.lead { overflow-y: auto; padding: 14px; display: grid; gap: 10px; align-content: start; }
.lead h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.lead .row { display: grid; gap: 4px; }
.lead .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lead label { font-size: 12px; color: var(--muted); font-weight: 500; }
.lead .vin { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .5px; }
.statusbar { display: flex; gap: 4px; flex-wrap: wrap; }
.statusbar button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.statusbar button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.note { font-size: 12px; color: var(--muted); }
.saved { font-size: 12px; color: var(--ok); }

/* ---------- leads board ---------- */
.page { overflow: auto; padding: 18px; }
.page h2 { margin: 0 0 12px; font-size: 20px; }
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; align-items: start; }
.lane { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; }
.lane h4 { margin: 0 0 2px; font-size: 13px; display: flex; justify-content: space-between; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 10px; display: grid; gap: 4px; cursor: pointer; box-shadow: var(--shadow); }
.card:hover { border-color: #c9c3b7; }
.card .t { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.card .s { font-size: 12.5px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- settings ---------- */
.settings { display: grid; grid-template-columns: 220px 1fr; min-height: 0; }
.settings .side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; display: grid; gap: 4px; align-content: start; }
.settings .side a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.settings .side a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); max-width: 920px; }
.box h3 { margin: 0 0 10px; font-size: 16px; }
.box p { margin: 6px 0; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.acc { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.acc:first-of-type { border-top: none; }
.acc .meta { font-size: 12.5px; color: var(--muted); word-break: break-all; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl td, table.tbl th { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); font-size: 13.5px; }
.sim { border: 1px solid var(--line); border-radius: var(--radius); height: 380px; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); padding: 28px; border-radius: 14px; width: min(380px, 100%); display: grid; gap: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login h1 { margin: 0 0 4px; font-size: 22px; display: flex; gap: 10px; align-items: center; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 8px; }

/* ---------- mobile ---------- */
@media (max-width: 1180px) { .inbox { grid-template-columns: 300px 1fr; } .inbox .lead-col { display: none; } .inbox.show-lead .lead-col { display: flex; position: fixed; right: 0; top: 52px; bottom: 0; width: min(360px, 100%); z-index: 20; box-shadow: -8px 0 30px rgba(0,0,0,.15); } }
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; } .brand span { display: none; } .topbar .me .name { display: none; }
  .nav a { padding: 7px 9px; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .pill-test { display: none; }
  .chat-head { gap: 8px; padding: 8px 10px; }
  .chat-head .actions { margin-left: 0; width: 100%; }
  .chat-head .actions select { flex: 1; min-width: 0; }
  .composer textarea { font-size: 16px; }
  .inbox .chat { display: none; }
  .inbox.open .list-col { display: none; } .inbox.open .chat { display: flex; }
  .back { display: inline-block; }
  .settings { grid-template-columns: 1fr; } .settings .side { grid-auto-flow: column; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .grid2, .lead .row2 { grid-template-columns: 1fr; }
  .board { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .msg { max-width: 88%; }
}
