/* Design tokens. The only app stylesheet allowed to contain colour literals
 * (spec/design_system/stylesheet_contract_spec.rb).
 *
 * Accent — change here. The accent family is the first group in each theme
 * block (dark in the first :root block, light in html[data-theme="light"] and
 * its prefers-color-scheme mirror), between the "Accent — change here" and
 * "End accent" markers. Change it with
 *   ruby script/design/set_accent.rb LIGHT_HEX DARK_HEX
 * which rewrites all three accent groups, derives hover, tint and hairline,
 * picks the on-accent text colour, updates the owned client's
 * config/agentify_client_themes.yml and prints the contrast pairs. Every other
 * accent-coloured token below references these tokens; never repeat an accent
 * hex elsewhere. See docs/design-system/tokens-and-theme.md.
 *
 * Selector layout is a contract:
 *   - spec/design_system/focus_ring_spec.rb reads the first column-0 ":root"
 *     block as dark and the column-0 html[data-theme="light"] block as light;
 *     --color-primary and the six background tokens stay 6-digit hex.
 *   - spec/design_system/theme_tokens_spec.rb: both themes define every hex
 *     colour token, the prefers-color-scheme block mirrors the light block,
 *     the AA pairs hold, and the accent matches the owned client's themes.
 *   - Comments inside a block contain no colon, semicolon or brace: the spec
 *     parsers read declarations with a plain regex.
 * Breakpoints are literal min-widths (640 / 768 / 1024 / 1200): custom
 * properties are invalid inside @media.
 */

