/*
 * SS-06 design system. Palette reused from GridSync's own real Tailwind
 * config (products/gridsync-mvp/tailwind.config.ts, the closest available
 * real GridSync design source in this workspace) so this reads as a
 * GridSync product, not an unrelated tool - per SS-06 §3's reuse directive.
 * One type scale, one color palette used semantically (status colors are
 * reserved for status, never decoration), consistent spacing via a single
 * --space-* scale.
 */
:root {
  color-scheme: dark;

  --bg: #020d1f;
  --surface: #071830;
  --card: #0b2240;
  --card-hover: #0f2d55;
  --border: #1a3d6b;
  --border-hi: #2563a8;

  --green: #00dc9d;
  --green-dim: #009e70;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a855f7;

  --text-pri: #e2ecff;
  --text-sec: #7ea3c4;
  --text-muted: #4a6a8a;

  --font-sans: -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius: 10px;
  --radius-sm: 6px;
}

/*
 * SS-08 §4: a real light theme, not just a `prefers-color-scheme` follow -
 * toggled explicitly via `data-theme` on <html> (app.js), remembered in
 * localStorage. Every color below was checked against WCAG AA's 4.5:1
 * minimum for normal text against this theme's own --bg (computed
 * directly, not eyeballed): text-pri 16.1:1, text-sec 7.8:1, text-muted
 * 4.8:1, green 5.6:1, blue 6.2:1, amber 5.5:1, red 5.3:1, purple 6.5:1.
 */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f4f7fc;
  --surface: #ffffff;
  --card: #ffffff;
  --card-hover: #eef3fb;
  --border: #d7e0ef;
  --border-hi: #aec3e3;

  --green: #00714f;
  --green-dim: #005c40;
  --blue: #1d4ed8;
  --amber: #a34a06;
  --red: #c81e1e;
  --purple: #7e22ce;

  --text-pri: #0f1b2d;
  --text-sec: #3d4f68;
  --text-muted: #5d6f89;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-pri);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

body { min-height: 100vh; }

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

/*
 * SS-08 §1: replaces the old full-width hazard-stripe banner. That banner
 * named internal dev-process codenames ("Lane SS") and an internal
 * production domain ("gridsync.cc") to any external party looking at the
 * screen - real information disclosure, not just an aesthetic problem. This
 * is a small, quiet, professional indicator instead: present everywhere
 * (so a capacity/telemetry figure is never mistaken for real), but reads as
 * a considered piece of the product, not a warning label. Built as the
 * softened-badge version per SS-08 §1's default; full removal is a
 * Founder-only call if it comes up again.
 */
.sandbox-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.12);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: default;
}
.sandbox-badge::before { content: "●"; font-size: 0.55rem; }

/* ── Persistent nav ────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: var(--space-2); }
.brand img.brand-icon { height: 28px; width: 28px; object-fit: contain; }
.brand .brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.brand .sub { color: var(--text-sec); font-size: 0.72rem; font-family: var(--font-mono); }

.topbar-right { display: flex; align-items: center; gap: var(--space-3); }
.auth-widget { display: flex; align-items: center; gap: var(--space-2); }
.auth-widget .who { color: var(--text-sec); font-size: 0.8rem; }
.role-pill { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 999px; background: var(--card-hover); color: var(--text-sec); border: 1px solid var(--border); }

/* SS-08 §4: theme toggle - lightweight per-viewer preference (localStorage), not OS-follow */
.theme-toggle {
  background: var(--card-hover);
  border: 1px solid var(--border);
  color: var(--text-pri);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}
.theme-toggle:hover { background: var(--border); }

.tabbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-5);
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
}

.tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-sec);
  padding: var(--space-3) var(--space-3);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text-pri); }
.tab.active { color: var(--text-pri); border-bottom-color: var(--blue); }

main { padding: var(--space-5); max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ── Layout primitives ─────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}
.grid.cols-wide { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.section-title {
  margin: 0 0 var(--space-3);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
h2.page-title { font-size: 1.15rem; margin: 0 0 var(--space-1); }
p.page-desc { color: var(--text-sec); margin: 0 0 var(--space-4); font-size: 0.85rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.kpi-card .kpi-label { color: var(--text-sec); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-2); }
.kpi-card .kpi-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-card .kpi-sub { color: var(--text-muted); font-size: 0.75rem; margin-top: var(--space-1); }
.kpi-card .kpi-value.unknown { color: var(--text-muted); font-size: 1.2rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  background: var(--card-hover);
  color: var(--text-pri);
  border: 1px solid var(--border-hi);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
}
.btn:hover { background: var(--border-hi); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); }
.btn.primary:hover { background: #2f6fe0; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: rgba(239, 68, 68, 0.12); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.small { padding: var(--space-1) var(--space-2); font-size: 0.75rem; }

/* ── Status pills - color + label/icon together, never color alone ───────── */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: rgba(0, 220, 157, 0.14); color: var(--green); }
.pill.bad { background: rgba(239, 68, 68, 0.14); color: var(--red); }
.pill.warn { background: rgba(245, 158, 11, 0.14); color: var(--amber); }
.pill.muted { background: rgba(74, 106, 138, 0.18); color: var(--text-sec); }
.pill::before { content: attr(data-icon); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td { text-align: left; padding: var(--space-2) var(--space-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-sec); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--card-hover); cursor: pointer; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--bg);
  color: var(--text-pri);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  font-size: 0.82rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; color: var(--text-sec); }
