:root {
  --page: #EEF1F4;
  --panel: #FFFFFF;
  --line: #D8DEE5;
  --line-soft: #E7EBEF;
  --ink: #1F2A37;
  --ink-2: #51606F;
  --ink-3: #8593A1;
  --brass: #9A6F1E;
  --brass-ink: #6E4E10;
  --brass-soft: #F6EEDB;
  --ok: #2F7D5A;
  --ok-soft: #E2F1E9;
  --warn: #B4740F;
  --warn-soft: #FBF0D6;
  --bad: #B3362B;
  --bad-soft: #F8E3E0;
  --info-soft: #E3EAF2;
  --radius: 6px;
  --nav-w: 200px;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); }
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
p { margin: 0; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 13px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.sub { color: var(--ink-2); font-size: 13px; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav { background: var(--ink); color: #DCE3EA; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.nav .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; padding: 4px 8px 20px; }
.nav .brand svg { width: 26px; height: 26px; }
.nav a { display: block; padding: 8px 10px; border-radius: var(--radius); color: #C3CCD6; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.nav .spacer { flex: 1; }
.nav .foot { font-size: 13px; color: #8593A1; padding: 8px 10px; }
.nav .foot button { background: none; border: 0; color: #C3CCD6; padding: 0; cursor: pointer; }
.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel + .panel, .section + .section { margin-top: 22px; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-b { padding: 14px; }
.empty { padding: 28px 14px; color: var(--ink-2); text-align: center; }
.empty strong { display: block; color: var(--ink); font-weight: 500; margin-bottom: 4px; }

/* ---- buttons / forms ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brass); border-color: var(--brass); color: #fff; }
.btn.primary:hover { background: var(--brass-ink); border-color: var(--brass-ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--brass-ink); font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; color: var(--ink-2); }
.field input, .field select { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-width: 0; }
.field input:focus, .field select:focus { border-color: var(--brass); outline: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.form-row .btn { height: 38px; }
.hint { font-size: 13px; color: var(--ink-3); }
.err { color: var(--bad); font-size: 14px; }

/* ---- state language ---- */
.state { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }
.state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.state.locked { color: var(--ok); }
.state.unlocked { color: var(--warn); }
.state.unknown, .state.offline { color: var(--ink-3); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--info-soft); color: var(--ink-2); }
.tag.guest { background: var(--info-soft); }
.tag.staff { background: var(--brass-soft); color: var(--brass-ink); }
.tag.owner { background: var(--ok-soft); color: var(--ok); }
.tag.backup { background: var(--warn-soft); color: var(--warn); }
.tag.failed, .tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.pending { background: var(--line-soft); color: var(--ink-2); }
.tag.active { background: var(--ok-soft); color: var(--ok); }
.code { font-variant-numeric: tabular-nums; letter-spacing: .12em; font-weight: 600; font-size: 17px; }
.code.big { font-size: 34px; letter-spacing: .14em; }
.batt { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.batt i { display: inline-block; width: 22px; height: 11px; border: 1.5px solid var(--ink-3); border-radius: 2px; position: relative; }
.batt i::after { content: ""; position: absolute; right: -4px; top: 2.5px; width: 2px; height: 4px; background: var(--ink-3); }
.batt b { display: block; height: 100%; background: var(--ok); }
.batt.low b { background: var(--bad); }
.batt.mid b { background: var(--warn); }

/* ---- overview ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(124px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .k { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.stat.bad .v { color: var(--bad); }
.stat.ok .v { color: var(--ok); }

/* ---- lock list ---- */
.unit-h td { background: #F6F8FA; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.unit-h .sub { font-weight: 400; margin-left: 10px; }
.lockrow td:first-child { padding-left: 22px; }
.lockrow a { font-weight: 500; }
.lockrow .acts { white-space: nowrap; text-align: right; }

/* ---- lock page ---- */
.lock-hero { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; padding: 20px 22px; }
.lock-hero .state { font-size: 22px; }
.lock-hero .state::before { width: 12px; height: 12px; }
.lock-hero .facts { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 10px; color: var(--ink-2); font-size: 14px; }
.lock-hero .facts b { color: var(--ink); font-weight: 500; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line-soft); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.timeline .what { font-weight: 500; }
.timeline .what.bad { color: var(--bad); }
.timeline .what.warn { color: var(--warn); }
.timeline .detail { color: var(--ink-2); font-size: 14px; }

/* ---- modal / toast ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(31,42,55,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal { background: #fff; border-radius: 8px; width: min(520px, 100%); padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { font-size: 18px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 14px; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(360px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; margin-bottom: 4px; }
.login .brand svg { width: 28px; height: 28px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 2px; }
  .nav .brand { padding: 4px 8px; margin-right: 8px; }
  .nav .spacer, .nav .foot { display: none; }
  .main { padding: 18px 16px 40px; }
  .two { grid-template-columns: 1fr; }
  .lock-hero { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .lockrow td:first-child { padding-left: 10px; }
  th:nth-child(4), td:nth-child(4), .lockrow td:nth-child(5), thead th:nth-child(5) { display: none; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat .v { font-size: 22px; }
}

/* viewers: hide everything that changes state */
.viewer [data-act="lock"], .viewer [data-act="unlock"], .viewer [data-act="assign"], .viewer [data-act="new-unit"], .viewer [data-edit], .viewer [data-add-temp],
.viewer [data-del], .viewer [data-new], .viewer [data-rotate], .viewer [data-regen], .viewer [data-revoke], .viewer [data-new-hub], .viewer .lock-hero .actions { display: none !important; }
.login details { margin-top: 4px; }
