:root {
  --bg: #0e0e12;
  --bg-2: #16161d;
  --card: #1c1c25;
  --card-2: #23232e;
  --line: #2e2e3b;
  --text: #ececf1;
  --muted: #9a9aab;
  --accent: #a970ff;
  --accent-2: #7c4dff;
  --ok: #3ccf91;
  --warn: #ffb547;
  --bad: #ff5c6c;
  --info: #4db5ff;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(14, 14, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 18px; white-space: nowrap; }
.brand span { color: var(--accent); }
.top-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--card-2); border: 1px solid var(--line); white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.warn .dot { background: var(--warn); }
.pill.bad .dot { background: var(--bad); }
.pill.dry { color: var(--warn); border-color: rgba(255, 181, 71, 0.4); }
.spend { font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 18px; height: 18px; }

/* -------------------------------------------------------------- layout */
main { max-width: 1180px; margin: 0 auto; padding: 14px 16px 24px; }
.view { display: none; }
.view.active { display: block; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 2px 8px; }

/* --------------------------------------------------------- bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(22, 22, 29, 0.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.nav button {
  flex: 1; background: none; border: 0; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px;
}
.nav button svg { width: 22px; height: 22px; }
.nav button.active { color: var(--text); }
.nav button.active svg { color: var(--accent); }
.badge-count {
  position: absolute; transform: translate(14px, -12px);
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
.nav button { position: relative; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .nav {
    position: sticky; top: 57px; bottom: auto; height: 48px; padding: 0;
    justify-content: center; gap: 8px; border-top: 0; border-bottom: 1px solid var(--line);
  }
  .nav button { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 0 18px; font-size: 14px; }
  .nav button.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .badge-count { position: static; transform: none; }
}

/* ------------------------------------------------------------- filters */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 999px;
  cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: center;
}
.chip-btn.on { border-color: var(--accent); color: var(--accent); }
.filters {
  margin-top: 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.filters label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(6, minmax(0, 1fr)); } .filters .full { grid-column: span 2; } }

select, input[type="text"], input[type="number"], input[type="password"], input[type="search"], textarea {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; outline: none; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }

