:root {
  --bg: #0e1013;
  --surface: #161a1f;
  --surface-2: #1d2228;
  --surface-3: #252b33;
  --line: #2a3139;
  --text: #e8ebef;
  --muted: #8b95a1;
  --faint: #5d6772;
  --accent: #4fd6a3;
  --accent-ink: #062418;
  --ok: #4fd6a3;
  --warn: #f3b54a;
  --crit: #ff6b6b;
  --info: #72a8ff;
  --violet: #b08cff;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabs-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f4f5f7;
    --surface-3: #e9ecef;
    --line: #e1e4e8;
    --text: #15191e;
    --muted: #5f6b77;
    --faint: #99a2ac;
    --accent: #10a874;
    --accent-ink: #ffffff;
    --ok: #10a874;
    --warn: #c98a12;
    --crit: #e04848;
    --info: #2f6fe0;
    --violet: #7b52e0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg.ic { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---------- boot / login */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px 22px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 18px; margin-bottom: 6px; }
.brand-mark { font-family: var(--mono); font-size: 14px; font-weight: 700; background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 6px 8px; letter-spacing: -.5px; }
.form-error { margin: 0; color: var(--crit); font-size: 14px; }

/* ---------- fields & buttons */
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 550; }
.field input, .field textarea, .field select, .input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px; font-size: 16px; outline: none; transition: border-color .15s;
}
.field textarea { font-family: var(--mono); font-size: 14px; resize: vertical; min-height: 96px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .input:focus { border-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: 12px; font-weight: 600;
  background: var(--surface-3); border: 1px solid var(--line);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: color-mix(in srgb, var(--crit) 16%, transparent); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 30%, transparent); }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--surface-2); }

