/*
 * Daslab house style for views: one grammar, any brand.
 *
 * Link it and write semantic HTML. The page looks finished with no CSS of
 * your own, and every view that links it improves when this file does.
 *
 * A brand sets the --brand-* knobs below and nothing else; surfaces,
 * hairlines and secondary text are derived from its ground and ink, so any
 * pair of colors yields a palette that holds together in light and dark.
 *
 * Named patterns, for what plain elements cannot say:
 *   .kicker  one mono line above the title: what kind of page, and when
 *   .dek     the sentence under the title that says what the page is for
 *   .stats   a <dl> of headline figures
 *   a.def    beside a figure's label, the link to the rule that works it out
 *   .items   a list of things that each carry a few sentences
 *   .state   a status word with a dot: .ok .info .warn .alert
 *   .steps   an ordered sequence
 *   .split   two columns that stack on a phone
 *   .bar     a horizontal bar, value in --v from 0 to 1
 *   .num     a right-aligned table column
 *   .glance  what a grid tile shows, when it should not be the top
 *   form.fields  a form whose fields wrap, labels above, hint and actions below
 *
 * Everything sits in a cascade layer, so any rule a view writes wins.
 * On the scene grid a view shows its face, the blocks that fit a tile
 * whole; house.js chooses them (see Tile, at the end).
 * Served at /widget/house.css (routes/widget-sdk.ts); what agents are told
 * about it is in lib/design-brief.ts and daslab_write_view's VISUAL LANGUAGE.
 */
@import url("https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400..700&family=JetBrains+Mono:wght@400;500&display=swap");

