/*
 * 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
 *   .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
 *
 * Everything sits in a cascade layer, so any rule a view writes wins.
 * 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: #17150f;
    --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;
  }

  /* ── 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));
    --on-accent: var(--bg);
    /* 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); }

  /* ── 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 {
    font: 500 14px/1 var(--brand-text);
    padding: 10px 16px;
    border-radius: var(--brand-radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }
  button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

  /* ── 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);
  }
}