textarea.code, pre.code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
}

/* ── Misc ──────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.sec { color: var(--text-sec); }
.mono { font-family: var(--font-mono); }
.empty-state { color: var(--text-muted); font-size: 0.85rem; padding: var(--space-4); text-align: center; }
.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 320px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 13, 31, 0.7); display: flex; align-items: flex-start; justify-content: center; padding: var(--space-6) var(--space-4); z-index: 50; overflow-y: auto; }
.modal { background: var(--card); border: 1px solid var(--border-hi); border-radius: var(--radius); padding: var(--space-5); max-width: 640px; width: 100%; }
.modal .row.between { margin-bottom: var(--space-3); }
.close-x { background: none; border: none; color: var(--text-sec); font-size: 1.1rem; cursor: pointer; }
.badge-count { background: var(--border); color: var(--text-pri); border-radius: 999px; padding: 0 7px; font-size: 0.7rem; font-weight: 700; }
.filter-bar { display: flex; gap: var(--space-2); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--space-3); }
.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus { left: var(--space-3); top: var(--space-3); z-index: 100; background: var(--blue); color: #fff; padding: var(--space-2); border-radius: var(--radius-sm); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media print {
  .topbar, .tabbar, .no-print { display: none !important; }
  body { background: #fff; color: #111; }
  .card { border-color: #ccc; }
}

@media (max-width: 640px) {
  main { padding: var(--space-3); }
  .topbar { padding: var(--space-2) var(--space-3); }
  .tabbar { padding: 0 var(--space-2); }
}

/* ── Login screen (SS-08 §2, restyled 2026-09-09) ──────────────────────────
 * Deliberately art-directed and SELF-CONTAINED: every value below is
 * hardcoded rather than read from the shared --token palette, and every
 * selector is scoped under .login-screen. Two reasons - it must not drift
 * when the in-app design system changes, and it must render identically
 * regardless of the viewer's stored light/dark preference (the gate is one
 * fixed composition, not a themed surface). Nothing here affects any other
 * screen; the in-app design system is untouched.
 *
 * The look is instrument-panel/CRT: near-black ground with a vignette,
 * low-contrast scanlines, technical-drawing corner brackets, wide-tracked
 * monospace, and GridSync's own brand green used sparingly as a phosphor
 * accent rather than as decoration.
 */
.login-screen {
  --lg-panel-line: #1b2b34;
  --lg-phos: #00dc9d;
  --lg-text: #dfe8ef;
  --lg-dim: #8fa3b0;

  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: radial-gradient(125% 95% at 50% 40%, #0d141c 0%, #05070a 62%, #030507 100%);
}
/* Scanlines: the strongest single retro cue, kept low enough not to fight text. */
.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.028) 0px,
    rgba(255, 255, 255, 0.028) 1px,
    transparent 1px,
    transparent 3px
  );
}

.login-panel {
  position: relative;
  width: 100%;
  max-width: 384px;
  padding: 46px 38px 40px;
  text-align: center;
  background: linear-gradient(180deg, rgba(18, 26, 34, 0.92), rgba(8, 12, 17, 0.94));
  border: 1px solid var(--lg-panel-line);
  border-radius: 3px;
  box-shadow:
    0 30px 70px -22px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.045);
  animation: loginPanelIn 620ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
/* Four corner brackets, drawn as eight 1px gradient slivers - a technical
 * drawing's crop marks rather than a decorative border. */
.login-panel::before {
  content: "";
  position: absolute;
  inset: 11px;
  pointer-events: none;
  opacity: 0.4;
  background:
    linear-gradient(var(--lg-phos), var(--lg-phos)) left top / 11px 1px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) left top / 1px 11px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) right top / 11px 1px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) right top / 1px 11px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) left bottom / 11px 1px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) left bottom / 1px 11px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) right bottom / 11px 1px no-repeat,
    linear-gradient(var(--lg-phos), var(--lg-phos)) right bottom / 1px 11px no-repeat;
}

.login-panel img.login-mark {
  height: 46px;
  width: 46px;
  object-fit: contain;
  filter: drop-shadow(0 0 15px rgba(0, 220, 157, 0.34));
}
/* text-indent cancels the trailing letter-space so tracked-out caps stay
 * optically centred rather than sitting one space to the left. */
