/*
 * Solemate design system. Plain CSS (custom properties, nesting, layers):
 * warm paper tones, photo-first cards, serif display type.
 */

@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, figure, dl, dd, ul { margin: 0; }
  ul { padding: 0; list-style: none; }
  img { display: block; max-width: 100%; }
  input, button, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  /* Components set display; hidden must still win (important in the
     first layer beats every later layer). */
  [hidden] { display: none !important; }
}

@layer tokens {
  /* docs/VISUAL-DIRECTION.md: ivory ground, charcoal green structure, sand
     accents, dark charcoal text. Sand is 2:1 on ivory: details and
     indicators only, never text. Fonts are bundled so they work offline. */
  @font-face {
    font-family: "Manrope";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("/assets/manrope-latin-wght-normal-757d91ba.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  @font-face {
    font-family: "Manrope";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("/assets/manrope-latin-ext-wght-normal-9b71bd72.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
  }
  @font-face {
    font-family: "DM Serif Display";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/assets/dm-serif-display-latin-400-normal-dd23de7b.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  @font-face {
    font-family: "DM Serif Display";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/assets/dm-serif-display-latin-ext-400-normal-5a8b4d02.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
  }

  :root {
    color-scheme: light dark;

    /* Brand */
    --ivory: #f5f1e8;
    --charcoal-green: #26352f;
    --sand: #c5a77d;
    --charcoal: #292b28;

    /* Roles (contrast on --paper: ink 12.7, primary 11.4, soft 5.5, faint 4.7) */
    --paper: var(--ivory);
    --surface: #fffdf8;
    --surface-sunken: #ebe5d8;
    --ink: var(--charcoal);
    --ink-soft: #5e625c;
    --ink-faint: #6a6e67;
    --line: #ddd5c6;
    --primary: var(--charcoal-green);
    --on-primary: var(--ivory);
    --accent: var(--sand);
    --accent-strong: #8a6d45;
    --link: var(--charcoal-green);
    --danger: #a3332b;
    --success: #3f6b4a;

    --status-active: #3f6b4a;
    --status-paused: #8a6420;
    --status-retired: #6a6e67;
    --status-archived: #6a6e67;

    --font-display: "DM Serif Display", Georgia, "Times New Roman", serif;
    --font-body: "Manrope", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    --radius-s: 8px;
    --radius-m: 14px;
    --radius-l: 22px;
    --shadow: 0 1px 2px rgb(38 53 47 / 6%), 0 8px 24px rgb(38 53 47 / 7%);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    --gutter: 16px;
    --page-width: 1120px;
    --bottom-nav-height: 72px;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --paper: #161b18;
      --surface: #1e2420;
      --surface-sunken: #262d28;
      --ink: #eee9df;
      --ink-soft: #b9b5aa;
      --ink-faint: #a29e93;
      --line: #333b35;
      --primary: var(--sand);
      --on-primary: #161b18;
      --accent: var(--sand);
      --accent-strong: var(--sand);
      --link: #e2cfae;
      --danger: #e06a5f;
      --success: #8fb79b;
      --status-active: #8fb79b;
      --status-paused: #d4a94e;
      --status-retired: #a29e93;
      --status-archived: #a29e93;
      --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    }
  }

  @media (min-width: 720px) {
    :root { --gutter: 32px; }
  }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; }

  body {
    min-height: 100dvh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  a { color: inherit; }
  a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

@layer layout {
  .topbar {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    max-width: var(--page-width);
    margin: 0 auto;
    padding: var(--space-4) var(--gutter);
    padding-top: max(var(--space-4), env(safe-area-inset-top));

    .nav--top { margin-right: auto; }
  }

  .page {
    max-width: var(--page-width);
    margin: 0 auto;
    padding: var(--space-4) var(--gutter) calc(var(--bottom-nav-height) + var(--space-6) + env(safe-area-inset-bottom));
  }

  .app--guest .page {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding-bottom: var(--space-6);
  }

  .page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
  }

  .section { margin-top: var(--space-7); }

  .section__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
  }

  @media (min-width: 720px) {
    .page { padding-bottom: var(--space-7); }
  }
}

@layer components {
  /* Typography */
  .brand {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 400;
    letter-spacing: 0.01em;
    text-decoration: none;
  }
  .brand--large { font-size: 32px; text-align: center; }

  .page-title {
    font-family: var(--font-display);
    font-size: clamp(28px, 6vw, 40px);
    font-weight: 400;
    line-height: 1.1;
    letter-spacing: -0.01em;
  }

  .section__title, .panel__title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 400;
  }

  .eyebrow {
    color: var(--ink-faint);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .hint { margin-top: var(--space-1); color: var(--ink-faint); font-size: 14px; }

  .link-arrow {
    color: var(--link);
    font-weight: 600;
    text-decoration: none;
    &::after { content: " →"; }
  }

  /* Navigation */
  .nav { display: flex; gap: var(--space-2); }

  .nav__link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: 999px;
    color: var(--ink-soft);
    font-weight: 500;
    text-decoration: none;

    &.is-active { background: var(--surface-sunken); color: var(--ink); }
  }

  .nav__icon { width: 20px; height: 20px; fill: currentColor; }

  .nav--bottom {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    justify-content: space-around;
    padding: var(--space-2) var(--space-4) max(var(--space-2), env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: blur(16px);

    .nav__link {
      flex-direction: column;
      gap: 2px;
      min-width: 72px;
      font-size: 12px;
      &.is-active { background: none; color: var(--primary); font-weight: 700; }
    }
  }

  @media (max-width: 719px) {
    .nav--top { display: none; }
    .topbar { justify-content: space-between; }
  }

  @media (min-width: 720px) {
    .nav--bottom { display: none; }
  }

  /* Buttons */
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-5);
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--surface);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
  }

  .button--primary { background: var(--primary); color: var(--on-primary); }
  .button--quiet { border-color: var(--line); background: transparent; }
  .button--danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; color: var(--danger); }
  .button--small { min-height: 36px; padding: 0 var(--space-4); font-size: 14px; }
  .button--block { width: 100%; }

  /* Flash and errors */
  .flash {
    margin-bottom: var(--space-5);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-m);
    background: var(--surface);
    border-left: 4px solid var(--success);
    box-shadow: var(--shadow);
  }
  .flash--alert { border-left-color: var(--danger); }
  .errors { padding-left: var(--space-4); list-style: disc; }

  /* Forms */
  .form { display: grid; gap: var(--space-4); width: 100%; }
  .form--wide { max-width: 720px; gap: var(--space-5); }

  .fieldset {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: var(--space-5);
    border: 0;
    border-radius: var(--radius-l);
    background: var(--surface);

    legend {
      float: left;
      width: 100%;
      font-family: var(--font-display);
      font-size: 18px;
      font-weight: 400;
    }
  }

  .field {
    display: grid;
    gap: var(--space-1);
    min-width: 0;

    label { color: var(--ink-soft); font-size: 14px; font-weight: 500; }

    input:not([type="file"]), select, textarea {
      width: 100%;
      min-height: 44px;
      padding: var(--space-2) var(--space-3);
      border: 1px solid var(--line);
      border-radius: var(--radius-s);
      background: var(--paper);
    }

    textarea { resize: vertical; }
  }

  .field-row {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .form__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }

  .photo-field {
    display: grid;
    grid-template-columns: 96px 1fr;
    align-items: center;
    gap: var(--space-4);

    input[type="file"] { max-width: 100%; }
  }

  .photo-field__input { display: grid; gap: var(--space-2); }
  .photo-field__label { font-weight: 600; }

  .photo-field__preview {
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius-m);
    background: var(--surface-sunken);

    img { width: 100%; height: 100%; object-fit: cover; }
  }

  /* Auth */
  .auth {
    display: grid;
    gap: var(--space-5);
    width: min(100%, 400px);
  }
  .auth__title { font-family: var(--font-display); font-size: 24px; font-weight: 400; text-align: center; }
  .auth__links {
    display: grid;
    gap: var(--space-2);
    color: var(--ink-soft);
    font-size: 14px;
    text-align: center;
    a { color: var(--link); font-weight: 600; }
  }

  /* Dashboard */
  .stats {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(3, 1fr);
  }

  .stat {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-4);
    border-radius: var(--radius-l);
    background: var(--surface);
  }
  .stat--lead {
    grid-column: 1 / -1;
    background: var(--primary);
    color: var(--on-primary);
    .stat__label { color: color-mix(in srgb, var(--on-primary) 78%, transparent); }
  }
  .stat__value { font-family: var(--font-display); font-size: 32px; font-weight: 400; line-height: 1; }
  .stat--lead .stat__value { font-size: 48px; }
  .stat__label { color: var(--ink-soft); font-size: 14px; }

  @media (min-width: 720px) {
    .stats { grid-template-columns: 2fr repeat(3, 1fr); }
    .stat--lead { grid-column: auto; }
  }

  .empty {
    display: grid;
    justify-items: start;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-5);
    border: 1px dashed var(--line);
    border-radius: var(--radius-l);
    color: var(--ink-soft);
  }
  .empty__title { font-family: var(--font-display); font-size: 22px; color: var(--ink); }

  /* Wardrobe toolbar */
  .toolbar { display: grid; gap: var(--space-3); margin-bottom: var(--space-4); }

  .toolbar__controls { display: flex; flex-wrap: wrap; gap: var(--space-2); }

  .chips {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-1);
    scrollbar-width: none;
  }

  .chip {
    flex: none;
    min-height: 36px;
    padding: 0 var(--space-4);
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-soft);
    font-size: 14px;
    font-weight: 500;

    &[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
  }

  .select select {
    min-height: 36px;
    padding: 0 var(--space-3);
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 14px;
  }

  .segmented {
    display: inline-flex;
    margin-left: auto;
    padding: 2px;
    border-radius: 999px;
    background: var(--surface-sunken);

    button {
      min-height: 32px;
      padding: 0 var(--space-3);
      border: 0;
      border-radius: 999px;
      background: transparent;
      color: var(--ink-soft);
      font-size: 14px;
      &[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
    }
  }

  .result-count { margin-bottom: var(--space-3); color: var(--ink-faint); font-size: 14px; }

  /* Shoe cards */
  .shoe-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  }

  @media (min-width: 720px) {
    .shoe-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-5); }
  }

  .shoe-card {
    display: grid;
    align-content: start;
    overflow: hidden;
    border-radius: var(--radius-l);
    background: var(--surface);
    text-decoration: none;
    transition: transform 160ms ease, box-shadow 160ms ease;

    &:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
  }

  .shoe-card__media {
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--surface-sunken);

    img { width: 100%; height: 100%; object-fit: cover; }
  }

  .shoe-card__placeholder {
    display: grid;
    place-items: center;
    height: 100%;
    color: var(--line);

    .silhouette { width: 45%; }
  }

  .silhouette { fill: currentColor; }

  .shoe-card__body { display: grid; justify-items: start; gap: 2px; padding: var(--space-3) var(--space-4) var(--space-4); }
  .shoe-card__title { font-size: 16px; font-weight: 600; line-height: 1.3; }
  .shoe-card__subtitle { color: var(--ink-soft); font-size: 14px; }
  .shoe-card .badge { margin-top: var(--space-2); }

  .shoe-list {
    display: grid;
    gap: var(--space-2);

    .shoe-card {
      grid-template-columns: 72px 1fr;
      align-items: center;
      border-radius: var(--radius-m);
    }
    .shoe-card__media { height: 72px; }
    .shoe-card__body { padding: var(--space-2) var(--space-4); }
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 600;

    &::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
  }
  .badge--active { color: var(--status-active); }
  .badge--paused { color: var(--status-paused); }
  .badge--retired { color: var(--status-retired); }
  .badge--archived { color: var(--status-archived); }

  /* Shoe detail */
  .shoe-detail {
    display: grid;
    gap: var(--space-5);
  }

  .shoe-detail__photo {
    overflow: hidden;
    aspect-ratio: 4 / 3;
    margin-inline: calc(var(--gutter) * -1);
    background: var(--surface-sunken);

    img { width: 100%; height: 100%; object-fit: cover; }
  }

  .shoe-detail__placeholder {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--space-2);
    height: 100%;
    color: var(--ink-faint);

    .silhouette { width: 120px; color: var(--line); }
  }

  .shoe-detail__header { display: grid; justify-items: start; gap: var(--space-1); }
  .shoe-detail__subtitle { color: var(--ink-soft); font-size: 18px; }

  .shoe-detail__sections { display: grid; gap: var(--space-4); }

  @media (min-width: 720px) {
    .shoe-detail { grid-template-columns: 1.1fr 1fr; align-items: start; column-gap: var(--space-6); }
    .shoe-detail__photo { grid-row: span 2; margin-inline: 0; border-radius: var(--radius-l); aspect-ratio: 1; }
  }

  .panel {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-5);
    border-radius: var(--radius-l);
    background: var(--surface);
  }

  .facts { display: grid; }
  .facts__row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--line);
    &:last-child { border-bottom: 0; }

    dt { color: var(--ink-soft); }
    dd { font-weight: 500; text-align: right; }
    dd.is-empty { color: var(--ink-faint); font-weight: 400; }
  }

  .notes { white-space: pre-line; }

  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--line);

    form { display: contents; }
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Usage, sessions and diary (M2) */
@layer components {
  .label { color: var(--ink-soft); font-size: 14px; font-weight: 500; }

  .button--light { background: var(--paper); color: var(--ink); }
  .button-form { display: contents; }

  .chip--light {
    border-color: color-mix(in srgb, var(--on-primary) 40%, transparent);
    color: var(--on-primary);
  }

  .nudges { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }

  .wear-actions { display: flex; justify-content: flex-end; margin-bottom: var(--space-4); }

  .wearing-panel {
    display: grid;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
    padding: var(--space-5);
    border-radius: var(--radius-l);
    background: var(--primary);
    color: var(--on-primary);
    border-top: 4px solid var(--accent);

    .eyebrow { color: color-mix(in srgb, var(--on-primary) 80%, transparent); }
    form { display: contents; }
  }

  .wearing-panel__current { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
  .wearing-panel__shoe { font-family: var(--font-display); font-size: 24px; font-weight: 400; text-decoration: none; }
  .wearing-panel__since { margin-right: auto; opacity: 0.85; }
  .wearing-panel__label { font-weight: 600; }
  .wearing-panel__shoes { display: flex; flex-wrap: wrap; gap: var(--space-2); }

  .week {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
    margin-top: var(--space-3);
    color: var(--ink-soft);
  }
  .week__value { font-family: var(--font-display); font-size: 28px; font-weight: 400; color: var(--ink); }

  .attention {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-3);

    li {
      display: flex;
      justify-content: space-between;
      gap: var(--space-3);
      padding: var(--space-3) var(--space-4);
      border-radius: var(--radius-m);
      background: var(--surface);
      border-left: 4px solid var(--status-paused);
    }
    a { font-weight: 600; text-decoration: none; }
  }

  .badge--wearing { color: var(--primary); &::before { background: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); } }

  .shoe-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-2); }
  .shoe-card .shoe-card__meta .badge { margin-top: 0; }
  .shoe-card__distance { color: var(--ink-soft); font-size: 12px; font-weight: 600; }
  .wear-indicator { margin-top: var(--space-1); }

  /* 1–5 dots; --value sets how many are filled. */
  .dots {
    --size: 8px;
    display: inline-block;
    width: calc(var(--size) * 5 + 4px * 4);
    height: var(--size);
    background:
      radial-gradient(circle at calc(var(--size) / 2) 50%, var(--fill, var(--primary)) calc(var(--size) / 2 - 0.5px), transparent calc(var(--size) / 2)) 0 0 / calc(var(--size) + 4px) 100% repeat-x;
    mask: linear-gradient(90deg, #000 calc((var(--size) + 4px) * var(--value) - 4px), #0003 0);
  }
  .dots--wear { --fill: var(--accent-strong); }

  .meter {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-sunken);

    span { display: block; height: 100%; background: var(--status-active); }
    &.is-warning span { background: var(--danger); }
  }

  .history { display: grid; gap: var(--space-2); }

  .entries { display: grid; gap: var(--space-2); }

  .entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-m);
    background: var(--surface);
  }
  .entry__main { display: grid; gap: 2px; min-width: 0; }
  .entry__shoe { font-weight: 600; }
  .entry__meta { color: var(--ink-soft); font-size: 14px; }
  .entry__notes { color: var(--ink-faint); font-size: 14px; }
  .entry__edit { flex: none; color: var(--link); font-size: 14px; font-weight: 600; text-decoration: none; }

  .day { margin-top: var(--space-5); }
  .day__title { margin-bottom: var(--space-2); color: var(--ink-faint); font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }

  .diary { display: grid; gap: var(--space-3); padding: 0; list-style: none; }
  .diary__header { display: flex; justify-content: space-between; color: var(--ink-soft); }
  .diary__photos {
    display: flex;
    gap: var(--space-2);
    img { width: 72px; height: 72px; border-radius: var(--radius-s); object-fit: cover; }
  }

  .scores {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-2) var(--space-4);
  }
  .scores__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    dt { color: var(--ink-soft); font-size: 14px; }
  }

  .scale {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--line);
    &:last-child { border-bottom: 0; }
  }
  .scale__label { font-weight: 500; }
  .scale__options { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .scale__option {
    input { position: absolute; opacity: 0; pointer-events: none; }
    span {
      display: grid;
      place-items: center;
      min-width: 44px;
      min-height: 40px;
      padding: 0 var(--space-3);
      border: 1px solid var(--line);
      border-radius: 999px;
      cursor: pointer;
    }
    input:checked + span { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
    input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
  }

  @media (min-width: 720px) {
    .scale { grid-template-columns: 180px 1fr; align-items: center; }
  }

  .conflict { gap: var(--space-3); border-left: 4px solid var(--status-paused); }
  .conflict__question { margin: var(--space-5) 0 var(--space-3); }
  .choices { display: grid; gap: var(--space-4); margin-bottom: var(--space-5); }
  @media (min-width: 720px) { .choices { grid-template-columns: 1fr 1fr; } }
  .choice { align-content: start; }
  .choice__title { font-size: 18px; }
  .choice__label { font-weight: 600; font-size: 14px; }

  .timeline { display: grid; gap: var(--space-1); }
  .timeline__item {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    background: var(--surface-sunken);
    &.is-proposed { background: color-mix(in srgb, var(--accent) 30%, var(--surface)); }
  }
}

/* Statistics and charts (M3) */
@layer tokens {
  /* Categorical series, validated with the dataviz palette checks (light and
     dark, all pairs): at most three compared shoes. */
  :root {
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --series-1: #3987e5;
      --series-2: #d95926;
      --series-3: #199e70;
    }
  }
}

