@layer reset, base, components, modules, utilities, native, platform;

:root {
  /* Spacing */
  --inline-space: 1ch;
  --inline-space-half: calc(var(--inline-space) / 2);
  --inline-space-double: calc(var(--inline-space) * 2);
  --block-space: 1rem;
  --block-space-half: calc(var(--block-space) / 2);
  --block-space-double: calc(var(--block-space) * 2);

  /* Font families */
  --font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --font-serif: ui-serif, serif;
  --font-mono: ui-monospace, monospace;

  /* Text sizes */
  --text-xx-small: 0.55rem;
  --text-x-small: 0.75rem;
  --text-small: 0.85rem;
  --text-normal: 1rem;
  --text-medium: 1.1rem;
  --text-large: 1.5rem;
  --text-x-large: 1.8rem;
  --text-xx-large: 2.5rem;

  @media (max-width: 639px) {
    --text-xx-small: 0.65rem;
    --text-x-small: 0.85rem;
    --text-small: 0.95rem;
    --text-normal: 1.1rem;
    --text-medium: 1.2rem;
    --text-large: 1.5rem;
    --text-x-large: 1.8rem;
    --text-xx-large: 2.5rem;
  }

  /* Borders */
  --border: 1px solid var(--color-ink-lighter);

  /* Shadows */
  --shadow: 0 0 0 1px oklch(var(--lch-black) / 5%),
            0 0.2em 0.2em oklch(var(--lch-black) / 5%),
            0 0.4em 0.4em oklch(var(--lch-black) / 5%),
            0 0.8em 0.8em oklch(var(--lch-black) / 5%);

  --shadow-lg: 0 0 0 1px oklch(var(--lch-black) / 8%),
               0 0.4em 0.6em oklch(var(--lch-black) / 10%),
               0 0.8em 1.2em oklch(var(--lch-black) / 10%),
               0 1.2em 1.8em oklch(var(--lch-black) / 8%);

  /* Components */
  --btn-size: 2.65em;
  --footer-height: 3.0rem;
  --dialog-duration: 150ms;


  /* Focus rings for keyboard navigation */
  --focus-ring-color: var(--color-link);
  --focus-ring-offset: 1px;
  --focus-ring-size: 2px;
  --focus-ring: var(--focus-ring-size) solid var(--focus-ring-color);

  /* Easing functions */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-overshoot: cubic-bezier(0.25, 1.75, 0.5, 1);
  --ease-out-overshoot-subtle: cubic-bezier(0.25, 1.25, 0.5, 1);

  /* Layout */
  --main-padding: clamp(var(--inline-space), 3vw, calc(var(--inline-space) * 3));
  --main-width: 1400px;
  --sidebar-width: 280px;
  /* Sidebar two-column breakpoint: 1024px / 1023px (used in sidebar.css) */

  /* Z-index */
  --z-popup: 10;
  --z-nav: 20;
  --z-flash: 30;
  --z-tooltip: 40;
  --z-bar: 50;
  --z-tray: 51;
  --z-welcome: 52;
  --z-nav-open: 100;

  /* =========================================================================
     OKLCH Colors: Fixed
     ========================================================================= */
  --lch-black: 0% 0 0;
  --lch-white: 100% 0 0;

  /* =========================================================================
     OKLCH Colors: Ink scale (from Fizzy - neutral grays)
     ========================================================================= */
  --lch-canvas: var(--lch-hogpoint-background);
  --lch-ink-inverted: var(--lch-white);

  --lch-ink-darkest: 26% 0.05 264;
  --lch-ink-darker: 40% 0.026 262;
  --lch-ink-dark: 56% 0.014 260;
  --lch-ink-medium: 66% 0.008 258;
  --lch-ink-light: 84% 0.005 256;
  --lch-ink-lighter: 92% 0.003 254;
  --lch-ink-lightest: 96% 0.002 252;

  /* =========================================================================
     OKLCH Colors: Fizzy color scales (for UI abstractions)
     ========================================================================= */
  --lch-red-dark: 59% 0.19 38;
  --lch-red-medium: 66% 0.204 40;
  --lch-red-lighter: 92% 0.03 44;

  --lch-yellow-lighter: 92% 0.076 90;

  --lch-green-dark: 55% 0.162 147;

  --lch-blue-dark: 57.02% 0.1895 260.46;
  --lch-blue-lighter: 92% 0.026 254;

  /* =========================================================================
     OKLCH Colors: HogPoint brand palette
     ========================================================================= */
  --lch-hogpoint-background: 97.1% 0.02 83.1;
  --lch-hogpoint-green: 79.4% 0.082 140.4;
  --lch-hogpoint-orange: 82% 0.15 46.1;
  --lch-hogpoint-yellow: 90.2% 0.118 88.6;
  --lch-hogpoint-purple: 82.6% 0.037 311.7;
  --lch-hogpoint-slaughter-red: 63.6% 0.09 19.5;
  --lch-hogpoint-slaughter-red2: 88.5% 0.041 17.7;
  --lch-hogpoint-blue1: 85.3% 0.038 224.7;
  --lch-hogpoint-blue2: 76.0% 0.054 227.1;
  --lch-hogpoint-blue3: 58.6% 0.062 233.1;
  --lch-hogpoint-blue4: 47.2% 0.059 234.5;
  --lch-hogpoint-teal: 85% 0.06 175;
  --lch-hogpoint-pink: 84% 0.07 350;
  --lch-hogpoint-blood-red: 45% 0.29 25;
  --lch-hogpoint-dark-orange: 58% 0.19 46;
  --lch-hogpoint-amber: 70% 0.18 85;

  /* Lightest variants for form backgrounds */
  --lch-hogpoint-orange-lightest: 95% 0.03 46.1;
  --lch-hogpoint-pink-lightest: 95% 0.02 350;
  --lch-hogpoint-purple-lightest: 95% 0.015 311.7;
  --lch-hogpoint-blue2-lightest: 95% 0.02 227.1;
  --lch-hogpoint-slaughter-lightest: 95% 0.02 19.5;
  --lch-hogpoint-notes: 99% 0.005 83.1;

  /* =========================================================================
     Colors: Named (fixed)
     ========================================================================= */
  --color-black: oklch(var(--lch-black));
  --color-white: oklch(var(--lch-white));

  /* =========================================================================
     Colors: Ink scale (text, borders, backgrounds)
     ========================================================================= */
  --color-ink: oklch(var(--lch-ink-darkest));
  --color-ink-darkest: oklch(var(--lch-ink-darkest));
  --color-ink-darker: oklch(var(--lch-ink-darker));
  --color-ink-dark: oklch(var(--lch-ink-dark));
  --color-ink-medium: oklch(var(--lch-ink-medium));
  --color-ink-light: oklch(var(--lch-ink-light));
  --color-ink-lighter: oklch(var(--lch-ink-lighter));
  --color-ink-lightest: oklch(var(--lch-ink-lightest));
  --color-ink-inverted: oklch(var(--lch-ink-inverted));

  /* =========================================================================
     Colors: HogPoint brand (named)
     ========================================================================= */
  --color-hogpoint-green: oklch(var(--lch-hogpoint-green));
  --color-hogpoint-orange: oklch(var(--lch-hogpoint-orange));
  --color-hogpoint-yellow: oklch(var(--lch-hogpoint-yellow));
  --color-hogpoint-purple: oklch(var(--lch-hogpoint-purple));
  --color-hogpoint-slaughter-red: oklch(var(--lch-hogpoint-slaughter-red));
  --color-hogpoint-slaughter-red2: oklch(var(--lch-hogpoint-slaughter-red2));
  --color-hogpoint-blue1: oklch(var(--lch-hogpoint-blue1));
  --color-hogpoint-blue2: oklch(var(--lch-hogpoint-blue2));
  --color-hogpoint-blue3: oklch(var(--lch-hogpoint-blue3));
  --color-hogpoint-blue4: oklch(var(--lch-hogpoint-blue4));
  --color-hogpoint-teal: oklch(var(--lch-hogpoint-teal));
  --color-hogpoint-pink: oklch(var(--lch-hogpoint-pink));

  /* =========================================================================
     Colors: Blue scale (mapped from HogPoint blues)
     ========================================================================= */
  --color-blue-lightest: var(--color-hogpoint-blue1);
  --color-blue-lighter: var(--color-hogpoint-blue1);
  --color-blue-light: var(--color-hogpoint-blue2);
  --color-blue: var(--color-hogpoint-blue3);
  --color-blue-dark: var(--color-hogpoint-blue3);
  --color-blue-darker: var(--color-hogpoint-blue4);
  --color-blue-darkest: var(--color-hogpoint-blue4);

  /* =========================================================================
     Colors: UI abstractions (semantic)
     ========================================================================= */
  --color-canvas: oklch(var(--lch-canvas));
  --color-link: oklch(var(--lch-blue-dark));
  --color-negative: oklch(var(--lch-red-dark));
  --color-negative-light: oklch(var(--lch-red-lighter));
  --color-positive: oklch(var(--lch-green-dark));
  --color-selected: oklch(var(--lch-blue-lighter));
  --color-selected-light: oklch(var(--lch-blue-lighter) / 0.5);
  --color-selected-dark: var(--color-blue-light);
  --color-highlight: oklch(var(--lch-yellow-lighter));
  --color-marker: oklch(var(--lch-red-medium));

  /* Gray aliases (mapped from ink scale for table/progress backgrounds) */
  --color-gray-50: var(--color-ink-lightest);
  --color-gray-200: var(--color-ink-lighter);

  /* =========================================================================
     Colors: Domain-specific (sow lifecycle stages)
     ========================================================================= */
  --color-servicing: var(--color-hogpoint-orange);           /* Løbning - breeding/insemination */
  --color-farrowing: var(--color-hogpoint-green);            /* Faring - giving birth */
  --color-weaning: var(--color-hogpoint-yellow);             /* Fravænning - piglet separation */
  --color-treatment: var(--color-hogpoint-purple);           /* Genbehandling - medical treatment */
  --color-slaughter: var(--color-hogpoint-slaughter-red);    /* Slagteliste - darker red */
  --color-slaughter-light: var(--color-hogpoint-slaughter-red2); /* Slagteliste - lighter red (menu) */
  --color-overview: var(--color-hogpoint-teal);                  /* Oversigt - dashboard overview */
  --color-offspring: var(--color-hogpoint-pink);                  /* Afkom - piglet inventory */
  --color-scanning: var(--color-blue-light);                     /* Scanning - pregnancy check */

  /* Farrowing urgency (text colors for "last observed" elapsed time) */
  --color-farrowing-ok: var(--color-positive);
  --color-farrowing-warning: oklch(var(--lch-hogpoint-amber));
  --color-farrowing-urgent: oklch(var(--lch-hogpoint-blood-red));

  /* Farrowing urgency backgrounds (tinted, for table cells) */
  --color-farrowing-ok-bg: oklch(var(--lch-green-dark) / 0.4);
  --color-farrowing-warning-bg: oklch(var(--lch-hogpoint-amber) / 0.5);
  --color-farrowing-urgent-bg: oklch(var(--lch-hogpoint-blood-red) / 0.5);

  /* Lightest variants for form backgrounds */
  --color-servicing-lightest: oklch(var(--lch-hogpoint-orange-lightest));
  --color-treatment-lightest: oklch(var(--lch-hogpoint-purple-lightest));
  --color-movement-lightest: oklch(var(--lch-hogpoint-blue2-lightest));
  --color-slaughter-lightest: oklch(var(--lch-hogpoint-slaughter-lightest));
  --color-offspring-lightest: oklch(var(--lch-hogpoint-pink-lightest));
  --color-notes-bg: oklch(var(--lch-hogpoint-notes));
}

