/* ==========================================================================
   Stackly UI Kit — base.css
   Design tokens (light + dark), reset, typography and layout utilities.
   Every other stylesheet reads from the custom properties defined here.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens — light theme (default)
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #F4F6F3;            /* page background (cool paper) */
  --surface: #FFFFFF;       /* cards, panels, inputs */
  --surface-2: #EDF1ED;     /* subtle fills, table headers */
  --surface-3: #E1E8E3;     /* hover fills, skeletons */
  --overlay: rgba(12, 20, 17, .48);

  /* Lines */
  --line: #DCE3DE;
  --line-strong: #C3CEC7;

  /* Text */
  --ink: #121A17;           /* headings and body */
  --ink-2: #435049;         /* secondary text */
  --ink-3: #5E6B65;         /* muted text (4.9:1 on --surface-2, 5.5:1 on white) */
  --ink-inverse: #FFFFFF;

  /* Brand — spruce */
  --brand: #0F6E56;
  --brand-hover: #0B5A46;
  --brand-contrast: #FFFFFF;  /* text on a brand fill */
  --brand-soft: #DCEFE7;
  --brand-soft-ink: #0A5543;

  /* Accent — highlighter yellow (sticky notes, "popular" tags) */
  --accent: #FFD84A;
  --accent-soft: #FFF3C4;
  --accent-ink: #4D3A00;

  /* Status */
  --success: #1A7A48;  --success-soft: #DDF2E5;
  --warning: #9A5B00;  --warning-soft: #FDEFD6;
  --danger:  #BF2F2A;  --danger-soft:  #FBE3E1;
  --info:    #2356C4;  --info-soft:    #E2EBFB;

  /* Charts (validated for CVD separation on each surface) */
  --series-1: #12805F;
  --series-2: #6B5BD6;
  --chart-grid: #E6ECE8;

  /* Typography */
  --font-sans: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --text-xs: .75rem;     /* 12 */
  --text-sm: .8125rem;   /* 13 */
  --text-base: .9375rem; /* 15 */
  --text-md: 1.0625rem;  /* 17 */
  --text-lg: 1.25rem;    /* 20 */
  --text-xl: 1.5rem;     /* 24 */
  --text-2xl: 1.875rem;  /* 30 */
  --text-3xl: clamp(1.875rem, 1.3rem + 2.2vw, 2.625rem);   /* 30 → 42 */
  --text-4xl: clamp(2.25rem, 1.4rem + 3.4vw, 3.5rem);      /* 36 → 56 */
  --text-5xl: clamp(2.5rem, 1.35rem + 4.6vw, 4.5rem);      /* 40 → 72 */

  --leading-tight: 1.08;
  --leading-snug: 1.3;
  --leading-body: 1.6;

  /* Spacing scale (4px base) */
  --space-1: .25rem;  --space-2: .5rem;   --space-3: .75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem;   --space-20: 5rem;   --space-24: 6rem;
  --section-y: clamp(4rem, 2.5rem + 6vw, 7.5rem);

  /* Radii — a hierarchy, not one value for everything */
  --radius-xs: 4px;    /* badges, checkboxes */
  --radius-sm: 7px;    /* buttons, inputs */
  --radius-md: 11px;   /* cards, menus */
  --radius-lg: 18px;   /* large panels, mockups */
  --radius-pill: 999px;

  /* Shadows — tinted with the ink colour, never flat grey */
  --shadow-xs: 0 1px 0 rgba(18, 26, 23, .05);
  --shadow-sm: 0 1px 2px rgba(18, 26, 23, .06), 0 1px 1px rgba(18, 26, 23, .04);
  --shadow-md: 0 6px 16px -6px rgba(18, 26, 23, .14), 0 2px 4px rgba(18, 26, 23, .05);
  --shadow-lg: 0 24px 48px -16px rgba(18, 26, 23, .22), 0 6px 12px -6px rgba(18, 26, 23, .08);
  --ring: 0 0 0 3px rgba(15, 110, 86, .28);

  /* Layout */
  --container: 1200px;
  --container-wide: 1400px;
  --gutter: clamp(1rem, .6rem + 2vw, 2rem);
  --header-h: 64px;

  /* Motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 420ms;

  /* Layering */
  --z-header: 40;
  --z-drawer: 60;
  --z-dropdown: 70;
  --z-modal: 80;
  --z-toast: 90;
}

