/*
 * Base: reset, typography, focus, utilities. Depends on tokens.css.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
  scroll-padding-top: calc(var(--topbar-h) + var(--space-4));
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-feature-settings: var(--font-features);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  letter-spacing: -0.003em;
  color: var(--text);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--text-2xl); letter-spacing: var(--tracking-tighter); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-sm); }

p { margin: 0; text-wrap: pretty; }

a {
  color: var(--accent-text);
  text-decoration: none;
  text-underline-offset: 2px;
}

a:hover { text-decoration: underline; }

img, svg, video, canvas { display: block; max-width: 100%; }

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

button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

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

pre { margin: 0; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

table { border-collapse: collapse; border-spacing: 0; }

dl, dd, ul, ol { margin: 0; padding: 0; }

ul[role="list"], ol[role="list"] { list-style: none; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

[hidden] { display: none !important; }

::selection {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

/* Focus: visible ring for keyboard users only. */
:focus { outline: none; }

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

/* Scrollbars: quiet, theme-aware. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* ---- Utilities ------------------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -100px;
  z-index: calc(var(--z-tooltip) + 1);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-weight: var(--weight-medium);
}

.skip-link:focus-visible { top: var(--space-3); }

.num { font-variant-numeric: tabular-nums; font-feature-settings: var(--font-features), "tnum"; }
.mono { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: 0; }
.muted { color: var(--text-3); }
.subtle { color: var(--text-2); }
.strong { font-weight: var(--weight-semibold); color: var(--text); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-right { text-align: right; }

.stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-4)); }
.stack-xs { --stack-gap: var(--space-1); }
.stack-sm { --stack-gap: var(--space-2); }
.stack-md { --stack-gap: var(--space-3); }
.stack-lg { --stack-gap: var(--space-6); }
.stack-xl { --stack-gap: var(--space-8); }

.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-2)); }
.cluster-xs { --cluster-gap: var(--space-1); }
.cluster-lg { --cluster-gap: var(--space-4); }
.cluster-between { justify-content: space-between; }
.cluster-end { justify-content: flex-end; }
.cluster-nowrap { flex-wrap: nowrap; }

.spacer { flex: 1 1 auto; }

.grid { display: grid; gap: var(--grid-gap, var(--space-4)); }
.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-auto { grid-template-columns: repeat(auto-fill, minmax(var(--grid-min, 260px), 1fr)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* Smooth theme swap (not on first paint: .theme-ready is added by JS after load). */
.theme-ready body,
.theme-ready .topbar,
.theme-ready .sidebar,
.theme-ready .card,
.theme-ready .statusbar {
  transition: background-color var(--dur) var(--ease-standard), border-color var(--dur) var(--ease-standard), color var(--dur) var(--ease-standard);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0ms !important;
  }
}
