/*
    forma-tokens.css — The design tokens every Forma component reads, and Forma's theme.

    A background ends in -bg-color, a foreground in -fg-color, and the readable content of a
    control in -text-color.

    A theme is a rule, [data-forma-theme="its-name"], that sets the base tokens: the gray scale, the
    six role solids, the canvas and the four chart series. It may set any other token as well. A
    value that differs by color scheme is a color, written as light-dark(light, dark). Forma's theme
    is the first rule below, which sets its base tokens, and the last, which sets the tokens its look
    takes apart from the defaults; a page that names no theme draws it.

    Every other token is declared under :where(:root, [data-forma-theme]), so it derives again from
    the base tokens wherever a theme applies, and a theme's own value for it wins. Every token is an
    unregistered custom property, so a color resolves light-dark() where it is drawn, by the
    color-scheme there, which data-forma-scheme sets.
*/

/* ============================================================
   Forma's theme — the base tokens, which nothing else derives.
   ============================================================ */
:where(:root, [data-forma-theme="forma"]) {
    /* Scale — the one gray ramp, paper to ink, light paper in the light scheme and dark paper in the
       dark one. Every gray-ish token points at a step by name and follows. Each step has one job:
         0    paper: a flat or raised backdrop, an input
         50   an inset backdrop, a surface gone inactive
         100  the light canvas, muted content, a disabled fill, a quiet button at rest
         200  a quiet button under the pointer
         300  a quiet button pressed, a subtle border; the dark secondary solid under the pointer
         400  disabled text; the dark secondary solid
         500  secondary text, a field's border
         600  the light secondary solid, quiet text, the hue a border and a hover tint are cut from
         700  the light secondary solid under the pointer, the secondary ink
         800  ink: primary text */
    --gray-0: light-dark(#fff, #16191e);
    --gray-50: light-dark(#f9fafb, #1c2026);
    --gray-100: light-dark(#f3f4f6, #22272e);
    --gray-200: light-dark(#e5e7eb, #2c323a);
    --gray-300: light-dark(#d1d5db, #373e47);
    --gray-400: light-dark(#9ca3af, #5c6570);
    --gray-500: light-dark(#677077, #8a939e);
    --gray-600: light-dark(#495361, #a9b2bc);
    --gray-700: light-dark(#374151, #c5ccd4);
    --gray-800: light-dark(#1f2937, #e6eaef);

    /* The solid of each role. Primary is the brand accent; Secondary is the neutral solid beside it,
       a dark gray under white in both schemes; the other four are status, the same in both. */
    --primary-color: light-dark(#0066bf, #1f6fd1);
    --secondary-color: light-dark(var(--gray-600), var(--gray-400));
    --success-color: #208738;
    --danger-color: #c4314b;
    --warning-color: #ffc107;
    --info-color: #2d76cd;

    /* The canvas: the backdrop other backdrops are laid on, below the paper, which a scale running
       from dark paper to light ink holds no step for. */
    --backdrop-canvas-bg-color: light-dark(var(--gray-100), #0f1115);

    /* A chart's series in the order a chart takes them, validated as a set against each scheme's
       paper so adjacent series stay apart for color-blind readers. */
    --chart-series-1-color: light-dark(#2a78d6, #3987e5);
    --chart-series-2-color: light-dark(#eb6834, #d95926);
    --chart-series-3-color: light-dark(#1baf7a, #199e70);
    --chart-series-4-color: light-dark(#eda100, #c98500);
}

/* The color scheme an element and everything inside it draws in; system follows the device's. */
[data-forma-scheme="light"] {
    color-scheme: light;
}

[data-forma-scheme="dark"] {
    color-scheme: dark;
}

[data-forma-scheme="system"] {
    color-scheme: light dark;
}

:where(:root, [data-forma-theme]) {
    /* Typography */
    --font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
        'Noto Sans Hebrew', sans-serif;
    --font-family-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
    /* Faces that draw signs and symbols as monochrome text, for a character standing in for an icon. */
    --font-family-symbol: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols 2', sans-serif;

    /* Type scale, in rem so a reader's own font size carries through. Each step has one job. */
    --font-size-xs: 0.75rem;    /* a caption, a badge, a keyboard hint */
    --font-size-sm: 0.875rem;   /* a target's label, dense data such as a grid cell or a menu item */
    --font-size-base: 1rem;     /* prose and the text inside an input */
    --font-size-lg: 1.125rem;   /* a section heading, a dialog title */
    --font-size-xl: 1.25rem;    /* a page title */
    --font-size-2xl: 1.5rem;    /* a display figure, an empty state's headline */

    /* Line height: prose breathes, a target stays tight so its box comes out on the grid. */
    --line-height-prose: 1.5;
    --line-height-target: 1.25;

    /* Spacing scale on a 4px grid, in rem so padding and gaps grow with the text they surround.
       Each step has one job. */
    --space-1: 0.25rem;   /* inside one target: a glyph beside its label, a badge's padding; between the backdrops laid on a canvas */
    --space-2: 0.5rem;    /* between targets in a row; a target's block padding */
    --space-3: 0.75rem;   /* a target's inline padding; between groups in a row */
    --space-4: 1rem;      /* between blocks; a panel's or a card's padding */
    --space-5: 1.5rem;    /* between sections; a dialog's padding */
    --space-6: 2rem;      /* between page regions */

    /* Standalone glyph sizes, each a whole multiple of a grid the artwork is drawn on (24 or 32), so
       a 2-unit stroke lands on whole pixels; a glyph inline with text is sized in em instead. */
    --icon-size-sm: 1.5rem;     /* 24px, the 24 grid: a button, a toolbar, a menu item, a grid cell, a toast marker */
    --icon-size-md: 2rem;       /* 32px, the 32 grid: a glyph that leads a panel, a tile or a picker cell */
    --icon-size-lg: 3rem;       /* 48px, the 24 grid: a section's figure */
    --icon-size-display: 4rem;  /* 64px, the 32 grid: the figure of an empty state, a drop zone, a media facade */

    /* The box a target is pressed or focused on, one height for a button and the input beside it. Each step is a
       line of 14px text at the target line height (17.5px) plus padding and a 1px border, rounded up
       to the 4px grid: one line tight, one line comfortable, a label over a value, and the finger. */
    --target-size-sm: 1.5rem;      /* 24px: an icon button, a compact toolbar cell, a dense row; WCAG's 24×24 floor */
    --target-size-md: 2rem;        /* 32px: a button, an input, a toolbar button, a menu item */
    --target-size-lg: 2.5rem;      /* 40px: a prominent action, a row that carries two lines */
    --target-size-xl: 3rem;        /* 48px: a field that stacks its label over its value (15 + 21 + 8 + 2) */
    --target-size-touch: 2.75rem;  /* 44px: any target under a coarse pointer; WCAG 2.5.5 and Apple */

    /* Radii, one per kind of surface. */
    --radius-sm: 0.25rem;   /* a target: button, input, checkbox, cell */
    --radius-md: 0.375rem;  /* a card, a popover, a panel */
    --radius-lg: 0.5rem;    /* a dialog, a toast */
    --radius-pill: 9999px;  /* a badge, a chip, a tab pill; oversized, which CSS caps to fully rounded ends */

    /* ============================================================
       Constants — the same in every theme.
       ============================================================ */
    --white-color: #fff;
    --black-color: #000;

    /* ============================================================
       Roles — the six colors a component reaches for by name. A theme sets each solid; the rest of
       the family derives. Every role has the same five members:
         -color           the solid
         -emphasis-color  stronger than the solid: the fill hover and active are cut from
         -subtle-color    the tint behind a selected row, an active tab, a badge
         -fg-color        text and marks drawn on the solid
         -ink-color       text and marks drawn in the role's color on the paper or on its subtle tint
       A light scheme's ink is its emphasis, but for warning, whose light solid takes a darker ink to
       read on the paper; a dark scheme sets the two apart, since text on dark paper wants a lighter
       shade than a fill under white text does, as Forma's theme does in its last rule.
       ============================================================ */
    --primary-emphasis-color: color-mix(in srgb, var(--primary-color) 82%, black);
    --primary-subtle-color: color-mix(in srgb, var(--primary-color) 10%, transparent);
    --primary-fg-color: var(--white-color);
    --primary-ink-color: var(--primary-emphasis-color);

    --secondary-emphasis-color: var(--gray-700);
    --secondary-subtle-color: var(--gray-100);
    --secondary-fg-color: var(--white-color);
    --secondary-ink-color: var(--secondary-emphasis-color);

    --success-emphasis-color: color-mix(in srgb, var(--success-color) 82%, black);
    --success-subtle-color: color-mix(in srgb, var(--success-color) 10%, transparent);
    --success-fg-color: var(--white-color);
    --success-ink-color: var(--success-emphasis-color);

    --danger-emphasis-color: color-mix(in srgb, var(--danger-color) 82%, black);
    --danger-subtle-color: color-mix(in srgb, var(--danger-color) 10%, transparent);
    --danger-fg-color: var(--white-color);
    --danger-ink-color: var(--danger-emphasis-color);

    --warning-emphasis-color: color-mix(in srgb, var(--warning-color) 82%, black);
    --warning-subtle-color: color-mix(in srgb, var(--warning-color) 10%, transparent);
    --warning-fg-color: var(--black-color);  /* dark on yellow, in both schemes */
    --warning-ink-color: color-mix(in srgb, var(--warning-color) 53%, black);

    --info-emphasis-color: color-mix(in srgb, var(--info-color) 82%, black);
    --info-subtle-color: color-mix(in srgb, var(--info-color) 10%, transparent);
    --info-fg-color: var(--white-color);
    --info-ink-color: var(--info-emphasis-color);

    /* ============================================================
       Text — primary and secondary. Content and every enabled target's label or glyph take the
       primary tone or the quiet text tone below, both past 7:1 on the backdrop; supporting text —
       a caption, a count, a placeholder, an empty state, a hint — takes the secondary tone,
       which still meets WCAG AA at 4.5:1.
       ============================================================ */
    --text-primary-color: var(--gray-800);
    --text-secondary-color: var(--gray-500);

    /* ============================================================
       Interactive states — two axes. Quiet is an emphasis level on something still usable: the
       label or glyph of an enabled target on a quiet fill or on no fill at all, such as a ghost
       button or a toolbar icon. It is the secondary role worn as text and as a subtle fill, so it
       points at secondary. Disabled is a state: every disabled target, whatever it was when live,
       so a gray that weak always means "unavailable."
       ============================================================ */
    --quiet-text-color: var(--secondary-color);
    --disabled-bg-color: var(--gray-100);
    --disabled-text-color: var(--gray-400);

    /* ============================================================
       Backdrops — the backdrops laid on the canvas, and the tone a region takes inside a backdrop,
       one token per BackdropVariant, the canvas's among the base tokens. Regions are told apart by
       tone and by a backdrop's own edge.
       ============================================================ */
    --backdrop-flat-bg-color: var(--gray-0);      /* a flat backdrop: a panel, a sheet, a content area */
    --backdrop-inset-bg-color: var(--gray-50);    /* an inset backdrop: a header strip, a toolbar band, a table header */
    --backdrop-raised-bg-color: var(--gray-0);    /* a raised backdrop: a card or a frame on the canvas */

    /* Backgrounds */
    --input-bg-color: var(--gray-0);
    --inactive-bg-color: var(--gray-50);  /* a whole surface gone inactive: a disabled or a read-only composer */
    --inactive-opacity: 0.6;              /* how far a whole surface gone inactive fades: a disabled composer, an inert backdrop */
    --muted-bg-color: var(--gray-100);    /* content decoration: inline code, a quote, a placeholder box */
    --hover-bg-color: color-mix(in srgb, var(--gray-600) 6%, transparent);
    --loading-bg-color: color-mix(in srgb, var(--gray-600) 12%, transparent);  /* the shape standing for content still loading: a row, a card, a value */

    /* ============================================================
       Popovers — the surface a menu, a list, a picker or a readout floats on over the page, and the
       edge that outlines it all round. In a dark scheme, where a shadow barely shows, the surface
       is a step toward the ink, so it stands apart from what it opens over.
       ============================================================ */
    --popover-bg-color: light-dark(var(--backdrop-raised-bg-color), var(--gray-50));
    --popover-border-color: var(--border-color);

    /* ============================================================
       Buttons — one family per variant, each the same four members: the fill at rest, under the
       pointer, pressed, and the label on it. Each maps a state to its role: hover is the role's
       emphasis, active is the emphasis darkened one step further, the label is the role's fg.
       Quiet is the secondary role worn as a subtle fill — the look a tertiary button rests in and
       a ghost button reaches on hover — so it rests on the secondary subtle and steps down the
       scale from there for hover and active.
       ============================================================ */
    --button-primary-color: var(--primary-color);
    --button-primary-hover-color: var(--primary-emphasis-color);
    --button-primary-active-color: color-mix(in srgb, var(--primary-emphasis-color) 88%, black);
    --button-primary-text-color: var(--primary-fg-color);

    --button-secondary-color: var(--secondary-color);
    --button-secondary-hover-color: var(--secondary-emphasis-color);
    --button-secondary-active-color: color-mix(in srgb, var(--secondary-emphasis-color) 88%, black);
    --button-secondary-text-color: var(--secondary-fg-color);

    --button-danger-color: var(--danger-color);
    --button-danger-hover-color: var(--danger-emphasis-color);
    --button-danger-active-color: color-mix(in srgb, var(--danger-emphasis-color) 88%, black);
    --button-danger-text-color: var(--danger-fg-color);

    --button-quiet-color: var(--secondary-subtle-color);
    --button-quiet-hover-color: var(--gray-200);
    --button-quiet-active-color: var(--gray-300);
    --button-quiet-text-color: var(--quiet-text-color);

    /* Focus ring — a gap in the backdrop color, then a band of the accent, drawn as shadows so it follows the
       corner; --focus-ring-inset is the same ring turned inward, for a target that clips its own box. */
    --focus-color: var(--primary-color);
    --focus-ring-gap: 2px;
    --focus-ring-width: 2px;
    --focus-ring: 0 0 0 var(--focus-ring-gap) var(--input-bg-color), 0 0 0 calc(var(--focus-ring-gap) + var(--focus-ring-width)) var(--focus-color);
    --focus-ring-inset: inset 0 0 0 var(--focus-ring-width) var(--focus-color), inset 0 0 0 calc(var(--focus-ring-gap) + var(--focus-ring-width)) var(--input-bg-color);

    /* Links — the primary ink, so a link reads as accent text over prose; hover moves it toward the text ink. */
    --link-color: var(--primary-ink-color);
    --link-hover-color: color-mix(in srgb, var(--primary-ink-color) 76%, var(--text-primary-color));

    /* Borders — cut from the scale, so they follow the theme. */
    --border-color: color-mix(in srgb, var(--gray-600) 16%, transparent);
    --border-subtle-color: var(--gray-300);
    --border-emphasis-color: var(--gray-500);  /* the border that marks a field, 3:1 or more on every backdrop */

    /* ============================================================
       Media — the chrome for viewing a photo, a video or a document, fixed to a dark viewer in
       every theme through the constants.
       ============================================================ */
    --media-bg-color: var(--black-color);
    --media-fg-color: var(--white-color);
    --media-muted-fg-color: color-mix(in srgb, var(--white-color) 72%, transparent);
    /* A shade is a translucent dark layer laid over a picture, keeping what is drawn on top of it — a
       caption, the viewer's arrows, a preview's surroundings — readable whatever the picture's colors are. */
    --media-shade-color: color-mix(in srgb, var(--black-color) 70%, transparent);

    /* ============================================================
       Charts — what a chart draws beside its series, which are among the base tokens. The grid, the
       baseline and a threshold are cut from the scale and the ink.
       ============================================================ */
    --chart-grid-color: var(--gray-200);
    --chart-baseline-color: var(--gray-400);
    --chart-threshold-color: var(--text-secondary-color);
    --chart-surface-color: var(--backdrop-flat-bg-color);  /* the ring around a marker, and the gap between bars */
    --chart-plot-block-size: 12rem;
    --chart-min-inline-size: 16rem;    /* 256px: the least a chart sized by its content takes, room for four time labels */
    --chart-bar-inline-size: 1.5rem;   /* 24px: the widest a bar draws, the air of its period beside it */
    --chart-marker-size: 0.5rem;       /* 8px: a line's marker */
    --chart-mark-size: 0.75rem;        /* 12px: a point carrying a mark, drawn apart from the markers */

    /* ============================================================
       Chrome — the band a specific kind of surface paints for itself, each themable on its own. A frame
       is a raised backdrop with chrome: a title bar, an optional header band, the body, an optional
       footer band; a window floats a frame and a dialog is a modal window, and both read the same tokens.
       The bands read as inset backdrops and the body as a flat one; a toolbar and a status strip read as
       the stronger muted tone, legible beside a dimmed, inactive surface.
       ============================================================ */
    --toolbar-bg-color: var(--muted-bg-color);
    --command-area-bg-color: var(--backdrop-inset-bg-color);
    --status-strip-bg-color: var(--muted-bg-color);
    --chrome-titlebar-bg-color: var(--backdrop-inset-bg-color);
    --chrome-header-bg-color: var(--backdrop-inset-bg-color);
    --chrome-body-bg-color: var(--backdrop-flat-bg-color);
    --chrome-footer-bg-color: var(--backdrop-inset-bg-color);
    /* The scrim: the translucent dark layer a modal stands on, dimming and blocking what lies beneath,
       named like the shade as a see-through layer and fixed dark in every theme. */
    --scrim-color: color-mix(in srgb, var(--black-color) 45%, transparent);

    /* Layers — what stacks over the page, on Bootstrap's scale. A native dialog sits in the top layer
       above all of these; stacking inside one component uses its own small integers. */
    --z-index-popover: 1000;    /* a popover, a drop-down menu, a maximized composer: over the page */
    --z-index-window: 1030;   /* a floating window or a placed frame: over the page and its popovers, which live in the top layer regardless */
    --z-index-floating-bar: 1060;  /* a bar floating over a popover, such as the selection bar */
    --z-index-toast: 1080;    /* a toast, over everything in flow */

    /* Shadows — cut from the ink on light paper and from black on dark paper, where the ink is light. */
    --shadow-color: light-dark(color-mix(in srgb, var(--gray-800) 12%, transparent), color-mix(in srgb, var(--black-color) 40%, transparent));  /* what a raised backdrop casts onto what slides beneath it, drawn as a fade */
    --shadow-small: light-dark(color-mix(in srgb, var(--gray-800) 4%, transparent), color-mix(in srgb, var(--black-color) 24%, transparent)) 0 2px 4px 0;
    --shadow-medium: 0 4px 16px light-dark(color-mix(in srgb, var(--black-color) 12%, transparent), color-mix(in srgb, var(--black-color) 40%, transparent));
    --shadow-large: 0 8px 30px light-dark(color-mix(in srgb, var(--black-color) 18%, transparent), color-mix(in srgb, var(--black-color) 48%, transparent));
}

/* ============================================================
   Forma's theme — the tokens its look takes apart from the defaults, after them so it wins, on an
   element naming it or on a document's root naming no theme. In the dark scheme each role's ink is
   its solid 60% toward white, and the secondary solid, a dark gray, steps toward the paper under
   the pointer, so quiet text and the secondary ink take light steps of their own.
   ============================================================ */
:where(:root:not([data-forma-theme]), [data-forma-theme="forma"]) {
    --primary-ink-color: light-dark(var(--primary-emphasis-color), color-mix(in srgb, var(--primary-color) 60%, white));
    --success-ink-color: light-dark(var(--success-emphasis-color), color-mix(in srgb, var(--success-color) 60%, white));
    --danger-ink-color: light-dark(var(--danger-emphasis-color), color-mix(in srgb, var(--danger-color) 60%, white));
    --warning-ink-color: light-dark(color-mix(in srgb, var(--warning-color) 53%, black), color-mix(in srgb, var(--warning-color) 60%, white));
    --info-ink-color: light-dark(var(--info-emphasis-color), color-mix(in srgb, var(--info-color) 60%, white));

    --secondary-emphasis-color: light-dark(var(--gray-700), var(--gray-300));
    --secondary-ink-color: var(--gray-700);
    --quiet-text-color: var(--gray-600);
}
