/* SandOS — reset, typography, app layout. */

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

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,.022) 1px, transparent 0);
  background-size: 28px 28px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

ul, ol { list-style: none; padding: 0; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--blue-bg); }

/* Scrollbars — subtle */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

/* ---- Accessibility helpers ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: var(--s2); left: var(--s2); z-index: var(--z-toast);
  padding: var(--s2) var(--s4); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transform: translateY(-200%); transition: transform var(--dur) var(--ease);
}
.skip-link:focus { transform: translateY(0); }

/* ---- Boot splash ---- */
.boot {
  position: fixed; inset: 0; display: grid; place-content: center;
  gap: var(--s5); justify-items: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(91,155,213,.07), transparent 70%);
}
.boot__mark {
  font-family: var(--font-mono); font-size: var(--fs-sm);
  letter-spacing: .22em; color: var(--accent); text-transform: uppercase;
  animation: boot-fade 1.8s var(--ease-out) infinite alternate;
}
@keyframes boot-fade { from { opacity: .5; } to { opacity: 1; } }

/* ---- App layout ---- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; position: relative; z-index: 1; }

.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  background-image: none; /* no dot grid on sidebar */
}

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

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--s3);
  height: var(--header-h); padding: 0 var(--s5);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid rgba(255,255,255,.04);
  box-shadow: 0 1px 0 var(--border), 0 4px 20px rgba(0,0,0,.2);
}
.topbar__title { font-size: var(--fs-lg); font-weight: 600; }
.topbar__status { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.topbar__menu { display: none; }

.view {
  width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: var(--s6) var(--s5) var(--s12);
}

/* Opt-out for pages that want the whole content column edge-to-edge and full
   height instead of the padded, centered document column (e.g. the topology
   map — a canvas reads as a "boxed card" otherwise). The double-class selector
   keeps this ahead of .view in specificity regardless of source order, so it
   also overrides the PWA-standalone .view rule below without needing !important. */
.view.view--full {
  max-width: none; margin: 0; padding: 0;
  height: calc(100dvh - var(--header-h));
  overflow: hidden; position: relative;
  /* Belt-and-suspenders for a plain (non-installed) mobile browser tab: the
     canvas itself already sets touch-action:none so a drag on it doesn't pan,
     but this stops that same drag from being read as an overscroll/pull-to-
     refresh gesture by the browser chrome. */
  overscroll-behavior: contain;
}
/* Installed PWA: the topbar grows by the safe-area inset (notch clearance),
   so the full-bleed page must shrink by that same amount or its bottom edge
   runs under the home-indicator / gesture bar. */
@media (display-mode: standalone) {
  .view.view--full { height: calc(100dvh - var(--header-h) - env(safe-area-inset-top)); }
}

.scrim {
  position: fixed; inset: 0; z-index: var(--z-scrim);
  background: rgba(0, 0, 0, .55);
}

/* ---- Mobile: sidebar becomes an off-canvas drawer ---- */
@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; width: var(--sidebar-w); z-index: var(--z-drawer);
    transform: translateX(-100%); transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-pop);
  }
  .sidebar.is-open { transform: translateX(0); }
  .topbar__menu { display: inline-flex; }
  .view { padding: var(--s5) var(--s4) var(--s10); }
}

/* ---- Installed PWA (standalone): keep the top bar & menu button below the
   iOS status bar / notch. Only applies when launched from the home screen. ---- */
@media (display-mode: standalone) {
  .topbar {
    height: calc(var(--header-h) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
  }
  .sidebar { padding-top: env(safe-area-inset-top); }

  /* iOS standalone rubber-bands the WHOLE webview on a top pull and ignores
     overscroll-behavior, which breaks a document-level pull-to-refresh. So lock
     the body and give the content (#view) its own scroll container — the pull
     gesture then works cleanly against that (see js/pull-refresh.js). */
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  .app  { height: 100dvh; }
  .main { height: 100dvh; min-height: 0; }
  .view {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }
  /* Login / boot screens still need to scroll when tall (body is locked). */
  #auth { max-height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- Layout utilities ---- */
.row { display: flex; align-items: center; gap: var(--s3); }
.row--wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.grid { display: grid; gap: var(--s4); }
.grid--stats { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.fw-600 { font-weight: 600; }
.mt-4 { margin-top: var(--s4); }
.mt-6 { margin-top: var(--s6); }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