@layer daslab-house {
  /* ── Brand: the only values a brand sets ─────────────────────────────── */
  :root {
    --brand-ground: #f2eee5;
    --brand-ink: #1b1b1d;
    --brand-accent: #315fc5;
    --brand-ground-dark: #1e1e1e;
    --brand-ink-dark: #ece8df;
    --brand-accent-dark: #6b9bff;
    --brand-display: "Inter", system-ui, -apple-system, sans-serif;
    --brand-text: "Inter", system-ui, -apple-system, sans-serif;
    --brand-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
    --brand-display-weight: 600;
    --brand-display-tracking: -0.032em;
    --brand-display-scale: 1;
    --brand-display-stretch: 100%;
    --brand-radius: 0px;
  }

  /* ── Appearance: the viewer's light or dark picks one side ───────────── */
  :root {
    color-scheme: light dark;
    --bg: var(--brand-ground-dark);
    --text: var(--brand-ink-dark);
    --accent: var(--brand-accent-dark);
    --ok: #5fd68a; --info: #6b9bff; --warn: #e8c96a; --alert: #e0584d;
  }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
      --bg: var(--brand-ground);
      --text: var(--brand-ink);
      --accent: var(--brand-accent);
      --ok: #2e7d4f; --info: #315fc5; --warn: #a87515; --alert: #b3392b;
    }
  }
  :root[data-theme="light"] {
    --bg: var(--brand-ground);
    --text: var(--brand-ink);
    --accent: var(--brand-accent);
    --ok: #2e7d4f; --info: #315fc5; --warn: #a87515; --alert: #b3392b;
  }
  /* The browser draws native parts (checkboxes, date pickers, scrollbars) in
     the appearance a page is pinned to, not the system's. */
  :root[data-theme="dark"] { color-scheme: dark; }
  :root[data-theme="light"] { color-scheme: light; }

  /* ── Derived: never set by a brand ───────────────────────────────────── */
  :root {
    --text-secondary: color-mix(in oklab, var(--text) 64%, var(--bg));
    --text-dim: color-mix(in oklab, var(--text) 44%, var(--bg));
    --border: color-mix(in oklab, var(--text) 14%, var(--bg));
    --bg-surface: color-mix(in oklab, var(--text) 4%, var(--bg));
    --bg-well: color-mix(in oklab, var(--text) 8%, var(--bg));
    /* A fill carries text, so it takes the deep accent in both appearances;
       the dark one is tuned to read as a link on a dark ground. */
    --accent-fill: var(--brand-accent-fill, var(--brand-accent));
    --on-accent-fill: var(--brand-on-accent-fill, #fff);
    --on-accent: var(--bg); /* older views read it */
    /* the names /widget/theme.css taught, so either vocabulary resolves */
    --bg-card: var(--bg-surface);
    --blue: var(--info); --green: var(--ok); --yellow: var(--warn); --red: var(--alert);
    --gutter: clamp(18px, 5vw, 40px);
    --measure: 48rem;
  }

  /* ── Ground and measure ──────────────────────────────────────────────── */
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 15px/1.55 var(--brand-text);
    font-optical-sizing: auto;
    -webkit-font-smoothing: antialiased;
  }
  body > main, body > article {
    max-width: var(--measure);
    margin: 0 auto;
    padding: calc(var(--gutter) + var(--daslab-inset-top, 0px)) var(--gutter) var(--gutter);
  }
  body:not(:has(> main, > article)) {
    padding: calc(var(--gutter) + var(--daslab-inset-top, 0px)) var(--gutter) var(--gutter);
  }

  /* ── Type: hierarchy by size and weight, never by case ───────────────── */
  h1, h2, h3 { margin: 0; color: var(--text); text-wrap: balance; }
  h1, h2 {
    font-family: var(--brand-display);
    font-weight: var(--brand-display-weight);
    font-stretch: var(--brand-display-stretch);
  }
  h1 {
    font-size: calc(clamp(26px, 6vw, 34px) * var(--brand-display-scale));
    line-height: 1.1;
    letter-spacing: var(--brand-display-tracking);
  }
  h2 {
    font-size: calc(19px * var(--brand-display-scale));
    line-height: 1.3;
    letter-spacing: calc(var(--brand-display-tracking) * 0.55);
  }
  h3 { font-size: 15px; line-height: 1.4; font-weight: 600; letter-spacing: -0.006em; }
  p { margin: 0; text-wrap: pretty; }
  p + p { margin-top: 0.7em; }
  strong { font-weight: 600; }
  small { font-size: 13px; color: var(--text-secondary); }
  a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
  code, kbd, samp, time, .mono { font-family: var(--brand-mono); font-size: 0.86em; }
  hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }

  .kicker { font: 500 12px/1.4 var(--brand-mono); color: var(--text-secondary); margin-bottom: 14px; }
  .dek { margin-top: 12px; font-size: 17px; line-height: 1.5; color: var(--text-secondary); max-width: 36em; }

  /* ── Flow: blocks a pattern does not space get a default gap. :where()
        adds no specificity, so every rule below still wins ───────────────── */
  :where(main, article, section, header) > * + * { margin-top: 16px; }

  /* ── Sections breathe; one hairline marks the turn ───────────────────── */
  section { margin-top: 48px; padding-top: 22px; border-top: 1px solid var(--border); }
  /* A section that opens its container has no turn to mark yet. */
  section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
  section > h2 + p { margin-top: 6px; color: var(--text-secondary); }
  section > h2 + :not(p), section > h2 + p + * { margin-top: 20px; }

  ul, ol { margin: 0; padding-left: 1.2em; }
  li + li { margin-top: 6px; }
  li::marker { color: var(--text-dim); }

  /* ── Headline figures: the number is the hero, in ink ────────────────── */
  .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 24px 22px;
    margin: 36px 0 0;
  }
  .stats > div { display: flex; flex-direction: column; min-width: 0; }
  .stats dd { margin: 0; }
  .stats dd:first-of-type {
    order: -1;
    font-family: var(--brand-display);
    font-weight: var(--brand-display-weight);
    font-stretch: var(--brand-display-stretch);
    font-size: calc(24px * var(--brand-display-scale));
    line-height: 1.1;
    letter-spacing: calc(var(--brand-display-tracking) * 0.75);
    font-variant-numeric: tabular-nums lining-nums;
    white-space: nowrap;
  }
  .stats dt { margin-top: 8px; font-size: 13px; font-weight: 500; }
  .stats dd + dd { margin-top: 2px; font-size: 13px; color: var(--text-secondary); }

  /* ── How a figure is worked out: a quiet mark beside its label, linking to
        the rule. The house draws the circle around a plain "i", because a
        brand's font need not have a glyph for ⓘ ─────────────────────────── */
  a.def {
    display: inline-grid; place-items: center;
    width: 1.6em; height: 1.6em; margin-left: 0.5em;
    border: 1px solid currentColor; border-radius: 50%;
    color: var(--text-dim);
    font: 600 0.66em/1 var(--brand-text);
    text-decoration: none;
    vertical-align: 0.2em;
  }
  a.def:hover, a.def:focus-visible { color: var(--accent); }
  :target { scroll-margin-top: 24px; }

  /* ── Things that each carry a few sentences ──────────────────────────── */
  .items { list-style: none; padding: 0; }
  .items > li { margin: 0; padding: 18px 0; border-bottom: 1px solid var(--border); }
  .items > li:first-child { padding-top: 0; }
  .items > li:last-child { padding-bottom: 0; border-bottom: 0; }
  .items h3, .split h3 {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px;
  }
  .items h3 + p { margin-top: 2px; font-size: 13.5px; color: var(--text-secondary); }
  .items h3 + p + p { margin-top: 10px; }

  /* ── State: a dot carries the color, the word stays readable ─────────── */
  .state {
    display: inline-flex; align-items: center; gap: 7px;
    font: 500 13px/1.3 var(--brand-text);
    letter-spacing: 0;
    color: var(--text-secondary);
    white-space: nowrap;
  }
  .state::before {
    content: ""; flex: none;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--state, var(--text-dim));
  }
  .state.ok { --state: var(--ok); }
  .state.info { --state: var(--info); }
  .state.warn { --state: var(--warn); }
  .state.alert { --state: var(--alert); }

  /* ── Sequence ────────────────────────────────────────────────────────── */
  .steps { list-style: none; padding: 0; counter-reset: step; }
  .steps > li {
    counter-increment: step;
    display: grid; grid-template-columns: 32px 1fr; align-items: baseline;
    margin: 0; padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .steps > li:last-child { border-bottom: 0; }
  .steps > li::before { content: counter(step, decimal-leading-zero); font: 500 12px/1 var(--brand-mono); color: var(--text-dim); }

  .split { display: grid; grid-template-columns: 1fr; gap: 32px; }
  @media (min-width: 640px) { .split { grid-template-columns: 1fr 1fr; gap: 40px; } }
  .split h3 { margin-bottom: 10px; }

  /* ── Tables are for numbers; rows read across, so no vertical rules ──── */
  table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums lining-nums; }
  th {
    text-align: left; font-size: 12.5px; font-weight: 500; color: var(--text-secondary);
    padding: 0 14px 10px 0; border-bottom: 1px solid var(--border);
  }
  td { padding: 12px 14px 12px 0; border-bottom: 1px solid var(--border); vertical-align: baseline; }
  tr:last-child td { border-bottom: 0; }
  :is(th, td):last-child { padding-right: 0; }
  :is(th, td).num { text-align: right; }

  /* ── Bar: the accent is "yours", so one data series may wear it ──────── */
  .bar {
    display: inline-block; vertical-align: middle;
    width: 72px; height: 6px; margin-right: 8px;
    border-radius: var(--brand-radius);
    background: linear-gradient(to right, var(--accent) calc(var(--v, 0) * 100%), var(--bg-well) 0);
  }

  /* ── Actions: the accent fill means the primary action, nothing else ─── */
  button {
    min-height: 36px;
    padding: 6px 16px;
    font: 500 14px/1.25 var(--brand-text);
    border-radius: var(--brand-radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }
  button.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent-fill); }

  /* ── Controls: one height, a hairline, the brand's corners, no wells.
        :where() keeps this at no specificity, so select and textarea below,
        and anything a view writes, win over it. ───────────────────────── */
  :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea) {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    height: 36px;
    margin: 0;
    padding: 0 10px;
    font: 400 14px/1.4 var(--brand-text);
    color: var(--text);
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: var(--brand-radius);
    -webkit-appearance: none;
    appearance: none;
  }
  textarea { height: auto; min-height: 88px; padding: 8px 10px; resize: vertical; }
  select {
    padding-right: 30px;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
      linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
  }
  ::placeholder { color: var(--text-dim); }
  :is(input, select, textarea, button):focus-visible {
    outline: 2px solid color-mix(in oklab, var(--accent) 55%, transparent);
    outline-offset: 1px;
  }
  :is(input, select, textarea):focus-visible { border-color: var(--accent); }
  input:is([type="checkbox"], [type="radio"]) { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent-fill); }

  /* ── A form: each field a label holding its control; fields wrap into
        columns rather than run off the edge, the hint and actions below ── */
  form.fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 16px;
    align-items: end;
  }
  form.fields > label { display: grid; gap: 6px; min-width: 0; font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
  form.fields > :is(.check, .actions, p, small) { grid-column: 1 / -1; }
  form.fields > label.check { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 400; color: var(--text); }
  form.fields > p { margin: -4px 0 0; font-size: 13px; color: var(--text-secondary); max-width: 60em; }
  form.fields > .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }

  /* ── Provenance is quiet and last ────────────────────────────────────── */
  body > footer, body > :is(main, article) > footer {
    margin-top: 56px; padding-top: 16px;
    border-top: 1px solid var(--border);
    font: 400 12px/1.6 var(--brand-mono);
    color: var(--text-dim);
  }

  /* ── Print: the page you forward ─────────────────────────────────────── *
     Paper is light whatever the reader works in. Headings stay with what
     follows, rows and figures never split, a table's head repeats on each
     page, and controls stay on the screen. The page's margin carries the
     numbers; the brand layer adds the world's name as a running head. */
  @page {
    margin: 18mm 16mm 20mm;
    @bottom-right { content: counter(page) " of " counter(pages); font: 400 8pt "JetBrains Mono", ui-monospace, monospace; color: #8e8e90; }
  }
  @media print {
    :root, :root[data-theme] {
      color-scheme: light;
      --bg: var(--brand-ground);
      --text: var(--brand-ink);
      --accent: var(--brand-accent);
      --ok: #2e7d4f; --info: #315fc5; --warn: #a87515; --alert: #b3392b;
    }
    body > :is(main, article), body:not(:has(> main, > article)) { max-width: none; padding: 0; }
    :is(h1, h2, h3) { break-after: avoid; }
    :is(tr, li, figure, .stats > div, .split > *) { break-inside: avoid; }
    thead { display: table-header-group; }
    :is(button, form.fields) { display: none; }
    /* A section that is only a form goes with it, heading and all. */
    section:has(> form.fields):not(:has(> :not(h2, h3, p, form.fields))) { display: none; }
  }

  /* ── Tile: the page's face on the scene grid ─────────────────────────── *
     On the grid a cell is a box that never scrolls. The renderer marks it
     html[data-cell="tile"] with its data-size, and house.js hides whatever
     would not fit whole: the face is the top of the page, or the blocks
     marked .glance. Opened, the same page scrolls in full. Hidden is
     !important so a view's own display rule cannot bring a block back.
     Every tile keeps one rhythm, so a row of different cells lines up: 16px
     in from the edge, the kicker on a 16px line, the title starting 40px
     down and sized by the tile's size, never its width; every line height
     a multiple of 4. */
  :root[data-cell="tile"] { --gutter: 16px; --tile-h1: 24px; }
  :root[data-cell="tile"] body { overflow: hidden; font-size: 14px; line-height: 20px; }
  :root[data-cell="tile"] body > :is(main, article) { max-width: none; }
  :root[data-cell="tile"] [data-tile-hidden] { display: none !important; }
  :root[data-cell="tile"] [data-tile-first] { margin-top: 0; padding-top: 0; border-top: 0; }
  :root[data-cell="tile"] [data-tile-blank] { visibility: hidden; height: 16px; overflow: hidden; }
  /* Text is whole or it goes: no ellipsis, no clamp. A headline that does
     not fit shrinks one notch (data-tile-tight) before it is cut. */
  :root[data-cell="tile"] h1 {
    --tile-h1-size: calc(var(--tile-h1) * var(--tile-tight, 1) * var(--brand-display-scale));
    font-size: var(--tile-h1-size);
    line-height: round(up, calc(var(--tile-h1-size) * 1.12), 4px);
  }
  :root[data-cell="tile"][data-tile-tight] { --tile-tight: 0.84; }
  :root[data-cell="tile"] .kicker { margin-bottom: 8px; line-height: 16px; }
  :root[data-cell="tile"] .dek { margin-top: 8px; font-size: 15px; line-height: 20px; }
  :root[data-cell="tile"] .stats { margin-top: 16px; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); align-items: start; }
  :root[data-cell="tile"] .stats dd:first-of-type { line-height: round(up, calc(24px * var(--brand-display-scale) * 1.1), 4px); }
  :root[data-cell="tile"] .stats :is(dt, dd + dd) { line-height: 20px; }
  :root[data-cell="tile"] .stats dt { margin-top: 4px; }
  :root[data-cell="tile"] h2 { line-height: round(up, calc(19px * var(--brand-display-scale) * 1.2), 4px); }
  :root[data-cell="tile"] section:where(:not(:first-child)) { margin-top: 16px; padding-top: 16px; }
  /* A section's intro line is for reading; on a tile its rows say more. */
  :root[data-cell="tile"] section > h2 + p:has(+ :is(table, ul, ol, dl, .split)) { display: none; }
  :root[data-cell="tile"] section > h2 + p + :is(table, ul, ol, dl, .split) { margin-top: 12px; }
  :root[data-cell="tile"] .glance > h2 + * { margin-top: 12px; }
  :root[data-cell="tile"] .items > li { padding: 12px 0; }
  :root[data-cell="tile"] .items h3 { line-height: 20px; }
  :root[data-cell="tile"] td { padding-top: 10px; padding-bottom: 10px; line-height: 20px; }
  /* A row is its title; a small tile is one figure, large. Both take the
     headline's short version, h1[data-short], when the view gives one. */
  :root[data-cell="tile"]:is([data-size="row"], [data-size="icon"]) { --tile-h1: 17px; }
  :root[data-cell="tile"]:is([data-size="row"], [data-size="icon"]) .kicker { display: none; }
  :root[data-cell="tile"][data-size="small"] { --tile-h1: 19px; }
  :root[data-cell="tile"]:is([data-size="small"], [data-size="row"], [data-size="icon"]) h1[data-short] { font-size: 0; }
  :root[data-cell="tile"]:is([data-size="small"], [data-size="row"], [data-size="icon"]) h1[data-short]::before {
    content: attr(data-short);
    font-size: var(--tile-h1-size);
  }
  :root[data-cell="tile"][data-size="small"] .stats { margin-top: 8px; }
  :root[data-cell="tile"][data-size="small"] .stats dd:first-of-type {
    font-size: calc(min(30px, 14.5vw) * var(--brand-display-scale));
    line-height: round(up, calc(min(30px, 14.5vw) * var(--brand-display-scale) * 1.1), 4px);
  }
}
