:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #070708);
  --bg2: #101012;
  --text: var(--tg-theme-text-color, #f4f4f5);
  --muted: color-mix(in srgb, var(--text) 58%, transparent);
  --quiet: color-mix(in srgb, var(--text) 34%, transparent);
  --line: rgba(255, 255, 255, 0.09);
  --fill: rgba(255, 255, 255, 0.045);
  --fill2: rgba(255, 255, 255, 0.075);
  --blue: var(--tg-theme-button-color, #3b82f6);
  --blue-ink: var(--tg-theme-button-text-color, #fff);
  --good: #3dd68c;
  --warn: #f5a524;
  --bad: #ff5c6a;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tabbar: calc(58px + var(--safe-bot));
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

.app {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 16px var(--tabbar);
}

/* header */
.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 18px;
}
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--quiet);
  font-weight: 600;
}
.top h1 {
  font-size: 28px;
  letter-spacing: -0.04em;
  font-weight: 590;
  line-height: 1.1;
  margin-top: 2px;
}
.live {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }

/* typography helpers */
.kicker { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--quiet); font-weight: 600; }
.muted { color: var(--muted); }
.quiet { color: var(--quiet); }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* health strip */
.strip {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.panel {
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
}
.ram-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ram-val { font-size: 22px; letter-spacing: -0.04em; font-weight: 560; }
.bar {
  height: 5px;
  background: var(--fill2);
  border-radius: 99px;
  margin: 10px 0 6px;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; width: 0; background: var(--blue); border-radius: 99px; }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* lists / rows */
.section { margin: 22px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.section h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.list { border-top: 1px solid var(--line); }
.row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
  color: inherit;
}
.row:active { background: var(--fill); }
.row .t { font-size: 15px; font-weight: 560; letter-spacing: -0.01em; }
.row .d { font-size: 12.5px; color: var(--muted); line-height: 1.35; grid-column: 1 / -1; }
.row .meta { font-size: 11px; color: var(--quiet); align-self: start; padding-top: 2px; text-align: right; }
.row.disabled { opacity: 0.55; cursor: not-allowed; }
.row.disabled .t::after { content: ""; }

/* quick actions */
.actions { display: flex; flex-direction: column; }
.btn-row { display: flex; gap: 8px; margin: 12px 0; }
.btn {
  flex: 1;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 590;
  border: 1px solid var(--line);
  background: var(--fill2);
}
.btn.primary { background: var(--blue); color: var(--blue-ink); border-color: transparent; }
.btn:disabled { opacity: 0.45; }
.btn.ghost { background: transparent; }

/* tabs */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 520px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(8px + var(--safe-bot));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--quiet);
  padding: 4px 0;
}
.tabbar button.on { color: var(--text); }
.tabbar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* studio */
.cats { display: flex; gap: 6px; margin: 4px 0 10px; overflow-x: auto; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 11px;
  font-size: 12px;
  color: var(--muted);
}
.cats button.on { color: var(--text); border-color: color-mix(in srgb, var(--text) 28%, transparent); background: var(--fill2); }

/* forms / sheet */
.sheet-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(100%, 520px);
  max-height: calc(100dvh - 8px - var(--safe-top));
  overflow: auto;
  background: var(--bg2);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(18px + var(--safe-bot));
}
.sheet h3 { font-size: 20px; letter-spacing: -0.03em; margin: 4px 0 6px; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: color-mix(in srgb, var(--blue) 60%, var(--line)); }

/* monitor */
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--fill); }
.metric .v { font-size: 20px; letter-spacing: -0.03em; font-weight: 560; margin-top: 4px; }
.job {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.job .id { font-family: var(--mono); font-size: 11px; color: var(--quiet); }
.st { font-size: 11px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
.st.done { color: var(--good); }
.st.running { color: var(--blue); }
.st.queued { color: var(--warn); }
.st.failed { color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + 12px);
  transform: translateX(-50%);
  background: #eee;
  color: #111;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

.gate {
  min-height: 70dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 24px 8px;
}
.gate h2 { font-size: 24px; letter-spacing: -0.03em; }
pre.prompt-preview {
  white-space: pre-wrap;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  max-height: 160px;
  overflow: auto;
  font-family: var(--mono);
}
.note { font-size: 12px; color: var(--muted); line-height: 1.45; }
footer.fine {
  margin: 28px 0 8px;
  font-size: 11px;
  color: var(--quiet);
  line-height: 1.4;
}
