:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #1f2937;
  --ink-soft: #4b5563;
  --ink-faint: #6b7280;
  --line: #e5e7eb;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --amber: #eab308;
  --amber-dark: #a16207;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --green: #059669;
  --green-soft: #ecfdf5;
  --grey-dot: #9ca3af;
  --housing: #2f343c;
  --housing-off: #b6b8be;
  --lantern-off: #e3e4e8;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 8px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
button, input, select { font: inherit; }
a { color: var(--blue); }

/* ---------------------------------------------------------------- buttons and inputs */
button, .button {
  border: 1px solid transparent; border-radius: 6px; padding: .5rem 1rem; cursor: pointer;
  font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem;
  line-height: 1.2;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, .user-list button:focus-visible {
  outline: 3px solid #93c5fd; outline-offset: 2px;
}
.primary { background: var(--blue); color: #fff; }
.primary:hover:not(:disabled) { background: var(--blue-dark); }
.secondary { background: #fff; color: var(--blue); border-color: #bfdbfe; }
.secondary:hover:not(:disabled) { background: var(--blue-soft); }
.warning { background: var(--amber); color: #fff; }
.warning:hover:not(:disabled) { background: #ca8a04; }
.danger { background: var(--red); color: #fff; }
.danger:hover:not(:disabled) { background: #b91c1c; }
.link { background: none; border: 0; color: var(--blue); padding: .25rem; }
.small { padding: .38rem .8rem; font-size: .88rem; }
.wide { width: 100%; justify-content: center; margin-top: 1rem; }

input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]), select {
  border: 1px solid #d1d5db; border-radius: 6px; padding: .5rem .65rem; background: #fff; color: var(--ink);
  width: 100%; min-width: 0;
}
input:focus, select:focus { border-color: var(--blue); }
label { font-size: .9rem; color: var(--ink-soft); }
.hint { color: var(--ink-faint); font-size: .88rem; }
.error { color: var(--red); min-height: 1.2em; margin: .6rem 0 0; font-size: .92rem; }
.spacer { flex: 1; }
.center { text-align: center; }

.pw { position: relative; }
.pw input { padding-right: 2.6rem; }
.eye {
  position: absolute; right: .3rem; top: 50%; transform: translateY(-50%);
  background: none; border: 0; padding: .35rem; width: 2rem; height: 2rem; justify-content: center;
}
.eye::before {   /* simple eye icon */
  content: ""; width: 18px; height: 12px; border: 2px solid var(--ink-soft); border-radius: 50% / 60%;
  background: radial-gradient(circle, var(--ink-soft) 0 3px, transparent 3.5px);
}
.eye.on::after { content: ""; position: absolute; width: 22px; height: 2px; background: var(--ink-soft); transform: rotate(-35deg); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  background: var(--card); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.08);
  padding: 2rem 2rem 1.5rem; width: 100%; max-width: 380px;
}
.login-card .brand { font-size: 1.6rem; text-align: center; margin-bottom: .5rem; }
.step { display: flex; flex-direction: column; gap: .35rem; }
.step label { margin-top: .5rem; }
.step-intro { margin: 0 0 .4rem; color: var(--ink-soft); }
.step .back { align-self: center; margin-top: .4rem; }
.code { font-size: 1.4rem; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { width: 200px; height: 200px; margin: .3rem auto; }
.qr svg { width: 100%; height: 100%; display: block; }
.setup-steps { margin: 0; padding-left: 1.2rem; color: var(--ink-soft); }
.setup-key { font: 600 1rem ui-monospace, Consolas, monospace; text-align: center; margin: 0; word-spacing: .2em; }

/* ---------------------------------------------------------------- navigation */
.brand { color: var(--blue); font-weight: 700; font-size: 1.15rem; letter-spacing: .01em; }
.nav { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); position: sticky; top: 0; z-index: 10; }
.nav-inner {
  max-width: 1400px; margin: 0 auto; padding: .55rem 1.25rem; display: flex; align-items: center; gap: 1.5rem;
}
.nav nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav nav a {
  color: var(--ink); text-decoration: none; font-size: .9rem; font-weight: 500; padding: .45rem .7rem; border-radius: 6px;
}
.nav nav a:hover { background: var(--bg); }
.nav nav a[aria-current=page] { color: var(--blue); background: var(--blue-soft); }
.who { font-size: .88rem; color: var(--ink-soft); }

.page { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar select, .toolbar input { width: auto; }

/* ---------------------------------------------------------------- signs */
.sign-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 1.75rem; }
.sign-card { padding: 1.5rem 1.75rem 1.25rem; display: flex; flex-direction: column; }
.sign-card h2 { font-size: 1.6rem; text-align: center; font-weight: 700; }
.sign-card h2 .na { color: var(--ink-soft); font-weight: 600; }
.sign-sub { text-align: center; color: var(--ink-faint); font-size: .88rem; margin: .2rem 0 .9rem; min-height: 1.3em; }

.housing {
  position: relative; background: var(--housing); border-radius: 6px; aspect-ratio: 16 / 10.4;
  box-shadow: inset 0 0 0 3px #1c2026, 0 2px 4px rgba(0,0,0,.15); max-width: 520px; width: 100%; margin: 0 auto;
}
.housing.off { background: var(--housing-off); box-shadow: inset 0 0 0 3px #a6a8ae; }
.lantern {
  position: absolute; width: 13%; aspect-ratio: 1; border-radius: 50%; background: #3d434c;
  box-shadow: inset 0 0 0 3px #1c2026;
}
.housing.off .lantern { background: var(--lantern-off); box-shadow: none; }
.lantern.tl { top: 4.5%; left: 3.2%; } .lantern.tr { top: 4.5%; right: 3.2%; }
.lantern.bl { bottom: 4.5%; left: 3.2%; } .lantern.br { bottom: 4.5%; right: 3.2%; }
.housing.lit .lantern { background: #ffbf2e; box-shadow: 0 0 18px 4px rgba(255,180,30,.6); }
.housing.lit.flash .lantern.tl, .housing.lit.flash .lantern.tr { animation: flashA 1s steps(1) infinite; }
.housing.lit.flash .lantern.bl, .housing.lit.flash .lantern.br { animation: flashB 1s steps(1) infinite; }
@keyframes flashA { 0% { opacity: 1; } 50% { opacity: .12; } }
@keyframes flashB { 0% { opacity: .12; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .housing.lit.flash .lantern { animation: none !important; } }
.matrix {
  position: absolute; left: 20%; right: 20%; top: 50%; transform: translateY(-50%);
  background: #000; border-radius: 3px; padding: 1.5%;
}
.housing.off .matrix { background: #c6c8cd; }
.matrix canvas { width: 100%; display: block; }
.busy-veil {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 600;
  background: rgba(15, 23, 42, .45); border-radius: 6px; letter-spacing: .02em;
}

.sign-caption { text-align: center; margin: .8rem 0 .2rem; font-size: .92rem; color: var(--ink-soft); min-height: 1.4em; }
.sign-caption .tag { font-weight: 600; color: var(--ink); }
.fault-chip {
  display: inline-block; background: var(--red-soft); color: var(--red); border: 1px solid #fecaca;
  border-radius: 999px; padding: .05rem .55rem; font-size: .8rem; font-weight: 600; margin: .15rem .15rem 0;
}
.faults { text-align: center; min-height: 0; }

.msg-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.msg {
  display: grid; grid-template-columns: 2.2rem 1fr 2.4rem; align-items: center; min-height: 4rem;
  border-bottom: 1px solid var(--line); padding: .35rem 0;
}
.msg.current { background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--blue); }
.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--grey-dot); justify-self: center; }
.dot.on { background: var(--amber); }
.msg-text { text-align: center; font-size: .86rem; letter-spacing: .06em; line-height: 1.5; color: var(--ink); text-transform: uppercase; }
.msg-text .blank { color: var(--ink-faint); text-transform: none; letter-spacing: 0; font-style: italic; }
.msg-text .on-sign {
  display: block; font-size: .68rem; letter-spacing: .04em; color: var(--blue); font-weight: 700; margin-top: .1rem;
}
.msg-text .nofit { display: block; color: var(--red); font-size: .72rem; letter-spacing: 0; text-transform: none; }
.kebab {
  background: none; border: 0; width: 2.2rem; height: 2.2rem; border-radius: 50%; justify-content: center;
  font-size: 1.35rem; line-height: 1; color: var(--ink); padding: 0;
}
.kebab:hover { background: var(--bg); }
.menu {
  position: absolute; z-index: 30; background: #fff; border-radius: 8px; min-width: 11rem; padding: .3rem 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.16); border: 1px solid var(--line);
}
.menu button { display: flex; width: 100%; background: none; border: 0; border-radius: 0; padding: .55rem 1rem; color: var(--ink); font-weight: 400; }
.menu button:hover, .menu button:focus-visible { background: var(--blue-soft); outline: none; }
.menu button.danger-item { color: var(--red); }
.fab {
  width: 3.2rem; height: 3.2rem; border-radius: 50%; background: #3b82f6; color: #fff; font-size: 1.6rem;
  justify-content: center; padding: 0; margin: 1.25rem auto 0; box-shadow: 0 4px 10px rgba(59,130,246,.35); font-weight: 400;
}
.fab:hover { background: var(--blue); }

/* ---------------------------------------------------------------- dialog */
dialog {
  border: 0; border-radius: 12px; padding: 1.5rem; width: min(92vw, 30rem); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h2 { font-size: 1.15rem; margin-bottom: .8rem; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .7rem; }
.check { display: flex; align-items: center; gap: .45rem; color: var(--ink); font-size: .95rem; }
.check input { width: 1.05rem; height: 1.05rem; }
.preview-wrap { background: var(--housing); border-radius: 6px; padding: .7rem; margin: .4rem 0 .6rem; }
.preview-wrap canvas { width: 100%; display: block; }
.line-input { font: 600 1rem ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .08em; }
.counter { font-size: .78rem; color: var(--ink-faint); text-align: right; }
.confirm-text { font: 600 1rem ui-monospace, Consolas, monospace; background: var(--bg); border-radius: 6px; padding: .6rem .8rem; white-space: pre; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(92vw, 26rem); }
.toast { background: #111827; color: #fff; border-radius: 8px; padding: .7rem 1rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .92rem; }
.toast.ok { border-left: 4px solid #34d399; }
.toast.bad { border-left: 4px solid #f87171; }

/* ---------------------------------------------------------------- users */
.users { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 1rem; align-items: start; }
.user-list-card { display: flex; flex-direction: column; min-height: 22rem; }
.user-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; flex: 1; }
.user-list button {
  width: 100%; justify-content: center; background: #fff; border: 1px solid #d1d5db; color: var(--ink);
  padding: .65rem; font-weight: 500;
}
.user-list button[aria-current=true] { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }
.user-list .badge { font-size: .7rem; color: var(--ink-faint); font-weight: 400; }
.user-detail .field { margin-bottom: 1rem; }
.key-row { display: flex; gap: .5rem; align-items: center; }
.key-row .pw { flex: 1; }
.key-input { font-family: ui-monospace, Consolas, monospace; font-size: .88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .55rem; }
.perm-row { display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; margin-top: .35rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; font-size: .88rem; margin: 0 0 1rem; }
.facts dt { color: var(--ink-faint); }
.facts dd { margin: 0; }
.notice { background: var(--amber); background: #fefce8; border: 1px solid #fde68a; color: #713f12; border-radius: 6px; padding: .6rem .8rem; font-size: .9rem; margin: .5rem 0; }

/* ---------------------------------------------------------------- logs */
.logs-card { max-width: 960px; margin: 0 auto; }
.event-list { list-style: none; margin: 0; padding: 0; }
.event { display: grid; grid-template-columns: 2rem 1fr; gap: .6rem; padding: .8rem .4rem; border-bottom: 1px solid var(--line); }
.event .icon { width: 1.15rem; height: 1.15rem; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font: 700 .72rem/1 Georgia, serif; margin-top: .2rem; }
.event.lvl-warning .icon { background: var(--amber); }
.event.lvl-error .icon { background: var(--red); }
.event time { font-weight: 700; display: block; font-variant-numeric: tabular-nums; }
.event .text { color: var(--ink-soft); }
.event .cat { font-size: .72rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; margin-left: .5rem; font-weight: 500; }

/* ---------------------------------------------------------------- status */
.subtabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.subtabs button { background: #fff; border: 1px solid #d1d5db; color: var(--ink); }
.subtabs button[aria-selected=true] { background: var(--blue); border-color: var(--blue); color: #fff; }
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 1rem; }
.health h2 { font-size: 1.2rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.pill { font-size: .78rem; font-weight: 600; border-radius: 999px; padding: .15rem .65rem; background: var(--bg); color: var(--ink-soft); }
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.warn { background: #fefce8; color: var(--amber-dark); }
.health h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); margin: 1rem 0 .4rem; }
.bits { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .3rem .8rem; font-size: .88rem; }
.bit { display: flex; justify-content: space-between; gap: .5rem; border-bottom: 1px dotted var(--line); padding: .15rem 0; }
.bit b { font-weight: 600; color: var(--green); }
.bit b.fault { color: var(--red); }

.config-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.config-table th { text-align: left; font-weight: 600; color: var(--ink-soft); padding: .4rem .3rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.config-table td { padding: .3rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.config-table input, .config-table select { padding: .35rem .45rem; }
.config-table .num { width: 4.5rem; }
.config-table .port { width: 5.5rem; }
.table-wrap { overflow-x: auto; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .4rem 1.2rem; margin-top: .5rem; }
.card h3 { font-size: 1rem; margin: 1.3rem 0 .4rem; }
.card h3:first-child { margin-top: 0; }

.comms {
  height: 65vh; overflow: auto; background: #0f172a; color: #e2e8f0; border-radius: 6px; padding: .8rem 1rem;
  font: .8rem/1.5 ui-monospace, Consolas, monospace; margin: 0; white-space: pre-wrap; word-break: break-all;
}
.comms .tx { color: #93c5fd; } .comms .rx { color: #86efac; } .comms .warn { color: #fca5a5; } .comms .note { color: #fcd34d; } .comms .raw { color: #94a3b8; }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 760px) {
  .nav-inner { flex-wrap: wrap; gap: .5rem; padding: .5rem 1rem; }
  .nav nav { order: 3; width: 100%; }
  .page { padding: 1rem 1rem 2rem; }
  .users { grid-template-columns: 1fr; }
  .user-list-card { min-height: 0; }
  .sign-card { padding: 1.1rem 1rem; }
  .sign-card h2 { font-size: 1.3rem; }
}