.login-panel h1 {
  margin: 19px 0 0;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--lg-text);
  text-shadow: 0 0 18px rgba(223, 232, 239, 0.16);
}
.login-eyebrow {
  margin-top: 9px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--lg-phos);
  opacity: 0.85;
}
.login-rule {
  position: relative;
  height: 1px;
  margin: 24px 0 28px;
  background: linear-gradient(90deg, transparent, var(--lg-panel-line) 18%, var(--lg-panel-line) 82%, transparent);
}
.login-rule::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--lg-phos);
  opacity: 0.7;
  box-shadow: 0 0 8px rgba(0, 220, 157, 0.6);
}

.login-panel form { text-align: left; display: flex; flex-direction: column; gap: 18px; }
.login-panel label { display: flex; flex-direction: column; gap: 7px; }
.login-panel label span {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--lg-dim);
}
.login-panel input {
  background: rgba(3, 6, 9, 0.75);
  border: 1px solid var(--lg-panel-line);
  border-radius: 2px;
  padding: 12px 13px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: var(--lg-text);
  transition: border-color 160ms, box-shadow 160ms, background 160ms;
}
.login-panel input:focus {
  outline: none;
  border-color: var(--lg-phos);
  background: rgba(0, 220, 157, 0.04);
  box-shadow: 0 0 0 1px rgba(0, 220, 157, 0.35), 0 0 18px -4px rgba(0, 220, 157, 0.45);
}
/* Without this the browser's autofill paints its own pale background over
 * the field and the whole composition falls apart on a returning visit. */
.login-panel input:-webkit-autofill,
.login-panel input:-webkit-autofill:hover,
.login-panel input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--lg-text);
  -webkit-box-shadow: 0 0 0 1000px #070b10 inset;
  caret-color: var(--lg-text);
}

.login-panel button[type="submit"] {
  width: 100%;
  margin-top: 4px;
  padding: 13px;
  border: 1px solid var(--lg-phos);
  border-radius: 2px;
  background: linear-gradient(180deg, #00e8a6, #00b881);
  color: #04120d;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 22px -6px rgba(0, 220, 157, 0.55);
  transition: filter 160ms, box-shadow 160ms, transform 80ms;
}
.login-panel button[type="submit"]:hover { filter: brightness(1.09); box-shadow: 0 0 30px -6px rgba(0, 220, 157, 0.75); }
.login-panel button[type="submit"]:active { transform: translateY(1px); }
.login-panel button[type="submit"]:focus-visible { outline: 2px solid #7ff5d2; outline-offset: 2px; }

.login-panel .login-error {
  min-height: 1.1em;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: #ff6b6b;
}

@keyframes loginPanelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .login-panel { animation: none; }
}

/* ── Console tooltips (SS-08 §5) ─────────────────────────────────────────── */
.tooltip-wrap { position: relative; display: inline-flex; margin-left: auto; }
.tooltip-icon {
  background: var(--card-hover);
  border: 1px solid var(--border);
  color: var(--text-sec);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  font-style: italic;
  font-family: Georgia, serif;
}
.tooltip-icon:hover, .tooltip-icon:focus-visible { background: var(--blue); border-color: var(--blue); color: #fff; outline: none; }
.tooltip-popover {
  display: none;
  position: absolute;
  z-index: 20;
  top: 24px;
  right: 0;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: 0.76rem;
  color: var(--text-pri);
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  text-align: left;
}
/* Shown on hover AND keyboard focus (not mouse-only) - same content, same
 * only-when-invoked behavior either way, just not exclusively mouse-dependent. */
.tooltip-wrap:hover .tooltip-popover,
.tooltip-icon:focus-visible + .tooltip-popover,
.tooltip-wrap:focus-within .tooltip-popover {
  display: block;
}

/* ── Settings (SS-08 §3) ─────────────────────────────────────────────────── */
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; }
.role-badge.admin { background: rgba(168, 85, 247, 0.14); color: var(--purple); }
.role-badge.viewer { background: rgba(59, 130, 246, 0.14); color: var(--blue); }

/* ── Docs / reference page (SS-08 §6) ───────────────────────────────────── */
.docs-search { width: 100%; max-width: 480px; padding: var(--space-3); font-size: 0.9rem; margin-bottom: var(--space-4); }
.docs-toc { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-5); }
.docs-toc a.btn { text-decoration: none; }
.docs-section { margin-bottom: var(--space-5); }
.docs-section h3 { margin: 0 0 var(--space-2); font-size: 1rem; }
.docs-section h4 { margin: var(--space-4) 0 var(--space-2); font-size: 0.85rem; color: var(--text-sec); text-transform: uppercase; letter-spacing: 0.04em; }
.docs-op-row { display: flex; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; align-items: baseline; }
.docs-op-row .docs-op-path { font-family: var(--font-mono); color: var(--text-pri); min-width: 260px; }
mark.docs-hit { background: rgba(245, 158, 11, 0.35); color: inherit; border-radius: 3px; padding: 0 1px; }
.docs-hidden { display: none !important; }
