/* atelier — dark first (it is a terminal app), light variant from the OS. */
:root {
  color-scheme: dark;
  --page: #0b0b0b;
  --surface: #191919;
  --surface-2: #222222;
  --surface-3: #2c2c2c;
  --ink: #efefef;
  --ink-2: #9c9c9c;
  --grid: #303030;
  --axis: #474747;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #338ced;
  --accent-ink: #ffffff;
  --series-1: #338ced;
  --good: #0aac23;
  --good-text: #53c556;
  --warning: #fbb315;
  --serious: #f18a59;
  --critical: #dc3c3d;
  --term-bg: #0f0f0f;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, "DejaVu Sans Mono", Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --page: #f9f9f9;
    --surface: #ffffff;
    --surface-2: #f2f2f2;
    --surface-3: #e7e7e7;
    --ink: #191919;
    --ink-2: #666666;
    --grid: #e7e7e7;
    --axis: #c2c2c2;
    --border: rgba(11, 11, 11, 0.10);
    --accent: #257de0;
    --series-1: #257de0;
    --good-text: #006c10;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f9; --surface: #ffffff; --surface-2: #f2f2f2; --surface-3: #e7e7e7;
  --ink: #191919; --ink-2: #666666; --grid: #e7e7e7; --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10); --accent: #257de0; --series-1: #257de0; --good-text: #006c10;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
#app { display: flex; flex-direction: column; height: var(--app-h, 100dvh); overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
h3 { font-size: 13px; margin: 0 0 10px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; font-weight: 400; }
.mono { font-family: var(--mono); font-size: 12px; }
.error { color: var(--critical); min-height: 1em; margin: 8px 0 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  flex: none; display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 650; min-width: 0; }
.brand svg { color: var(--accent); flex: none; }
.brand-host { color: var(--ink-2); font-weight: 400; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { margin-left: auto; display: flex; gap: 2px; }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 550;
  display: inline-flex; align-items: center; gap: 6px;
}
.nav a svg { flex: none; }
.profile-btn {
  appearance: none; display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 30vw;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.profile-btn:hover { background: var(--surface-3); }
.profile-btn .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-btn .caret { color: var(--ink-2); font-size: 11px; }
.limits {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink);
  padding: 4px 8px; border-radius: 8px; flex: none;
}
.limits:hover { background: var(--surface-2); }
.limits .spark { flex: none; transition: color .4s ease; }
.limits .lim { display: inline-flex; align-items: baseline; gap: 3px; font-variant-numeric: tabular-nums; }
.limits .lim b { font-weight: 650; font-size: 13px; }
.limits .lim small { color: var(--ink-2); font-size: 11px; }
.limits.stale .lim b { color: var(--ink-2); }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--surface-3); }

main { flex: 1; min-height: 0; position: relative; }
.page { position: absolute; inset: 0; display: none; overflow: auto; -webkit-overflow-scrolling: touch; }
.page.active { display: block; }
#page-prod.active { display: flex; flex-direction: column; overflow: hidden; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 4px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

/* ---------- generic controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 550; padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.inline-form input { flex: 1 1 140px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + h2, .grid2 + .card { margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; margin: 4px 6px 0 0;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  font: inherit; font-size: 12px; cursor: pointer;
}
.chip:hover { background: var(--surface-3); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); }
.badge.ok { color: var(--good-text); }
.badge.warn { color: var(--warning); }
dialog textarea { font-family: var(--mono); font-size: 12px; min-height: 90px; resize: vertical; }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.menu .sep { height: 1px; background: var(--border); margin: 4px 6px; }
.menu button.current { font-weight: 650; position: relative; padding-right: 30px; }
.menu button.current::after { content: "✓"; color: var(--accent); position: absolute; right: 10px; top: 8px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--ink-2); font-weight: 550; font-size: 12px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.wrap-any { word-break: break-all; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 10vh auto 0; display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 400px) { .login { margin: 6vh 16px 0; } }

/* ---------- prod ---------- */
.scroller { display: flex; overflow-x: auto; scrollbar-width: none; flex: none; }
.scroller::-webkit-scrollbar { display: none; }
.ptabs { gap: 4px; padding: 6px max(8px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--border); }
.wbar { gap: 2px; padding: 4px max(8px, env(safe-area-inset-left)); background: var(--page); border-bottom: 1px solid var(--border); align-items: center; }
.tab {
  appearance: none; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 550;
  padding: 5px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  flex: none;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: var(--ink); background: var(--surface-3); }
