/*
  Network Info. Each site carries a cable-jacket colour (the way a patch cable is colour-coded by purpose);
  that jacket is the one bold element. Everything else stays quiet so addresses and names read first.
  Atkinson Hyperlegible Next for interface text; JetBrains Mono for addresses, MACs and credentials,
  where 0/O and 1/l/I must never be confused.
*/
:root {
  --paper: #eef1f3;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --ink: #18212b;
  --ink-2: #4b5866;
  --ink-3: #7a8693;
  --rule: #d5dbe1;
  --rule-strong: #b9c2cb;
  --accent: #1452b8;
  --accent-ink: #ffffff;
  --accent-soft: #e3ecfb;
  --warn: #9a5800;
  --warn-soft: #fff2dc;
  --danger: #b3261e;
  --danger-soft: #fde8e6;
  --ok: #1d7a43;
  --flash: #fff6c2;

  --j-blue: #2f6fe0;
  --j-green: #2e9a55;
  --j-yellow: #d8a60a;
  --j-purple: #8455d6;
  --j-orange: #e0731e;
  --j-red: #d23c3c;
  --j-grey: #7d8894;
  --j-teal: #1f9a9a;

  --font: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
  --radius-s: 4px;
  --radius-m: 8px;
  --sidebar: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #11161c;
    --surface: #182029;
    --surface-2: #1d2630;
    --ink: #e4e9ee;
    --ink-2: #a3afbb;
    --ink-3: #74808c;
    --rule: #2b3540;
    --rule-strong: #3b4753;
    --accent: #6fa3ff;
    --accent-ink: #0d1520;
    --accent-soft: #1e3150;
    --warn: #f0b350;
    --warn-soft: #3a2a10;
    --danger: #ff8a80;
    --danger-soft: #3d1d1b;
    --ok: #63c98d;
    --flash: #4a4310;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 13px; letter-spacing: 0; }
.muted { color: var(--ink-2); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.jacket-blue { --jacket: var(--j-blue); }
.jacket-green { --jacket: var(--j-green); }
.jacket-yellow { --jacket: var(--j-yellow); }
.jacket-purple { --jacket: var(--j-purple); }
.jacket-orange { --jacket: var(--j-orange); }
.jacket-red { --jacket: var(--j-red); }
.jacket-grey { --jacket: var(--j-grey); }
.jacket-teal { --jacket: var(--j-teal); }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap; line-height: 1.3; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--rule); }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 28px; height: 28px; display: inline-grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius-s); background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--rule); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12px; }
.input, .select, textarea.input {
  width: 100%; padding: 7px 10px; border-radius: var(--radius-s);
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: var(--radius-s); margin: 0 0 14px; font-size: 14px; }

