:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #2a2f3a;
  --text: #e8eaee;
  --muted: #8b93a3;
  --accent: #4da3ff;
  --ok: #3ecf8e;
  --amber: #ffb020;
  --red: #ff5d5d;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(15, 17, 21, 0.95);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 0.1em; }

.pill { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.pill.off { color: var(--muted); }
.pill.busy { color: var(--amber); border-color: var(--amber); }
.pill.on { color: var(--ok); border-color: var(--ok); }

.panel { padding: 16px; max-width: 720px; margin: 0 auto; }
h1 { font-size: 22px; margin: 8px 0; }
h2 { font-size: 17px; margin: 0 0 8px; }

.muted { color: var(--muted); font-size: 14px; }
.warn { color: var(--amber); }
.error { color: var(--red); font-weight: 600; }
.ok-text { color: var(--ok); }
.hist.backup { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.tight { margin: 0; gap: 6px; }
.module-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.module .mcodes { margin-top: 8px; }
.mot { border-radius: var(--radius); padding: 14px; margin: 12px 0; font-weight: 600; border: 1px solid var(--line); background: var(--panel); }
.mot.ok { border-color: var(--ok); color: var(--ok); }
.mot.warn { border-color: var(--amber); color: var(--amber); }
.mot.bad { border-color: var(--red); color: var(--red); }
.name-input { display: block; width: 100%; margin: 4px 0 12px; font-family: inherit; }
.tabs button { padding-left: 4px; padding-right: 4px; font-size: 15px; }
.log.short { max-height: 40vh; }
.hidden { display: none !important; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0; }

button {
  font: inherit; color: var(--text);
  background: #222733; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 16px; min-height: 46px;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
button.danger { background: transparent; border-color: var(--red); color: var(--red); font-weight: 600; }
dialog button.danger { background: var(--red); color: #1a0505; }
button.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }

input {
  flex: 1; min-width: 0;
  font: 15px ui-monospace, Menlo, Consolas, monospace;
  color: var(--text); background: #0b0d11;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}

.tabs {
  position: sticky; top: 49px; z-index: 4;
  display: flex; background: var(--bg); border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; border: 0; border-radius: 0; background: transparent;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 12px 0;
}
details.card summary { cursor: pointer; font-weight: 600; }

.mil {
  display: flex; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.mil-icon { color: var(--muted); }
.mil.on .mil-icon { color: var(--amber); filter: drop-shadow(0 0 8px rgba(255, 176, 32, 0.6)); }
.mil.on { border-color: var(--amber); }
.mil.off .mil-icon { color: var(--ok); }
.mil-text { font-weight: 600; font-size: 17px; }

.code-group h3 { font-size: 15px; margin: 18px 0 6px; color: var(--muted); font-weight: 600; }
.code {
  display: flex; gap: 12px; align-items: baseline;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; margin: 6px 0;
}
.code b { font: 700 17px ui-monospace, Menlo, Consolas, monospace; min-width: 62px; }
.code.stored b { color: var(--amber); }
.code.pending b { color: var(--accent); }
.code.permanent b { color: var(--red); }
.code a { color: var(--accent); font-size: 13px; white-space: nowrap; }
.code .desc { flex: 1; }

.gauges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gauge { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.gauge .label { color: var(--muted); font-size: 13px; }
.gauge .value { font: 600 28px ui-monospace, Menlo, Consolas, monospace; }
.gauge .unit { color: var(--muted); font-size: 14px; margin-left: 4px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }

.monitor { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.monitor:last-child { border-bottom: 0; }
.monitor .ok { color: var(--ok); }
.monitor .no { color: var(--amber); }

.hist { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.hist .when { color: var(--muted); }

.log {
  background: #0b0d11; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all; max-height: 60vh; overflow: auto;
}
.log .out { color: var(--accent); }
.log .in { color: var(--text); }
.log .info { color: var(--muted); }
.log .err { color: var(--red); }

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  max-width: 460px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog li { margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #222733; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; max-width: calc(100% - 32px); z-index: 10;
}
.toast.err { border-color: var(--red); }