/* =========================================================================
   Dark mode - explicit theme choice overrides system preference
   ========================================================================= */
html[data-theme="dark"] {
  --lch-canvas: 20% 0.0195 232.58;
  --lch-ink-inverted: var(--lch-black);

  /* Ink scale (inverted from light — Fizzy's exact values) */
  --lch-ink-darkest: 96.02% 0.0034 260;
  --lch-ink-darker: 86% 0.0061 260;
  --lch-ink-dark: 73.97% 0.009 260;
  --lch-ink-medium: 62% 0.0122 260;
  --lch-ink-light: 40% 0.0148 260;
  --lch-ink-lighter: 30% 0.0178 260;
  --lch-ink-lightest: 25% 0.0204 260;

  /* Fizzy color scales (kept exact) */
  --lch-red-dark: 73.95% 0.139 42;
  --lch-red-medium: 62% 0.154 40;
  --lch-red-lighter: 30% 0.032 36;

  --lch-yellow-lighter: 30% 0.026 50;

  --lch-green-dark: 73.99% 0.117 145;

  --lch-blue-dark: 74% 0.1293 256;
  --lch-blue-lighter: 30% 0.0452 262;

  /* HogPoint brand colors (tuned for dark backgrounds) */
  --lch-hogpoint-background: var(--lch-canvas);
  --lch-hogpoint-green: 70% 0.07 140.4;
  --lch-hogpoint-orange: 72% 0.12 46.1;
  --lch-hogpoint-yellow: 80% 0.09 88.6;
  --lch-hogpoint-purple: 72% 0.035 311.7;
  --lch-hogpoint-slaughter-red: 60% 0.08 19.5;
  --lch-hogpoint-slaughter-red2: 45% 0.04 17.7;
  --lch-hogpoint-blue1: 45% 0.035 224.7;
  --lch-hogpoint-blue2: 55% 0.05 227.1;
  --lch-hogpoint-blue3: 65% 0.06 233.1;
  --lch-hogpoint-blue4: 72% 0.055 234.5;
  --lch-hogpoint-teal: 70% 0.05 175;
  --lch-hogpoint-pink: 70% 0.06 350;

  /* Lightest variants for form backgrounds (dark equivalents) */
  --lch-hogpoint-orange-lightest: 25% 0.02 46.1;
  --lch-hogpoint-pink-lightest: 25% 0.015 350;
  --lch-hogpoint-purple-lightest: 25% 0.012 311.7;
  --lch-hogpoint-blue2-lightest: 25% 0.015 227.1;
  --lch-hogpoint-slaughter-lightest: 25% 0.015 19.5;
  --lch-hogpoint-notes: 23% 0.005 83.1;

  /* Shadows (higher opacity for dark) */
  --shadow: 0 0 0 1px oklch(var(--lch-black) / 0.42),
            0 0.2em 1.6em -0.8em oklch(var(--lch-black) / 0.6),
            0 0.4em 2.4em -1em oklch(var(--lch-black) / 0.7),
            0 0.4em 0.8em -1.2em oklch(var(--lch-black) / 0.8),
            0 0.8em 1.2em -1.6em oklch(var(--lch-black) / 0.9),
            0 1.2em 1.6em -2em oklch(var(--lch-black) / 1);

  --shadow-lg: 0 0 0 1px oklch(var(--lch-black) / 0.5),
               0 0.4em 2em -0.6em oklch(var(--lch-black) / 0.7),
               0 0.8em 3em -1em oklch(var(--lch-black) / 0.8),
               0 1.2em 4em -1.4em oklch(var(--lch-black) / 0.9);

  --color-highlight: oklch(var(--lch-blue-lighter));
}