.tab .count { font-size: 11px; color: var(--ink-2); font-weight: 500; }
.tab .kind { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.wbar .tab { font-size: 13px; padding: 4px 9px; }
.wbar .tab .sub { font-size: 11px; color: var(--ink-2); font-weight: 400; }
.wbar .spacer { flex: 1; min-width: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--axis); flex: none; }
.dot.busy { background: var(--good); animation: pulse 1.2s ease-in-out infinite; }
.dot.bell { background: var(--warning); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }
.termwrap { flex: 1; min-height: 0; position: relative; background: var(--term-bg); }
.term-host { position: absolute; inset: 0; padding: 4px 2px 0 6px; display: none; }
.term-host.active { display: block; }
.term-host .xterm { height: 100%; }
.term-host .xterm-viewport { background: var(--term-bg) !important; }
.term-status {
  position: absolute; top: 8px; right: 10px; z-index: 5; font-size: 12px; padding: 3px 8px; border-radius: 6px;
  background: rgba(0,0,0,.7); color: #efefef; pointer-events: none;
}
.term-overlay {
  position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center;
  background: rgba(10,10,10,.82); color: #efefef; text-align: center; padding: 20px;
}
.term-empty { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; color: #9c9c9c; padding: 24px; text-align: center; }
.term-empty .row { justify-content: center; }
.keys {
  gap: 4px; padding: 5px max(6px, env(safe-area-inset-left)); background: var(--surface); border-top: 1px solid var(--border); align-items: center;
}
.keys button {
  appearance: none; flex: none; min-width: 40px; height: 34px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font: 13px/1 var(--mono); cursor: pointer; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.keys button:active { background: var(--surface-3); }
.keys button.mod[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.keys button.word { font: 600 12px/1 system-ui, sans-serif; }
.keys .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
.compose { display: flex; gap: 8px; padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); flex: none; }
.compose textarea { flex: 1; resize: none; max-height: 30vh; font-size: 15px; }
.compose-actions { display: flex; flex-direction: column; gap: 6px; }
#page-prod .keys:last-child, #page-prod .keys:has(+ .compose[hidden]) { padding-bottom: calc(5px + env(safe-area-inset-bottom)); }
.unfocus {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 10px; z-index: 20; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: rgba(25,25,25,.85); color: #efefef; font-size: 16px; cursor: pointer;
}
#page-prod.no-window .keys, #page-prod.no-window .compose { display: none !important; }
body.focus .topbar, body.focus .ptabs, body.focus .wbar { display: none; }
body.focus #app { padding-top: env(safe-area-inset-top); }

/* menus & dialogs */
.menu {
  position: fixed; z-index: 50; min-width: 200px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.menu button {
  display: block; width: 100%; text-align: left; appearance: none; border: 0; background: transparent; color: var(--ink);
  font: inherit; padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button .muted { font-size: 12px; display: block; }
.menu button.danger { color: var(--critical); }
dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink);
  padding: 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h1 { font-size: 17px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog.snapshot { width: min(1000px, calc(100vw - 16px)); height: calc(100dvh - 40px); display: none; flex-direction: column; padding: 12px; }
dialog.snapshot[open] { display: flex; }
dialog.snapshot pre {
  flex: 1; min-height: 0; overflow: auto; margin: 8px 0; padding: 10px; background: var(--term-bg); color: #e6e6e6;
  border-radius: 8px; font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; -webkit-user-select: text; user-select: text;
}
.qr-secret { font-family: var(--mono); font-size: 15px; letter-spacing: .08em; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(150%); visibility: hidden;
  background: var(--surface-3); color: var(--ink); border: 1px solid var(--border); padding: 8px 14px; border-radius: 10px;
  max-width: calc(100vw - 32px); z-index: 100; transition: transform .2s ease; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
.toast.err { border-color: var(--critical); }

/* ---------- monitoring ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 12px; color: var(--ink-2); }
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.meter.warning > span { background: var(--warning); }
.meter.serious > span { background: var(--serious); }
.meter.critical > span { background: var(--critical); }
.status { font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.status.warning { color: var(--warning); } .status.serious { color: var(--serious); } .status.critical { color: var(--critical); }
.disk { margin-bottom: 12px; }
.disk .line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }

.chart { position: relative; width: 100%; min-height: 160px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--ink-2); font-size: 11px; font-family: system-ui, sans-serif; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .12; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: .45; }
.chart .guide { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .empty { fill: var(--ink-2); font-size: 13px; }
.tooltip {
  position: absolute; z-index: 10; pointer-events: none; background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .r span:last-child { font-variant-numeric: tabular-nums; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--ink-2); font-size: 12px; }

/* ---------- settings ---------- */
.proj { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); align-items: center; }
.proj:last-of-type { border-bottom: none; }
.proj .name { font-weight: 600; }
.proj .meta { grid-column: 1; font-size: 12px; color: var(--ink-2); word-break: break-all; }
.proj .actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 760px) {
  .nav .lbl { display: none; }
  .brand-host { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; }
  .brand-name { display: none; }
  .nav a { padding: 6px 7px; }
  .limits { gap: 6px; padding: 4px 4px; }
  h2 { margin-top: 18px; }
  .tile .value { font-size: 20px; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 12px; }
}
@media (max-width: 370px) { .brand { display: none; } .profile-btn { max-width: 26vw; } }
@media (hover: none) { .tab { padding: 7px 11px; } }
