:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --line: #e3e8f0;
  --line-strong: #cfd8e6;
  --text: #101828;
  --muted: #667085;
  --brand: #2f6bff;
  --brand-soft: #eef3ff;
  --ok: #12b76a;
  --warn: #f79009;
  --danger: #f04438;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1a2029;
  --line: #26303c;
  --line-strong: #35414f;
  --text: #eef2f7;
  --muted: #97a3b4;
  --brand: #6f96ff;
  --brand-soft: #1b2740;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
a { color: inherit; }
button { font: inherit; }
.app { min-height: 100%; }

/* --- auth --- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% 10%, rgba(47, 107, 255, .13), transparent 60%),
    radial-gradient(700px 400px at 88% 90%, rgba(18, 183, 106, .12), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 30px;
}
.auth-card h1 { margin: 18px 0 6px; font-size: 22px; letter-spacing: -.02em; }
.auth-card p.lead { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 13px;
  background: radial-gradient(130% 130% at 24% 18%, #8ab4ff, #2f6bff 65%);
  display: grid; place-items: center; box-shadow: 0 8px 20px rgba(47, 107, 255, .3);
}
.brand-mark svg { width: 22px; height: 22px; fill: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.field .hint { font-size: 12px; color: var(--muted); }
.field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: filter .15s ease, transform .12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; display: none; }
.alert.show { display: block; }
.alert-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert-ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-switch button { background: none; border: 0; color: var(--brand); font-weight: 600; cursor: pointer; padding: 0; }

/* --- shell --- */
.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.side-title { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.side-title .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
.side-title .brand-mark svg { width: 17px; height: 17px; }
.widget-list { display: flex; flex-direction: column; gap: 4px; }
.widget-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
  background: none; color: var(--text); cursor: pointer; font-size: 13.5px;
}
.widget-item:hover { background: var(--surface-2); }
.widget-item.active { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--brand); font-weight: 600; }
.widget-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.widget-item span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 11px; border-radius: 10px;
  border: 0; background: none; color: var(--text); cursor: pointer; font-size: 13.5px; text-align: left; width: 100%;
}
.nav-item svg { width: 17px; height: 17px; fill: var(--muted); flex: 0 0 auto; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active svg { fill: var(--brand); }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 6px; border-radius: 999px; background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok);
}
.side-note {
  margin-top: auto; border-radius: 12px; padding: 12px; font-size: 12.5px; line-height: 1.45;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.side-note b { display: block; color: var(--text); margin-bottom: 4px; font-size: 13px; }
.side-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.side-foot button { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.side-foot button:hover { color: var(--text); }

.main { padding: 26px 30px 90px; max-width: 1240px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow);
}
.step { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; margin-bottom: 26px; }
.step-num {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 14px;
}
.step h2 { margin: 3px 0 4px; font-size: 16.5px; letter-spacing: -.01em; }
.step .step-lead { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.step-body { min-width: 0; }

.channels { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.channel-tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px; cursor: pointer;
  padding: 12px 14px; min-width: 96px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 12.5px; font-weight: 500;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.channel-tile .ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); }
.channel-tile .ico svg { width: 22px; height: 22px; fill: var(--muted); }
.channel-tile:hover { border-color: var(--line-strong); }
.channel-tile.on { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); color: var(--text); font-weight: 600; }
.channel-tile.on .ico { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.channel-tile.on .ico svg { fill: var(--ok); }

.channel-editor { display: flex; flex-direction: column; gap: 12px; }
.channel-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface-2); }
.channel-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 600; font-size: 13.5px; }
.channel-card-head .ico { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; }
.channel-card-head .ico svg { width: 16px; height: 16px; fill: #fff; }
.channel-card-head .remove { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.channel-card-head .remove:hover { color: var(--danger); }
.channel-empty { font-size: 13px; color: var(--muted); }

.install-card { border: 1px dashed var(--line-strong); border-radius: 14px; padding: 16px; }
.install-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.install-head b { font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
pre.code {
  margin: 0; padding: 12px; border-radius: 10px; overflow: auto; max-height: 190px;
  background: #0f1420; color: #dbe4f3; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-all;
}
.code-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

.preview-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.browser-card { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--surface-2); }
.browser-bar { display: flex; align-items: center; gap: 6px; padding: 9px 12px; background: #232b38; }
.browser-bar i { width: 9px; height: 9px; border-radius: 50%; background: #ff5f57; }
.browser-bar i:nth-child(2) { background: #febc2e; }
.browser-bar i:nth-child(3) { background: #28c840; }
.browser-bar .url {
  flex: 1; margin-left: 8px; height: 20px; border-radius: 6px; background: rgba(255, 255, 255, .13);
  color: rgba(255, 255, 255, .6); font-size: 11px; display: flex; align-items: center; padding: 0 8px;
}
.preview-frame { width: 100%; height: 420px; border: 0; display: block; background: #eef1f6; }
.preview-note { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.toggle { display: flex; align-items: center; gap: 10px; font-size: 13.5px; cursor: pointer; user-select: none; }
.toggle input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .18s ease; flex: 0 0 auto; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
.toggle input:checked { background: var(--brand); }
.toggle input:checked::after { transform: translateX(16px); }

.tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); gap: 3px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; font-weight: 500; }
.tabs button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, .09); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface); }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; margin-bottom: 2px; }
.stat span { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bars .bar i { width: 100%; border-radius: 6px 6px 3px 3px; background: color-mix(in srgb, var(--brand) 70%, transparent); min-height: 2px; display: block; }
.bars .bar span { font-size: 10.5px; color: var(--muted); }
.channel-stats { display: flex; flex-direction: column; gap: 8px; }
.channel-stat { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.channel-stat .track { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.channel-stat .track i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.channel-stat b { min-width: 34px; text-align: right; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0 auto 16px; max-width: 380px; font-size: 13px; line-height: 1.55; }

.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.save-bar {
  position: sticky; bottom: 0; margin-top: 8px; padding: 12px 0;
  display: flex; align-items: center; gap: 12px; justify-content: flex-end;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.save-state { margin-right: auto; font-size: 12.5px; color: var(--muted); }
.save-state.dirty { color: var(--warn); }
.save-state.saved { color: var(--ok); }

@media (max-width: 1080px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding: 20px 16px 80px; }
  .field-row { grid-template-columns: 1fr; }
}
