[hidden] { display: none !important; }

:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #161a23;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #3d6bff;
  --accent-ink: #ffffff;
  --accent-soft: #e8eeff;
  --ok: #12a150;
  --ok-soft: #e3f6ec;
  --warn: #c27803;
  --warn-soft: #fff4dd;
  --bad: #d92d20;
  --bad-soft: #fde8e7;
  --bubble-in: #ffffff;
  --bubble-out: #e3ecff;
  --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);
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f14;
    --panel: #151821;
    --panel-2: #1a1e29;
    --line: #262b38;
    --line-strong: #333a4a;
    --text: #e8eaf0;
    --muted: #98a0b3;
    --faint: #6b7385;
    --accent: #6d8dff;
    --accent-ink: #0b0d12;
    --accent-soft: #1d2540;
    --ok: #3ccf7f;
    --ok-soft: #15291f;
    --warn: #f0b44c;
    --warn-soft: #2d2412;
    --bad: #ff6b5f;
    --bad-soft: #351a19;
    --bubble-in: #1d2130;
    --bubble-out: #24305a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f14;
  --panel: #151821;
  --panel-2: #1a1e29;
  --line: #262b38;
  --line-strong: #333a4a;
  --text: #e8eaf0;
  --muted: #98a0b3;
  --faint: #6b7385;
  --accent: #6d8dff;
  --accent-ink: #0b0d12;
  --accent-soft: #1d2540;
  --ok: #3ccf7f;
  --ok-soft: #15291f;
  --warn: #f0b44c;
  --warn-soft: #2d2412;
  --bad: #ff6b5f;
  --bad-soft: #351a19;
  --bubble-in: #1d2130;
  --bubble-out: #24305a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px; border-right: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #9b6bff); color: #fff; font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 520; text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px; }
.main { min-width: 0; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.page-head p { color: var(--muted); margin-top: 2px; }

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; } /* let long selects / text shrink instead of widening the page */
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row .spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 560; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 34px; padding: 0; }
.btn svg { width: 16px; height: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px; border-radius: 99px; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.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; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 560; font-size: 13px; }
label.field .hint, .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); font: inherit; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
select { max-width: 100%; text-overflow: ellipsis; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--line-strong); cursor: pointer; transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; 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 + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.switch-row .txt { display: flex; flex-direction: column; }
.pres-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pres-table th, .pres-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.pres-table th { font-weight: 600; color: var(--muted); }
.switch-row .txt b { font-weight: 560; }

