/* ============================================================================
   Ryvem — components: nav, buttons, cards, badges, code+copy, tabs, stats,
   callouts, tables, pager, footer, theme toggle
   ============================================================================ */

/* ---- top nav (sticky, glass) ------------------------------------------ */
.nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.nav__inner {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}
.nav__spacer { flex: 1 1 auto; }

/* ---- brand lockup (nav + footer): gradient SVG mark + wordmark text ----
   The mark is a self-contained SVG (its own gradient); the wordmark is real
   HTML text in currentColor, so it adapts to either theme with no image swap. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 27px; height: 27px;
  border-radius: 8px;
  flex: none;
}
.brand__word {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand--sm .brand__mark { width: 22px; height: 22px; }
.brand--sm .brand__word { font-size: var(--fs-md); }

.nav__menu {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}
.nav__link {
  color: var(--muted);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: color var(--t) var(--ease);
}
.nav__link:hover,
.nav__link[aria-current="page"] { color: var(--text); text-decoration: none; }

/* Hamburger (mobile) */
.nav__toggle {
  display: none;
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
}
.nav__toggle span {
  display: block;
  width: 17px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--t) var(--ease), opacity var(--t) var(--ease);
}
.nav__toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav__toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav__toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---- theme toggle ------------------------------------------------------ */
.theme-toggle {
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--muted);
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: none; }
}

/* ---- buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.6rem 1.15rem;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  line-height: 1;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), border-color var(--t) var(--ease),
              background-color var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

/* The single "hero moment" — the one gradient-filled button. Use once. */
.btn--gradient {
  background-image: var(--gradient-line);
  color: var(--grad-ink);
  border: 0;
  box-shadow: var(--shadow-glow);
}
.btn--gradient:hover { filter: brightness(1.05); }

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn--lg { padding: 0.8rem 1.5rem; font-size: var(--fs-base); }
.btn--sm { padding: 0.4rem 0.8rem; font-size: var(--fs-xs); }

/* ---- badges ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.badge--accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.badge--version {
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.badge--version::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
.badge--dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---- cards ------------------------------------------------------------- */
.card {
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  transition: border-color var(--t) var(--ease), transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  margin-bottom: var(--sp-4);
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent);
}
.card__icon svg { width: 20px; height: 20px; }
.card__title { font-size: var(--fs-md); margin-bottom: var(--sp-2); }
.card__body { color: var(--muted); font-size: var(--fs-sm); line-height: var(--lh-snug); }

