:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f9fafb; --line: #e2e5ea; --text: #1b2330; --muted: #657084;
  --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e8efff; --ok: #15803d; --ok-soft: #e3f5e8;
  --warn: #a15c07; --warn-soft: #fff1d6; --bad: #b42318; --bad-soft: #fde8e6; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 8px; --side: 220px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1319; --panel: #171c24; --panel2: #1c222b; --line: #2a323e; --text: #e6e9ee; --muted: #93a0b4;
    --accent: #5b8cff; --accent-text: #0b1020; --accent-soft: #1b2744; --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #3a2a0a;
    --bad: #f87171; --bad-soft: #3b1614; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
.boot { padding: 40px; color: var(--muted); }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 6px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, Consolas, monospace; }

/* layout */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 14px; }
.brand i { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--panel2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { padding: 22px 28px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .grow { flex: 1; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* controls */
.btn { font: inherit; font-weight: 550; padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--panel2); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.sm { padding: 3px 8px; font-size: 12px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 90px; font-family: inherit; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 12px; } .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; } .row > * { flex: 1; min-width: 140px; }
.row.tight { gap: 8px; align-items: center; } .row.tight > * { min-width: 0; } .row.tight > input { flex: 1 1 0; } .row.auto > * { flex: 0 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.flat { box-shadow: none; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } .side .who { display: none; } .main { padding: 16px; } .nav { display: flex; flex-wrap: wrap; gap: 2px; } .brand { padding-bottom: 6px; width: 100%; } }

/* table */
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 12px; background: var(--panel2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; } .tbl tbody tr.click { cursor: pointer; } .tbl tbody tr.click:hover { background: var(--panel2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.scroll { overflow-x: auto; }

/* badges */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; } .badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.notice { padding: 10px 12px; border-radius: 6px; margin-bottom: 10px; background: var(--accent-soft); font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); } .notice.bad { background: var(--bad-soft); color: var(--bad); } .notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* photos */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; background: var(--panel2); }
.drop.over, .drop:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.photo { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); display: flex; flex-direction: column; }
.photo .img { aspect-ratio: 1; background: var(--panel2) center/cover no-repeat; position: relative; }
.photo .img .n { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.photo .img .busy { position: absolute; inset: 0; background: rgba(255,255,255,.65); display: grid; place-items: center; color: #111; font-size: 12px; }
.photo .cap { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 6px 8px; font-size: 12px; }
.photo .acts { display: flex; border-top: 1px solid var(--line); } .photo .acts button { flex: 1; border: 0; background: transparent; color: var(--text); padding: 5px 0; cursor: pointer; font-size: 14px; }
.photo .acts button:hover { background: var(--panel2); } .photo .acts button.del:hover { color: var(--bad); } .photo .acts button:disabled { opacity: .3; cursor: default; }

/* telegram-like preview */
.tg { background: #dfe9f2; border-radius: var(--radius); padding: 14px; } @media (prefers-color-scheme: dark) { .tg { background: #0e1621; } }
.tg .bubble { background: #fff; color: #111; border-radius: 12px; max-width: 100%; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
@media (prefers-color-scheme: dark) { .tg .bubble { background: #182533; color: #e8eef5; } }
.tg .pics { display: grid; gap: 2px; } .tg .pics.n1 { grid-template-columns: 1fr; } .tg .pics.n2, .tg .pics.n4 { grid-template-columns: 1fr 1fr; } .tg .pics.n3 { grid-template-columns: 1fr 1fr; }
.tg .pics img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4/3; display: block; max-height: 260px; }
.tg .txt { padding: 8px 12px 10px; white-space: pre-wrap; word-break: break-word; }
.tg .txt a { color: #3390ec; } .tg .txt blockquote { margin: 4px 0; padding-left: 8px; border-left: 3px solid #3390ec; } .tg .txt code, .tg .txt pre { font-family: ui-monospace, Consolas, monospace; background: rgba(127,127,127,.18); border-radius: 4px; padding: 0 3px; }
.tg .txt .spoiler { background: rgba(127,127,127,.4); border-radius: 3px; color: transparent; }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 10px; } .chip { font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; color: var(--text); } .chip:hover { border-color: var(--accent); color: var(--accent); }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(8,12,20,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 20px; width: min(480px, 100%); max-height: 90vh; overflow: auto; }
.modal h2 { font-size: 16px; } .modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; } @media (prefers-color-scheme: dark) { .toast.ok { color: #04210f; } .toast.bad { color: #1c0604; } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 26px; box-shadow: var(--shadow); }
.login .brand { padding-left: 0; font-size: 20px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; } .stat b { font-size: 20px; display: block; font-variant-numeric: tabular-nums; } .stat span { font-size: 12px; color: var(--muted); }
.steps { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; } .steps span { padding: 4px 11px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); } .steps span.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); } .steps span.done { color: var(--ok); }
/* inbox / leads */
.inbox { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 860px) { .inbox { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 99px; padding: 5px 12px; cursor: pointer; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.convs { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-height: 70vh; overflow-y: auto; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:last-child { border-bottom: 0; } .conv:hover { background: var(--panel2); } .conv.on { background: var(--accent-soft); }
.conv .top { display: flex; gap: 8px; align-items: center; } .conv .top b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .pv { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 11px; min-width: 18px; height: 18px; display: inline-grid; place-items: center; padding: 0 5px; font-weight: 700; }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 12px; background: var(--panel2); border-radius: var(--radius); max-height: 52vh; overflow-y: auto; margin-bottom: 10px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg.auto { align-self: flex-end; background: var(--warn-soft); border-color: transparent; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg.failed .meta { color: var(--bad); }
.note { background: var(--warn-soft); border-radius: 6px; padding: 7px 10px; margin-bottom: 6px; font-size: 13px; white-space: pre-wrap; }
.navdot { margin-left: auto; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; } .checks label { display: flex; gap: 6px; align-items: center; font-weight: 500; } .checks input { width: auto; }
[hidden] { display: none !important; }
