:root {
  --bg: #f4f3ee;
  --panel: #ffffff;
  --ink: #16201b;
  --muted: #66716b;
  --line: #e2e0d8;
  --accent: #1d7a4e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1e9;
  --warn: #b26a00;
  --warn-soft: #fbf0dc;
  --bad: #b3261e;
  --bad-soft: #f9e3e1;
  --side: #13201a;
  --side-ink: #cfd8d2;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1411; --panel: #151d18; --ink: #e6ebe7; --muted: #8e9a93; --line: #26302a;
    --accent: #3fae78; --accent-ink: #06130c; --accent-soft: #173326;
    --warn: #e0a24a; --warn-soft: #33270f; --bad: #ef7a70; --bad-soft: #3a1714;
    --side: #0a0f0c; --side-ink: #b8c3bc; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 700; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 13px; }
.brand small { display: block; font-weight: 400; color: var(--side-ink); opacity: .7; font-size: 11.5px; }
.nav button { all: unset; display: flex; align-items: center; gap: 10px; width: 100%; box-sizing: border-box; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--side-ink); }
.nav button:hover { background: rgba(255,255,255,.06); }
.nav button.on { background: rgba(255,255,255,.1); color: #fff; }
.nav button:focus-visible { outline: 2px solid var(--accent); }
.side .foot { margin-top: auto; font-size: 12px; opacity: .8; padding: 8px; }
.side .foot form button { all: unset; cursor: pointer; text-decoration: underline; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--line); color: var(--ink); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.view { display: none; } .view.on { display: block; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin: 0; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.stat .v { font-family: var(--mono); font-size: 26px; font-weight: 600; }
.stat .l { color: var(--muted); font-size: 12.5px; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=date], textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 10px 0 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.has { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.drop input { display: none; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font: inherit; color: var(--muted); }
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.vars { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.vars button { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 2px 8px; font-family: var(--mono); font-size: 12px; cursor: pointer; color: var(--ink); }

/* phone preview */
.phone { background: #e9e2d6; border-radius: 14px; padding: 16px; min-height: 160px; }
@media (prefers-color-scheme: dark) { .phone { background: #0b1410; } }
.bubble { background: #d9fdd3; color: #111; border-radius: 10px 10px 2px 10px; padding: 8px 10px; max-width: 92%; margin-left: auto; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 14px; }
@media (prefers-color-scheme: dark) { .bubble { background: #144d37; color: #e9edef; } }
.bubble .att { font-size: 12px; opacity: .75; border-bottom: 1px solid rgba(0,0,0,.1); padding-bottom: 6px; margin-bottom: 6px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 120px; display: flex; }
.bar span { display: block; height: 100%; }
.bar .s { background: var(--accent); } .bar .f { background: var(--bad); } .bar .i { background: var(--warn); }

.qr { display: grid; place-items: center; min-height: 300px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); }
.qr img { width: 280px; height: 280px; background: #fff; padding: 10px; border-radius: 8px; }
.code { font-family: var(--mono); font-size: 30px; letter-spacing: .2em; font-weight: 700; }
.steps { margin: 0; padding-left: 18px; color: var(--muted); } .steps li { margin: 4px 0; }
.note { background: var(--warn-soft); color: var(--ink); border-left: 3px solid var(--warn); padding: 10px 14px; border-radius: 6px; font-size: 13.5px; }
.err { color: var(--bad); font-size: 13.5px; }
.muted { color: var(--muted); }
.log { font-family: var(--mono); font-size: 12.5px; max-height: 320px; overflow: auto; background: var(--bg); border-radius: 8px; padding: 10px; border: 1px solid var(--line); }
.log div { padding: 2px 0; white-space: nowrap; }
.log .sent { color: var(--accent); } .log .failed, .log .error { color: var(--bad); } .log .invalid, .log .skipped { color: var(--warn); }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; max-width: 360px; z-index: 50; }
.toast.on { opacity: 1; transform: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 40; }
.modal.on { display: flex; }
.modal .card { max-width: 860px; width: 100%; }
.hide { display: none !important; }

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

/* mobile */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 2px; }
  .brand { padding: 4px 8px; flex: 1 0 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav button { width: auto; padding: 7px 10px; font-size: 13px; }
  .side .foot { margin: 0 0 0 auto; }
  main { padding: 18px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: 1fr 1fr; }
}

/* ---- multi-user additions ---- */
.gbtn { width: 100%; justify-content: center; gap: 10px; padding: 11px 14px; background: #fff; color: #1f1f1f; border-color: #dadce0; }
.gbtn:hover { border-color: #b7bbc1; background: #f8f9fa; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 8px; }
.me img, .avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: rgba(255,255,255,.15); flex: none; }
.me .who { min-width: 0; line-height: 1.25; }
.me .who b { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who small { display: block; font-size: 11.5px; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quota { margin: 0 8px 10px; font-size: 12px; }
.quota .bar { margin-top: 5px; min-width: 0; background: rgba(255,255,255,.12); }
.nav .sep { height: 1px; background: rgba(255,255,255,.1); margin: 8px 4px; }
.user-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.user-cell .avatar { background: var(--line); display: grid; place-items: center; font-weight: 700; color: var(--muted); font-size: 13px; }
.user-cell small { display: block; color: var(--muted); font-size: 12px; }
.limit-edit { display: flex; gap: 6px; align-items: center; }
.limit-edit input { width: 90px; padding: 5px 8px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-left: 6px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input { max-width: 280px; }
.pkg-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 860px) { .pkg-row { grid-template-columns: 1fr; } .me { flex: 1 0 100%; } .quota { flex: 1 0 100%; } }

/* ---- inbox & bot ---- */
.badge { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; margin-left: 6px; font-weight: 700; }
.lock { font-size: 11px; margin-left: 4px; opacity: .7; }
.inbox { display: grid; grid-template-columns: 340px 1fr; gap: 16px; height: calc(100vh - 170px); min-height: 480px; }
.inbox .card { padding: 14px; display: flex; flex-direction: column; min-height: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chips button { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 99px; padding: 3px 10px; font: inherit; font-size: 12.5px; cursor: pointer; }
.chips button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.chips b { font-weight: 700; }
.conv-list { overflow-y: auto; flex: 1; margin: 0 -14px; }
.conv { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: transparent; padding: 10px 14px; cursor: pointer; font: inherit; color: var(--ink); }
.conv:hover { background: var(--bg); } .conv.on { background: var(--accent-soft); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv .meta { display: flex; gap: 6px; margin-top: 4px; align-items: center; }
.conv .un { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.stage { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--line); color: var(--ink); text-transform: capitalize; }
.stage.interested { background: #e6effc; color: #2457a6; } .stage.qualified { background: var(--warn-soft); color: var(--warn); }
.stage.converted { background: var(--accent-soft); color: var(--accent); } .stage.lost { background: var(--bad-soft); color: var(--bad); }
@media (prefers-color-scheme: dark) { .stage.interested { background: #1b2b45; color: #8db4ef; } }
.human { font-size: 11px; color: var(--bad); font-weight: 700; }
.inbox-thread { padding: 0 !important; }
.inbox-thread .empty { margin: auto; }
.th-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.th-body { display: grid; grid-template-columns: 1fr 260px; flex: 1; min-height: 0; }
.th-msgs { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.th-side { border-left: 1px solid var(--line); padding: 14px; overflow-y: auto; }
.th-side label { margin-top: 10px; }
.th-side input, .th-side select, .th-side textarea { padding: 6px 9px; font-size: 13px; }
.msg { max-width: 78%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg.in { background: var(--panel); align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { background: #d9fdd3; color: #111; align-self: flex-end; border-top-right-radius: 2px; }
@media (prefers-color-scheme: dark) { .msg.out { background: #144d37; color: #e9edef; } }
.msg .src { display: block; font-size: 10.5px; opacity: .6; margin-top: 3px; text-align: right; text-transform: uppercase; letter-spacing: .04em; }
.msg.out.campaign { background: var(--line); color: var(--ink); }
.th-reply { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; }
.th-reply textarea { min-height: 42px; height: 42px; resize: none; }
.modes { display: grid; gap: 8px; }
.mode { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 400; }
.mode input { grid-row: span 2; margin-top: 3px; }
.mode span { color: var(--muted); font-size: 13px; }
.mode.locked { opacity: .5; cursor: not-allowed; }
.mode:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.item:first-child { border-top: 0; }
.item .t { min-width: 0; } .item .t div { white-space: pre-wrap; word-wrap: break-word; }
.chat { display: flex; flex-direction: column; gap: 6px; height: 360px; overflow-y: auto; }
.lead-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.lead-grid span:nth-child(odd) { color: var(--muted); }
@media (max-width: 1100px) { .th-body { grid-template-columns: 1fr; } .th-side { border-left: 0; border-top: 1px solid var(--line); max-height: 220px; } }
@media (max-width: 860px) { .inbox { grid-template-columns: 1fr; height: auto; } .inbox-list { max-height: 360px; } .inbox-thread { min-height: 520px; } }
