:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #14171c;
  --muted: #5f6772;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --danger: #c73a3a;
  --success: #1f8f4e;
  --warning: #b7791f;
  --wa: #25d366;
  --tg: #229ed9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #e9ecf1;
    --muted: #98a1ae;
    --accent: #6d8cff;
    --accent-text: #0b0d12;
    --danger: #ef6b6b;
    --success: #4cc387;
    --warning: #e0a94a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.input:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---------- авторизация ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--wa), var(--tg)); color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; height: 34px; border-radius: 8px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.auth-form { display: grid; gap: 14px; }

/* ---------- кабинет ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 920px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.topbar .spacer { flex: 1; }
.topbar .email { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

main { max-width: 920px; margin: 0 auto; padding: 32px 16px 64px; display: grid; gap: 36px; }
.page-head { display: grid; gap: 6px; }
section { display: grid; gap: 14px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.channel-list { display: grid; gap: 12px; }
.channel-row { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.channel-row .info { flex: 1; min-width: 0; display: grid; gap: 2px; }
.channel-row .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.channel-row .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; color: #fff; }
.logo svg { width: 24px; height: 24px; }
.logo.whatsapp { background: var(--wa); }
.logo.telegram { background: var(--tg); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.connected { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.badge.pending { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.badge.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

.empty { padding: 28px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.add-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.add-card { padding: 18px; display: grid; gap: 14px; align-content: start; }
.add-card .head { display: flex; align-items: center; gap: 12px; }
.add-card .btn { justify-self: start; }

/* ---------- MCP ---------- */
.mcp-card { padding: 20px; display: grid; gap: 18px; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row .value {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); overflow-x: auto; white-space: nowrap;
}
.token-list { display: grid; gap: 8px; }
.token-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.token-item .info { flex: 1; min-width: 0; display: grid; }
.new-token { display: grid; gap: 12px; padding: 16px; border-radius: 12px; background: color-mix(in srgb, var(--success) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border)); }
pre.snippet { margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); overflow-x: auto; font-size: 12.5px; line-height: 1.55; }
.snippet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---------- модалка подключения ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: 100%; max-width: 720px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 18px; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { display: grid; grid-template-columns: 1fr 300px; gap: 24px; padding: 24px 20px; align-items: center; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 14px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.steps li::before { content: counter(step); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: 13px; }
.qr-box { width: 300px; height: 300px; border-radius: 16px; background: #fff; border: 1px solid var(--border); display: grid; place-items: center; position: relative; overflow: hidden; }
.qr-box img { width: 280px; height: 280px; image-rendering: pixelated; }
.qr-box .state { display: grid; justify-items: center; gap: 12px; padding: 20px; text-align: center; color: #3b414b; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #d7dbe2; border-top-color: #2f5bea; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.success-mark { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: #1f8f4e; color: #fff; }
.success-mark svg { width: 30px; height: 30px; }
.password-form { display: grid; gap: 12px; width: 100%; padding: 20px; color: var(--text); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

@media (max-width: 720px) {
  .modal-body { grid-template-columns: 1fr; }
  .qr-box { width: 100%; max-width: 300px; justify-self: center; }
  .qr-box img { width: min(280px, 100%); height: auto; }
  .channel-row { flex-wrap: wrap; }
  .channel-row .actions { width: 100%; display: flex; justify-content: flex-end; }
  h1 { font-size: 22px; }
}