.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); }
.seg { flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 560; padding: 5px 12px;
  border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 560; padding: 9px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 6px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  font-weight: 650; font-size: 14px; color: #fff; background: var(--accent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 46px; height: 46px; font-size: 17px; }

/* ---------- dashboard ---------- */
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 560; display: flex; align-items: center; gap: 7px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.hero {
  display: flex; align-items: center; gap: 18px; padding: 20px 22px;
  background: linear-gradient(120deg, var(--accent-soft), var(--panel) 60%);
}
.hero .big { font-size: 18px; font-weight: 650; }
.checklist { display: flex; flex-direction: column; }
.check { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); }
.check:first-child { border-top: 0; }
.check .num {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); flex: none;
}
.check.done .num { background: var(--ok); color: #fff; border-color: var(--ok); }
.check .txt { flex: 1; }
.check.done .txt b { text-decoration: line-through; color: var(--muted); }

.feed { max-height: 560px; overflow: auto; }
.feed-item { display: flex; gap: 12px; padding: 11px 18px; border-top: 1px solid var(--line); animation: fadein .25s ease; }
.feed-item:first-child { border-top: 0; }
/* Rows scrolled out of the feed's 560 px box skip layout and paint until they come near (80 rows took ~300 ms of
   layout on a ×4-throttled phone, 2026-10-15 trace). */
.feed .feed-item { content-visibility: auto; contain-intrinsic-size: auto 62px; }
.feed-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; font-size: 14px; background: var(--panel-2); }
.feed-icon.incoming { background: var(--accent-soft); }
.feed-icon.sent { background: var(--ok-soft); }
.feed-icon.draft { background: var(--warn-soft); }
.feed-icon.error { background: var(--bad-soft); }
.feed-body { min-width: 0; flex: 1; }
.feed-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--muted); }
.feed-meta b { color: var(--text); font-weight: 600; }
.feed-text { white-space: pre-wrap; word-break: break-word; margin-top: 1px; }
@keyframes fadein { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ---------- chats ---------- */
.chats-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; height: calc(100vh - 130px); min-height: 520px; }
.chat-list { display: flex; flex-direction: column; overflow: hidden; }
.chat-list-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.chat-list-items { overflow: auto; flex: 1; }
.chat-row { display: flex; align-items: center; gap: 11px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.chat-row:hover { background: var(--panel-2); }
.chat-row.sel { background: var(--accent-soft); }
.chat-row .info { min-width: 0; flex: 1; }
.chat-row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.chat-row .last { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-pane { display: flex; flex-direction: column; overflow: hidden; }
.chat-pane-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-pane-body { flex: 1; overflow: auto; }
.messages { display: flex; flex-direction: column; gap: 6px; padding: 18px; }
.bubble {
  max-width: 72%; padding: 7px 11px 6px; border-radius: 14px; background: var(--bubble-in); border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word; align-self: flex-start;
}
.bubble.out { background: var(--bubble-out); border-color: transparent; align-self: flex-end; }
.bubble .who { font-size: 12px; font-weight: 650; color: var(--accent); }
.bubble .time { font-size: 11px; color: var(--faint); text-align: right; margin-top: 2px; }
.bubble .media-tag { color: var(--muted); font-style: italic; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.composer textarea { min-height: 44px; max-height: 160px; }
.suggestion { border: 1px dashed var(--accent); border-radius: 12px; padding: 12px; background: var(--accent-soft); display: flex; flex-direction: column; gap: 8px; }

.plan-msg { display: flex; gap: 8px; align-items: flex-start; }
.plan-msg textarea { min-height: 40px; }
.media-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); flex: 1; }
.media-chip img, .media-chip video { width: 48px; height: 48px; object-fit: cover; border-radius: 7px; background: var(--panel-2); }

.settings-form { padding: 18px; display: flex; flex-direction: column; gap: 18px; max-width: 760px; }
.form-section { display: flex; flex-direction: column; gap: 12px; }
.form-section > h3 { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- drafts ---------- */
.draft { display: flex; flex-direction: column; }
.draft-quote { border-left: 3px solid var(--line-strong); padding: 4px 10px; color: var(--muted); white-space: pre-wrap; }

/* ---------- media ---------- */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .12s, background .12s; background: var(--panel);
}
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.media-card { overflow: hidden; display: flex; flex-direction: column; }
.media-card.off { opacity: .6; }
.media-thumb { height: 170px; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; position: relative; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .glyph { font-size: 40px; }
.media-thumb .kind { position: absolute; top: 8px; left: 8px; }
.media-meta { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.media-meta textarea { min-height: 72px; font-size: 13px; }
.media-meta input, .media-meta select { font-size: 13px; padding: 6px 8px; }

/* ---------- style ---------- */
.profile-list { display: flex; flex-direction: column; }
.profile-item { padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.profile-item:first-child { border-top: 0; }
.profile-item:hover { background: var(--panel-2); }
.profile-item.sel { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; }
.pick-list { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.pick:first-child { border-top: 0; }
.pick:hover { background: var(--panel-2); }

/* ---------- overlays ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10, 12, 18, .45); display: grid; place-items: center; z-index: 50;
  padding: 20px; animation: fadein .15s;
}
.modal { width: min(620px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: var(--shadow-lg); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  min-width: 240px; max-width: 420px; padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); animation: fadein .2s; font-weight: 520;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.qr-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr { width: 220px; height: 220px; border-radius: 14px; background: #fff; padding: 6px; border: 1px solid var(--line); flex: none; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.btn.tg-login { height: auto; min-height: 44px; padding: 8px 16px; font-size: 15px; white-space: normal; text-align: center;
  background: #2aabee; border-color: #2aabee; color: #fff; align-self: flex-start; max-width: 100%; }
.check .btn { white-space: normal; height: auto; min-height: 28px; padding: 4px 10px; text-align: center; }
.btn.tg-login:hover { filter: brightness(1.05); background: #2aabee; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(400px, 100%); padding: 28px; }

.kbd { font-family: var(--mono); font-size: 11.5px; padding: 1px 5px; border: 1px solid var(--line-strong); border-radius: 4px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--text); border: 1px solid transparent; }
.notice.info { background: var(--accent-soft); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  /* One column: the top bar takes its own height and the page the rest. With implicit auto rows the free height
     of min-height: 100vh was split between both, so a short "Loading…" page stretched the bar and the page
     jumped up once the data came (CLS 0.27 on a 412x823 phone). */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav a span.lbl { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 0; min-width: 0; }
  .app > * { min-width: 0; }
  .main { padding: 18px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .chats-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list-items { max-height: 340px; }
  .chat-pane { min-height: 520px; }
  .hero { flex-wrap: wrap; }
}