@layer components {
  .tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    margin-top: var(--space-4);
  }
  @media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

  .chart { position: relative; height: 240px; }
  .chart--short { height: 200px; }

  .chart-grid { display: grid; gap: var(--space-4); margin-top: var(--space-4); }
  @media (min-width: 900px) { .chart-grid { grid-template-columns: repeat(2, 1fr); } }

  .chart-card {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-l);
    background: var(--surface);

    figcaption { font-weight: 600; }
  }

  .table-wrap { overflow-x: auto; border-radius: var(--radius-l); background: var(--surface); }

  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;

    th, td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--line); }
    thead th { color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
    tbody tr:last-child > * { border-bottom: 0; }
    tbody th { color: var(--ink-soft); font-weight: 500; }
    .num { text-align: right; font-variant-numeric: tabular-nums; }
    a { font-weight: 600; text-decoration: none; }
  }
  .table--compare td { font-variant-numeric: tabular-nums; }

  .chips--wrap { flex-wrap: wrap; overflow: visible; }

  .chip--series {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);

    &[aria-pressed="true"] { border-color: var(--chip-color); background: transparent; color: var(--ink); }
    &:disabled { opacity: 0.45; cursor: not-allowed; }
  }

  .chip__swatch, .swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: var(--space-2);
    border-radius: 50%;
    background: var(--chip-color);
  }
  .chip__swatch { margin-right: 0; }

  .same-model { display: flex; flex-wrap: wrap; gap: var(--space-3); margin: var(--space-3) 0; }

  .link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--link);
    font-weight: 600;
  }
}

