:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --text: #17212b;
  --muted: #687684;
  --line: #e2e7ec;
  --accent: #0f766e;
  --accent-2: #e6f4f2;
  --accent-text: #ffffff;
  --green: #15803d;
  --red: #c2410c;
  --amber: #b45309;
  --blue: #0369a1;
  --bubble-in: #ffffff;
  --bubble-out: #dcf3ee;
  --chat-bg: #eef2f1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --panel: #151d23; --panel-2: #1a242b; --text: #e4eaee; --muted: #8d9ba6; --line: #26323a;
    --accent: #2bb3a3; --accent-2: #173431; --accent-text: #06201d; --green: #4ade80; --red: #fb923c; --amber: #fbbf24; --blue: #38bdf8;
    --bubble-in: #1d2930; --bubble-out: #144039; --chat-bg: #10181d; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav:hover { background: var(--panel-2); }
.nav.on { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.side-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; font-size: 13px; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 20px 24px; overflow: auto; flex: 1; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; margin-right: auto; }

/* ui */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); }
.btn.ok { color: var(--green); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; }
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { resize: vertical; min-height: 70px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; font-size: 12px; margin: 2px 4px 2px 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.connected { background: var(--green); } .dot.qr, .dot.connecting { background: var(--amber); } .dot.disconnected { background: var(--red); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-2); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; font-size: 13px; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.err { color: var(--red); font-size: 13px; }
.banner { background: #fff7e6; color: #8a5300; border-bottom: 1px solid #f3dfb3; padding: 8px 16px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .banner { background: #2b2210; color: #fbbf24; border-color: #4a3a17; } }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: var(--panel-2); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 16, 20, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 12px; width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 330px 1fr 300px; height: 100%; min-height: 0; }
.inbox > * { min-height: 0; }
.conv-list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.conv-list .head { padding: 14px 14px 0; display: grid; gap: 10px; }
.conv-items { overflow: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: var(--panel-2); }
.conv.on { background: var(--accent-2); }
.conv .top { display: flex; gap: 6px; align-items: baseline; }
.conv .name { font-weight: 600; }
.conv .time { margin-left: auto; font-size: 11px; color: var(--muted); flex: none; }
.conv .last { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.chat { display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-head .assignee { width: auto; max-width: 180px; }
.msgs { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(75%, 560px); padding: 7px 10px 5px; border-radius: 10px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--bubble-out); }
.msg .media { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; display: block; }
.msg.ai { background: #e9e7fb; }
@media (prefers-color-scheme: dark) { .msg.ai { background: #2a2650; } }
.ai-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .kind { font-style: italic; color: var(--muted); }
.day { align-self: center; font-size: 12px; background: var(--panel); border-radius: 8px; padding: 2px 10px; color: var(--muted); margin: 8px 0; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; position: relative; }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; }
.qr-pop { position: absolute; bottom: 100%; left: 10px; right: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; }
.qr-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; }
.qr-pop button:hover, .qr-pop button.on { background: var(--accent-2); }
.details { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 16px; }
.details h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.mini-deal { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; }
.mini-deal:hover { background: var(--panel-2); }
.only-mobile { display: none; }

/* kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; min-height: 60vh; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); width: 280px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col.drop { outline: 2px dashed var(--accent); }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.col-head .bar { height: 3px; border-radius: 3px; margin-bottom: 8px; }
.col-items { padding: 8px; display: grid; gap: 8px; overflow: auto; align-content: start; min-height: 60px; }
.deal { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: var(--shadow); }
.deal:active { cursor: grabbing; }
.deal .v { font-weight: 700; color: var(--green); }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .n { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 8px; }
.chart .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; min-width: 2px; height: 100%; }
.chart .b span { display: block; border-radius: 2px 2px 0 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hbar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.hbar span { display: block; height: 100%; background: var(--accent); }

/* settings */
.qr-box img { width: 260px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.wa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stage-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.stage-row input[type=color] { width: 36px; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--panel); }

/* mobile */
.mobile-nav { display: none; }
@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } .details { display: none; } .inbox.show-details .details { display: block; position: fixed; inset: 0 0 0 auto; width: min(340px, 100%); z-index: 40; box-shadow: -10px 0 30px rgba(0,0,0,.2); } .only-wide { display: none; } .only-mobile.dt { display: inline-flex; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { display: none; }
  .mobile-nav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav button { flex: 1; border: 0; background: none; padding: 8px 0 6px; font-size: 11px; color: var(--muted); display: grid; justify-items: center; gap: 2px; position: relative; }
  .mobile-nav button.on { color: var(--accent); font-weight: 600; }
  .mobile-nav svg { width: 20px; height: 20px; }
  .mobile-nav .count { position: absolute; top: 2px; left: 55%; background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 10px; padding: 0 5px; }
  .page { padding: 16px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-chat .conv-list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
  .only-mobile { display: inline-flex; }
  .dash-grid, .grid2 { grid-template-columns: 1fr; }
  .col { width: 82vw; }
  .msg { max-width: 88%; }
  .chat-head .actions { width: 100%; }
  .chat-head .assignee { flex: 1; max-width: none; }
}
