/* =============================================================================
   EnergiAcres design tokens, in the UX Prototype kit's variable naming.
   Source kit: ux-prototype-agent-kit (tokens/theme.css + src/exports/components.css).
   Re-skin for energiacres.ai (static, Cloudflare Pages) and later energiacres.com.

   HOW THEMES WORK
   - Light paper is the default (:root and [data-theme="light"]).
   - Dark teal-black is opt-in per element: <section data-theme="dark">.
   - Sections choose their theme explicitly. There is NO prefers-color-scheme logic.
   - Dark hero + light paper bands alternate by flipping data-theme on <section>.
   - The kit's own tokens/theme.css uses [data-system-mode="dark"]; the dark block
     below also answers to that attribute so kit-derived markup keeps working.

   NAMING
   - Kit names are kept exactly: --canvas --surface --text --ink --muted --line
     --strong-line --action-primary --action-on-primary --system-accent
     --specimen-hover --specimen-secondary(-text) --blue --blue-soft --success
     --warning --error --info (+ -soft) --control-radius --system-font ...
   - "--blue" is a legacy kit name. In EnergiAcres it is an ALIAS of
     --action-primary (teal). New code must use --action-primary, never --blue.
   - Tokens marked (EA) do not exist in the kit (the kit has no spacing, type
     scale, shadow, focus or orange-accent tokens). They are additions.
   - Tokens marked (derived) are not in the EA brand palette; they were computed
     to hit WCAG AA. Everything else is a brand hex.

   RULES FOR BUILDERS
   - Never write a hex value outside this file. Use var(--token).
   - Bright teal #28AFB0 is NOT a text colour on light (2.44:1). On light, teal text
     and links use --action-primary (#1A686B). Orange text on light uses
     --accent-text (#B4520F), valid on paper and white only; on a
     [data-band="alt"] (#E7EDE8) band it is remapped automatically.
   - Contrast pairs are listed and computed in kit-extraction.md section 3.
   ============================================================================= */


/* ---------------------------------------------------------------------------
   1. Theme-independent tokens
   --------------------------------------------------------------------------- */
:root {
  /* Fonts (Google Fonts: Barlow Condensed 600/700, Inter, IBM Plex Mono 400/500) */
  --system-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-body: var(--system-font);                                  /* (EA) */
  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif; /* (EA) */
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;       /* (EA) */

  /* Type scale (EA). Kit base is .8125rem (13px), too small for marketing. */
  --body-size: 1rem;
  --text-xs: .75rem;      /* eyebrows, mono labels (min size) */
  --text-sm: .875rem;     /* captions, helper + error text */
  --text-base: 1rem;      /* body */
  --text-lg: 1.125rem;    /* lead paragraph (small) */
  --text-xl: 1.25rem;     /* lead paragraph / h4 */
  --text-2xl: 1.5rem;     /* h3 */
  --text-3xl: clamp(1.75rem, 1.35rem + 1.4vw, 2.5rem);   /* h2 (small) */
  --text-4xl: clamp(2.25rem, 1.6rem + 2.6vw, 3.75rem);   /* h2 */
  --text-5xl: clamp(2.75rem, 1.6rem + 4.6vw, 5.5rem);    /* h1 / hero display */
  --weight-body: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-display: 600;    /* Barlow Condensed 600 or 700 only */
  --weight-display-strong: 700;
  --lh-display: 1.02;
  --lh-heading: 1.12;
  --lh-snug: 1.3;
  --lh-body: 1.6;
  --tracking-display: .005em;
  --tracking-label: .14em;  /* IBM Plex Mono uppercase labels / eyebrows */
  --measure: 65ch;

  /* Spacing scale (EA), 4px base, rem so it follows user font size */
  --space-1: .25rem;   /*  4 */
  --space-2: .5rem;    /*  8 */
  --space-3: .75rem;   /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.5rem;   /* 24 */
  --space-6: 2rem;     /* 32 */
  --space-7: 3rem;     /* 48 */
  --space-8: 4rem;     /* 64 */
  --space-9: 6rem;     /* 96 */
  --space-10: 8rem;    /* 128 */
  --section-y: clamp(4rem, 3rem + 5vw, 7.5rem);   /* vertical padding of a band */
  --gutter: clamp(1rem, .5rem + 2.5vw, 2rem);     /* >= 16px side gutter at 360px */
  --container: 72rem;
  --container-narrow: 44rem;

  /* Radius scale. Restrained: smaller than the kit (kit control 8px, panel 12px). */
  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-pill: 999px;
  --control-radius: var(--radius-md);     /* kit name: buttons, inputs, selects */
  --system-radius: var(--radius-md);      /* kit name */
  --panel-radius: var(--radius-lg);       /* kit name: cards, dialogs */

  /* Control sizing. Kit: 32/40/48 and 44px under (pointer:coarse). EA default 48. */
  --control-height: 3rem;
  --control-height-sm: 2.5rem;
  --component-height: var(--control-height);
  --component-font: var(--text-base);     /* kit: .8125rem; inputs must stay >= 16px on phones */
  --touch-target: 44px;

  /* Focus indicator geometry (kit: outline 2px, offset 3px) */
  --focus-width: 2px;
  --focus-offset: 3px;

  /* Motion (kit uses .12-.15s transitions and honours prefers-reduced-motion) */
  --dur-fast: .14s;
  --dur-base: .2s;
  --dur-slow: .4s;
  --ease-out: cubic-bezier(.2, .7, .2, 1);

  /* Stacking (kit values: popover 100, tooltip 110, modal 1200) */
  --z-sticky: 50;
  --z-popover: 100;
  --z-tooltip: 110;
  --z-modal: 1200;
}


