/* Nephysis base: reset, typography, layout primitives, top bar, nav, breadcrumb, footer.
 * Depends on tokens.css. Components live in components.css. */

/* ---- Reset ------------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
table { border-collapse: collapse; }
h1, h2, h3, h4, p, ul, ol, dl, figure, pre { margin: 0; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
[hidden] { display: none !important; }
::selection { background: var(--accent-dim); color: var(--text); }

/* ---- Focus: accent ring, keyboard only -------------------------------------------- */
:focus { outline: none; }
:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ---- Typography ------------------------------------------------------------------- */
h1, h2, h3, h4, .h1, .h2, .h3, .h4, .display { font-family: var(--font-display); }
h1, .h1 { font-size: var(--fs-2xl); font-weight: 500; line-height: 1.15; letter-spacing: -0.015em; }
h2, .h2 { font-size: var(--fs-xl); font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; }
h3, .h3 { font-size: var(--fs-lg); font-weight: 500; line-height: 1.3; }
h4, .h4 { font-size: var(--fs-md); font-weight: 600; line-height: 1.4; }
.display { font-size: clamp(2rem, 6vw, var(--fs-3xl)); font-weight: 400; line-height: 1.05; letter-spacing: -0.02em; }
p { max-width: 72ch; }
small, .small { font-size: var(--fs-sm); }

a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; text-decoration-thickness: 1px; transition: text-decoration-color var(--dur) var(--ease), color var(--dur) var(--ease); }
a:hover { text-decoration-color: var(--accent); }

code, kbd, samp, pre, .mono {
  font-family: var(--font-mono);
  font-feature-settings: "zero", "tnum";
  font-variant-numeric: tabular-nums slashed-zero;
}
code { font-size: 0.9em; padding: 0 0.25em; background: var(--surface); border: var(--border); border-radius: var(--radius); }
kbd { font-size: var(--fs-xs); padding: 1px 5px; border: var(--border-strong); border-bottom-width: 2px; border-radius: var(--radius); }

/* Small uppercase label for UI captions (sans; data stays mono). */
.label {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--muted);
}
.label--wide { letter-spacing: var(--tracking-wide); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.accent { color: var(--accent); }
.error-text { color: var(--error); }
.num, .tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.upper { text-transform: uppercase; letter-spacing: var(--tracking-label); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Rule: thin separator; --accent variant for the one highlight per view. */
.rule { height: 0; border: 0; border-top: var(--border); margin: var(--s-5) 0; }
.rule--accent { border-top-color: var(--accent); width: 48px; }

/* Theme-dependent visibility (used for the logo swap). */
.only-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-dark { display: revert !important; }
  :root:not([data-theme="light"]) .only-light { display: none !important; }
}
:root[data-theme="dark"] .only-dark { display: revert !important; }
:root[data-theme="dark"] .only-light { display: none !important; }

/* ---- Layout primitives ------------------------------------------------------------ */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.page { flex: 1 0 auto; padding-block: var(--s-5) var(--s-8); }
/* Vertical rhythm between the blocks of a page (panels, grids, stats). */
.page > * + * { margin-top: var(--s-5); }
.page > .page-head + * { margin-top: 0; }

/* .stack: vertical rhythm. --gap overrides. */
.stack { display: flex; flex-direction: column; gap: var(--gap, var(--s-4)); }
.stack--sm { --gap: var(--s-2); }
.stack--lg { --gap: var(--s-6); }
/* .cluster: horizontal wrap row. */
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s-3)); }
.cluster--between { justify-content: space-between; }
.cluster--end { justify-content: flex-end; }
/* .grid: responsive auto-fit columns. --min sets the min column width. */
.grid { display: grid; gap: var(--gap, var(--s-4)); grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 240px), 100%), 1fr)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); }
@media (max-width: 899px) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 599px) {
  .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); }
}
.span-all { grid-column: 1 / -1; }

/* Page header: title + actions. */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); padding-bottom: var(--s-2); margin-bottom: var(--s-6); }
.page-head__title { display: flex; flex-direction: column; gap: var(--s-2); }

/* ---- Skip link -------------------------------------------------------------------- */
.skip {
  position: absolute; left: var(--gutter); top: -100px; z-index: 100;
  padding: var(--s-2) var(--s-3); background: var(--text); color: var(--bg);
  font-family: var(--font-sans); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: var(--tracking-label);
}
.skip:focus { top: var(--s-2); }

/* ---- Top bar ---------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: var(--border);
}
.topbar__inner {
  display: flex; align-items: center; gap: var(--s-4);
  height: var(--bar-h);
}
.brand { display: flex; align-items: center; flex-shrink: 0; text-decoration: none; height: 100%; }
.brand img { height: 34px; width: auto; }
.topbar__module {
  display: flex; align-items: center; gap: var(--s-2);
  padding-left: var(--s-4); border-left: var(--border); height: 20px;
  font-family: var(--font-sans); font-size: var(--fs-xs); letter-spacing: var(--tracking-wide); color: var(--text);
}
.topbar__module::before { content: ""; width: 5px; height: 5px; background: var(--accent); }
.topbar__end { display: flex; align-items: center; gap: var(--s-2); margin-left: auto; }

/* Square icon button used by the theme toggle and the mobile menu button. */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 32px; min-width: 32px; padding: 0 var(--s-2);
  background: transparent; border: var(--border); border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--font-sans); font-size: var(--fs-xs); letter-spacing: var(--tracking-label); text-transform: uppercase;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.iconbtn:hover { color: var(--text); border-color: var(--line-strong); }
