/*
 * NodeBook — base elements, the shell (the ink top bar, sidebar and phone tab bar), page header,
 * split panes. Radio-Actief house style; tokens live in tokens.css. index.html loads shell, forms, lists, views, dialogs, responsive,
 * bulk, extras and touch.css in this order; the cascade depends on it.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--link);
}

@media (hover: hover) {
  a:hover {
    color: var(--link-hover);
  }
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
}

p {
  margin: 0;
}

code,
kbd,
samp,
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.muted {
  color: var(--text-2);
}

.faint {
  color: var(--text-3);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  display: inline-flex;
  flex: none;
  line-height: 0;
}

/* ---------- shell ---------- */

/* Off screen until focused: the first Tab stop, past the navigation to the page. */
.skip-link {
  position: fixed;
  z-index: 3000;
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  min-height: var(--tap);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.main:focus {
  outline: none;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-3);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
}

/* The open section: the pale gold of the active item, in bold (never colour alone). */
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 700;
}

@media (hover: hover) {
  .nav-item:hover {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
    color: var(--text);
  }
}

/* Muted text on the pale gold and blue tints: ra-mut is too light there (4.3:1), so whatever sits on
   one takes the darker muted shade (--text-on-tint). */
.nav-item[aria-current="page"],
.row[aria-current="true"],
.row.is-selected,
.chip[aria-pressed="true"],
.bulk-item[aria-selected="true"],
button.stat--button[aria-pressed="true"],
.callout,
.updatebar,
.bulk-queue {
  --text-2: var(--text-on-tint);
  --text-3: var(--text-on-tint);
}

@media (hover: hover) {
  .nav-item:hover,
  .row:hover,
  button.chip:hover,
  .bulk-item:hover,
  button.stat--button:hover,
  .choice:hover,
  .action-tile:hover,
  .more-menu-item:hover {
    --text-2: var(--text-on-tint);
    --text-3: var(--text-on-tint);
  }
}

.nav-count {
  margin-left: auto;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.server-state {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-3);
  padding: 0 var(--space-2);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}

.dot--ok {
  background: var(--ok);
}

.dot--bad {
  background: var(--danger);
}

.main {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* clip, not just hide: focusing a control inside must never scroll the shell itself */
  overflow: clip;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tabbar {
  display: none;
}

/* ---------- the ink top bar (Inktbalk) ----------
   Ink in both themes, 44 px: the #BEmesh word mark, the tool switcher (the #BEmesh tools, NodeBook,
   MeshMate), Help, the ☰ menu, the theme button and the account area. On a phone it carries the
   #BEmesh word mark (a back link instead on a page that has one), the page title and its actions. */

.topbar {
  grid-column: 1 / -1;
  position: relative;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--topbar-h);
  padding: 0 var(--space-3);
  background: var(--bar-bg);
  color: var(--bar-text);
  border-bottom: 1px solid var(--bar-line);
}

.topbar h1 {
  font-size: var(--text-lg);
}

.wordmark {
  flex-shrink: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  line-height: 20px;
  white-space: nowrap;
}

.wordmark b {
  font-weight: inherit;
  color: var(--bar-accent);
}

/* The switcher starts at the same x as on the tools' pages. */
.topbar .wordmark {
  min-width: 192px;
}

.topbar .spacer {
  flex: 1;
}