:root {
  color-scheme: dark;

  /* Accent — change here (script/design/set_accent.rb) */
  --color-primary: #59c8bc;
  --color-primary-hover: #78d8cf;
  --color-primary-surface: #173c38;
  --color-primary-border: #2f6f68;
  --color-on-primary: #121211;
  /* End accent */

  /* Neutrals */
  --color-background: #121211;
  --color-background-subtle: #0d0d0c;
  --color-surface: #1a1a19;
  --color-surface-subtle: #161615;
  --color-surface-raised: #222220;
  --color-surface-elevated: #2c2c2a;
  --color-surface-hover: #252523;
  --color-surface-active: #2c2c2a;
  --color-surface-inverse: #e9e9e5;
  --color-border: #33332f;
  --color-border-subtle: #272725;
  --color-border-hover: #45453f;
  --color-border-control: #85857d;
  --color-text: #e9e9e5;
  --color-text-emphasis: #f7f6f2;
  --color-text-muted: #adada6;
  --color-text-subtle: #a2a29b;
  --color-text-inverse: #121211;

  /* Status */
  --color-success: #8de0ae;
  --color-success-surface: #173a27;
  --color-success-border: #2f6e4a;
  --color-warning: #ffd38a;
  --color-warning-surface: #442f12;
  --color-warning-border: #7a5a26;
  --color-danger: #ffb3b8;
  --color-danger-hover: #ffc9cc;
  --color-danger-surface: #4a1f24;
  --color-danger-surface-hover: #5e272d;
  --color-danger-border: #8a3a42;
  --color-info: #b7c4d8;
  --color-info-surface: #1d232c;
  --color-info-border: #45536a;
  --color-neutral: #adada6;
  --color-neutral-surface: #262624;
  --color-neutral-border: #3d3d38;
  --color-on-success: #121211;
  --color-on-warning: #121211;
  --color-on-danger: #121211;

  /* Data series (chart-1 is the accent, declared with the aliases) */
  --color-chart-2: #adada6;
  --color-chart-3: #7d7d75;
  --color-chart-4: #b7c4d8;

  /* Select chevron, stroke equals --color-text-muted (per theme) */
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23adada6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  /* Scrim and floating-layer shadows */
  --color-overlay: rgba(0, 0, 0, 0.6);
  --shadow-color: 0 0% 0%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.5);
  --shadow-md: 0 4px 12px -2px hsl(var(--shadow-color) / 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --shadow-lg: 0 16px 40px -8px hsl(var(--shadow-color) / 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

html[data-theme="light"] {
  color-scheme: light;

  /* Accent — change here (script/design/set_accent.rb) */
  --color-primary: #1f615b;
  --color-primary-hover: #174c47;
  --color-primary-surface: #e6f3f1;
  --color-primary-border: #93c4be;
  --color-on-primary: #ffffff;
  /* End accent */

  --color-background: #f7f6f2;
  --color-background-subtle: #efeee9;
  --color-surface: #ffffff;
  --color-surface-subtle: #fbfbf9;
  --color-surface-raised: #f1f0eb;
  --color-surface-elevated: #e6e5df;
  --color-surface-hover: #eeede8;
  --color-surface-active: #e6e5df;
  --color-surface-inverse: #1c1c1a;
  --color-border: #d9dcd8;
  --color-border-subtle: #e8e7e1;
  --color-border-hover: #c4c3bb;
  --color-border-control: #82817a;
  --color-text: #1c1c1a;
  --color-text-emphasis: #0b0b0c;
  --color-text-muted: #55554f;
  --color-text-subtle: #62625f;
  --color-text-inverse: #f7f6f2;
  --color-success: #176b3a;
  --color-success-surface: #e7f4eb;
  --color-success-border: #9fcdb0;
  --color-warning: #704b00;
  --color-warning-surface: #fff2d6;
  --color-warning-border: #e3c27d;
  --color-danger: #8f2029;
  --color-danger-hover: #741a21;
  --color-danger-surface: #fcebec;
  --color-danger-surface-hover: #f6d3d5;
  --color-danger-border: #eba9ad;
  --color-info: #3b4b63;
  --color-info-surface: #eef1f5;
  --color-info-border: #b3bfcf;
  --color-neutral: #55554f;
  --color-neutral-surface: #efeee9;
  --color-neutral-border: #d4d3cc;
  --color-on-success: #ffffff;
  --color-on-warning: #ffffff;
  --color-on-danger: #ffffff;
  --color-chart-2: #55554f;
  --color-chart-3: #8a8982;
  --color-chart-4: #3b4b63;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2355554f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  --color-overlay: rgba(11, 11, 12, 0.32);
  --shadow-color: 40 6% 10%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.06);
  --shadow-md: 0 4px 12px -2px hsl(var(--shadow-color) / 0.1), 0 1px 3px hsl(var(--shadow-color) / 0.06);
  --shadow-lg: 0 16px 40px -8px hsl(var(--shadow-color) / 0.18), 0 2px 6px hsl(var(--shadow-color) / 0.06);
}

/* System theme without JavaScript (and before a preference exists). The
 * declarations are html[data-theme="light"]'s, verbatim and in order;
 * theme_tokens_spec keeps the two identical and set_accent.rb rewrites both.
 * An explicit data-theme="dark" switches the mirror off. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;

    /* Accent — change here (script/design/set_accent.rb) */
    --color-primary: #1f615b;
    --color-primary-hover: #174c47;
    --color-primary-surface: #e6f3f1;
    --color-primary-border: #93c4be;
    --color-on-primary: #ffffff;
    /* End accent */

    --color-background: #f7f6f2;
    --color-background-subtle: #efeee9;
    --color-surface: #ffffff;
    --color-surface-subtle: #fbfbf9;
    --color-surface-raised: #f1f0eb;
    --color-surface-elevated: #e6e5df;
    --color-surface-hover: #eeede8;
    --color-surface-active: #e6e5df;
    --color-surface-inverse: #1c1c1a;
    --color-border: #d9dcd8;
    --color-border-subtle: #e8e7e1;
    --color-border-hover: #c4c3bb;
    --color-border-control: #82817a;
    --color-text: #1c1c1a;
    --color-text-emphasis: #0b0b0c;
    --color-text-muted: #55554f;
    --color-text-subtle: #62625f;
    --color-text-inverse: #f7f6f2;
    --color-success: #176b3a;
    --color-success-surface: #e7f4eb;
    --color-success-border: #9fcdb0;
    --color-warning: #704b00;
    --color-warning-surface: #fff2d6;
    --color-warning-border: #e3c27d;
    --color-danger: #8f2029;
    --color-danger-hover: #741a21;
    --color-danger-surface: #fcebec;
    --color-danger-surface-hover: #f6d3d5;
    --color-danger-border: #eba9ad;
    --color-info: #3b4b63;
    --color-info-surface: #eef1f5;
    --color-info-border: #b3bfcf;
    --color-neutral: #55554f;
    --color-neutral-surface: #efeee9;
    --color-neutral-border: #d4d3cc;
    --color-on-success: #ffffff;
    --color-on-warning: #ffffff;
    --color-on-danger: #ffffff;
    --color-chart-2: #55554f;
    --color-chart-3: #8a8982;
    --color-chart-4: #3b4b63;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2355554f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    --color-overlay: rgba(11, 11, 12, 0.32);
    --shadow-color: 40 6% 10%;
    --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.06);
    --shadow-md: 0 4px 12px -2px hsl(var(--shadow-color) / 0.1), 0 1px 3px hsl(var(--shadow-color) / 0.06);
    --shadow-lg: 0 16px 40px -8px hsl(var(--shadow-color) / 0.18), 0 2px 6px hsl(var(--shadow-color) / 0.06);
  }
}

