/* ============================================================
   MISSION CONTROL — design system
   Aesthetic: aerospace ops console. Deep space navy, blueprint
   grid atmosphere, signal-amber commands, JetBrains Mono
   telemetry, traffic-light status language.
   ============================================================ */

:root, body.dark {
  --bg: #0a0e14;
  --bg2: #0d1219;
  --card: #121821;
  --card2: #171f2a;
  --text: #e8edf2;
  --muted: #6d7b8c;
  --accent: #ffb020;
  --accent-ink: #171004;
  --ok: #34d17b;
  --warn: #ffb020;
  --fail: #ff5449;
  --border: rgba(140,170,210,.13);
  --border2: rgba(140,170,210,.22);
  --grid: rgba(120,160,210,.05);
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: 'IBM Plex Sans', -apple-system, 'Segoe UI', sans-serif;
}
body.light {
  --bg: #e9edf1;
  --bg2: #eef1f5;
  --card: #ffffff;
  --card2: #f4f6f9;
  --text: #131a22;
  --muted: #66727f;
  --accent: #c47f00;
  --accent-ink: #ffffff;
  --ok: #1e9e5a;
  --warn: #c47f00;
  --fail: #d4382e;
  --border: rgba(30,50,80,.12);
  --border2: rgba(30,50,80,.22);
  --grid: rgba(40,70,120,.06);
  --shadow: 0 8px 24px rgba(20,40,70,.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
}

/* Blueprint grid atmosphere */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse 120% 70% at 50% 0%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 120% 70% at 50% 0%, #000 0%, transparent 75%);
}

#app {
  max-width: 640px; width: 100%;
  margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}

/* ============ Header ============ */
#header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.h-title {
  font-family: var(--mono); font-size: 15px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.h-title::before { content: '◤ '; color: var(--accent); }
.h-status {
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  letter-spacing: .12em; color: var(--ok);
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border: 1px solid var(--border2); border-radius: 6px;
}
.icon-btn {
  background: none; border: none; color: var(--text);
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 10px;
  transition: background .15s;
}
.icon-btn:active { background: var(--border); }

/* ============ Main / screens ============ */
#main { flex: 1; padding: 14px 14px calc(96px + env(safe-area-inset-bottom)); overflow-x: hidden; }

.screen > * { animation: rise .38s cubic-bezier(.2,.7,.3,1) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen > * { animation: none; }
}

/* ============ Tabbar ============ */
#tabbar {
  position: fixed; bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 640px;
  display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 9px 0;
  min-height: 58px; text-decoration: none;
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  font-family: var(--mono); letter-spacing: .08em; text-transform: uppercase;
  position: relative;
  transition: color .18s;
}
.tab svg { transition: transform .18s; }
.tab.active { color: var(--accent); }
.tab.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 2px; background: var(--accent); border-radius: 0 0 3px 3px;
}
.tab:active svg { transform: scale(.85); }

/* ============ Cards — HUD framed ============ */
.card {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
}
.tappable { cursor: pointer; transition: border-color .18s, transform .12s; }
.tappable:active { transform: scale(.985); border-color: var(--border2); }

.card-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card-name {
  font-weight: 700; font-size: 15px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--mono); }

/* corner brackets on primary cards */
.card--hud { }
.card--hud::before, .card--hud::after {
  content: ''; position: absolute; width: 12px; height: 12px; pointer-events: none;
}
.card--hud::before { top: -1px; left: -1px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); border-radius: 10px 0 0 0; }
.card--hud::after { bottom: -1px; right: -1px; border-bottom: 2px solid var(--border2); border-right: 2px solid var(--border2); border-radius: 0 0 12px 0; }