.switcher {
  display: inline-flex;
  flex-shrink: 0;
  border: 1px solid var(--bar-control);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.switcher a {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-left: 1px solid var(--bar-control);
  color: var(--bar-text);
  font-size: var(--text-sm);
  text-decoration: none;
  white-space: nowrap;
}

.switcher a:first-child {
  border-left: 0;
}

/* The tool open here: signal yellow on ink, in bold; the only yellow on the screen. */
.switcher a[aria-current="page"] {
  background: var(--signal);
  color: var(--ink);
  font-weight: 700;
}

.switcher a:focus-visible {
  outline-offset: -2px;
}

.switcher a[aria-current="page"]:focus-visible {
  outline-color: var(--ink);
}

/* The tools' pages are in ☰ only where the switcher has no room; the theme only on a phone. */
.tools-menu .menu-page,
.tools-menu .menu-theme {
  display: none;
}

@media (max-width: 820px) {
  .topbar .theme-btn {
    display: none;
  }

  .tools-menu .menu-theme {
    display: block;
  }
}

@media (max-width: 1023px) {
  .topbar .switcher {
    display: none;
  }

  .tools-menu .menu-page {
    display: block;
  }
}

/* Controls on the bar take its colours in both themes; the menus that open from it keep the theme's. */
.topbar :focus-visible {
  outline-color: var(--bar-focus);
}

.topbar .more-menu-list :focus-visible {
  outline-color: var(--focus);
}

.topbar .icon-btn,
.topbar .menu-btn {
  color: var(--bar-text);
  border: 1px solid transparent;
}

/* Log in: a 36 px frame like the other bar controls, inside a full 44 px tap area. */
.topbar .btn {
  position: relative;
  isolation: isolate;
  height: var(--tap);
  min-height: var(--tap);
  background: transparent;
  border-color: transparent;
  color: var(--bar-text);
}

.topbar .btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 4px 0;
  border: 1px solid var(--bar-control);
  border-radius: var(--radius-md);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.topbar .btn:focus-visible {
  outline-offset: -2px;
}

.topbar .menu-btn[aria-expanded="true"],
.topbar .icon-btn[aria-expanded="true"] {
  background: var(--bar-open);
  border-color: var(--accent);
}

@media (hover: hover) {
  .switcher a:not([aria-current="page"]):hover {
    background: var(--bar-open);
    color: var(--bar-text);
  }

  .topbar .icon-btn:hover:not(:disabled),
  .topbar .menu-btn:hover {
    background: var(--bar-open);
    border-color: var(--accent);
    color: var(--bar-text);
  }

  .topbar .btn:hover:not(:disabled) {
    background: transparent;
    border-color: transparent;
    color: var(--bar-text);
  }

  .topbar .btn:hover:not(:disabled)::before {
    background: var(--bar-open);
    border-color: var(--accent);
  }
}

.topbar .account-name {
  color: var(--bar-text);
}

.topbar .account-avatar {
  background: var(--bar-open);
  color: var(--bar-text);
}

/* The right side, as on the other #BEmesh tools (their bemesh-shell.css): 28 px framed buttons,
   the guest's "Sign in with Discord" pill and EN · NL, 6 px above and below, so the bar is 41 px.
   A phone keeps 44 px tap areas (responsive.css) and moves the pill and the language into ☰. */
@media (min-width: 821px) {
  .topbar {
    min-height: 0;
    gap: 8px;
    padding: 6px 12px;
  }
}

.topbar .bar-btn,
.topbar .tools-menu > .menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--bar-control);
  border-radius: 8px;
  background: transparent;
  color: var(--bar-text);
  cursor: pointer;
}

.topbar .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 3px 10px;
  border: 1px solid var(--bar-control);
  border-radius: 999px;
  background: transparent;
  color: var(--bar-text);
  min-height: 0;
  height: auto;
  font-size: 12px;
  font-weight: 400;
  line-height: normal;
  text-decoration: none;
  white-space: nowrap;
}

/* The device chip (views/device-chip.js), as on every #BEmesh tool: a dot and a text that gives way first. */
.topbar .device-chip {
  display: inline-flex;
  flex: 0 1 auto;
  min-width: 0;
}

.topbar .device-chip .more-menu {
  display: inline-flex;
  min-width: 0;
}

.topbar .device-chip .more-menu-list {
  left: 0;
  right: auto;
}

.topbar .chip.conn {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 260px;
  font-family: inherit;
}

.topbar .chip.conn.action {
  cursor: pointer;
}

.topbar .chip.conn[aria-expanded="true"] {
  background: var(--bar-open);
  border-color: var(--accent);
}

.topbar .chip.conn .chip-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .chip.conn .dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bar-ok);
}

.topbar .chip.conn .dot.off {
  background: var(--bar-mut);
}

.tools-menu .menu-device {
  display: none;
}