/* ---------- Sign-in ---------- */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-m); padding: 28px 28px 22px; position: relative; overflow: hidden;
}
.gate-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 6px;
  background: linear-gradient(90deg, var(--j-blue) 0 17%, var(--j-green) 17% 34%, var(--j-yellow) 34% 51%, var(--j-purple) 51% 68%, var(--j-orange) 68% 85%, var(--j-grey) 85%);
}
.gate-card h1 { font-size: 24px; margin: 4px 0 4px; }
.gate-card p.lede { margin: 0 0 22px; color: var(--ink-2); }
.gate-card .btn.wide { width: 100%; justify-content: center; padding: 9px; }
.gate-card > .btn.wide { margin-bottom: 14px; }
.local-login { border-top: 1px solid var(--rule); padding-top: 12px; }
.local-login summary { cursor: pointer; color: var(--ink-2); font-size: 14px; margin-bottom: 12px; }
.gate-foot { margin-top: 16px; font-size: 13px; color: var(--ink-3); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; min-height: 0;
}
.brand { text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; font-weight: 700; font-size: 17px; }
.brand img { width: 22px; height: 22px; }
.nav { overflow-y: auto; padding: 4px 8px 16px; flex: 1; }
.site { margin-top: 10px; }
.site-head {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 0;
}
.site-head h2 {
  flex: 1; margin: 0; font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 10px;
}
.site-head h2::before {
  content: ''; width: 18px; height: 8px; border-radius: 4px; background: var(--jacket);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / .18);
}
.site ul { list-style: none; margin: 2px 0 0; padding: 0 0 0 9px; border-left: 2px solid var(--jacket); margin-left: 8px; }
.site li a {
  display: flex; justify-content: space-between; gap: 8px; text-decoration: none; color: var(--ink);
  padding: 5px 8px 5px 12px; border-radius: var(--radius-s); font-size: 14px;
}
.site li a:hover { background: var(--surface-2); }
.site li a[aria-current='page'] { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.site li a .count { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 400; }
.site .empty { color: var(--ink-3); font-size: 13px; padding: 4px 12px; }
.nav-group { margin-top: 22px; padding: 10px 4px 0; border-top: 1px solid var(--rule); }
.nav-group a { display: block; padding: 5px 8px; border-radius: var(--radius-s); text-decoration: none; color: var(--ink); font-size: 14px; }
.nav-group a:hover { background: var(--surface-2); }
.nav-group a[aria-current='page'] { background: var(--accent-soft); font-weight: 700; }
.nav-group h3 { margin: 0 0 4px 8px; font-size: 12px; color: var(--ink-3); font-weight: 700; }
.nav-foot { border-top: 1px solid var(--rule); padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.nav-foot .who { flex: 1; min-width: 0; font-size: 13px; line-height: 1.25; }
.nav-foot .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge { font-size: 12px; color: var(--ink-2); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  border-bottom: 1px solid var(--rule); background: var(--surface);
}
.topbar .menu-btn { display: none; }
.search-box { flex: 1; max-width: 560px; position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.search-box .input { padding-left: 34px; background: var(--surface-2); }
.live-dot { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; margin-left: auto; }
.live-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.live-dot.on::before { background: var(--ok); }

.view { flex: 1; overflow: auto; padding: 20px 24px 40px; }

/* ---------- Table view ---------- */
.label-tag {
  display: inline-flex; align-items: stretch; border-radius: var(--radius-s); overflow: hidden;
  border: 1px solid var(--rule-strong); background: var(--surface); margin-bottom: 8px;
}
.label-tag .band {
  background: var(--jacket); color: #fff; font-weight: 700; padding: 3px 10px; font-size: 13px;
  text-shadow: 0 1px 0 rgb(0 0 0 / .25);
}
.jacket-yellow .label-tag .band, .label-tag.jacket-yellow .band { color: #2a2000; text-shadow: none; }
.label-tag .rest { padding: 3px 10px; font-size: 13px; color: var(--ink-2); }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.view-head h1 { margin: 0; font-size: 26px; line-height: 1.15; }
.view-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 70ch; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .filter { width: 260px; }
.toolbar .meta { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.toolbar .spacer { flex: 1; }
.sort-note { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }

.grid-wrap {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  overflow: auto; max-height: calc(100vh - 230px);
}
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 14px; }
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left;
  border-bottom: 1px solid var(--rule-strong); padding: 0; font-weight: 700; color: var(--ink-2); font-size: 13px;
}
.grid thead th button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 8px 10px; cursor: pointer; white-space: nowrap;
}
.grid thead th button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid thead th .arrow { color: var(--accent); font-size: 11px; }
.grid thead th .lock { width: 12px; height: 12px; color: var(--ink-3); }
.grid td {
  border-bottom: 1px solid var(--rule); padding: 6px 10px; vertical-align: top; white-space: nowrap;
}
.grid tbody tr:hover td { background: var(--surface-2); }
.grid td.editable { cursor: text; }
.grid td.kind-notes { white-space: pre-wrap; min-width: 180px; max-width: 360px; overflow-wrap: anywhere; }
.grid td.kind-ip, .grid td.kind-mac, .grid td.kind-secret { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.grid td.actions, .grid th.actions { width: 36px; padding: 2px 4px; text-align: right; }
.grid td.warn { box-shadow: inset 3px 0 0 var(--warn); }
.grid td.warn .flag { color: var(--warn); font-family: var(--font); font-size: 12px; display: block; white-space: normal; }
.grid tr.section td {
  background: var(--surface-2); font-weight: 700; padding-top: 12px; color: var(--ink);
  border-bottom-color: var(--rule-strong);
}
.grid tr.section td.section-label { box-shadow: inset 4px 0 0 var(--jacket); }
.grid tr.flash td { background: var(--flash) !important; transition: background 1.5s ease 1.2s; }
.grid tr.flash.fade td { background: transparent !important; }
.grid td.saving { opacity: .55; }
.grid td.editing { padding: 2px; background: var(--surface) !important; outline: 2px solid var(--accent); outline-offset: -2px; }
.cell-input {
  width: 100%; min-width: 120px; border: 0; padding: 4px 8px; background: transparent; outline: none;
}
.cell-input.mono { font-family: var(--mono); font-size: 13px; }
textarea.cell-input { min-height: 64px; resize: vertical; display: block; }
.cell-editor { display: flex; align-items: center; gap: 4px; }
.cell-hint { font-family: var(--font); font-size: 11px; color: var(--ink-3); padding: 0 8px 2px; white-space: nowrap; }

.secret { display: inline-flex; align-items: center; gap: 4px; }
.secret .dots { color: var(--ink-3); letter-spacing: 2px; }
.secret .value { background: var(--accent-soft); padding: 1px 6px; border-radius: 3px; user-select: all; }
.secret .icon-btn { width: 22px; height: 22px; }
.secret .icon-btn svg { width: 14px; height: 14px; }

.empty-state { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty-state p { margin: 0 0 12px; }

/* ---------- Popover menu ---------- */
.popover {
  position: fixed; z-index: 50; min-width: 200px; background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: var(--radius-m); padding: 4px; box-shadow: 0 10px 30px rgb(0 0 0 / .18);
}
.popover button {
  all: unset; box-sizing: border-box; display: block; width: 100%; padding: 7px 10px; border-radius: var(--radius-s);
  cursor: pointer; font-size: 14px;
}
.popover button:hover, .popover button:focus-visible { background: var(--surface-2); }
.popover button.danger { color: var(--danger); }
.popover button:disabled { color: var(--ink-3); cursor: not-allowed; }
.popover hr { border: 0; border-top: 1px solid var(--rule); margin: 4px 0; }

/* ---------- Modal ---------- */
dialog {
  border: 1px solid var(--rule-strong); border-radius: var(--radius-m); padding: 0; background: var(--surface); color: var(--ink);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 16 24 / .45); }
.modal-body { padding: 20px 22px 8px; overflow: auto; max-height: calc(100vh - 140px); }
.modal-body h2 { margin: 0 0 6px; font-size: 20px; }
.modal-body > p { margin: 0 0 16px; color: var(--ink-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }
.modal-foot .left { margin-right: auto; }
.temp-pass {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: var(--radius-s);
  background: var(--accent-soft); font-family: var(--mono); font-size: 18px; margin: 8px 0 16px; word-break: break-all;
}
.temp-pass span { flex: 1; }

.col-list { display: grid; gap: 8px; margin-bottom: 16px; }
.col-row { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; align-items: center; }
.col-row .order { display: flex; }
.col-add { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; padding-top: 14px; border-top: 1px solid var(--rule); }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); }
.danger-zone h3 { margin: 0 0 6px; font-size: 15px; color: var(--danger); }
.danger-zone p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }
.color-picks { display: flex; gap: 8px; flex-wrap: wrap; }
.color-picks label { cursor: pointer; }
.color-picks input { position: absolute; opacity: 0; }
.color-picks span {
  display: block; width: 40px; height: 16px; border-radius: 8px; background: var(--jacket);
  outline: 2px solid transparent; outline-offset: 3px;
}
.color-picks input:checked + span { outline-color: var(--ink); }
.color-picks input:focus-visible + span { outline-color: var(--accent); }

/* ---------- Lists (search, users, activity) ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); }
.results { list-style: none; margin: 0; padding: 0; }
.results li + li { border-top: 1px solid var(--rule); }
.results a { display: grid; grid-template-columns: 200px 1fr; gap: 16px; padding: 10px 14px; text-decoration: none; color: var(--ink); }
.results a:hover { background: var(--surface-2); }
.results .where { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.results .where::before { content: ''; flex: none; width: 14px; height: 6px; border-radius: 3px; background: var(--jacket); }
.results .what strong { display: block; }
.results .match { font-size: 13px; color: var(--ink-2); }
.results mark { background: var(--flash); color: inherit; padding: 0 1px; border-radius: 2px; }

table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain th { text-align: left; font-size: 13px; color: var(--ink-2); padding: 8px 12px; border-bottom: 1px solid var(--rule-strong); background: var(--surface-2); }
table.plain td { padding: 8px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.plain tr:last-child td { border-bottom: 0; }
table.plain .row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.status-off { color: var(--danger); }
.status-pending { color: var(--warn); }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 170px 140px 1fr; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--rule); font-size: 14px; }
.activity li:first-child { border-top: 0; }
.activity time { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.activity .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.activity details { margin-top: 4px; }
.activity summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.activity .diff { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; }
.activity .diff li { display: block; padding: 2px 0; border: 0; }
.activity .diff del { color: var(--danger); text-decoration: line-through; }
.activity .diff ins { color: var(--ok); text-decoration: none; }
.activity .sensitive { color: var(--warn); }

.section-title { font-size: 16px; margin: 26px 0 10px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 10px; align-items: end; padding: 14px; }
.form-grid .field { margin: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: var(--radius-s);
  max-width: 380px; font-size: 14px; box-shadow: 0 8px 24px rgb(0 0 0 / .2);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40;
    transform: translateX(-100%); transition: transform .18s ease;
  }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgb(10 16 24 / .4); }
  .topbar { padding: 8px 12px; }
  .topbar .menu-btn { display: inline-grid; }
  .live-dot span { display: none; }
  .view { padding: 14px 12px 32px; }
  .toolbar .filter { width: 100%; }
  .grid-wrap { max-height: none; }
  .results a { grid-template-columns: 1fr; gap: 4px; }
  .activity li { grid-template-columns: 1fr; gap: 2px; }
  .form-grid { grid-template-columns: 1fr; }
  .col-row, .col-add { grid-template-columns: 1fr 120px auto; }
}

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