/* ============ Chips / dots ============ */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 5px;
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid transparent; flex: none;
}
.chip.development { background: transparent; color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.chip.production, .chip.active { background: transparent; color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.chip.paused, .chip.inactive { background: transparent; color: var(--muted); border-color: var(--border2); }
.chip.failed { background: transparent; color: var(--fail); border-color: color-mix(in srgb, var(--fail) 45%, transparent); }
.chip.phase { background: transparent; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.green { background: var(--ok); box-shadow: 0 0 6px color-mix(in srgb, var(--ok) 60%, transparent); }
.dot.red { background: var(--fail); box-shadow: 0 0 6px color-mix(in srgb, var(--fail) 60%, transparent); }
.dot.gray { background: var(--muted); }
.dot.amber { background: var(--warn); box-shadow: 0 0 6px color-mix(in srgb, var(--warn) 60%, transparent); }
.dot.live { animation: pulse 2s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 0%, var(--ok) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ============ Progress ============ */
.progress { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; margin: 10px 0 6px; }
.progress .fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  transition: width .5s cubic-bezier(.2,.7,.3,1);
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.14) 0 5px, transparent 5px 10px);
}

/* ============ Telemetry rings (server strip) ============ */
.server-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.metric {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.ring {
  --p: 0; --c: var(--ok);
  width: 62px; height: 62px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--border) 0);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: --p .6s;
}
.ring::before {
  content: ''; position: absolute; inset: 6px; border-radius: 50%;
  background: var(--card);
}
.ring .m-val {
  position: relative; font-family: var(--mono); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; gap: 3px;
}
.m-label {
  font-family: var(--mono); font-size: 9.5px; font-weight: 700;
  letter-spacing: .16em; color: var(--muted); text-transform: uppercase;
}
.m-sub {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

/* server strip wrapper (tappable → monitor) */
.server-wrap { margin-bottom: 16px; }
.server-wrap .server-strip { margin-bottom: 0; }
.server-wrap:active .metric { border-color: var(--border2); }

/* Sparklines under rings */
.sparkline { width: 100%; height: 22px; }
.sparkline svg { width: 100%; height: 100%; display: block; }
.sparkline .sp-line { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.sparkline .sp-area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.spark-empty { font-family: var(--mono); font-size: 10px; color: var(--muted); text-align: center; }

/* Monitor screen: big charts */
.chart-svg { width: 100%; height: 150px; display: block; margin: 10px 0 4px; }
.chart-svg .ch-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-svg .ch-area { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.chart-now { font-family: var(--mono); font-size: 14px; font-weight: 700; flex: none; }
.chart-axis {
  display: flex; gap: 8px; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: .06em;
}
.disk-table .dt-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.disk-table .dt-row:last-of-type { border-bottom: none; }
.dt-bar { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 8px; }
.dt-bar .fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ============ Meta rows ============ */
.meta {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  color: var(--muted); font-size: 12px; flex-wrap: wrap;
  font-family: var(--mono);
}
.meta .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--sans); }

.section-title {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .18em;
  margin: 20px 0 10px; display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.section-title::before { content: '//'; color: var(--accent); }

/* ============ Stages ============ */
.stage {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
  cursor: pointer; min-height: 48px;
  transition: border-color .15s;
}
.stage:active { border-color: var(--border2); }
.st-ico { font-family: var(--mono); font-size: 17px; flex: none; width: 22px; text-align: center; }
.stage .st-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.stage.todo .st-ico { color: var(--muted); }
.stage.in_progress .st-ico { color: var(--accent); }
.stage.done .st-ico { color: var(--ok); }
.stage.done .st-title { color: var(--muted); text-decoration: line-through; }

/* ============ Activity timeline ============ */
.timeline { position: relative; padding-left: 15px; }
.timeline::before {
  content: ''; position: absolute; left: 32px; top: 8px; bottom: 8px;
  width: 1px; background: linear-gradient(var(--border2), var(--border));
}
.activity {
  display: flex; gap: 12px; padding: 4px 0; position: relative;
  cursor: pointer; margin-bottom: 2px;
}
.activity .avatar { position: relative; z-index: 1; }
.act-body {
  flex: 1; min-width: 0;
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
  transition: border-color .15s;
}
.activity:active .act-body { border-color: var(--border2); }
.date-sep {
  font-family: var(--mono); color: var(--muted); font-size: 10.5px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  margin: 16px 0 10px; display: flex; align-items: center; gap: 10px;
}
.date-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; flex: none;
  font-family: var(--mono);
  border: 1px solid rgba(255,255,255,.18);
}
.avatar.busy { position: relative; }
.avatar.busy::after {
  content: ''; position: absolute; right: -2px; bottom: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--warn); border: 2px solid var(--bg);
  animation: pulse 2s ease-out infinite;
}