.iconbtn svg { width: 14px; height: 14px; }
.theme-toggle__sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle__moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle__sun { display: block; }
:root[data-theme="dark"] .theme-toggle__moon { display: none; }

/* ---- Section nav ------------------------------------------------------------------ */
.nav { display: flex; align-items: center; flex: 1; min-width: 0; height: 100%; }
.nav__list { display: flex; align-items: stretch; height: 100%; margin: 0; padding: 0; list-style: none; }
.nav__link {
  position: relative; display: flex; align-items: center; height: 100%;
  padding: 0 var(--s-3);
  color: var(--muted); text-decoration: none;
  font-size: var(--fs-sm); font-weight: 500; letter-spacing: 0.01em;
  transition: color var(--dur) var(--ease);
}
.nav__link:hover { color: var(--text); }
.nav__link::after {
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 2px;
  background: transparent; transition: background-color var(--dur) var(--ease);
}
.nav__link:hover::after { background: var(--line-strong); }
.nav__link.is-active, .nav__link[aria-current="page"] { color: var(--text); }
.nav__link.is-active::after, .nav__link[aria-current="page"]::after { background: var(--accent); }
.nav__sep { width: 1px; margin: 16px var(--s-2); background: var(--line); }

/* User menu: button + panel toggled by app.js ([data-usermenu]); :focus-within fallback. */
.usermenu { position: relative; margin-left: auto; }
.usermenu__btn {
  display: flex; align-items: center; gap: var(--s-2);
  height: 32px; padding: 0 var(--s-2);
  background: transparent; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: var(--font-sans); font-size: var(--fs-xs); color: var(--muted);
}
.usermenu__btn:hover, .usermenu.is-open .usermenu__btn { color: var(--text); border-color: var(--line); }
.usermenu__name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu__caret { width: 8px; height: 8px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.usermenu__panel {
  position: absolute; right: 0; top: calc(100% + 9px); z-index: 60;
  min-width: 240px; padding: var(--s-3);
  background: var(--raised); border: var(--border-strong); border-radius: var(--radius);
  display: none; flex-direction: column; gap: var(--s-3);
}
.usermenu.is-open .usermenu__panel, html:not(.js) .usermenu:focus-within .usermenu__panel { display: flex; }
.usermenu__panel::before { content: ""; position: absolute; left: -1px; top: -1px; width: 12px; height: 1px; background: var(--accent); }
.usermenu__row { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
.usermenu__panel form { margin: 0; }

.menubtn { display: none; }

/* Mobile: nav collapses behind the menu button into a full-width panel. */
@media (max-width: 899px) {
  .topbar__inner { gap: var(--s-3); }
  .brand img { height: 30px; }
  .menubtn { display: inline-flex; }
  .nav {
    position: absolute; left: 0; right: 0; top: var(--bar-h);
    flex-direction: column; align-items: stretch; height: auto;
    padding: var(--s-2) var(--gutter) var(--s-4);
    background: var(--bg); border-bottom: var(--border);
    display: none;
  }
  .nav.is-open { display: flex; }
  .nav__list { flex-direction: column; height: auto; }
  .nav__link { height: 44px; padding: 0 var(--s-3); border-left: 2px solid transparent; }
  .nav__link::after { display: none; }
  .nav__link.is-active, .nav__link[aria-current="page"] { border-left-color: var(--accent); background: var(--accent-dim); }
  .nav__sep { width: auto; height: 1px; margin: var(--s-2) 0; }
  .usermenu { margin: var(--s-3) 0 0; border-top: var(--border); padding-top: var(--s-3); }
  .usermenu__btn { display: none; }
  .usermenu__panel { position: static; display: flex; background: transparent; border: 0; padding: 0 var(--s-3); min-width: 0; }
  .usermenu__panel::before { display: none; }
}
@media (max-width: 420px) {
  .topbar__module { display: none; }
}

/* ---- Breadcrumb (prompt line) ----------------------------------------------------- */
.crumbs { border-bottom: var(--border); background: var(--bg); }
.crumbs__inner {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 32px;
  font-family: var(--font-sans); font-size: var(--fs-xs); letter-spacing: 0.06em; color: var(--muted);
}
.crumbs__path { display: flex; align-items: center; gap: var(--s-2); min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-transform: lowercase; }
.crumbs__prompt { color: var(--accent); }
.crumbs__path a { color: var(--muted); text-decoration: none; }
.crumbs__path a:hover { color: var(--text); }
.crumbs__path .sep { color: var(--faint); }
.crumbs__path > :last-child:not(.sep) { color: var(--text); }
.crumbs__cursor { display: inline-block; width: 7px; height: 12px; background: var(--muted); opacity: 0.6; animation: blink 1.1s steps(1) infinite; }
.crumbs__meta { margin-left: auto; display: flex; gap: var(--s-4); white-space: nowrap; color: var(--faint); text-transform: uppercase; letter-spacing: var(--tracking-label); }
@media (max-width: 599px) { .crumbs__meta { display: none; } }
@keyframes blink { 50% { opacity: 0; } }

/* ---- Footer ----------------------------------------------------------------------- */
.footer { border-top: var(--border); }
.footer__inner {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2) var(--s-4);
  padding-block: var(--s-3);
  font-family: var(--font-sans); font-size: var(--fs-xs); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--faint);
}

/* ---- Motion ----------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
}