/* ---- code block + copy button ----------------------------------------- */
.code {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.code__pre {
  margin: 0;
  padding: var(--sp-4) var(--sp-5);
  padding-right: 4.5rem;      /* room for the copy button */
  overflow-x: auto;
  font-size: var(--fs-sm);
  line-height: 1.7;
  color: var(--text);
}
.code__pre code { font-family: var(--mono); white-space: pre; }
.code__prompt { color: var(--faint); user-select: none; }
.code__copy {
  position: absolute;
  top: 10px; right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.code__copy:hover { color: var(--text); border-color: var(--accent); }
.code__copy.is-copied { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.code__copy svg { width: 13px; height: 13px; }
.code__copy .icon-check { display: none; }
.code__copy.is-copied .icon-copy { display: none; }
.code__copy.is-copied .icon-check { display: inline; }

/* Syntax tokens emitted by highlight.js. Plain runs stay in the code element's
   own --text colour; only these classes tint. Colours (both themes) and their
   contrast are defined in tokens.css. */
.tok-comment  { color: var(--tok-comment); font-style: italic; }
.tok-string   { color: var(--tok-string); }
.tok-number   { color: var(--tok-number); }
.tok-keyword  { color: var(--tok-keyword); }
.tok-property,
.tok-command  { color: var(--tok-key); }
.tok-variable { color: var(--tok-key); }
.tok-flag     { color: var(--tok-flag); }
.tok-operator,
.tok-punct    { color: var(--tok-punct); }

/* Inline code (in prose) */
:where(.prose, .lede) code:not(pre code) {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.12em 0.4em;
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
}

/* Inline code chips are atomic: a line break lands BETWEEN chips, never inside
   one — so a flag like "-h" or a path like "~/.ryvem/config.json" is never split
   mid-token (which the hyphen/slash would otherwise invite). No single chip on
   the site exceeds ~260px, so this never overflows a 390px viewport; the rare
   wide table row instead scrolls inside its own .table-wrap (overflow-x:auto). */
code:not(pre code) { white-space: nowrap; }

/* ---- OS / generic tabs ------------------------------------------------- */
.tabs__list {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.tabs__tab {
  padding: 0.4rem 0.9rem;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--muted);
  border-radius: var(--r-sm);
  transition: color var(--t) var(--ease), background-color var(--t) var(--ease);
}
.tabs__tab:hover { color: var(--text); }
.tabs__tab[aria-selected="true"] {
  color: var(--text);
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.tabs__panel { animation: fade-in var(--t) var(--ease); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---- stat tiles (KPI row) ---------------------------------------------
   Contract: label = sentence case, muted. value = >=48px, semibold, PRIMARY
   ink, proportional figures (NO tabular-nums at display size). One small
   context line. One subtle accent detail per tile (the label dot). No bars,
   no gradient on the number. Text always wears text tokens. */
.stats {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat {
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.stat__label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-bottom: var(--sp-3);
}
.stat__label::before {           /* the one subtle accent detail */
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.stat__value {
  font-size: var(--fs-stat);
  font-weight: var(--fw-semi);
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: proportional-nums;   /* explicit: not tabular at display size */
}
/* the qualifier sits on its own line under the number — muted, small, so the
   figure dominates and never collides with the tile edge */
.stat__unit {
  display: block;
  margin-top: 4px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--muted);
  letter-spacing: 0;
}
.stat__context {
  margin-top: var(--sp-3);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--muted);
}
.stats__caption {
  margin-top: var(--sp-5);
  font-size: var(--fs-xs);
  color: var(--faint);
}
.stats__caption code {
  font-family: var(--mono);
  color: var(--muted);
}

/* ---- callouts / notes (docs) ------------------------------------------ */
.callout {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  margin: var(--sp-5) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
}
.callout__icon { flex: none; color: var(--accent); line-height: 1.5; }
.callout__icon svg { width: 18px; height: 18px; }
.callout__body { font-size: var(--fs-sm); color: var(--text); }
.callout__body > :first-child { margin-top: 0; }
.callout__body > :last-child { margin-bottom: 0; }
.callout__title { font-weight: var(--fw-semi); margin-bottom: 2px; }
.callout--tip  { border-left-color: var(--ok); }
.callout--tip  .callout__icon { color: var(--ok); }
.callout--warn { border-left-color: var(--warn); }
.callout--warn .callout__icon { color: var(--warn); }

/* ---- tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; margin: var(--sp-5) 0; border-radius: var(--r-md); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
th, td {
  padding: 0.55rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  color: var(--muted);
  font-weight: var(--fw-semi);
  background: var(--surface);
  border-bottom-color: var(--border);
}
tbody tr:hover { background: var(--surface); }
td code, th code { font-family: var(--mono); font-size: 0.9em; }

/* ---- prev / next pager (docs) ----------------------------------------- */
.pager-row {
  display: flex;
  gap: var(--sp-4);
  margin-top: var(--sp-8);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}
.pager {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--t) var(--ease);
}
.pager:hover { border-color: var(--accent); text-decoration: none; }
.pager--next { text-align: right; }
.pager__dir { font-size: var(--fs-xs); color: var(--muted); }
.pager__label { font-weight: var(--fw-semi); font-size: var(--fs-sm); }

/* ---- footer ------------------------------------------------------------ */
.footer {
  margin-top: var(--sp-9);
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
.footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-6);
  justify-content: space-between;
  align-items: flex-start;
  padding-block: var(--sp-7);
}
.footer__brand { max-width: 340px; }
.footer__brand .brand { margin-bottom: var(--sp-3); }
.footer__tagline { font-size: var(--fs-sm); color: var(--muted); }
.footer__cols { display: flex; gap: var(--sp-8); flex-wrap: wrap; }
.footer__col h4 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin-bottom: var(--sp-3);
}
.footer__col a {
  display: block;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-decoration: none;
  padding: 3px 0;
  transition: color var(--t) var(--ease);
}
.footer__col a:hover { color: var(--text); }
.footer__bottom {
  padding-block: var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--faint);
}

/* ---- responsive: nav collapse ----------------------------------------- */
@media (max-width: 760px) {
  .nav__toggle { display: inline-flex; }
  .nav__spacer { display: none; }
  .nav__menu {
    position: absolute;
    top: var(--nav-h);
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5) var(--sp-5);
    background: var(--glass);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
  }
  .nav__menu:not(.is-open) { display: none; }
  .nav__link { padding: var(--sp-2) 0; font-size: var(--fs-base); }
  .footer__inner { flex-direction: column; }
}