/* ---------------------------------------------------------------------------
   2. LIGHT theme (paper). Default.
   --------------------------------------------------------------------------- */
:root,
[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --canvas: #F3F5F0;            /* paper: page + section background */
  --canvas-alt: #E7EDE8;        /* (EA) alternate light band */
  --surface: #FFFFFF;           /* (derived) cards, fields; white keeps field borders legible */
  --surface-raised: #FFFFFF;    /* (EA) popovers, dialogs */

  /* Text */
  --text: #12282A;              /* body */
  --ink: #0B1F20;               /* headings */
  --muted: #3D5252;             /* secondary text (7.0:1 on every light surface) */
  --subtle: #3D5252;            /* (EA) same as muted on light; dark theme differs */

  /* Borders */
  --line: #BFD8D5;              /* decorative dividers, card borders (not a control boundary) */
  --strong-line: #6B8583;       /* (derived) input / control boundary, >= 3:1 on paper, white, alt */

  /* Primary action = teal. Light theme uses the DARK teal. */
  --action-primary: #1A686B;
  --action-on-primary: #F3F5F0;
  --specimen-hover: #155457;    /* (derived) primary hover */
  --system-accent: var(--action-primary);
  --blue-soft: #E7EDE8;         /* soft primary tint: selected, hover wash */

  /* Accent = orange. Fill is the bright orange; text on light uses the dark orange. */
  --accent: #FF9E4F;            /* (EA) fill: CTA background */
  --accent-on: #0B1F20;         /* (EA) text on --accent */
  --accent-hover: #FFB070;      /* (EA)(derived) */
  --accent-text: #B4520F;       /* (EA) orange used AS TEXT / icon on light */
  --specimen-secondary: var(--accent);
  --specimen-secondary-text: var(--accent-on);

  /* Focus */
  --system-focus: #1A686B;      /* (EA) kit's verify script names --system-focus as the focus role */

  /* Status (derived: the brand has no red/green/yellow). Text colour on its own soft bg. */
  --success: #17623C;  --success-soft: #E1F0E6;
  --warning: #7A5200;  --warning-soft: #FBF0D5;
  --error:   #A6231B;  --error-soft:   #FBE9E7;
  --info:    #1A686B;  --info-soft:    #E7EDE8;
  --danger-on: #FFFFFF;         /* (EA) text on a solid --error button */

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(11, 31, 32, .06);
  --shadow-md: 0 6px 20px -8px rgba(11, 31, 32, .18);
  --shadow-lg: 0 24px 64px -20px rgba(11, 31, 32, .35);
  --overlay: rgba(11, 31, 32, .6);   /* dialog ::backdrop */
}