/* --------------------------------------------------------------- cards */
.grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.clip {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; min-width: 0;
}
.clip.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { 0% { box-shadow: 0 0 0 2px var(--accent); transform: translateY(-6px); } 100% { box-shadow: 0 0 0 0 transparent; transform: none; } }
.media { position: relative; aspect-ratio: 16 / 9; background: #000; }
.media img, .media iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: cover; }
.media .play {
  position: absolute; inset: 0; display: grid; place-items: center; cursor: pointer; border: 0;
  background: linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, 0.55));
}
.media .play span {
  width: 58px; height: 58px; border-radius: 50%; background: rgba(169, 112, 255, 0.92);
  display: grid; place-items: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.media .play svg { width: 26px; height: 26px; margin-left: 4px; color: #fff; }
.media .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.score {
  position: absolute; top: 10px; left: 10px; font-weight: 800; font-size: 14px;
  padding: 3px 9px; border-radius: 9px; background: rgba(0, 0, 0, 0.72); border: 1px solid rgba(255, 255, 255, 0.15);
}
.score.s-high { color: #ffd166; }
.score.s-mid { color: var(--ok); }
.score.s-low { color: var(--muted); }
.status-tag {
  position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  padding: 3px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.72); letter-spacing: 0.04em;
}
.st-clip { color: var(--ok); } .st-vod { color: var(--info); } .st-dry_run { color: var(--warn); }
.st-timestamp { color: var(--info); } .st-rejected { color: var(--muted); } .st-no_ai { color: var(--bad); }

.clip-body { padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.clip-title { font-weight: 700; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.meta b { color: var(--text); font-weight: 600; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); }
.reason { color: #c9c9d6; font-size: 13px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.err { color: var(--warn); font-size: 12px; overflow-wrap: anywhere; }
.clip-actions { display: flex; gap: 8px; align-items: center; padding: 10px 14px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.vote {
  border: 1px solid var(--line); background: var(--card-2); border-radius: 10px; padding: 6px 12px;
  cursor: pointer; font-size: 16px; line-height: 1;
}
.vote.on-up { border-color: var(--ok); background: rgba(60, 207, 145, 0.15); }
.vote.on-down { border-color: var(--bad); background: rgba(255, 92, 108, 0.15); }
.clip-actions .links { margin-left: auto; display: flex; gap: 12px; font-size: 13px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; border: 1px dashed var(--line); border-radius: var(--radius); margin-top: 14px; }
.more { display: block; margin: 18px auto 0; }

.new-banner {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(70px + env(safe-area-inset-top)); z-index: 25;
  background: var(--accent-2); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); cursor: pointer;
}

/* ---------------------------------------------------------------- live */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
@media (max-width: 480px) {
  .topbar { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 16px; }
  .top-meta { gap: 6px; }
  .pill { padding: 4px 8px; }
  #status-text { display: none; }
  .dry-long { display: none; }
}
.status-msg { margin-top: 10px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.agents { display: grid; gap: 10px; margin-top: 14px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .agents { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.agent { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.agent.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(169, 112, 255, 0.35); } 100% { border-color: var(--line); box-shadow: none; } }
.agent-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.agent-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-viewers { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; white-space: nowrap; }
.agent-title { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 8px; }
.state { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--card-2); white-space: nowrap; }
.state.listen { color: var(--ok); } .state.busy { color: var(--accent); } .state.cool { color: var(--info); }
.state.warm { color: var(--warn); } .state.error { color: var(--bad); }
.zbar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; position: relative; }
.zbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.6s; }
.zbar.hot i { background: linear-gradient(90deg, #ff7a59, #ffd166); }
.agent-stats { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.agent-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.agent-last { font-size: 12px; margin-top: 6px; color: #c9c9d6; overflow-wrap: anywhere; }

/* ------------------------------------------------------------ settings */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 16px; }
.panel p.hint { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row > label:not(.switch) { flex: 1; min-width: 0; }
.sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.row input[type="number"] { width: 110px; flex: none; text-align: right; }
.stack { display: flex; flex-direction: column; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.stack:first-of-type { border-top: 0; }
.range-wrap { display: flex; align-items: center; gap: 12px; }
.range-wrap output { min-width: 34px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; min-width: 0; }
.estimate { font-size: 13px; color: var(--muted); }
.estimate b { color: var(--text); }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; transition: 0.2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; border-radius: 50%; background: #fff; transition: 0.2s; }
.switch input:checked + span { background: var(--accent-2); border-color: var(--accent-2); }
.switch input:checked + span::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 13px; max-width: 100%; }
.chip img { width: 20px; height: 26px; border-radius: 3px; object-fit: cover; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.search-box { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); }
.suggest button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 8px 12px; cursor: pointer; text-align: left; }
.suggest button:hover, .suggest button:focus { background: rgba(169, 112, 255, 0.15); }
.suggest img { width: 28px; height: 38px; border-radius: 4px; object-fit: cover; background: var(--card); }
.suggest .none { padding: 10px 12px; color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--line); background: var(--card-2); border-radius: 10px; padding: 9px 14px;
  cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.device-code { font-size: 30px; font-weight: 800; letter-spacing: 0.12em; text-align: center; padding: 12px; background: var(--bg-2); border-radius: 12px; border: 1px dashed var(--accent); margin: 8px 0; font-variant-numeric: tabular-nums; }
.kv { font-size: 13px; color: var(--muted); }
.kv b { color: var(--text); }
.bar { height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar.warn i { background: var(--warn); } .bar.bad i { background: var(--bad); }
.settings-cols { display: grid; gap: 12px; }
@media (min-width: 900px) { .settings-cols { grid-template-columns: 1fr 1fr; align-items: start; } .settings-cols > div { min-width: 0; } }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 0; }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  background: var(--card-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-size: 14px; max-width: calc(100% - 32px);
}
.toast.err { border-color: var(--bad); color: #ffd0d5; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* --------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.login-card h1 span { color: var(--accent); }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .msg { color: var(--bad); font-size: 13px; min-height: 18px; }
body.login { padding-bottom: 0; }
.mt { margin-top: 8px; }
.bar i { width: 0; }
.tag.eye { border-color: rgba(77, 181, 255, 0.5); color: var(--info); }
#eye-estimate { margin-top: 8px; }