/* PWA offline mode (M4) */
@layer components {
  .offline-banner {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: var(--space-2) var(--gutter);
    background: var(--status-paused);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
  }

  /* Covers forms the shared views render after the check. */
  .is-offline main form :is(button, input[type="submit"]) { opacity: 0.45; pointer-events: none; }
}

/* Inside the iOS app (M4): the native tab bar and title bar take over. */
@layer layout {
  .app--native .page { padding-bottom: var(--space-6); }
  .app--native .topbar .brand { visibility: hidden; }
}

/* Sync conflicts and devices (M5) */
@layer components {
  .topbar form { display: contents; }

  .pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    border-radius: 999px;
    background: color-mix(in srgb, var(--status-paused) 18%, var(--surface));
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
  }
  .pill__count { padding: 0 6px; border-radius: 999px; background: var(--status-paused); color: #fff; }

  .conflicts { display: grid; gap: var(--space-4); }
  .conflict__intro { margin-bottom: var(--space-4); }
  .proposal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    form { display: contents; }
  }
  .conflict > form { display: contents; }
}

/* Health queues (M7) */
@layer components {
  .queue-links { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
  .entry--queue { flex-wrap: wrap; }
  .queue-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);

    select { min-height: 36px; padding: 0 var(--space-3); border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
  }
}

