:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8ef; --text: #0f1b2d; --muted: #5d6b80;
  --brand: #0b2a4a; --brand-2: #133e6b; --accent: #f26b1d; --accent-weak: #fff1e8;
  --ok: #138a4b; --ok-weak: #e6f6ed; --warn: #b46a00; --warn-weak: #fff5e0; --bad: #c62828; --bad-weak: #fdecec;
  --info: #1f63c6; --info-weak: #e8f0fc; --bar: #2f6db5;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,27,45,.06), 0 1px 8px rgba(15,27,45,.04);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1420; --surface: #141d2b; --surface-2: #182233; --border: #263247; --text: #e6ecf5; --muted: #93a1b7;
    --brand: #0a1a2e; --brand-2: #12304f; --accent-weak: #3a2414; --ok-weak: #0f2e1f; --warn-weak: #33260c;
    --bad-weak: #3a1616; --info-weak: #13284a; --bar: #5b95dd; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--info); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #cfd9e6; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; }
.logo-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-weight: 800; color: #fff; }
.logo small { display: block; font-weight: 500; font-size: 11px; color: #9fb2c9; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f93ad; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfd9e6; padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--brand-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .badge { margin-left: auto; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1500px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { filter: brightness(.95); }
.btn.dark { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--bad); } .btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12px; } .btn.lg { padding: 11px 18px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-weak); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-weak); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-weak); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
.tbl-compact th, .tbl-compact td { padding: 7px 8px; }
/* AI Sales Manager */
.ai-box { border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius); padding: 12px 14px; background: var(--info-weak); }
.why { list-style: none; padding: 0; margin: 8px 0 4px; }
.why li { display: grid; grid-template-columns: 38px 1fr; gap: 6px; padding: 3px 0; font-size: 13px; }
.why .pts { font-weight: 700; color: var(--ok); text-align: right; font-variant-numeric: tabular-nums; }
.why li.neg .pts { color: var(--bad); }
.script-ai { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; line-height: 1.55; }
.script-ai h4 { margin: 12px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.script-ai h4:first-of-type { margin-top: 4px; }
.script-ai ul, .script-ai ol { margin: 0; padding-left: 20px; }
.script-ai .say { background: var(--surface); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; font-size: 15px; }
.script-ai .obj { padding: 6px 0; border-bottom: 1px dashed var(--border); } .script-ai .obj:last-of-type { border-bottom: 0; }
.role-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.role-chip { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: pointer; background: var(--surface); }
.role-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); }
.role-chip span { display: grid; gap: 2px; } .role-chip small { color: var(--muted); font-size: 12px; line-height: 1.4; }
@media (max-width: 800px) { .role-checks { grid-template-columns: 1fr; } }
/* flowchart */
.flow-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.flow-wrap svg { display: block; }
.flow-node { cursor: pointer; }
.flow-node rect { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.flow-node:hover rect, .flow-node.sel rect { stroke: var(--accent); stroke-width: 2.5; }
.flow-node.auto rect { fill: var(--info-weak); }
.flow-node.decision rect { fill: var(--warn-weak); }
.flow-node.money rect { fill: var(--ok-weak); }
.flow-node text { fill: var(--text); font-size: 12.5px; font-weight: 600; }
.flow-node text.sub { fill: var(--muted); font-size: 11px; font-weight: 500; }
.flow-lane-label { fill: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.flow-edge { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.flow-edge-label { fill: var(--muted); font-size: 10.5px; }
.org { display: grid; gap: 10px; justify-items: center; }
.org .node { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; background: var(--surface); text-align: center; min-width: 200px; }
.org .node.me { border: 2px solid var(--accent); }
.org .arrow { color: var(--muted); font-size: 13px; }
.org .row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.date-sel { display: flex; gap: 6px; }
.date-sel select { flex: 1.4; min-width: 0; } .date-sel select.dd { flex: .8; } .date-sel select.yy { flex: 1; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.src-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.src-row:last-child { border-bottom: 0; }
label.field { display: block; } label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 10px; border-radius: var(--radius); background: var(--info-weak); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.switch { position: relative; width: 52px; height: 28px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #b7c1cf; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span:before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); } .switch input:checked + span:before { transform: translateX(24px); }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 6px; }
.bars .b { flex: 1; background: var(--bar); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .b:hover { filter: brightness(1.15); }
.bars-x { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 48px; gap: 10px; align-items: center; margin: 7px 0; }
.funnel-track { background: var(--surface-2); border-radius: 4px; height: 14px; overflow: hidden; }
.funnel-fill { background: var(--bar); height: 100%; border-radius: 4px; }

/* modal & drawer */
.overlay { position: fixed; inset: 0; background: rgba(8,15,28,.45); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 5vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px; } .modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.drawer-overlay { position: fixed; inset: 0; background: rgba(8,15,28,.35); z-index: 40; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(760px, 100%); background: var(--bg); z-index: 41; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.2); }
.drawer-head { background: var(--surface); padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.drawer-body { padding: 16px 20px; display: grid; gap: 14px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li:before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--bar); }
.timeline li.call:before { background: var(--accent); } .timeline li.reply:before { background: var(--ok); } .timeline li.note:before { background: var(--warn); }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--brand); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.err { background: var(--bad); }

/* call center */
.callcenter { display: grid; grid-template-columns: 340px 1fr; gap: 14px; align-items: start; }
.queue { max-height: 75vh; overflow-y: auto; padding: 0; }
.queue-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.queue-item:hover { background: var(--surface-2); } .queue-item.active { background: var(--accent-weak); box-shadow: inset 3px 0 0 var(--accent); }
.phone-big { font-size: 26px; font-weight: 800; letter-spacing: .02em; }
.script { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; line-height: 1.55; max-height: 360px; overflow-y: auto; }
.outcomes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.outcomes .btn { justify-content: center; } .outcomes .btn.sel { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.task-card { display: grid; gap: 8px; }
.msg-box { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 10px; border: 1px dashed var(--border); }
.step { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); } .dot.off { background: var(--bad); }
.checklist li { margin: 6px 0; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), #163f6b); }
.login .card { width: 100%; max-width: 400px; padding: 28px; }

@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } .callcenter { grid-template-columns: 1fr; } .queue { max-height: 300px; } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 240px; z-index: 60; transition: left .2s; }
  .sidebar.open { left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 16px; } .topbar { padding: 12px 16px; }
  .g2, .g3, .form-grid { grid-template-columns: 1fr; }
  .outcomes { grid-template-columns: 1fr 1fr; }
}