/* Theme-independent tokens. The var() aliases resolve per theme, because
 * every theme block above targets the same root element. */
:root {
  /* Accent references (never repeat the accent hex) */
  --color-chart-1: var(--color-primary);

  /* Colourless chevron, painted with currentColor through mask */
  --icon-chevron-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23000000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  /* Colourless tick for custom checkboxes, painted through mask */
  --icon-check-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23000000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");

  /* Role aliases (permanent) */
  --color-text-secondary: var(--color-text-muted);
  --color-success-text: var(--color-success);
  --color-warning-text: var(--color-warning);
  --color-danger-text: var(--color-danger);
  --color-info-text: var(--color-info);
  --color-neutral-text: var(--color-neutral);

  /* Type */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-display: var(--font-sans);
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.75rem;
  --text-4xl: 2rem;
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  --leading-loose: var(--leading-relaxed);
  --tracking-tighter: -0.02em;
  --tracking-tight: -0.01em;
  --tracking-normal: 0;
  --tracking-wider: 0.04em;

  /* Space, shape, layout */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 0.75rem;
  --spacing-lg: 1rem;
  --spacing-xl: 1.5rem;
  --spacing-2xl: 2rem;
  --spacing-3xl: 3rem;
  --spacing-4xl: 4rem;
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  --nav-width: 240px;
  --drawer-width: 18rem;
  --sidebar-width: 320px;
  --header-height: 56px;
  --content-max-width: 75rem;
  --form-max-width: 40rem;
  --prose-max-width: 45rem;
  --page-gutter: 1rem;
  --control-height: 2.75rem;
  --control-height-sm: 2rem;
  --control-height-lg: 3rem;
  --touch-target: 2.75rem;

  /* Layers */
  --z-base: 0;
  --z-sticky: 10;
  --z-dropdown: 20;
  --z-overlay: 30;
  --z-drawer: 40;
  --z-modal-backdrop: 50;
  --z-modal: 51;
  --z-popover: 60;
  --z-toast: 70;
  --z-tooltip: 80;

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 120ms;
  --duration-normal: 160ms;
  --duration-slow: 200ms;
}

@media (min-width: 768px) {
  :root { --page-gutter: 1.5rem; }
}

@media (min-width: 1024px) {
  :root { --control-height: 2.25rem; }
}

@media (min-width: 1200px) {
  :root { --page-gutter: 2rem; }
}

@media (pointer: coarse) {
  :root { --control-height: 2.75rem; --control-height-sm: 2.75rem; }
}