/* --------------------------------------------------------------------------
   2. Dark theme — follows the OS unless the user picked "light",
      and always applies when the user picked "dark".
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0C1210;
    --surface: #131A17;
    --surface-2: #19221F;
    --surface-3: #212C28;
    --overlay: rgba(0, 0, 0, .62);
    --line: #25302C;
    --line-strong: #34423C;
    --ink: #ECF2EF;
    --ink-2: #B2BFB9;
    --ink-3: #8A9892;
    --ink-inverse: #0C1210;
    --brand: #3CC49A;
    --brand-hover: #5CD3AE;
    --brand-contrast: #03130D;
    --brand-soft: #123128;
    --brand-soft-ink: #86E3C4;
    --accent: #FFD84A;
    --accent-soft: #3A3113;
    --accent-ink: #FFE68F;
    --success: #4BCB86;  --success-soft: #133021;
    --warning: #F2B04E;  --warning-soft: #3A2A10;
    --danger:  #FF7A72;  --danger-soft:  #3D1817;
    --info:    #7FA8FF;  --info-soft:    #172642;
    --series-1: #23A07C;
    --series-2: #8A7BE8;
    --chart-grid: #222C28;
    --shadow-xs: 0 1px 0 rgba(0, 0, 0, .3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 20px -8px rgba(0, 0, 0, .6), 0 2px 4px rgba(0, 0, 0, .3);
    --shadow-lg: 0 28px 56px -18px rgba(0, 0, 0, .75), 0 6px 12px -6px rgba(0, 0, 0, .4);
    --ring: 0 0 0 3px rgba(60, 196, 154, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0C1210;
  --surface: #131A17;
  --surface-2: #19221F;
  --surface-3: #212C28;
  --overlay: rgba(0, 0, 0, .62);
  --line: #25302C;
  --line-strong: #34423C;
  --ink: #ECF2EF;
  --ink-2: #B2BFB9;
  --ink-3: #8A9892;
  --ink-inverse: #0C1210;
  --brand: #3CC49A;
  --brand-hover: #5CD3AE;
  --brand-contrast: #03130D;
  --brand-soft: #123128;
  --brand-soft-ink: #86E3C4;
  --accent: #FFD84A;
  --accent-soft: #3A3113;
  --accent-ink: #FFE68F;
  --success: #4BCB86;  --success-soft: #133021;
  --warning: #F2B04E;  --warning-soft: #3A2A10;
  --danger:  #FF7A72;  --danger-soft:  #3D1817;
  --info:    #7FA8FF;  --info-soft:    #172642;
  --series-1: #23A07C;
  --series-2: #8A7BE8;
  --chart-grid: #222C28;
  --shadow-xs: 0 1px 0 rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 20px -8px rgba(0, 0, 0, .6), 0 2px 4px rgba(0, 0, 0, .3);
  --shadow-lg: 0 28px 56px -18px rgba(0, 0, 0, .75), 0 6px 12px -6px rgba(0, 0, 0, .4);
  --ring: 0 0 0 3px rgba(60, 196, 154, .35);
}

/* --------------------------------------------------------------------------
   3. Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}
img, svg, video, canvas { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
table { border-collapse: collapse; border-spacing: 0; }
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: var(--leading-snug); letter-spacing: -.015em; text-wrap: balance; }
p { text-wrap: pretty; }
hr { border: 0; border-top: 1px solid var(--line); }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #1A1400; }

/* Visible, consistent focus for keyboard users only */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* --------------------------------------------------------------------------
   4. Typography helpers
   -------------------------------------------------------------------------- */
.display   { font-size: var(--text-5xl); line-height: 1.02; letter-spacing: -.035em; font-weight: 800; }
.h1        { font-size: var(--text-4xl); line-height: var(--leading-tight); letter-spacing: -.03em; font-weight: 750; }
.h2        { font-size: var(--text-3xl); line-height: 1.12; letter-spacing: -.025em; font-weight: 700; }
.h3        { font-size: var(--text-xl); line-height: 1.25; letter-spacing: -.015em; font-weight: 650; }
.h4        { font-size: var(--text-lg); line-height: 1.3; font-weight: 650; }
.lead      { font-size: clamp(1.0625rem, 1rem + .35vw, 1.25rem); line-height: 1.55; color: var(--ink-2); max-width: 62ch; }
.text-sm   { font-size: var(--text-sm); }
.text-xs   { font-size: var(--text-xs); }
.muted     { color: var(--ink-3); }
.secondary { color: var(--ink-2); }
.strong    { font-weight: 600; }
.mono      { font-family: var(--font-mono); font-size: .92em; }
.tabular   { font-variant-numeric: tabular-nums; }
.link      { color: var(--brand); font-weight: 550; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--brand) 40%, transparent); }
.link:hover { text-decoration-color: currentColor; }
.measure   { max-width: 65ch; }

kbd, .kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; padding: 0 .35em; height: 1.5em;
  font-family: var(--font-mono); font-size: .75rem; line-height: 1;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; border-radius: 5px;
}

/* --------------------------------------------------------------------------
   5. Layout utilities
   -------------------------------------------------------------------------- */
.container { width: 100%; max-width: calc(var(--container) + var(--gutter) * 2); margin-inline: auto; padding-inline: var(--gutter); }
.container--wide { max-width: calc(var(--container-wide) + var(--gutter) * 2); }
.container--narrow { max-width: calc(760px + var(--gutter) * 2); }
.section { padding-block: var(--section-y); }

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

.row      { display: flex; align-items: center; gap: var(--gap, var(--space-3)); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--space-3)); }
.between  { justify-content: space-between; }
.grow     { flex: 1 1 auto; min-width: 0; }

.grid     { display: grid; gap: var(--gap, var(--space-6)); }
.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)); }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px)  { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }

.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;
}
.skip-link {
  position: fixed; left: var(--space-4); top: -100px; z-index: 100;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  background: var(--ink); color: var(--ink-inverse); font-weight: 600;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--space-4); }

.mt-0 { margin-top: 0 !important; } .mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); } .mt-8 { margin-top: var(--space-8); } .mt-12 { margin-top: var(--space-12); }
.mb-2 { margin-bottom: var(--space-2); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }
.w-full { width: 100%; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* --------------------------------------------------------------------------
   6. Motion preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Programmatic focus targets (skip link destination, notices) don't need a ring */
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }
main[tabindex="-1"]:focus { outline: none; }
