/* Devtower dashboard — Telegram theme-aware Mini App styling */
:root {
  --bg:            var(--tg-theme-bg-color, #17212b);
  --bg2:           var(--tg-theme-secondary-bg-color, #232e3c);
  --fg:            var(--tg-theme-text-color, #f5f5f5);
  --muted:         var(--tg-theme-hint-color, #7f91a3);
  --link:          var(--tg-theme-link-color, #62bcf9);
  --accent:        var(--tg-theme-button-color, #3390ec);
  --accent-fg:     var(--tg-theme-button-text-color, #fff);
  --border:        rgba(255,255,255,0.08);
  --ok:            #3ecf8e;
  --warn:          #f5a524;
  --err:           #ef4444;
  --radius:        10px;
  --mono:          ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

header#header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 0 12px;
}
header .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
}
header .brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
header .logo { color: var(--accent); font-size: 22px; }
header nav#tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 4px 0 6px 0;
  scrollbar-width: none;
}
header nav#tabs::-webkit-scrollbar { display: none; }
header nav#tabs button {
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
header nav#tabs button.active {
  background: var(--accent);
  color: var(--accent-fg);
}

main#view {
  padding: 12px;
  padding-bottom: 72px;
  max-width: 720px;
  margin: 0 auto;
}

.iconbtn {
  background: var(--bg2);
  color: var(--fg);
  border: 0;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
}
.iconbtn:active { background: var(--accent); }

/* ⚡ live toggle on Schedules rows — pulses green while polling. */
.live-btn.active {
  background: rgba(62, 207, 142, 0.18);
  color: var(--ok);
  border: 1px solid rgba(62, 207, 142, 0.35);
  animation: livePulse 1.4s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.35); }
  50%      { box-shadow: 0 0 0 4px rgba(62, 207, 142, 0.00); }
}

/* ─── Cards / KPIs ─── */
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  font-feature-settings: "tnum" 1;
}
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.block { margin-top: 16px; }
.block h2 { font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; margin: 8px 0; }
.block p { margin: 4px 0; }
code { font-family: var(--mono); background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* ─── Toolbar / list ─── */
.toolbar {
  position: sticky;
  top: 74px;
  background: var(--bg);
  padding: 4px 0 8px 0;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.toolbar input, .toolbar select {
  flex: 1;
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.toolbar input::placeholder { color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.item header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.item .title { font-weight: 600; font-size: 14px; }
.item .sub { font-size: 12px; color: var(--muted); }
.item .body {
  font-size: 13px;
  color: var(--muted);
  max-height: 0;
  overflow: hidden;
  transition: max-height 200ms ease;
}
.item.expanded .body { max-height: 800px; overflow: auto; }
.item.clickable { cursor: pointer; }
.item pre {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0 0 0;
  color: var(--fg);
}

/* Pills */
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.open   { background: rgba(245,165,36,0.15); color: var(--warn); border-color: transparent; }
.pill.shipped,
.pill.resolved,
.pill.closed,
.pill.triaged,
.pill.active  { background: rgba(62,207,142,0.15); color: var(--ok); border-color: transparent; }
.pill.untriaged,
.pill.down,
.pill.p0,
.pill.err    { background: rgba(239,68,68,0.15); color: var(--err); border-color: transparent; }
.pill.slash  { background: rgba(98,188,249,0.15); color: var(--link); border-color: transparent; }

.section-heading {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 12px 0 4px 0;
  padding: 0 2px;
}

footer#footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 6px 12px calc(env(safe-area-inset-bottom) + 6px) 12px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

.muted { color: var(--muted); }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; gap: 12px; }
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.err-box {
  background: rgba(239,68,68,0.12);
  color: var(--err);
  border: 1px solid rgba(239,68,68,0.3);
  padding: 12px;
  border-radius: var(--radius);
  margin: 16px;
  font-size: 13px;
}

@media (min-width: 540px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ─── Commands tab ─── */
.cmd-page { display: flex; flex-direction: column; gap: 12px; }
.cmd-output {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 72px;
  font-size: 13px;
}
.cmd-output .cmd-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.cmd-output pre {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0 0 0;
  color: var(--fg);
  max-height: 420px;
  overflow: auto;
}
.cmd-output details { margin-top: 6px; }
.cmd-output details pre { font-size: 11px; color: var(--muted); }
.cmd-output .cmd-err { color: var(--err); }
.cmd-output .cmd-latency { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.cmd-output.running { opacity: 0.6; }

.cmd-groups { display: flex; flex-direction: column; gap: 14px; }
.cmd-group { display: flex; flex-direction: column; gap: 6px; }
.cmd-group h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 2px 0;
}
.cmd-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.cmd-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cmd-btn:active { background: var(--accent); color: var(--accent-fg); }
.cmd-btn.busy { opacity: 0.5; pointer-events: none; }
.cmd-btn .cmd-name { font-family: var(--mono); font-size: 13px; color: var(--link); }
.cmd-btn .cmd-summary { font-size: 11px; color: var(--muted); }

/* Input-bearing command card — stacks header → input → Run, full column width. */
.cmd-input-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.cmd-input-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cmd-input-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--link);
  font-weight: 600;
}
.cmd-input-summary {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.cmd-input-hint {
  font-size: 11px;
  color: var(--muted);
}
.cmd-input,
.cmd-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px; /* ≥16px on mobile would suppress zoom; 14px is fine with viewport user-scalable=no */
  font-family: inherit;
}
.cmd-textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.4;
}
.cmd-input::placeholder,
.cmd-textarea::placeholder { color: var(--muted); }
.cmd-input:focus,
.cmd-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Chip picker (for /map section) */
.cmd-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cmd-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--fg);
  cursor: pointer;
  font-family: var(--mono);
}
.cmd-chip.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.cmd-chip:active { opacity: 0.85; }

/* Run button below the input — big tap target, full width on mobile. */
.cmd-run-btn {
  align-self: stretch;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--mono);
  cursor: pointer;
}
.cmd-run-btn:active { opacity: 0.85; }
.cmd-run-btn.busy { opacity: 0.5; pointer-events: none; }

@media (min-width: 540px) {
  .cmd-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cmd-run-btn { align-self: flex-start; min-width: 140px; }
}

