:root {
  --bg: #0E0E10; --surface: #16161A; --surface-2: #1E1E24; --line: #2A2A31;
  --text: #F2F2F4; --muted: #9A9AA6; --accent: #87EFFF; --accent-ink: #062A30;
  --good: #8BE38B; --warn: #FFD37A; --bad: #FF8A80;
  --r: 16px; --r-s: 10px;
  --safe-top: max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --content-top: var(--tg-content-safe-area-inset-top, 0px);
  font-family: Inter, Manrope, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
html.light {
  --bg: #F6F6F7; --surface: #FFFFFF; --surface-2: #F0F0F2; --line: #E2E2E6;
  --text: #121216; --muted: #6B6B76; --accent: #0FA3B8; --accent-ink: #FFFFFF;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
body { overflow-x: hidden; }
#app { min-height: 100vh; padding: calc(var(--safe-top) + var(--content-top)) 0 calc(76px + var(--safe-bottom)); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.top-title { color: var(--muted); font-size: 13px; }
main { padding: 4px 16px 24px; max-width: 720px; margin: 0 auto; }
h1 { font-size: 22px; margin: 8px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface-2); border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 42px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg, .tabs svg, .icon { width: 18px; height: 18px; flex: none; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; }
.chip.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--accent); font-weight: 600; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=url], input[type=datetime-local], textarea, select {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 92px; }
textarea.editor { min-height: 220px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }

.steps { display: flex; gap: 6px; margin: 2px 0 14px; }
.steps div { flex: 1; height: 3px; border-radius: 2px; background: var(--line); }
.steps div.on { background: var(--accent); }

.variant .label { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.score { font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.score.hi { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.bubble { background: var(--surface-2); border-radius: 14px 14px 14px 4px; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble code { background: rgba(127,127,127,.18); border-radius: 4px; padding: 0 4px; font-size: 13px; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble .photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 4px; margin: -4px -6px 8px; }
.bubble .photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; }
.counter.warn { color: var(--warn); } .counter.bad { color: var(--bad); }
.toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.toolbar button { width: 40px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; }
.copybox { position: relative; background: var(--surface-2); border-radius: 12px; padding: 10px 44px 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.copybox .copy { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; }
.frames { counter-reset: f; list-style: none; padding: 0; margin: 0; }
.frames li { counter-increment: f; display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.frames li::before { content: counter(f); color: var(--muted); font-size: 13px; }
.frames b { display: block; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; min-width: 0; }
.kpi .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .t { font-size: 12px; color: var(--muted); }
.kpi .d { font-size: 12px; font-variant-numeric: tabular-nums; }
.d.up { color: var(--good); } .d.down { color: var(--bad); }

.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.badge.scheduled { color: var(--accent); border-color: var(--accent); }
.badge.published { color: var(--good); }
.badge.failed { color: var(--bad); border-color: var(--bad); }
.badge.generated, .badge.approved { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .icon { width: 28px; height: 28px; margin-bottom: 8px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-bottom)); z-index: 10; }
.tabs button { flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; padding: 4px 0; cursor: pointer; }
.tabs button.on { color: var(--accent); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-bottom)); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: var(--bad); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 18px 4px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bars { width: 100%; height: auto; display: block; }
.nav-list button { width: 100%; display: flex; align-items: center; justify-content: space-between; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 14px 2px; cursor: pointer; text-align: left; }
.nav-list button:last-child { border-bottom: 0; }
.tabs[hidden] { display: none; }
