:root {
  /* Antarestar brand: orange + dark teal */
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #e4e8ee;
  --border-2: #eef1f5;
  --text: #14242b;
  --muted: #64757e;
  --faint: #97a4ac;
  --accent: #f15a22;        /* orange */
  --accent-dark: #d4480f;
  --accent-tint: #fdeee7;
  --teal: #15323c;          /* dark teal */
  --teal-2: #1d4a59;
  --blue: #2563eb;
  --blue-tint: #e5edfb;
  --green: #10b981;
  --green-tint: #d8f5ea;
  --warn: #f59e0b;
  --danger: #ef4444;
  --danger-tint: #fde7e7;
  --shadow-sm: 0 1px 2px rgba(20, 36, 43, .06);
  --shadow: 0 4px 16px rgba(20, 36, 43, .09);
  --shadow-lg: 0 14px 44px rgba(20, 36, 43, .16);
  --radius: 14px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-wrap { height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1000px 520px at 50% -8%, #ffd9c7 0%, var(--bg) 55%); }
.login-card { width: 350px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 38px 30px; text-align: center; box-shadow: var(--shadow-lg); }
.login-card .logo-badge { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px;
  display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #ff7d4d); color: #fff; font-size: 26px; font-weight: 900; box-shadow: var(--shadow); }
.login-logo { width: 76px; margin: 0 auto 8px; }
.login-logo svg { width: 100%; height: auto; display: block; }
.login-wordmark { font-weight: 800; letter-spacing: 4.5px; color: var(--teal); font-size: 18px; margin-bottom: 20px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .3px; color: var(--accent-dark); }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-card input { width: 100%; padding: 13px 15px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 11px; color: var(--text); margin-bottom: 12px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border: none; font-weight: 700;
  padding: 13px 16px; border-radius: 11px; width: 100%; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-dark); }
.err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 8px; }

/* ---------- Shell ---------- */
.app { display: none; grid-template-rows: 60px 1fr; height: 100vh; }
.app.show { display: grid; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--teal); border-bottom: 1px solid var(--teal); box-shadow: var(--shadow-sm); z-index: 5; }
.brand { font-weight: 800; letter-spacing: .4px; display: flex; align-items: center; gap: 10px; font-size: 16px; color: #fff; }
.brand .logo { width: 30px; height: 28px; display: grid; place-items: center; }
.brand .logo svg { width: 100%; height: 100%; display: block; }
.brand small { color: #9fb4bd; font-weight: 500; font-size: 11px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #5b7682; }
.dot.on { background: #2ee08f; box-shadow: 0 0 0 3px rgba(46,224,143,.25); }
.status-pill { font-size: 12px; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.1); color: #cdd9de; }
.status-pill b { color: #fff; }
.spacer { flex: 1; }
.ai-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #cdd9de; }
.tbtn { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.18);
  padding: 8px 13px; border-radius: 9px; font-size: 13px; }
.tbtn:hover { background: rgba(255,255,255,.2); }
.tbtn.solid { background: var(--accent); border-color: var(--accent); }
.tbtn.solid:hover { background: var(--accent-dark); }
.tbtn.danger:hover { background: var(--danger); border-color: var(--danger); }

.body { display: grid; grid-template-columns: 84px 1fr; min-height: 0; }
.rail { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  align-items: center; padding: 14px 0; gap: 5px; }
.rail .nav { width: 64px; height: 60px; border: none; background: transparent; border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 10px; font-weight: 700; transition: all .15s; }
.rail .nav .ic { font-size: 19px; }
.rail .nav:hover { background: var(--surface-2); color: var(--text); }
.rail .nav.active { background: var(--accent-tint); color: var(--accent-dark); }
.view { min-height: 0; overflow: hidden; display: none; }
.view.active { display: block; height: 100%; }
.view-head { padding: 18px 24px 14px; }
.view-head h1 { margin: 0; font-size: 20px; }
.view-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 310px 1fr 320px; height: 100%; min-height: 0; }
.col { min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.col.list { border-right: 1px solid var(--border); }
.col.crm { border-left: 1px solid var(--border); }
.account-bar { display: flex; gap: 6px; padding: 8px 10px 0; flex-wrap: wrap; align-items: center; }
.acct-tab { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.acct-tab:hover { border-color: var(--accent); }
.acct-tab.active { background: var(--accent-tint); color: var(--accent-dark); border-color: var(--accent); }
.acct-add { border: 1px dashed var(--border); background: transparent; color: var(--muted); border-radius: 999px; width: 28px; height: 28px; font-size: 16px; line-height: 1; }
.acct-add:hover { border-color: var(--accent); color: var(--accent); }
.badge.acct { background: var(--teal); color: #fff; }
.search { padding: 12px; border-bottom: 1px solid var(--border-2); }
.search input { width: 100%; padding: 10px 13px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); outline: none; }
.chats { overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border-2); }
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-tint); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #ffd9c7, #ffe9b8);
  display: grid; place-items: center; font-weight: 800; color: var(--accent-dark); flex: none; font-size: 16px; }
.chat-meta { flex: 1; min-width: 0; }
.chat-meta .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-meta .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta .time { font-size: 11px; color: var(--faint); flex: none; }
.chat-meta .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.badges { display: flex; gap: 5px; align-items: center; margin-top: 5px; flex-wrap: wrap; }
.badge { font-size: 10px; padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge.stage { color: #fff; }
.badge.ai { background: var(--blue-tint); color: var(--blue); }
.badge.human { background: #fef0d6; color: #a96a08; }
.badge.cs { background: var(--danger); color: #fff; animation: csblink 1.4s ease-in-out infinite; }
@keyframes csblink { 0%,100%{opacity:1} 50%{opacity:.55} }
.badge.unread { background: var(--accent); color: #fff; }
.badge.val { background: var(--green-tint); color: #047857; }
.badge.pay-paid { background: var(--green-tint); color: #047857; }
.badge.pay-dp { background: #fef0d6; color: #a96a08; }
.badge.pay-unpaid { background: var(--danger-tint); color: var(--danger); }

.conv { background: #eaeef1; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 11px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.conv-head .name { font-weight: 700; }
.conv-head .sub { font-size: 12px; color: var(--muted); }
.conv-head .actions { margin-left: auto; display: flex; gap: 9px; align-items: center; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { display: none; }
.track { width: 38px; height: 21px; border-radius: 999px; background: #cbd5db; position: relative; transition: background .2s; }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(17px); }
.messages { flex: 1; overflow-y: auto; padding: 18px 7%; display: flex; flex-direction: column; gap: 4px; }
.bubble { max-width: 74%; padding: 8px 12px 9px; border-radius: 11px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap; box-shadow: var(--shadow-sm); }
.bubble .t { font-size: 10px; color: var(--faint); float: right; margin: 7px 0 -4px 12px; }
.bubble .tag { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; color: var(--blue); display: block; margin-bottom: 2px; font-weight: 700; }
.b-them { align-self: flex-start; background: #fff; border-top-left-radius: 3px; }
.b-me { align-self: flex-end; background: #ffe7d9; border-top-right-radius: 3px; }
.b-ai { align-self: flex-end; background: var(--blue-tint); border-top-right-radius: 3px; }
.b-system { align-self: center; background: #fff4d6; color: #92600a; font-size: 12px; max-width: 80%; text-align: center; }
.composer { display: flex; gap: 10px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; height: 42px; max-height: 120px; padding: 11px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; color: var(--text); outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.composer button { background: var(--accent); color: #fff; border: none; border-radius: 11px; padding: 0 20px; font-weight: 700; }
.composer button:hover { background: var(--accent-dark); }
.composer .attach-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 0 12px; font-size: 17px; }
.composer .attach-btn:hover { background: var(--accent-tint); border-color: var(--accent); }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 40px; }
.empty .big { font-size: 46px; margin-bottom: 10px; }

/* CRM panel (deal) */
.crm-panel { padding: 14px 16px; overflow-y: auto; }
.crm-panel.disabled { display: grid; place-items: center; color: var(--faint); text-align: center; }
.crm-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent-dark); font-weight: 800; margin: 14px 0 8px; }
.crm-sec:first-child { margin-top: 0; }
.crm-field { margin-bottom: 10px; }
.crm-field label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 4px; font-weight: 700; }
.crm-field input, .crm-field textarea, .crm-field select { width: 100%; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); outline: none; }
.crm-field input:focus, .crm-field textarea:focus, .crm-field select:focus { border-color: var(--accent); background: #fff; }
.crm-field textarea { resize: vertical; min-height: 52px; }
.crm-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.deal-total { background: var(--accent-tint); border-radius: 10px; padding: 9px 12px; margin: 8px 0; display: flex; justify-content: space-between; align-items: center; font-weight: 800; color: var(--accent-dark); }
.deal-total small { color: var(--muted); font-weight: 600; }
.crm-save { width: 100%; margin-top: 4px; }
.crm-meta { font-size: 11px; color: var(--faint); margin-top: 8px; text-align: center; }

/* ---------- Pipeline ---------- */
.pipeline { height: 100%; display: flex; flex-direction: column; }
.kanban { flex: 1; overflow-x: auto; overflow-y: hidden; display: flex; gap: 13px; padding: 0 24px 24px; }
.kcol { flex: 0 0 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: 100%; box-shadow: var(--shadow-sm); }
.kcol-head { padding: 12px 14px; border-bottom: 1px solid var(--border-2); display: flex; align-items: center; gap: 8px; }
.kcol-head .swatch { width: 10px; height: 10px; border-radius: 3px; }
.kcol-head .ktitle { font-weight: 800; font-size: 13px; }
.kcol-head .kcount { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 1px 9px; border-radius: 999px; }
.kcol-val { padding: 6px 14px; font-size: 12px; color: var(--accent-dark); font-weight: 800; border-bottom: 1px solid var(--border-2); }
.kcards { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px; cursor: grab; box-shadow: var(--shadow-sm); transition: box-shadow .15s; }
.kcard:hover { box-shadow: var(--shadow); border-color: #d4dbe2; }
.kcard.dragging { opacity: .5; }
.kcard .kc-name { font-weight: 800; font-size: 13px; }
.kcard .kc-co { font-size: 11px; color: var(--accent-dark); font-weight: 700; }
.kcard .kc-prod { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kcard .kc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; gap: 6px; }
.kcard .kc-val { font-weight: 800; color: var(--text); font-size: 13px; }
.kcard .kc-dl { font-size: 10px; color: var(--warn); font-weight: 700; }
.kcol.drop-hover .kcards { background: var(--accent-tint); }
.kcol.drop-hover { border-color: var(--accent); }

/* ---------- Dashboard ---------- */
.dash, .train, .catalog, .report { height: 100%; overflow-y: auto; }
.dash-body, .train-body, .cat-body, .report-body { padding: 4px 24px 28px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 13px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.metric::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.metric.teal::before { background: var(--teal); }
.metric.green::before { background: var(--green); }
.metric.blue::before { background: var(--blue); }
.metric .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric .value { font-size: 25px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.metric .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.metric .ic { position: absolute; top: 15px; right: 15px; font-size: 21px; opacity: .22; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.panel h3 { margin: 0 0 16px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px){ .grid2 { grid-template-columns: 1fr; } .inbox { grid-template-columns: 280px 1fr; } .col.crm { display: none; } }
.frow { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.frow .fl { width: 110px; font-size: 12px; color: var(--muted); flex: none; text-align: right; font-weight: 600; }
.frow .bar-wrap { flex: 1; background: var(--surface-2); border-radius: 7px; height: 24px; overflow: hidden; }
.frow .bar { height: 100%; border-radius: 7px; display: flex; align-items: center; padding: 0 9px; color: #fff; font-size: 11px; font-weight: 700; min-width: 24px; transition: width .4s; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv b { font-weight: 800; }

/* ---------- Catalog ---------- */
.cat-toolbar { display: flex; gap: 10px; padding: 0 24px 14px; flex-wrap: wrap; align-items: center; }
.cat-toolbar input { flex: 1; min-width: 180px; padding: 10px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; outline: none; }
.cat-toolbar input:focus { border-color: var(--accent); }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 600; color: var(--muted); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.pcard:hover { box-shadow: var(--shadow); }
.pcard .pcat { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--faint); font-weight: 700; }
.pcard .pname { font-weight: 800; font-size: 14px; }
.pcard .pspec { font-size: 12px; color: var(--muted); flex: 1; }
.pcard .pfoot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.pcard .pprice { font-weight: 800; color: var(--accent-dark); }
.pcard .pcopy { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: 11px; font-weight: 700; color: var(--muted); }
.pcard .pcopy:hover { border-color: var(--accent); color: var(--accent-dark); }

/* ---------- Report ---------- */
.report-body { max-width: 760px; }
.report-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); white-space: pre-wrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.55; }
.report-actions { display: flex; gap: 10px; margin-bottom: 14px; }

/* ---------- Training ---------- */
.train-body { max-width: 880px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.field input, .field textarea, .field select { width: 100%; padding: 11px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); outline: none; }
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.inline-toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.qa-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.qa-list { display: flex; flex-direction: column; gap: 10px; }
.qa-item { background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.qa-item .q { font-weight: 700; font-size: 13px; }
.qa-item .a { color: var(--muted); font-size: 13px; margin-top: 4px; }
.qa-item .del { float: right; background: none; border: none; color: var(--faint); font-size: 16px; }
.qa-item .del:hover { color: var(--danger); }
.btn-accent { background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 11px 20px; font-weight: 700; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 11px 18px; font-weight: 600; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-dark); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,36,43,.5); display: none; place-items: center; z-index: 50; backdrop-filter: blur(2px); }
.modal-bg.show { display: grid; }
.modal { width: 460px; max-width: 92vw; background: var(--surface); border-radius: 18px; padding: 28px; box-shadow: var(--shadow-lg); }
.qr-box { text-align: center; }
.qr-box h2 { margin: 0 0 4px; }
.qr-box .hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.qr-box img { width: 250px; height: 250px; padding: 8px; border-radius: 12px; border: 1px solid var(--border); }
.qr-box .steps { text-align: left; color: var(--muted); font-size: 13px; margin: 16px auto 0; max-width: 340px; line-height: 1.7; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--teal); color: #fff; padding: 11px 20px; border-radius: 11px; z-index: 100; opacity: 0; transition: opacity .25s; pointer-events: none; box-shadow: var(--shadow-lg); font-size: 13px; }
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cbd5db; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #9aa9b1; }
