/* Reset + global typography + layout primitives. */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

/* ── Typography ────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  line-height: var(--leading-tight);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); font-weight: var(--weight-bold); }

p + p { margin-top: var(--space-4); }

a {
  color: var(--color-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-default);
}

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

a:focus-visible { border-radius: var(--radius-sm); }

small { font-size: var(--text-sm); }

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

code {
  padding: 0.125em 0.25em;
  background: var(--color-bg-muted);
  border-radius: var(--radius-sm);
}

pre {
  padding: var(--space-4);
  background: var(--color-bg-muted);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

pre code { padding: 0; background: none; }

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

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

/* ── Form defaults (catches Django's auto-rendered widgets) ── */

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not(.btn),
select,
textarea {
  width: 100%;
  min-height: var(--control-min-size);
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}

input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not(.btn):focus,
select:focus,
textarea:focus {
  border-color: var(--color-primary);
}

/* ── Focus ─────────────────────────────────────────────── */

:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Layout primitives ─────────────────────────────────── */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 640px) {
  .container { padding-inline: var(--space-6); }
}

.content-width {
  max-width: var(--content-max);
}

.stack > * + * {
  margin-top: var(--space-4);
}

.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-6); }
.stack-xl > * + * { margin-top: var(--space-8); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.grid-auto {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr));
}

/* ── Page layout (shell) ───────────────────────────────── */

.page-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.page-main {
  flex: 1;
  padding: var(--space-6) 0;
}

/* ── Skip link (accessibility) ─────────────────────────── */

.skip-link {
  position: absolute;
  top: 0;
  left: var(--space-4);
  min-height: var(--control-min-size);
  padding: var(--space-3) var(--space-4);
  background: var(--color-secondary);
  color: var(--color-secondary-text);
  border-radius: var(--radius-md);
  z-index: var(--z-toast);
  font-weight: var(--weight-bold);
  transform: translateY(calc(-100% - 6px));
}

.skip-link:focus-visible {
  transform: translateY(var(--space-2));
}

/* ── Responsive visibility ─────────────────────────────── */

.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;
}