/* ---------------------------------------------------------------------------
   3. DARK theme (teal-black). Opt in per section: <section data-theme="dark">
   MUST stay after the light block (equal specificity, later wins on <html>).
   --------------------------------------------------------------------------- */
[data-theme="dark"],
[data-system-mode="dark"] {
  color-scheme: dark;

  /* Surfaces: 0B1F20 canvas, 12282A alt band, 0F2A2B cards, 163B3C raised */
  --canvas: #0B1F20;
  --canvas-alt: #12282A;
  --surface: #0F2A2B;
  --surface-raised: #163B3C;

  /* Text */
  --text: #E7EDE8;
  --ink: #F3F5F0;
  --muted: #BFD8D5;
  --subtle: #8FB1AE;            /* captions, >= 5.2:1 on every dark surface */

  /* Borders */
  --line: #163B3C;              /* decorative; use --strong-line on --surface-raised */
  --strong-line: #6C9190;       /* (derived) control boundary, >= 3.5:1 on every dark surface */

  /* Primary action = bright teal with teal-black text */
  --action-primary: #28AFB0;
  --action-on-primary: #0B1F20;
  --specimen-hover: #4CC3C4;    /* (derived) */
  --system-accent: var(--action-primary);
  --blue-soft: #163B3C;

  /* Accent = orange (same fill; orange is also valid as text on dark) */
  --accent: #FF9E4F;
  --accent-on: #0B1F20;
  --accent-hover: #FFB070;
  --accent-text: #FF9E4F;
  --specimen-secondary: var(--accent);
  --specimen-secondary-text: var(--accent-on);

  --system-focus: #28AFB0;

  --success: #7FD6A3;  --success-soft: #12382B;
  --warning: #F2C46B;  --warning-soft: #33290F;
  --error:   #FF9C94;  --error-soft:   #3A1E22;
  --info:    #4CC3C4;  --info-soft:    #163B3C;
  --danger-on: #0B1F20;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 8px 24px -10px rgba(0, 0, 0, .55);
  --shadow-lg: 0 28px 72px -20px rgba(0, 0, 0, .65);
  --overlay: rgba(4, 14, 15, .72);
}


/* ---------------------------------------------------------------------------
   4. Section surface + band helpers
   Any element carrying data-theme paints its own background, so
   <section data-theme="dark"> is a complete dark band.
   --------------------------------------------------------------------------- */
[data-theme="light"],
[data-theme="dark"] {
  background-color: var(--canvas);
  color: var(--text);
}

/* Alternate light band (#E7EDE8). Orange text drops to 4.25:1 here, so use the
   deeper orange (derived, 5.30:1) and keep teal as is (5.46:1). */
[data-theme="light"][data-band="alt"],
:root[data-band="alt"] {
  --canvas: #E7EDE8;
  --accent-text: #9E4609;
}
/* Dark alt band: #12282A is almost identical to --surface (#0F2A2B), so cards
   on it move up one step to #163B3C. */
[data-theme="dark"][data-band="alt"] {
  --canvas: #12282A;
  --surface: #163B3C;
}


/* ---------------------------------------------------------------------------
   5. Kit-compatibility aliases
   components.css / examples/starter read these names. They are re-declared on
   EVERY themed element, because a var() inside a custom property is resolved
   where it is declared, not where it is used.
   --------------------------------------------------------------------------- */
:root,
[data-theme="light"],
[data-theme="dark"],
[data-system-mode="dark"] {
  --blue: var(--action-primary);          /* legacy name; do not use in new code */
  --preview-accent: var(--action-primary);
  --preview-on-accent: var(--action-on-primary);
  --green: var(--success);
  --green-soft: var(--success-soft);
  --diagram: var(--action-primary);
  --diagram-soft: var(--blue-soft);
  --font-interface: var(--system-font);
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--system-focus) 28%, transparent);
}

/* Shared focus indicator (kit: outline 2px var(--blue), offset 3px). */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--focus-width) solid var(--system-focus);
  outline-offset: var(--focus-offset);
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0s; --dur-base: 0s; --dur-slow: 0s; }
}