/* ---------- layout */
#app { min-height: 100%; }
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.host { display: flex; align-items: center; gap: 12px; min-width: 0; }
.host-name { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host-sub { font-size: 12px; color: var(--muted); }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: pulse 2.4s infinite; flex: none; }
.pulse.off { background: var(--crit); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.top-actions { display: flex; gap: 2px; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
.view { display: grid; gap: 12px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab { position: relative; display: grid; place-items: center; align-content: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 600; }
.tab .ic { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab b { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #1d1300; font-size: 11px; line-height: 17px; text-align: center; }

/* ---------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 620px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
.section-label { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 2px -2px; display: flex; justify-content: space-between; align-items: center; }

.meter .meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.meter .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.meter .big { font-family: var(--mono); font-size: 26px; font-weight: 600; letter-spacing: -1px; }
.meter .sub { font-size: 12px; color: var(--muted); margin-top: 8px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--ok); transition: width .5s ease; }
.warn .bar > i, .bar.warn > i { background: var(--warn); }
.crit .bar > i, .bar.crit > i { background: var(--crit); }
.warn .big { color: var(--warn); }
.crit .big { color: var(--crit); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.disk + .disk { margin-top: 12px; }
.disk-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.disk-head span:last-child { font-family: var(--mono); font-size: 13px; color: var(--muted); }

.net { display: flex; gap: 18px; font-family: var(--mono); font-size: 15px; }
.net small { display: block; font-family: var(--sans); color: var(--muted); font-size: 12px; }

.procs { width: 100%; border-collapse: collapse; font-size: 13px; }
.procs td { padding: 6px 0; border-top: 1px solid var(--line); }
.procs tr:first-child td { border-top: 0; }
.procs td.n { text-align: right; font-family: var(--mono); width: 56px; color: var(--muted); }
.procs td.c { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0; }

/* ---------- list rows */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-head { display: flex; align-items: center; gap: 10px; padding: 12px 8px 12px 14px; border-bottom: 1px solid var(--line); }
.list-head .t { flex: 1; min-width: 0; }
.list-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.list-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-top: 1px solid var(--line); }
.list-head + .row, .list > .row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row .side { text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); flex: none; line-height: 1.5; }
.row .chev { color: var(--faint); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--faint); }
.dot.running, .dot.online { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.restarting, .dot.launching, .dot.paused, .dot.created, .dot.waiting-restart { background: var(--warn); }
.dot.exited, .dot.stopped, .dot.dead, .dot.errored { background: var(--crit); }
.dot.stopping { background: var(--warn); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--crit); }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.err-card { border-color: color-mix(in srgb, var(--crit) 40%, var(--line)); color: var(--crit); }

/* ---------- shortcuts */
.quick form { display: flex; gap: 8px; }
.quick input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 15px; }
.quick .cwd { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.quick .cwd input { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 96px; overflow: hidden; }
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tile, var(--faint)); }
.tile[data-color=green] { --tile: var(--ok); }
.tile[data-color=blue] { --tile: var(--info); }
.tile[data-color=amber] { --tile: var(--warn); }
.tile[data-color=red] { --tile: var(--crit); }
.tile[data-color=violet] { --tile: var(--violet); }
.tile-run { display: flex; flex-direction: column; justify-content: space-between; gap: 10px; width: 100%; height: 100%; min-height: 96px; padding: 14px 40px 12px 16px; text-align: left; }
.tile-run:active { background: var(--surface-2); }
.tile-run .tn { font-weight: 650; font-size: 15px; line-height: 1.25; }
.tile-run .tc { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-run .tc .ic { width: 12px; height: 12px; vertical-align: -2px; margin-right: 3px; }
.tile-edit { position: absolute; top: 6px; right: 4px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--faint); }
.tile-edit .ic { width: 18px; height: 18px; }
.tile.add { display: grid; place-items: center; border-style: dashed; color: var(--muted); font-weight: 600; }
.tile.add::before { display: none; }
.tile.add button { width: 100%; height: 100%; min-height: 96px; display: grid; place-items: center; align-content: center; gap: 6px; }
.colors { display: flex; gap: 10px; }
.colors label { position: relative; }
.colors input { position: absolute; opacity: 0; }
.colors span { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.colors input:checked + span { box-shadow: 0 0 0 2px var(--text); }

/* ---------- activity */
.job .side .pill { margin-bottom: 3px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-family: var(--sans); }
.pill.running { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.running::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1s infinite; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.error, .pill.killed { color: var(--crit); background: color-mix(in srgb, var(--crit) 14%, transparent); }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); opacity: 0; transition: opacity .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 12px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
@media (min-width: 620px) {
  .sheet-panel { bottom: auto; top: 50%; border-radius: 20px; border-bottom: 1px solid var(--line); transform: translateY(-46%) scale(.98); opacity: 0; transition: transform .2s, opacity .2s; }
  .sheet.open .sheet-panel { transform: translateY(-50%); opacity: 1; }
  .sheet-grip { display: none; }
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 6px; flex: none; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 6px 10px 10px 18px; flex: none; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 6px 0 0; font-size: 18px; font-weight: 700; }
.sheet-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); font-family: var(--mono); word-break: break-all; }
.sheet-head p:empty { display: none; }
.sheet-body { padding: 0 18px; overflow-y: auto; }
.sheet-body:empty { display: none; }
.sheet-body form, .sheet-body .stack { display: grid; gap: 14px; padding-bottom: 6px; }
.sheet-actions { display: grid; padding: 4px 8px 0; overflow-y: auto; }
.sheet-actions:empty { display: none; }
.sheet-action { display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-radius: 12px; text-align: left; font-weight: 550; }
.sheet-action:active { background: var(--surface-2); }
.sheet-action .ic { color: var(--muted); }
.sheet-action span { flex: 1; }
.sheet-action small { color: var(--faint); font-size: 12px; font-weight: 500; }
.sheet-action.danger, .sheet-action.danger .ic { color: var(--crit); }
.sheet-action.primary, .sheet-action.primary .ic { color: var(--accent); }
.sheet-sep { height: 1px; background: var(--line); margin: 4px 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.form-actions .spacer { flex: 1; }
pre.plan { margin: 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--muted); }

/* ---------- console */
.console { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: #0a0c0e; color: #d8dde3; }
.console-head { display: flex; align-items: center; gap: 6px; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px 6px; border-bottom: 1px solid #22282f; background: #111418; }
.console-head .icon-btn { color: #a7b0ba; }
.console-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.console-title > div:first-child { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.console-out { flex: 1; margin: 0; padding: 14px 14px calc(env(safe-area-inset-bottom) + 20px); overflow: auto; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; -webkit-overflow-scrolling: touch; }

/* ---------- toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 80; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { max-width: 520px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; font-weight: 550; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); animation: toastIn .2s ease; }
.toast.error { background: var(--crit); color: #fff; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; border: 1px solid var(--line); }
@keyframes sk { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