.lang-switch {
  display: inline-flex;
  flex-shrink: 0;
  border: 1px solid var(--bar-control);
  border-radius: 8px;
  overflow: hidden;
}

.lang-switch button {
  padding: 4px 7px;
  border: 0;
  border-left: 1px solid var(--bar-control);
  background: transparent;
  color: var(--bar-text);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 14px;
  cursor: pointer;
}

.lang-switch button:first-child {
  border-left: 0;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--signal);
  color: var(--bar-bg);
  font-weight: 700;
}

.lang-switch button:focus-visible {
  outline-offset: -2px;
}

.topbar .tools-menu > .menu-btn[aria-expanded="true"] {
  background: var(--bar-open);
  border-color: var(--accent);
}

@media (hover: hover) {
  .topbar .bar-btn:hover,
  .topbar .chip:hover,
  .lang-switch button:not([aria-pressed="true"]):hover {
    background: var(--bar-open);
    border-color: var(--accent);
  }
}

/* In ☰: who is logged in (a plain line), the language only on a phone. */
.more-menu-sep {
  margin: var(--space-1) 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.more-menu-note {
  padding: var(--space-2) var(--space-3);
  color: var(--text-2);
  font-size: var(--text-sm);
}

.menu-user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* In the menu the name takes the menu's colours and shows on a phone too (the bar's rules don't apply). */
.tools-menu .menu-user .account-name {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  color: var(--text);
}

.tools-menu .menu-lang {
  display: none;
}

@media (max-width: 820px) {
  .topbar .chip,
  .topbar .lang-switch,
  .topbar .theme-btn {
    display: none;
  }

  .tools-menu .menu-lang {
    display: flex;
  }

  .tools-menu hr.menu-lang,
  .tools-menu .menu-device {
    display: block;
  }

  .topbar .device-chip {
    display: none;
  }
}

/* The page title and its actions are the phone's (responsive.css); a wide screen shows the word mark and the switcher. */
@media (min-width: 821px) {
  .topbar > h1,
  .topbar > .topbar-back,
  .topbar > .topbar-actions {
    display: none;
  }
}

/* ---------- page header ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-5) var(--space-6) var(--space-4);
}

/* A header above a page body ends where the body does. */
.page-head:has(+ .page-body) {
  max-width: 1100px;
}

/* A short page heading in Orbitron (the house style's display face; never running text). */
.page-head h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
}

.page-head .spacer {
  flex: 1;
}

.page-sub {
  color: var(--text-2);
  font-size: var(--text-sm);
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.page-body {
  padding: 0 var(--space-6) calc(var(--space-8) + 64px);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 1100px;
}

/* ---------- split (master / detail) ---------- */

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--list-w) minmax(0, 1fr);
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane--list {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
}

.pane--detail {
  background: var(--bg);
}

.empty-detail {
  margin: auto;
  max-width: 420px;
  text-align: center;
  color: var(--text-2);
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.empty-detail .icon {
  color: var(--text-3);
}

/* On a phone: what the empty right-hand pane holds, above the list (views/split.js). */
.list-overview {
  border-bottom: 1px solid var(--border);
}

.list-overview > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  cursor: pointer;
  list-style: none;
}

.list-overview > summary::-webkit-details-marker {
  display: none;
}

.list-overview[open] > summary .icon {
  transform: rotate(180deg);
}

.list-overview .page-head {
  padding-top: 0;
}

.list-overview .page-body {
  padding-bottom: var(--space-4);
}

.list-overview .stat-grid {
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--space-2);
}

.list-overview .stat {
  padding: var(--space-2) var(--space-3);
  gap: 0;
}

.list-overview .stat-value {
  font-size: var(--text-lg);
}

/* A long label ("Flagged by record checks") wraps inside its tile. */
.list-overview .stat-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.list-overview .empty-detail {
  padding: 0 var(--space-4) var(--space-6);
}

.list-overview .empty-detail > .icon {
  display: none;
}

/* While rows are being selected the bulk bar's actions take the overview's place. */
.pane--list:has(> .bulkbar:not([hidden])) .list-overview {
  display: none;
}