/* Reminders, insights, account (M9) */
@layer components {
  .reminders { display: grid; gap: var(--space-2); margin-bottom: var(--space-5); }
  .reminder {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-m);
    background: var(--surface);
    border-left: 4px solid var(--accent);
  }

  .insights {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-3);

    a {
      display: block;
      padding: var(--space-3) var(--space-4);
      border-radius: var(--radius-m);
      background: var(--surface);
      text-decoration: none;
    }
  }

  .prose {
    display: grid;
    gap: var(--space-3);
    max-width: 68ch;

    h2 { margin-top: var(--space-4); font-family: var(--font-display); font-size: 20px; }
    ul { padding-left: var(--space-5); list-style: disc; }
  }
}

/* Brand, central quick action and quick pick (docs/VISUAL-DIRECTION.md) */
@layer components {
  .brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--primary); }
  .brand__mark { width: 28px; height: 28px; }

  .page-title, .section__title, .panel__title, .auth__title, .empty__title, .choice__title { color: var(--ink); }

  .quick-action {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-top: -22px;
    border: 3px solid var(--paper);
    border-radius: 50%;
    background: var(--primary);
    box-shadow: var(--shadow);
    color: var(--on-primary);
    font-size: 30px;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
  }

  .nav--bottom { align-items: center; }

  @media (max-width: 719px) {
    .quick-action--top { display: none; }
  }

  .quick-pick { display: grid; gap: var(--space-2); }
  @media (min-width: 720px) { .quick-pick { grid-template-columns: repeat(2, 1fr); } }

  .quick-pick__hint { margin-bottom: var(--space-3); }

  .quick-pick__shoe {
    display: grid;
    grid-template-columns: 64px 1fr;
    align-items: center;
    gap: var(--space-4);
    width: 100%;
    min-height: 80px;
    padding: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius-m);
    background: var(--surface);
    text-align: left;

    &:hover { border-color: var(--accent); }
  }

  .quick-pick__media {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    overflow: hidden;
    border-radius: var(--radius-s);
    background: var(--surface-sunken);
    color: var(--line);

    img { width: 100%; height: 100%; object-fit: cover; }
    .silhouette { width: 60%; }
  }

  .quick-pick__text { display: grid; gap: 2px; }
}

@layer components {
  .source { display: block; color: var(--ink-faint); font-size: 12px; font-weight: 500; }
}

@layer components {
  .barcode-field {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);

    input {
      flex: 1 1 180px;
      min-height: 44px;
      padding: var(--space-2) var(--space-3);
      border: 1px solid var(--line);
      border-radius: var(--radius-s);
      background: var(--paper);
      font-variant-numeric: tabular-nums;
      letter-spacing: 0.04em;
    }
  }
  .lookup-status:empty { display: none; }

  .search-results {
    display: grid;
    gap: var(--space-2);
    margin: var(--space-3) 0 0;
    padding: 0;
    list-style: none;

    button {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      width: 100%;
      min-height: 44px;
      padding: var(--space-2) var(--space-3);
      border: 1px solid var(--line);
      border-radius: var(--radius-s);
      background: transparent;
      color: inherit;
      font: inherit;
      text-align: left;
      cursor: pointer;
    }

    img { width: 48px; height: 48px; object-fit: contain; border-radius: 4px; }
    small { display: block; opacity: 0.75; }
  }
}