/* No-JS fallback: system preference when theme_controller hasn't set data-theme yet.
   Keep in sync with html[data-theme="dark"] above — the JS controller resolves "auto"
   to an explicit data-theme attribute, so this block only fires briefly before Stimulus
   connects or when JavaScript is disabled. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --lch-canvas: 20% 0.0195 232.58;
    --lch-ink-inverted: var(--lch-black);

    --lch-ink-darkest: 96.02% 0.0034 260;
    --lch-ink-darker: 86% 0.0061 260;
    --lch-ink-dark: 73.97% 0.009 260;
    --lch-ink-medium: 62% 0.0122 260;
    --lch-ink-light: 40% 0.0148 260;
    --lch-ink-lighter: 30% 0.0178 260;
    --lch-ink-lightest: 25% 0.0204 260;

    --lch-red-dark: 73.95% 0.139 42;
    --lch-red-medium: 62% 0.154 40;
    --lch-red-lighter: 30% 0.032 36;

    --lch-yellow-lighter: 30% 0.026 50;

    --lch-green-dark: 73.99% 0.117 145;

    --lch-blue-dark: 74% 0.1293 256;
    --lch-blue-lighter: 30% 0.0452 262;

    --lch-hogpoint-background: var(--lch-canvas);
    --lch-hogpoint-green: 70% 0.07 140.4;
    --lch-hogpoint-orange: 72% 0.12 46.1;
    --lch-hogpoint-yellow: 80% 0.09 88.6;
    --lch-hogpoint-purple: 72% 0.035 311.7;
    --lch-hogpoint-slaughter-red: 60% 0.08 19.5;
    --lch-hogpoint-slaughter-red2: 45% 0.04 17.7;
    --lch-hogpoint-blue1: 45% 0.035 224.7;
    --lch-hogpoint-blue2: 55% 0.05 227.1;
    --lch-hogpoint-blue3: 65% 0.06 233.1;
    --lch-hogpoint-blue4: 72% 0.055 234.5;
    --lch-hogpoint-teal: 70% 0.05 175;
    --lch-hogpoint-pink: 70% 0.06 350;

    --lch-hogpoint-orange-lightest: 25% 0.02 46.1;
    --lch-hogpoint-pink-lightest: 25% 0.015 350;
    --lch-hogpoint-purple-lightest: 25% 0.012 311.7;
    --lch-hogpoint-blue2-lightest: 25% 0.015 227.1;
    --lch-hogpoint-slaughter-lightest: 25% 0.015 19.5;
    --lch-hogpoint-notes: 23% 0.005 83.1;

    --shadow: 0 0 0 1px oklch(var(--lch-black) / 0.42),
              0 0.2em 1.6em -0.8em oklch(var(--lch-black) / 0.6),
              0 0.4em 2.4em -1em oklch(var(--lch-black) / 0.7),
              0 0.4em 0.8em -1.2em oklch(var(--lch-black) / 0.8),
              0 0.8em 1.2em -1.6em oklch(var(--lch-black) / 0.9),
              0 1.2em 1.6em -2em oklch(var(--lch-black) / 1);

    --shadow-lg: 0 0 0 1px oklch(var(--lch-black) / 0.5),
                 0 0.4em 2em -0.6em oklch(var(--lch-black) / 0.7),
                 0 0.8em 3em -1em oklch(var(--lch-black) / 0.8),
                 0 1.2em 4em -1.4em oklch(var(--lch-black) / 0.9);

    --color-highlight: oklch(var(--lch-blue-lighter));
  }
}
