:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f7f9fc; --surface-3: #eef2f7;
  --line: #e3e8ef; --line-strong: #cfd7e3;
  --ink: #0f1728; --ink-2: #475467; --ink-3: #8592a6;
  --accent: #2481cc; --accent-ink: #ffffff; --accent-soft: #e7f2fc; --accent-strong: #1b6bb0;
  --good: #12805c; --good-soft: #e4f6ee; --warn: #b25e09; --warn-soft: #fdf1e2;
  --bad: #c8322b; --bad-soft: #fdeceb; --muted-soft: #eef1f5;
  --chat-bg: #cfdcb8; --bubble: #ffffff; --bubble-ink: #0f1728; --bubble-link: #2481cc; --kb: rgba(255,255,255,.72);
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 20px 50px -12px rgba(16,24,40,.25);
  --r: 12px; --r-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #151b24; --surface-2: #1a212c; --surface-3: #222b38;
    --line: #283242; --line-strong: #364256;
    --ink: #e8edf4; --ink-2: #a9b4c4; --ink-3: #6f7c90;
    --accent: #4ea4f0; --accent-ink: #06121f; --accent-soft: #15283d; --accent-strong: #7bbcf5;
    --good: #3fc492; --good-soft: #10291f; --warn: #e9a24a; --warn-soft: #2e2212; --bad: #f07067; --bad-soft: #321716; --muted-soft: #1f2732;
    --chat-bg: #0e1621; --bubble: #182533; --bubble-ink: #e8edf4; --bubble-link: #6ab3f3; --kb: rgba(40,60,82,.85);
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b24; --surface-2: #1a212c; --surface-3: #222b38;
  --line: #283242; --line-strong: #364256;
  --ink: #e8edf4; --ink-2: #a9b4c4; --ink-3: #6f7c90;
  --accent: #4ea4f0; --accent-ink: #06121f; --accent-soft: #15283d; --accent-strong: #7bbcf5;
  --good: #3fc492; --good-soft: #10291f; --warn: #e9a24a; --warn-soft: #2e2212; --bad: #f07067; --bad-soft: #321716; --muted-soft: #1f2732;
  --chat-bg: #0e1621; --bubble: #182533; --bubble-ink: #e8edf4; --bubble-link: #6ab3f3; --kb: rgba(40,60,82,.85);
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sm svg.i, svg.i.sm { width: 15px; height: 15px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); } .small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; } .between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Shell ── */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 16px; font-weight: 750; font-size: 17px; letter-spacing: -.02em; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.brand-mark svg.i { width: 17px; height: 17px; }
.compose-btn { margin: 0 4px 12px; justify-content: center; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px; color: var(--ink-2); font-weight: 520; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent-strong); }
.nav a .count { margin-left: auto; font-size: 11.5px; font-weight: 650; padding: 0 7px; border-radius: 99px; background: var(--surface-3); color: var(--ink-2); line-height: 19px; }
.nav a.on .count { background: var(--accent); color: var(--accent-ink); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.bot-pill { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 9px; background: var(--surface-2); font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.main { min-width: 0; }
.topbar { display: none; }
.view { max-width: 1200px; margin: 0 auto; padding: 28px 32px 120px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; color: var(--ink-2); }

/* ── Controls ── */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 580; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn .spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.danger:hover { color: var(--bad); background: var(--bad-soft); }
.input, .select, .textarea { width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; }
.textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 120px; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; }
.field > label span { font-weight: 450; color: var(--ink-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.seg button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); font-weight: 560; cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.full { display: flex; } .seg.full button { flex: 1; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 540; color: var(--ink-2); }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chip.tiny { height: 24px; padding: 0 9px; font-size: 12px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 4px 0; }
.switch input { display: none; }
.switch .track { width: 34px; height: 20px; border-radius: 99px; background: var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch b { font-weight: 560; display: block; } .switch small { color: var(--ink-3); display: block; font-size: 12px; line-height: 1.35; }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 650; text-transform: capitalize; background: var(--muted-soft); color: var(--ink-2); white-space: nowrap; }
.badge.scheduled, .badge.sending { background: var(--accent-soft); color: var(--accent-strong); }
.badge.sent, .badge.done { background: var(--good-soft); color: var(--good); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.paused { background: var(--warn-soft); color: var(--warn); }
.badge.repeat { background: transparent; border: 1px solid var(--line-strong); color: var(--ink-2); text-transform: none; font-weight: 560; }

/* ── Cards & lists ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-b { padding: 18px; }
.card-b.tight { padding: 6px 8px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .label { font-weight: 560; }
.stat .num { font-size: 28px; font-weight: 720; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--ink-3); }
.cols { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; }
.cols > *, .stats > * { min-width: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 10px; }
.item:hover { background: var(--surface-2); }
.item + .item { border-top: 1px solid var(--line); border-radius: 0; }
.item:hover + .item { border-top-color: transparent; }
.tile { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); flex: none; overflow: hidden; }
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile.ok { background: var(--good-soft); color: var(--good); } .tile.bad { background: var(--bad-soft); color: var(--bad); }
.item-t { font-weight: 580; }
.item-s { font-size: 12.5px; color: var(--ink-2); }
.item-err { font-size: 12.5px; color: var(--bad); margin-top: 2px; }
.when { text-align: right; font-size: 12.5px; white-space: nowrap; }
.when b { display: block; font-weight: 600; font-size: 13px; }
.actions { display: flex; gap: 2px; opacity: .65; }
.item:hover .actions { opacity: 1; }
.day-h { padding: 16px 10px 6px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-2); }
.empty .tile { margin: 0 auto 12px; width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search svg { position: absolute; left: 11px; top: 10px; color: var(--ink-3); }
.search .input { padding-left: 36px; }
.bulkbar { position: sticky; top: 10px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; margin-bottom: 12px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); }
.bulkbar .btn { background: transparent; color: inherit; border-color: rgba(127,127,127,.4); }
input[type=checkbox].ck { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: none; }
.notice { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink); margin-bottom: 18px; align-items: flex-start; }
.notice svg { color: var(--accent); margin-top: 2px; }
.notice.warn { background: var(--warn-soft); } .notice.warn svg { color: var(--warn); }
.steps { display: grid; gap: 10px; counter-reset: s; padding: 0; margin: 0; list-style: none; }
.steps li { display: flex; gap: 12px; align-items: flex-start; counter-increment: s; }
.steps li::before { content: counter(s); width: 24px; height: 24px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-size: 12px; font-weight: 700; color: var(--ink-2); }
.steps li.done::before { content: "✓"; background: var(--good-soft); color: var(--good); }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

/* ── Chart ── */
.chart { padding: 8px 18px 14px; }
.chart svg { width: 100%; height: 190px; display: block; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font-size: 10.5px; }
.chart .s { fill: var(--accent); } .chart .f { fill: var(--bad); }
.chart rect.hit { fill: transparent; cursor: default; }
.chart g.col:hover rect.hit { fill: var(--surface-3); opacity: .6; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--bg); padding: 7px 10px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow-lg); white-space: nowrap; }

/* ── Composer ── */
.composer { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }
.composer .card + .card { margin-top: 14px; }
.sec-t { display: flex; align-items: center; gap: 8px; font-weight: 650; margin-bottom: 12px; }
.sec-t .faint { font-weight: 450; margin-left: auto; font-size: 12.5px; }
.types { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.types button { display: grid; justify-items: center; gap: 5px; padding: 11px 4px 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink-2); font-size: 12.5px; font-weight: 580; cursor: pointer; }
.types button:hover { border-color: var(--line-strong); color: var(--ink); }
.types button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent) inset; }
.types svg.i { width: 20px; height: 20px; }
.editor { border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor .textarea { border: 0; border-radius: 0; box-shadow: none !important; min-height: 160px; }
.fmt { display: flex; gap: 2px; padding: 5px 6px; border-bottom: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; align-items: center; }
.fmt button { height: 28px; min-width: 30px; padding: 0 7px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 13px; }
.fmt button:hover { background: var(--surface-3); color: var(--ink); }
.fmt .sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 4px; }
.fmt .counter { margin-left: auto; font-size: 12px; color: var(--ink-3); padding-right: 4px; font-variant-numeric: tabular-nums; }
.fmt .counter.over { color: var(--bad); font-weight: 650; }
.var-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.drop { border: 1.5px dashed var(--line-strong); border-radius: 12px; padding: 22px; text-align: center; color: var(--ink-2); cursor: pointer; background: var(--surface-2); transition: border-color .12s, background .12s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop b { color: var(--ink); }
.media-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 12px; }
.media-list .m { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--line); display: grid; place-items: center; text-align: center; font-size: 11.5px; color: var(--ink-2); padding: 6px; }
.media-list .m img, .media-list .m video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.media-list .m .x { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer; z-index: 2; }
.media-list .m .x svg { width: 13px; height: 13px; }
.media-list .m .nm { position: relative; z-index: 1; word-break: break-all; }
.media-list .m .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); z-index: 2; transition: width .2s; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.opt-row .num { width: 22px; text-align: center; color: var(--ink-3); font-size: 12px; font-weight: 650; }
.opt-row input[type=radio] { accent-color: var(--good); width: 17px; height: 17px; cursor: pointer; }
.kb-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); flex-wrap: wrap; }
.kb-btn { display: flex; gap: 6px; flex: 1; min-width: 240px; }
.kb-btn .input { height: 34px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days .chip { width: 42px; justify-content: center; padding: 0; }
.summary { margin-top: 14px; padding: 11px 13px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); display: flex; gap: 9px; }
.summary svg { color: var(--accent); margin-top: 1px; }
.summary b { color: var(--ink); font-weight: 600; }
details.more { border-top: 1px solid var(--line); }
details.more > summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; align-items: center; gap: 8px; font-weight: 650; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: "›"; margin-left: auto; color: var(--ink-3); font-size: 18px; transition: transform .15s; }
details.more[open] > summary::after { transform: rotate(90deg); }
details.more > div { padding: 0 18px 18px; }
details.more:first-child { border-top: 0; }
.actionbar { position: sticky; bottom: 0; z-index: 10; margin-top: 16px; padding: 12px 0 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); display: flex; gap: 8px; align-items: center; }
.actionbar .grow { font-size: 12.5px; color: var(--ink-3); }
.restore { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 10px; background: var(--warn-soft); margin-bottom: 14px; font-size: 13px; }