/* ============ Buttons ============ */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px;
  padding: 13px; border: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--mono); font-size: 13.5px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer; margin-top: 10px;
  transition: transform .12s, filter .15s;
}
.btn:active { transform: scale(.98); filter: brightness(1.08); }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.btn.danger { background: transparent; color: var(--fail); border: 1px solid color-mix(in srgb, var(--fail) 55%, transparent); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* Action tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 14px; min-height: 92px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 6px;
  cursor: pointer; text-align: left;
  transition: border-color .15s, transform .12s;
}
.tile:active { transform: scale(.97); border-color: var(--border2); }
.tile .t-ico { font-size: 22px; line-height: 1; }
.tile .t-name { font-family: var(--mono); font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.tile .t-sub { font-size: 12px; color: var(--muted); }
.tile.danger .t-name { color: var(--fail); }

/* ============ Services list ============ */
.svc-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
  min-height: 48px;
}
.svc-name { flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Commits ============ */
.commit {
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
.commit .hash { font-family: var(--mono); color: var(--accent); font-size: 12px; font-weight: 700; }
.commit .sub { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ============ Empty / error ============ */
.empty, .error-screen {
  text-align: center; padding: 44px 16px; color: var(--muted);
}
.empty .big, .error-screen .big { font-size: 40px; margin-bottom: 14px; }
.empty .e-title, .error-screen b { display: block; color: var(--text); font-weight: 700; margin-bottom: 4px; font-size: 16px; }
.empty .e-sub { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
a { color: var(--accent); text-decoration: none; }
a:active { opacity: .7; }

/* ============ Skeletons ============ */
.skeleton {
  position: relative; overflow: hidden;
  background: var(--border); border-radius: 8px;
}
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.sk-card { border-radius: 12px; padding: 14px; margin-bottom: 10px; background: var(--card); border: 1px solid var(--border); }
.sk-line { height: 14px; margin: 6px 0; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: calc(100px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  background: var(--card2); color: var(--text);
  border: 1px solid var(--border2);
  padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 60; max-width: 88%;
  font-family: var(--mono); font-size: 13px;
  animation: rise .25s cubic-bezier(.2,.7,.3,1);
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4,8,14,.6);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .2s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--bg2); width: 100%; max-width: 640px;
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--border2); border-bottom: none;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
  animation: sheetUp .28s cubic-bezier(.2,.7,.3,1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } }
.modal::before {
  content: ''; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 3px; border-radius: 2px; background: var(--border2);
}
.modal h2 {
  margin: 4px 0 14px; font-size: 16px;
  font-family: var(--mono); letter-spacing: .05em;
}
.modal pre {
  white-space: pre-wrap; word-break: break-word;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  margin: 8px 0;
}

/* ============ Forms ============ */
.field { margin-bottom: 12px; }
.field label {
  display: block; font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  color: var(--muted); margin-bottom: 5px; letter-spacing: .12em; text-transform: uppercase;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; min-height: 46px;
  border-radius: 10px; border: 1px solid var(--border2);
  background: var(--card); color: var(--text);
  font-size: 15px; outline: none; font-family: inherit;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 90px; resize: vertical; }

.ptr { text-align: center; color: var(--muted); font-family: var(--mono); font-size: 11px; letter-spacing: .15em; padding: 6px 0; }