/* ── Telegram preview ── */
.preview { position: sticky; top: 20px; }
.phone { border-radius: 22px; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow-lg); background: var(--chat-bg); }
.phone-h { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.ava { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; background: linear-gradient(135deg, #5bb3f0, #2481cc); flex: none; font-size: 14px; }
.phone-h b { display: block; font-size: 14px; } .phone-h small { color: var(--ink-3); font-size: 12px; }
.chat { min-height: 440px; max-height: 70vh; overflow: auto; padding: 18px 12px; display: flex; flex-direction: column; justify-content: flex-end;
  background-image: radial-gradient(rgba(255,255,255,.18) 1px, transparent 1px); background-size: 18px 18px; }
.bubble { max-width: 92%; background: var(--bubble); color: var(--bubble-ink); border-radius: 14px 14px 14px 4px; box-shadow: 0 1px 1px rgba(0,0,0,.12); overflow: hidden; font-size: 14.5px; line-height: 1.42; }
.bubble .txt { padding: 7px 11px 4px; white-space: pre-wrap; word-wrap: break-word; }
.bubble .txt a { color: var(--bubble-link); }
.bubble .txt code, .bubble .txt pre { background: rgba(127,127,127,.15); font-size: 13px; }
.bubble .txt pre { padding: 6px 8px; border-radius: 6px; margin: 4px 0; white-space: pre-wrap; }
.bubble .txt blockquote { margin: 3px 0; padding: 2px 8px; border-left: 3px solid var(--bubble-link); background: rgba(36,129,204,.1); border-radius: 4px; }
.bubble tg-spoiler, .bubble .sp { background: rgba(127,127,127,.5); color: transparent; border-radius: 4px; }
.bubble .meta { display: flex; justify-content: flex-end; gap: 6px; padding: 0 10px 6px; font-size: 11.5px; color: var(--ink-3); }
.bubble .pv { width: 100%; display: block; max-height: 340px; object-fit: cover; background: var(--surface-3); }
.bubble .ph { height: 190px; display: grid; place-items: center; background: linear-gradient(135deg, #8fb9de, #476f99); color: #fff; }
.bubble .ph svg.i { width: 40px; height: 40px; opacity: .85; }
.bubble .alb { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.bubble .alb > * { aspect-ratio: 1; object-fit: cover; width: 100%; height: 100%; }
.bubble .alb .ph { height: auto; }
.bubble .alb > :first-child:nth-last-child(odd) { grid-column: span 2; aspect-ratio: 2 / 1; }
.bubble .file { display: flex; gap: 11px; align-items: center; padding: 10px 11px 2px; }
.bubble .file .tile { background: var(--bubble-link); color: #fff; border-radius: 50%; width: 44px; height: 44px; }
.bubble .blur { filter: blur(14px); }
.bubble .poll { padding: 10px 12px 4px; }
.bubble .poll b { display: block; margin-bottom: 2px; }
.bubble .poll small { color: var(--ink-3); font-size: 12px; }
.bubble .poll .o { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px solid rgba(127,127,127,.15); }
.bubble .poll .o i { width: 17px; height: 17px; border: 2px solid var(--ink-3); border-radius: 50%; flex: none; }
.bubble .poll.multi .o i { border-radius: 5px; }
.bubble .poll .o.ok i { border-color: var(--good); background: var(--good); }
.bubble .poll .vote { text-align: center; color: var(--bubble-link); font-weight: 600; padding: 8px 0 2px; font-size: 13px; }
.bubble .map { height: 150px; background: linear-gradient(135deg,#d8e6c9,#a9c9a0); display: grid; place-items: center; color: #c8322b; }
.bubble .map svg.i { width: 36px; height: 36px; }
.kbd { display: grid; gap: 3px; margin-top: 3px; max-width: 92%; }
.kbd .r { display: flex; gap: 3px; }
.kbd span { flex: 1; text-align: center; padding: 8px 6px; border-radius: 8px; background: var(--kb); color: var(--bubble-ink); font-size: 13.5px; font-weight: 560; backdrop-filter: blur(6px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-note { margin-top: 10px; font-size: 12px; color: var(--ink-3); text-align: center; }

/* ── Bulk ── */
.bk-list { display: grid; gap: 8px; max-height: 70vh; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.bitem { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.bitem .textarea { min-height: 0; padding: 7px 9px; font-size: 13.5px; background: var(--surface); }
.bitem b { font-weight: 600; }
.bnum { width: 22px; text-align: center; font-size: 12px; font-weight: 700; color: var(--ink-3); padding-top: 10px; flex: none; }
.bact { display: flex; flex-direction: column; gap: 0; }
.bact .icon-btn { width: 28px; height: 26px; }
.bact .icon-btn[disabled] { opacity: .3; pointer-events: none; }
.bprog, .progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.bprog span, .progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s; }
.progress { margin: 14px 0 8px; height: 8px; }
.camp .tile { background: var(--accent-soft); color: var(--accent); }

/* ── Templates ── */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tpl { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.tpl p { margin: 0; color: var(--ink-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-height: 3.9em; }

/* ── History table ── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl .pv { max-width: 420px; }
.tbl-wrap { overflow-x: auto; }

/* ── Auth ── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.auth .card { width: min(410px, 100%); padding: 32px; box-shadow: var(--shadow-lg); }
.auth .brand { padding: 0 0 22px; }
.auth h1 { margin-bottom: 4px; } .auth p { margin: 0 0 22px; color: var(--ink-2); }
.auth form { display: grid; gap: 14px; }

/* ── Overlays ── */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; }
.toast { display: flex; gap: 10px; align-items: flex-start; max-width: 380px; padding: 11px 14px; border-radius: 11px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); font-weight: 520; animation: up .18s ease-out; }
.toast svg { color: var(--good); margin-top: 1px; }
.toast.err svg { color: var(--bad); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.overlay { position: fixed; inset: 0; z-index: 70; background: rgba(9,14,22,.5); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(520px, 100%); max-height: 86vh; overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); }
.modal .card-h { border: 0; padding: 20px 22px 6px; }
.modal .card-b { padding: 12px 22px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
.result { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.result:last-child { border: 0; }

/* ── Responsive ── */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .composer { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 980px) {
  .composer, .cols { grid-template-columns: 1fr; }
  .preview { position: static; }
  .chat { min-height: 260px; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .shell.menu .side { transform: none; }
  .shell.menu::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; font-weight: 700; }
  .topbar .btn { margin-left: auto; }
  .view { padding: 18px 16px 110px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .types { grid-template-columns: repeat(3, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .when { display: none; }
  .item { flex-wrap: wrap; }
  .actions { opacity: 1; width: 100%; justify-content: flex-end; }
  .item .mob-when { display: block !important; }
  .tbl .hide-m { display: none; }
  .hide-s, .actionbar .grow { display: none; }
  .actionbar { justify-content: flex-end; }
}

/* ── Workspaces, AI, approvals ── */
.ws-select { height: 34px; margin: -6px 0 12px; font-weight: 600; font-size: 13px; background: var(--surface-2); }
.nav a .count.warn { background: var(--warn-soft); color: var(--warn); }
.fmt .ai-btn { color: var(--accent-strong); font-weight: 650; display: inline-flex; align-items: center; gap: 4px; }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.library { background: var(--accent-soft); color: var(--accent-strong); }

/* ── Calendar ── */
.cal { overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-h { padding: 8px 10px; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.cal-c { min-height: 112px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; min-width: 0; transition: background .1s; }
.cal-c:nth-child(7n) { border-right: 0; }
.cal-c.blank { background: var(--surface-2); }
.cal-c.past { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.cal-c.today .cal-d { color: var(--accent-ink); background: var(--accent); border-radius: 99px; padding: 0 8px; width: fit-content; }
.cal-c.over { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -3px; }
.cal-d { font-size: 12.5px; font-weight: 650; display: flex; gap: 6px; align-items: center; margin-bottom: 2px; }
.cal-d .faint { font-weight: 500; font-size: 11px; }
.cal-chip { display: block; font-size: 11.5px; line-height: 1.3; padding: 3px 6px; border-radius: 6px; color: var(--ink); background: var(--accent-soft); border-left: 3px solid var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cal-chip[draggable="true"] { cursor: grab; }
.cal-chip.drag { opacity: .4; }
.cal-chip.done { background: var(--good-soft); border-color: var(--good); }
.cal-chip.failed { background: var(--bad-soft); border-color: var(--bad); }
.cal-chip.paused, .cal-chip.pending { background: var(--warn-soft); border-color: var(--warn); }
.cal-more { border: 0; background: none; color: var(--accent); font-size: 11.5px; text-align: left; padding: 2px 6px; cursor: pointer; }

/* ── Settings ── */
.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }
.set-nav { position: sticky; top: 20px; display: grid; gap: 2px; }
.set-nav button { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink-2); font-weight: 560; cursor: pointer; text-align: left; }
.set-nav button:hover { background: var(--surface-3); color: var(--ink); }
.set-nav button.on { background: var(--accent-soft); color: var(--accent-strong); }
.cmd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.link-box { margin-top: 4px; padding: 16px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--line-strong); display: grid; gap: 10px; justify-items: start; }
.link-box .code { font: 700 22px ui-monospace, Consolas, monospace; letter-spacing: .06em; padding: 6px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); user-select: all; }
.wm-preview { border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); min-height: 220px; display: grid; place-items: center; overflow: hidden; }
.wm-preview img { width: 100%; display: block; }
input[type=range] { width: 100%; accent-color: var(--accent); }

@media (max-width: 820px) {
  .settings { grid-template-columns: 1fr; }
  .set-nav { position: static; display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .set-nav button { white-space: nowrap; }
  .cal-c { min-height: 70px; padding: 3px; }
  .cal-chip { font-size: 10px; padding: 2px 4px; }
  .types { grid-template-columns: repeat(3, 1fr); }
}

/* ── Mobile app layout (overrides above) ── */
.bnav, .cal-mob { display: none; }
.composer, .cols { min-width: 0; }
.grid2 > *, .grid3 > *, .composer > *, .cols > * { min-width: 0; }
@media (max-width: 980px) {
  .composer, .cols, .cols[style] { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 820px) {
  body { font-size: 14.5px; }
  .view { padding: 14px 14px calc(96px + env(safe-area-inset-bottom)); }
  .topbar { padding: 8px 12px; gap: 8px; font-size: 16px; }
  .topbar .ws-select { margin: 0; height: 32px; max-width: 150px; }

  /* bottom tab bar */
  .bnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px -12px rgba(0,0,0,.35); }
  .bnav a, .bnav button { display: grid; justify-items: center; gap: 2px; padding: 4px 0; border: 0; background: none; color: var(--ink-3); font-size: 11px; font-weight: 600; cursor: pointer; }
  .bnav a.on { color: var(--accent); }
  .bnav svg.i { width: 22px; height: 22px; }
  .bnav .fab svg.i { width: 26px; height: 26px; padding: 4px; box-sizing: content-box; border-radius: 14px; background: var(--accent); color: var(--accent-ink); margin-top: -18px; box-shadow: 0 6px 16px -6px var(--accent); }
  .bnav .fab { color: var(--ink-2); }

  /* page headers & toolbars */
  .head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  h1 { font-size: 21px; }
  .head p { font-size: 13.5px; }
  .head > .row { flex-wrap: wrap; }
  .head > .row > .btn, .head > .btn { flex: 1 1 auto; justify-content: center; }
  .head > .row > .seg { flex: 1 1 100%; }
  .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { white-space: nowrap; flex: 1 0 auto; justify-content: center; padding: 0 11px; }
  .toolbar { gap: 8px; }
  .toolbar > .seg { flex: 1 1 100%; }
  .toolbar .search { flex: 1 1 100%; max-width: none; min-width: 0; }
  .toolbar .select { flex: 1 1 0; width: auto !important; min-width: 0; }
  .card-h { padding: 12px 14px; flex-wrap: wrap; }
  .card-b { padding: 14px; }
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  .input, .select { height: 42px; font-size: 16px; } /* 16px stops iOS zoom */
  .textarea { font-size: 16px; }
  .icon-btn { width: 38px; height: 38px; }

  /* lists */
  .item { flex-wrap: wrap; padding: 12px 8px; gap: 10px; }
  .item > .grow { flex: 1 1 calc(100% - 60px); }
  .actions { opacity: 1; width: 100%; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
  .actions .btn.sm { flex: 1 1 auto; justify-content: center; }
  .bulkbar { flex-wrap: wrap; top: 60px; }

  /* composer */
  .types { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .types button { padding: 9px 2px 7px; }
  .fmt { flex-wrap: wrap; row-gap: 2px; }
  .fmt button { min-width: 34px; height: 32px; }
  .seg.seg-grid { display: grid; grid-template-columns: repeat(3, 1fr); overflow: visible; }
  .seg.seg-grid button { padding: 0 6px; }
  .kb-btn { min-width: 0; flex: 1 1 100%; }
  details.more > summary { padding: 14px; }
  details.more > summary .faint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; text-align: right; }
  details.more > div { padding: 0 14px 14px; }
  .actionbar { bottom: calc(62px + env(safe-area-inset-bottom)); padding: 8px 0 10px; gap: 6px; }
  .actionbar .btn { padding: 0 12px; }
  .actionbar .btn.lg { flex: 1; justify-content: center; height: 44px; font-size: 15px; }
  .preview { margin-top: 6px; }
  .chat { min-height: 220px; max-height: 60vh; }
  .media-list { grid-template-columns: repeat(3, 1fr); }
  .opt-row .input { min-width: 0; }
  .days .chip { width: auto; flex: 1 0 40px; }

  /* bulk */
  .bitem { padding: 8px; gap: 8px; }
  .bitem .tile { width: 32px; height: 32px; }
  .bnum { width: 16px; }
  .bk-list { max-height: none; }

  /* history: table becomes cards */
  .tbl, .tbl tbody { display: block; }
  .tbl thead { display: none; }
  .tbl tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .tbl tr:last-child { border-bottom: 0; }
  .tbl td { padding: 0; border: 0 !important; background: none !important; }
  .tbl td.c-when { grid-column: 1; grid-row: 1; display: flex; gap: 8px; align-items: baseline; }
  .tbl td.c-when div { display: inline; }
  .tbl td.c-st { grid-column: 2; grid-row: 1; text-align: right; }
  .tbl td.pv { grid-column: 1 / -1; max-width: none; }
  .tbl td.c-act { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 4px; }
  .tbl td.c-act:empty { display: none; }

  /* calendar: compact month, tap a day */
  .cal-c { min-height: 54px; padding: 4px 2px; align-items: center; }
  .cal-d { justify-content: center; margin: 0; }
  .cal-d .faint, .cal-chip, .cal-more { display: none; }
  .cal-mob { display: block; border: 0; border-radius: 99px; min-width: 24px; height: 20px; padding: 0 6px; margin-top: 2px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; cursor: pointer; }
  .cal-mob.bad { background: var(--bad); color: #fff; }
  .cal-h { padding: 6px 0; text-align: center; font-size: 10.5px; }
  .toolbar .legend { flex-wrap: wrap; gap: 8px; font-size: 11px; }

  /* misc */
  .tpl-grid { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .num { font-size: 24px; }
  .chart svg { height: 150px; }
  #toasts { left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .overlay { padding: 10px; align-items: end; }
  .modal { max-height: 88vh; border-radius: 16px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
  .link-box .code { font-size: 18px; }
  .notice { padding: 12px; }
  .switch { align-items: flex-start; }
  .switch .track { margin-top: 2px; }
  .side { width: 280px; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
