@layer components {
  /* ---------- Card ---------- */
  .card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-card);
    min-width: 0;
  }
  .card__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--card-head-h);
    padding: var(--space-3) var(--card-pad);
    border-bottom: 1px solid var(--border);
  }
  .card__title {
    flex: 1;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
  }
  .card__body {
    padding: var(--card-pad);
  }
  .card__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--card-pad);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  @media (max-width: 640px) {
    .card__header,
    .card__body,
    .card__footer {
      padding-inline: var(--space-4);
    }
  }

  /* ---------- Badge & status chip ---------- */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 20px;
    padding: 0 var(--space-1-5);
    border-radius: var(--radius-sm);
    background: var(--tone-neutral-bg);
    color: var(--tone-neutral-fg);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .badge--count {
    min-width: 20px;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--accent-contrast);
  }
  .chip {
    --chip-bg: var(--tone-neutral-bg);
    --chip-fg: var(--tone-neutral-fg);
    --chip-dot: var(--tone-neutral-dot);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    height: 22px;
    padding: 0 var(--space-2) 0 var(--space-1-5);
    border-radius: var(--radius-full);
    background: var(--chip-bg);
    color: var(--chip-fg);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
  }
  .chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chip-dot);
  }
  .chip--outline {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--border-strong);
  }
  .chip--lg {
    height: 28px;
    padding-inline: var(--space-2-5) var(--space-3);
    font-size: var(--text-sm);
  }
  [data-tone="blue"] {
    --chip-bg: var(--tone-blue-bg);
    --chip-fg: var(--tone-blue-fg);
    --chip-dot: var(--tone-blue-dot);
  }
  [data-tone="teal"] {
    --chip-bg: var(--tone-teal-bg);
    --chip-fg: var(--tone-teal-fg);
    --chip-dot: var(--tone-teal-dot);
  }
  [data-tone="violet"] {
    --chip-bg: var(--tone-violet-bg);
    --chip-fg: var(--tone-violet-fg);
    --chip-dot: var(--tone-violet-dot);
  }
  [data-tone="green"] {
    --chip-bg: var(--tone-green-bg);
    --chip-fg: var(--tone-green-fg);
    --chip-dot: var(--tone-green-dot);
  }
  [data-tone="amber"] {
    --chip-bg: var(--tone-amber-bg);
    --chip-fg: var(--tone-amber-fg);
    --chip-dot: var(--tone-amber-dot);
  }
  [data-tone="red"] {
    --chip-bg: var(--tone-red-bg);
    --chip-fg: var(--tone-red-fg);
    --chip-dot: var(--tone-red-dot);
  }
  .badge[data-tone] {
    background: var(--chip-bg);
    color: var(--chip-fg);
  }

  /* ---------- Alert (inline message) ---------- */
  .alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--alert-border, var(--border));
    border-radius: var(--radius-md);
    background: var(--alert-bg, var(--surface-2));
    color: var(--text);
    font-size: var(--text-sm);
  }
  .alert > .icon {
    margin-top: 1px;
    color: var(--alert-icon, var(--info));
  }
  .alert__title {
    font-weight: var(--weight-semibold);
  }
  .alert__body {
    flex: 1;
    min-width: 0;
  }
  .alert__body p {
    color: var(--text-muted);
  }
  .alert--info {
    --alert-bg: var(--info-soft);
    --alert-border: var(--cobalt-100);
    --alert-icon: var(--info);
  }
  .alert--success {
    --alert-bg: var(--success-soft);
    --alert-border: var(--green-100);
    --alert-icon: var(--success);
  }
  .alert--warning {
    --alert-bg: var(--warning-soft);
    --alert-border: var(--amber-100);
    --alert-icon: var(--warning-text);
  }
  .alert--error {
    --alert-bg: var(--danger-soft);
    --alert-border: var(--red-100);
    --alert-icon: var(--danger);
  }

  /* ---------- Kbd ---------- */
  .kbd {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    justify-content: center;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--surface);
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
  }

  /* ---------- Avatar ---------- */
  .avatar {
    --avatar-size: 32px;
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    background: var(--avatar-bg, var(--cobalt-100));
    color: var(--avatar-fg, var(--cobalt-800));
    font-size: calc(var(--avatar-size) * 0.4);
    font-weight: var(--weight-semibold);
    line-height: 1;
    letter-spacing: -0.02em;
    overflow: hidden;
    user-select: none;
  }
  .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .avatar--sm {
    --avatar-size: 24px;
  }
  .avatar--lg {
    --avatar-size: 40px;
  }
  .avatar--xl {
    --avatar-size: 56px;
  }
  .avatar[data-hue="0"] {
    --avatar-bg: var(--cobalt-100);
    --avatar-fg: var(--cobalt-800);
  }
  .avatar[data-hue="1"] {
    --avatar-bg: var(--teal-100);
    --avatar-fg: var(--teal-700);
  }
  .avatar[data-hue="2"] {
    --avatar-bg: var(--violet-100);
    --avatar-fg: var(--violet-700);
  }
  .avatar[data-hue="3"] {
    --avatar-bg: var(--amber-100);
    --avatar-fg: var(--amber-700);
  }
  .avatar[data-hue="4"] {
    --avatar-bg: var(--green-100);
    --avatar-fg: var(--green-700);
  }
  .avatar[data-hue="5"] {
    --avatar-bg: var(--red-100);
    --avatar-fg: var(--red-700);
  }
  .avatar-group {
    display: inline-flex;
  }
  .avatar-group > .avatar {
    box-shadow: 0 0 0 2px var(--surface);
  }
  .avatar-group > .avatar + .avatar {
    margin-inline-start: -8px;
  }

  /* ---------- Tabs ---------- */
  .tabs__list {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs__tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
    height: calc(var(--control-h) + 4px);
    padding: 0 var(--space-3);
    color: var(--text-muted);
    font-size: var(--control-font);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }
  .tabs__tab::after {
    content: "";
    position: absolute;
    inset: auto var(--space-2) -1px;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: transparent;
    transition: background-color var(--dur) var(--ease);
  }
  .tabs__tab:hover {
    color: var(--text);
  }
  .tabs__tab[aria-selected="true"] {
    color: var(--text);
  }
  .tabs__tab[aria-selected="true"]::after {
    background: var(--accent);
  }
  .tabs__tab:focus-visible {
    outline: none;
    box-shadow: inset var(--focus-ring);
  }
  .tabs__tab[aria-disabled="true"] {
    color: var(--text-disabled);
    cursor: not-allowed;
  }
  .tabs__panel {
    padding-top: var(--space-4);
  }
  .tabs__panel:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
  }

  /* ---------- Stepper ---------- */
  .stepper {
    display: flex;
    gap: var(--space-2);
    counter-reset: step;
    list-style: none;
    padding: 0;
  }
  .stepper__step {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2-5);
    min-width: 0;
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .stepper__step:not(:last-child)::after {
    content: "";
    flex: 1;
    min-width: var(--space-4);
    height: 2px;
    border-radius: 2px;
    background: var(--border-strong);
  }
  .stepper__step[data-state="done"]:not(:last-child)::after {
    background: var(--accent);
  }
  .stepper__marker {
    display: grid;
    place-items: center;
    flex: none;
    width: 28px;
    height: 28px;
    border: 1.5px solid var(--border-input);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
  }
  .stepper__label {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .stepper__title {
    font-weight: var(--weight-medium);
    color: inherit;
  }
  .stepper__desc {
    font-size: var(--text-xs);
    color: var(--text-subtle);
  }
  .stepper__step[data-state="current"] {
    color: var(--text);
  }
  .stepper__step[data-state="current"] .stepper__marker {
    border-color: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 0 0 4px var(--accent-soft);
  }
  .stepper__step[data-state="done"] .stepper__marker {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-contrast);
  }
  .stepper__step[data-state="error"] .stepper__marker {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger-text);
  }
  @media (max-width: 640px) {
    .stepper__step:not([data-state="current"]) .stepper__label {
      display: none;
    }
  }

  /* ---------- Progress ---------- */
  .progress {
    display: flex;
    flex-direction: column;
    gap: var(--space-1-5);
  }
  .progress__meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: var(--text-sm);
  }
  .progress__label {
    color: var(--text);
    font-weight: var(--weight-medium);
  }
  .progress__value {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
  }
  .progress__track {
    position: relative;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    overflow: hidden;
  }
  .progress--sm .progress__track {
    height: 4px;
  }
  .progress__bar {
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: var(--progress-color, var(--accent));
    transform-origin: left;
    transform: scaleX(var(--progress, 0));
    transition: transform var(--dur-slow) var(--ease);
  }
  .progress[data-tone="success"] {
    --progress-color: var(--success);
  }
  .progress[data-tone="warning"] {
    --progress-color: var(--warning);
  }
  .progress[data-tone="danger"] {
    --progress-color: var(--danger);
  }
  .progress[data-tone="teal"] {
    --progress-color: var(--secondary);
  }
  .progress--indeterminate .progress__bar {
    width: 40%;
    transform: none;
    animation: ui-indeterminate 1.3s var(--ease) infinite;
  }
  @keyframes ui-indeterminate {
    from {
      margin-left: -40%;
    }
    to {
      margin-left: 100%;
    }
  }
  .progress-stack {
    display: flex;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    overflow: hidden;
    gap: 2px;
  }

  /* ---------- Skeleton ---------- */
  .skeleton {
    display: block;
    height: 0.9em;
    border-radius: var(--radius-sm);
    background: linear-gradient(
      90deg,
      var(--surface-sunken) 0%,
      var(--n-50) 45%,
      var(--surface-sunken) 90%
    );
    background-size: 300% 100%;
    animation: ui-shimmer 1.6s ease-in-out infinite;
  }
  .skeleton--title {
    height: 1.4em;
    width: 40%;
  }
  .skeleton--line {
    width: 100%;
  }
  .skeleton--short {
    width: 60%;
  }
  .skeleton--circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
  }
  .skeleton--block {
    height: 120px;
    border-radius: var(--radius-md);
  }
  @keyframes ui-shimmer {
    from {
      background-position: 100% 0;
    }
    to {
      background-position: -50% 0;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    .skeleton {
      animation: none;
    }
  }

  /* ---------- Empty state ---------- */
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-12) var(--space-6);
    text-align: center;
  }
  .empty__icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-3);
    border-radius: var(--radius-xl);
    background: linear-gradient(145deg, var(--accent-soft), var(--secondary-soft));
    color: var(--accent);
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.7), 0 8px 20px -10px var(--accent);
    animation: ui-float 4s ease-in-out infinite;
  }
  .empty__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
  }
  .empty__text {
    max-width: 52ch;
    color: var(--text-muted);
    font-size: var(--text-base);
  }
  .empty__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-3);
  }
  .empty--compact {
    padding: var(--space-6) var(--space-4);
  }
  .empty--compact .empty__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
  }

  /* ---------- Reports ---------- */
  .reports {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: var(--section-gap);
  }
  /* One anatomy for every report: title, a line of what it is, the content, the action below. */
  .report {
    display: flex;
    flex-direction: column;
  }
  .report > .card__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--space-4);
  }
  .report__lead {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .report__list {
    display: flex;
    flex-direction: column;
    margin-block: calc(var(--space-2) * -1);
  }
  .report__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    border-bottom: 1px solid var(--border);
  }
  .report__item:last-child {
    border-bottom: 0;
  }
  .report__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .report__note {
    color: var(--text-subtle);
    font-size: var(--text-xs);
  }
  .report__empty {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .report__empty .icon {
    flex: none;
    color: var(--text-subtle);
  }

  /* ---------- Audit log: a feed of days and rows ---------- */
  .journal-filters {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-bottom: var(--section-gap);
  }
  .journal-filters__fields {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    align-items: end;
  }
  .journal-region {
    position: relative;
  }
  .journal-region.htmx-request .journal {
    opacity: 0.55;
    transition: opacity var(--dur) var(--ease);
  }
  .journal {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-card);
    overflow: clip;
  }
  .journal__day {
    padding: var(--space-2) var(--card-pad);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
  }
  .journal__day:not(:first-child) {
    border-top: 1px solid var(--border);
    margin-top: -1px;
  }
  .journal__day-title {
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .journal__row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--space-1) var(--space-3);
    align-items: start;
    padding: var(--space-3) var(--card-pad);
  }
  .journal__row + .journal__row {
    border-top: 1px solid var(--border);
  }
  .journal__icon[data-tone="neutral"] {
    --chip-bg: var(--tone-neutral-bg);
    --chip-fg: var(--tone-neutral-fg);
  }
  .journal__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--chip-bg);
    color: var(--chip-fg);
  }
  .journal__main {
    display: flex;
    flex-direction: column;
    gap: var(--space-0-5);
    min-width: 0;
    padding-top: var(--space-0-5);
  }
  .journal__title {
    font-weight: var(--weight-medium);
  }
  .journal__times {
    margin-inline-start: var(--space-1);
    padding: 0 var(--space-1-5);
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
  }
  .journal__facts {
    color: var(--text-muted);
    font-size: var(--text-sm);
    overflow-wrap: anywhere;
  }
  .journal__fact + .journal__fact::before {
    content: "·";
    margin-inline: var(--space-1-5);
    color: var(--text-subtle);
  }
  .journal__label {
    color: var(--text-subtle);
  }
  .journal__fact--strong {
    color: var(--text);
    font-weight: var(--weight-medium);
  }
  .journal__fact--mono {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
  }
  .journal__fact--alert {
    color: var(--danger-text);
    font-weight: var(--weight-medium);
  }
  .journal__fact--quote {
    font-style: italic;
  }
  .journal__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-0-5);
    padding-top: var(--space-0-5);
    font-size: var(--text-sm);
    text-align: end;
  }
  .journal__who {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 240px;
  }
  .journal__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .journal__who--system {
    color: var(--text-muted);
  }
  .journal__when {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0 var(--space-2);
    color: var(--text-subtle);
    font-size: var(--text-xs);
  }
  .journal__ip::before {
    content: "·";
    margin-inline-end: var(--space-2);
  }
  .journal__fold {
    margin-top: var(--space-1);
    font-size: var(--text-sm);
  }
  .journal__fold > summary {
    width: fit-content;
    border-radius: var(--radius-sm);
    color: var(--accent-text);
    cursor: pointer;
  }
  .journal__fold > summary:focus-visible {
    box-shadow: var(--focus-ring);
    outline: none;
  }
  .journal__items {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    max-height: 320px;
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    overflow-y: auto;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
  }
  .journal__items > li {
    display: flex;
    gap: var(--space-3);
  }
  .journal__item-time {
    flex: none;
    color: var(--text-subtle);
    font-size: var(--text-xs);
    line-height: inherit;
  }
  .journal__items-more {
    color: var(--text-subtle);
  }
  .journal__next {
    display: flex;
    justify-content: center;
    padding: var(--space-3);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
  }
  /* The preview on the reports page: no frame, the date with the time. */
  .journal--compact {
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    margin-block: calc(var(--space-2) * -1);
  }
  .journal--compact .journal__row {
    padding-inline: 0;
  }
  .journal--compact .journal__facts {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  @media (max-width: 640px) {
    .journal__row {
      grid-template-columns: auto minmax(0, 1fr);
    }
    .journal__meta {
      grid-column: 2;
      flex-flow: row wrap;
      align-items: center;
      gap: var(--space-1) var(--space-3);
      text-align: start;
    }
    .journal__day,
    .journal__row {
      padding-inline: var(--space-4);
    }
  }

  /* ---------- What next ---------- */
  .next-step {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--accent-soft);
    border-radius: var(--radius-lg);
    background: linear-gradient(100deg, var(--accent-soft), var(--surface) 60%);
  }
  .next-step__icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--accent-contrast);
  }
  .next-step__eyebrow {
    color: var(--accent);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .next-step__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
  }
  .next-step__text {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .next-step__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  @media (max-width: 640px) {
    .next-step {
      grid-template-columns: auto 1fr;
    }
    .next-step__actions {
      grid-column: 1 / -1;
    }
  }

  /* ---------- Bulk action bar ---------- */
  .bulk-bar {
    position: sticky;
    bottom: var(--space-4);
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: fit-content;
    max-width: 100%;
    margin: var(--space-4) auto 0;
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--surface-inverse);
    color: var(--text-inverse);
    box-shadow: var(--shadow-3);
    font-size: var(--text-sm);
    animation: ui-toast-in var(--dur-slow) var(--ease);
  }
  .bulk-bar__count {
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .bulk-bar__actions {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
  }
  .bulk-bar .btn--ghost {
    --btn-fg: var(--n-200);
    --btn-bg-hover: rgb(255 255 255 / 0.1);
    --btn-bg-active: rgb(255 255 255 / 0.16);
  }
  .bulk-bar .btn--ghost:hover {
    color: var(--n-0);
  }
}

@layer components {
  /* ---------- DataTable ---------- */
  .dtable {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
  }
  .dtable__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }
  .dtable__search {
    flex: 1 1 260px;
    max-width: 480px;
  }
  .dtable__region {
    position: relative;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-card);
    overflow: hidden;
  }
  .dtable__region::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    z-index: 3;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--secondary));
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
  }
  .dtable__region.htmx-request::before {
    opacity: 1;
    animation: ui-table-loading 1.2s var(--ease) infinite;
  }
  .dtable__region.htmx-request tbody {
    opacity: 0.55;
    transition: opacity var(--dur) var(--ease);
  }
  @keyframes ui-table-loading {
    0% {
      transform: scaleX(0);
    }
    60% {
      transform: scaleX(0.8);
    }
    100% {
      transform: scaleX(1);
      opacity: 0;
    }
  }
  .dtable__scroll {
    max-height: max(420px, calc(100dvh - 300px));
    overflow: auto;
    overscroll-behavior-x: contain;
  }
  .dtable__scroll:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
  .dtable__table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--control-font);
  }
  .dtable__table th {
    position: sticky;
    top: 0;
    z-index: 2;
    height: calc(var(--row-h) - 6px);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-subtle);
    font-size: 0.75rem;
    font-weight: var(--weight-semibold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: start;
    white-space: nowrap;
  }
  .dtable__table tbody tr {
    position: relative; /* anchors the .row-link overlay */
  }
  .dtable__table td {
    height: var(--row-h);
    padding: var(--space-1) var(--space-4);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    transition: background-color var(--dur-fast) var(--ease);
  }
  .dtable__table tbody tr:last-child td {
    border-bottom: 0;
  }
  /* A totals row: not sticky like the header, set apart by a line. */
  .dtable__table tfoot th,
  .dtable__table tfoot td {
    position: static;
    height: var(--row-h);
    border-top: 1px solid var(--border-strong);
    border-bottom: 0;
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--control-font);
    font-weight: var(--weight-semibold);
    letter-spacing: normal;
    text-transform: none;
  }
  .dtable__table tbody tr:hover td {
    background: var(--surface-hover);
  }
  .dtable__table tbody tr:has(.row-link) {
    cursor: pointer;
  }
  .dtable__table tbody tr:has(.row-link:focus-visible) td {
    background: var(--accent-soft);
  }
  /* The row's main link covers the whole row; controls inside the row stay on top of it. */
  .row-link {
    color: var(--text);
    font-weight: var(--weight-semibold);
    text-decoration: none;
  }
  .row-link::after {
    content: "";
    position: absolute;
    inset: 0;
  }
  .row-link:hover,
  tr:hover .row-link {
    color: var(--accent-text);
  }
  .row-link:focus-visible {
    outline: none;
  }
  /* Controls in later cells paint above the overlay by DOM order. No z-index here: it would
     trap their dropdown menus under the sticky header. */
  .dtable__table .row-actions,
  .dtable__table td a:not(.row-link),
  .dtable__table td button {
    position: relative;
  }
  .dtable__table .dtable__select > *,
  .dtable__table .dtable__copy {
    position: relative;
    z-index: 1;
  }
  .dtable__table tbody tr:has([data-select-item]:checked) td {
    background: var(--accent-soft);
  }
  .dtable__table [data-align="end"] {
    text-align: end;
  }
  .dtable__table td[data-kind="number"] {
    font-variant-numeric: tabular-nums;
  }
  .dtable__table td[data-kind="mono"] {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
  }
  .dtable__select {
    width: 1%;
    padding-inline-end: 0 !important;
  }
  .dtable__select .check__input {
    margin-top: 0;
  }
  .dtable__sort {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: inherit;
    text-decoration: none;
  }
  .dtable__sort:hover {
    color: var(--text);
  }
  .dtable__sort:focus-visible {
    outline: none;
    border-radius: 4px;
    box-shadow: var(--focus-ring);
  }
  .dtable__sort-icon {
    opacity: 0.45;
  }
  th[aria-sort] .dtable__sort {
    color: var(--text);
  }
  th[aria-sort] .dtable__sort-icon {
    opacity: 1;
    color: var(--accent);
  }
  .dtable__copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-inline-start: var(--space-1-5);
    border-radius: 4px;
    color: var(--text-subtle);
    vertical-align: middle;
    opacity: 0;
  }
  .dtable__table tr:hover .dtable__copy,
  .dtable__copy:focus-visible {
    opacity: 1;
  }
  .dtable__copy:hover {
    background: var(--surface-active);
    color: var(--text);
  }
  .dtable__copy:focus-visible {
    outline: 2px solid var(--accent);
  }
  @media (hover: none) {
    .dtable__copy {
      opacity: 1;
    }
  }
  .dtable__table td.dtable__empty {
    height: auto;
    padding: var(--space-6) var(--space-4);
    white-space: normal;
  }
  .dtable__table td.dtable__empty:hover {
    background: none;
  }
  .dtable__footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2-5) var(--space-4);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
}

@layer components {
  /* ---------- Stat tile ---------- */
  .stat {
    --stat-fg: var(--tone-blue-fg);
    --stat-bg: var(--tone-blue-bg);
    --stat-dot: var(--tone-blue-dot);
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "label icon"
      "value value"
      "hint hint";
    align-items: center;
    align-content: start;
    gap: var(--space-1) var(--space-3);
    min-width: 0;
    padding: var(--stat-pad);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-card);
    overflow: hidden;
  }
  .stat::after {
    content: "";
    position: absolute;
    inset: auto -30% -60% auto;
    width: 60%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--stat-dot) 16%, transparent), transparent);
    pointer-events: none;
  }
  .stat[data-tone="violet"] {
    --stat-fg: var(--tone-violet-fg);
    --stat-bg: var(--tone-violet-bg);
    --stat-dot: var(--tone-violet-dot);
  }
  .stat[data-tone="teal"] {
    --stat-fg: var(--tone-teal-fg);
    --stat-bg: var(--tone-teal-bg);
    --stat-dot: var(--tone-teal-dot);
  }
  .stat[data-tone="green"] {
    --stat-fg: var(--tone-green-fg);
    --stat-bg: var(--tone-green-bg);
    --stat-dot: var(--tone-green-dot);
  }
  .stat[data-tone="amber"] {
    --stat-fg: var(--tone-amber-fg);
    --stat-bg: var(--tone-amber-bg);
    --stat-dot: var(--tone-amber-dot);
  }
  .stat__label {
    grid-area: label;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
  }
  .stat__icon {
    grid-area: icon;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--stat-bg);
    color: var(--stat-fg);
  }
  .stat__value {
    grid-area: value;
    margin-top: var(--space-1);
    color: var(--text);
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.1;
  }
  .stat__hint {
    grid-area: hint;
    color: var(--text-subtle);
    font-size: var(--text-sm);
  }

  /* ---------- Meter: a single-series bar drawn as SVG (widths are attributes, not styles) ---------- */
  .meter {
    display: block;
    width: 100%;
    height: 8px;
    overflow: visible;
  }
  .meter__track {
    fill: var(--surface-sunken);
  }
  .meter__fill {
    fill: var(--accent);
    transform-box: fill-box;
    transform-origin: left center;
    animation: ui-grow-x 1s var(--ease-out) 150ms both;
  }
  .meter--teal .meter__fill {
    fill: var(--secondary);
  }

  /* ---------- Dashboard ---------- */
  .dash-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: var(--stack-gap);
    margin-bottom: var(--stack-gap);
  }
  @media (max-width: 640px) {
    .dash-kpis {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--space-3);
    }
    .stat {
      padding: var(--space-4);
    }
    .stat__icon {
      width: 32px;
      height: 32px;
    }
    .stat__value {
      font-size: var(--text-xl);
    }
  }
  .dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
    gap: var(--stack-gap);
    margin-bottom: var(--stack-gap);
  }
  @media (max-width: 1100px) {
    .dash-grid {
      grid-template-columns: minmax(0, 1fr);
    }
  }
  .flow {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
  }
  .flow__step {
    display: grid;
    grid-template-columns: 12px minmax(110px, 0.6fr) minmax(80px, 2fr) 9ch 6ch;
    align-items: center;
    gap: var(--space-4);
    min-height: 44px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    transition: background-color var(--dur-fast) var(--ease);
  }
  .flow__step:hover {
    background: var(--surface-hover);
  }
  .flow__step:nth-child(2) .meter__fill {
    animation-delay: 220ms;
  }
  .flow__step:nth-child(3) .meter__fill {
    animation-delay: 290ms;
  }
  .flow__step:nth-child(4) .meter__fill {
    animation-delay: 360ms;
  }
  .flow__step:nth-child(5) .meter__fill {
    animation-delay: 430ms;
  }
  .flow__step:nth-child(6) .meter__fill {
    animation-delay: 500ms;
  }
  .flow__step:nth-child(7) .meter__fill {
    animation-delay: 570ms;
  }
  /* The dots are joined by a thin line: the order of the steps is the path of a code. */
  .flow__dot {
    position: relative;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--tone-neutral-dot);
    box-shadow: 0 0 0 3px var(--surface);
  }
  .flow__step:not(:last-child) .flow__dot::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 15px;
    width: 2px;
    height: 32px;
    border-radius: 1px;
    background: var(--border-strong);
  }
  .flow__dot[data-tone="blue"] {
    background: var(--tone-blue-dot);
  }
  .flow__dot[data-tone="teal"] {
    background: var(--tone-teal-dot);
  }
  .flow__dot[data-tone="violet"] {
    background: var(--tone-violet-dot);
  }
  .flow__dot[data-tone="green"] {
    background: var(--tone-green-dot);
  }
  .flow__dot[data-tone="amber"] {
    background: var(--tone-amber-dot);
  }
  .flow__dot[data-tone="red"] {
    background: var(--tone-red-dot);
  }
  .flow__label {
    font-weight: var(--weight-medium);
  }
  .flow__count {
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-semibold);
    text-align: end;
  }
  .flow__share {
    color: var(--text-subtle);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    text-align: end;
  }
  .flow-off {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-6);
    margin: var(--space-4) 0 0;
    padding: var(--space-4) var(--space-2) 0;
    border-top: 1px dashed var(--border-strong);
    list-style: none;
  }
  .flow-off li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
  }
  @media (max-width: 640px) {
    .flow__step {
      grid-template-columns: 12px minmax(0, 1fr) auto auto;
      grid-template-areas: "dot label count share" ". meter meter meter";
      row-gap: var(--space-1);
      padding-block: var(--space-2);
    }
    .flow__dot {
      grid-area: dot;
    }
    .flow__label {
      grid-area: label;
    }
    .flow__step .meter {
      grid-area: meter;
    }
    .flow__count {
      grid-area: count;
    }
    .flow__share {
      grid-area: share;
    }
    .flow__step:not(:last-child) .flow__dot::after {
      display: none;
    }
  }
  .pools {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin: 0;
  }
  .pools__item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-1-5) var(--space-3);
  }
  .pools__name {
    font-weight: var(--weight-medium);
  }
  .pools__count {
    font-variant-numeric: tabular-nums;
    font-weight: var(--weight-semibold);
  }
  .pools__item .meter {
    grid-column: 1 / -1;
  }
  /* Applied by day: one series, columns drawn as SVG (sizes are attributes, not styles). */
  .dash-days {
    display: flex;
    flex-direction: column;
  }
  .dash-days .card__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
  }
  .dash-days__total {
    margin: 0 0 var(--space-4);
  }
  .dash-days__value {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
  }
  .days {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-height: 148px;
    border-bottom: 1px solid var(--border);
  }
  .days__bar {
    fill: var(--tone-teal-dot);
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: ui-grow-y 0.8s var(--ease-out) 150ms backwards;
    transition: fill var(--dur) var(--ease);
  }
  .days__bar.is-today {
    fill: var(--accent);
  }
  .days__bar:hover {
    fill: var(--teal-600);
  }
  .days__axis {
    display: grid;
    grid-template-columns: repeat(14, minmax(0, 1fr));
    margin: var(--space-1-5) 0 0;
    padding: 0;
    list-style: none;
    color: var(--text-subtle);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }
  .days__axis .is-today {
    color: var(--text);
    font-weight: var(--weight-semibold);
  }
  @media (max-width: 480px) {
    .days__axis li:nth-child(even):not(.is-today) {
      visibility: hidden;
    }
  }

  /* Codes supply: buyer → GTIN against the work ahead. */
  .dash-supply,
  .dash-problems {
    margin-bottom: var(--stack-gap);
  }
  .dash-supply__note {
    margin: 0 0 var(--space-4);
  }
  .supply-scroll {
    overflow-x: auto;
  }
  .supply {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }
  .supply th,
  .supply td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
  }
  .supply thead th {
    color: var(--text-muted);
    font-weight: var(--weight-medium);
    white-space: nowrap;
  }
  .supply .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .supply__buyer th,
  .supply__buyer td {
    padding-top: var(--space-4);
    background: var(--surface-sunken);
    font-weight: var(--weight-semibold);
  }
  .supply__sku {
    display: flex;
    flex-direction: column;
    max-width: 320px;
    font-weight: var(--weight-regular);
  }
  .supply__gtin {
    color: var(--text-subtle);
    font-size: var(--text-xs);
  }

  /* Problems of the last days. */
  .week-problems {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .week-problems__item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--space-3);
  }
  .week-problems__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--chip-bg);
    color: var(--chip-fg);
  }
  .week-problems__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .week-problems__detail {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .week-problems__time {
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .dash-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: var(--stack-gap);
  }
  .dash-link {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6);
    color: var(--text);
    text-decoration: none;
  }
  .dash-link:hover {
    color: var(--text);
  }
  .dash-link:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }
  .dash-link__icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
  }
  .dash-link__text {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .dash-link__value {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    line-height: 1.15;
  }
  .dash-link__label {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .dash-link__go {
    color: var(--text-subtle);
    transition:
      transform var(--dur) var(--ease-out),
      color var(--dur) var(--ease);
  }
  .dash-link:hover .dash-link__go {
    color: var(--accent);
    transform: translateX(4px);
  }

  /* ---------- Integrations ---------- */
  .link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
    gap: var(--stack-gap);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .integration__name {
    font-weight: var(--weight-semibold);
  }
  .tokens {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .tokens__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
  }
  .tokens__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .tokens__name {
    font-weight: var(--weight-medium);
  }
  .token-value {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2) 0 0;
    overflow-wrap: anywhere;
  }
  .operator-requests {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    margin: var(--space-4) 0 0;
    padding: var(--space-4) 0 0;
    border-top: 1px solid var(--border);
    list-style: none;
  }

  /* ---------- Buyer portal ---------- */
  .portal-list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0 var(--space-5);
    list-style: none;
  }
  .portal-list__item {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-3) 0;
  }
  .portal-list__item + .portal-list__item {
    border-top: 1px solid var(--border);
  }
  .portal-list__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .portal-list__title {
    font-weight: var(--weight-medium);
  }
  .portal-list__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* ---------- Notifications ---------- */
  .notices {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .notice {
    --notice-dot: var(--tone-blue-dot);
  }
  .notice[data-tone="success"] {
    --notice-dot: var(--tone-green-dot);
  }
  .notice[data-tone="warning"] {
    --notice-dot: var(--tone-amber-dot);
  }
  .notice[data-tone="danger"] {
    --notice-dot: var(--tone-red-dot);
  }
  .notice__link {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-2-5) var(--space-2);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
  }
  .notice__link:hover {
    background: var(--surface-hover);
    color: var(--text);
  }
  .notice__link:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
  }
  .notice__dot {
    width: 8px;
    height: 8px;
    margin-top: 0.45em;
    border-radius: var(--radius-full);
    background: var(--notice-dot);
    opacity: 0.35;
  }
  .notice.is-unread .notice__dot {
    opacity: 1;
  }
  .notice__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .notice__title {
    font-weight: var(--weight-regular);
  }
  .notice.is-unread .notice__title {
    font-weight: var(--weight-semibold);
  }
  .notice__body {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .notice__time {
    color: var(--text-subtle);
    font-size: var(--text-xs);
  }
  .notices--page .notice + .notice {
    border-top: 1px solid var(--border);
  }
  .telegram-state {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-weight: var(--weight-medium);
  }
  .telegram-state__icon {
    color: var(--success);
  }
  .telegram-steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin: 0;
    padding-left: var(--space-5);
  }
  .telegram-code {
    padding: 2px var(--space-1-5);
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    overflow-wrap: anywhere;
  }

  /* ---------- First-run checklist ---------- */
  .setup {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.6fr);
    gap: var(--space-6) var(--space-10);
    margin-bottom: var(--stack-gap);
    padding: var(--space-8);
    border-color: var(--cobalt-200);
    background:
      radial-gradient(70% 120% at 0% 0%, var(--accent-soft), transparent 60%),
      var(--surface);
  }
  @media (max-width: 1100px) {
    .setup {
      grid-template-columns: minmax(0, 1fr);
      padding: var(--space-6);
    }
  }
  .setup__title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    letter-spacing: -0.02em;
  }
  .setup__text {
    margin-top: var(--space-3);
    color: var(--text-muted);
  }
  .setup__steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
  }
  .setup__step {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .setup__mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-text);
    font-weight: var(--weight-bold);
  }
  .setup__step.is-done .setup__mark {
    background: var(--success);
    color: var(--n-0);
  }
  .setup__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .setup__name {
    font-weight: var(--weight-semibold);
  }
  .setup__step.is-done .setup__name {
    color: var(--text-muted);
  }
  .setup__hint {
    color: var(--text-subtle);
    font-size: var(--text-sm);
  }
}

@layer components {
  /* ---------- Codes: import wizard ---------- */
  .page-section {
    margin-top: var(--section-gap);
  }
  .import-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: var(--stack-gap);
    align-items: start;
  }
  @media (max-width: 1100px) {
    .import-layout {
      grid-template-columns: minmax(0, 1fr);
    }
  }
  .import-guide {
    padding: var(--space-6);
    background:
      radial-gradient(90% 120% at 100% 0%, var(--accent-soft), transparent 65%),
      var(--surface);
  }
  .import-guide__title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--weight-medium);
    letter-spacing: -0.01em;
  }
  .import-guide__steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin: var(--space-5) 0 0;
    color: var(--text-muted);
  }
  .import-guide__steps li {
    display: flex;
    gap: var(--space-3);
  }
  .import-guide__steps b {
    color: var(--text);
  }
  .import-guide__num {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-text);
    font-weight: var(--weight-bold);
    font-size: var(--text-sm);
  }

  .batch-head .card__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
  }
  .batch-file {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-right: var(--space-3);
  }
  .batch-progress__note {
    margin-top: var(--space-3);
  }

  .problems {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
    gap: var(--stack-gap);
  }
  .problem {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
    border-top: 3px solid var(--chip-dot);
  }
  .problem__head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }
  .problem__title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
  }
  .problem__hint {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
  .problem__examples {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    font-size: var(--text-sm);
  }
  .problem__examples li {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .problem__where {
    color: var(--text-subtle);
    font-size: var(--text-xs);
  }
  .problem__code {
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
  }
  .problem__detail {
    color: var(--text-muted);
  }

  .gtin-list {
    overflow-x: auto;
  }
  .gtin-list td,
  .gtin-list th {
    vertical-align: middle;
  }
  .sku-proposals td {
    vertical-align: top;
    min-width: 8rem;
  }
  .gtin-sku {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1-5);
  }
  .gtin-sku__ok {
    color: var(--success);
  }
  .gtin-link {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-2);
  }
  .gtin-link__form {
    display: flex;
    flex: 1 1 320px;
    align-items: end;
    gap: var(--space-2);
    min-width: 0;
  }
  .gtin-link__form .field {
    flex: 1;
    min-width: 0;
  }
  .gtin-link__form .field__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .import-confirm {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-6);
    border-color: var(--cobalt-200);
    background:
      radial-gradient(70% 140% at 0% 0%, var(--accent-soft), transparent 60%),
      var(--surface);
  }
  .import-confirm__title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    letter-spacing: -0.02em;
  }
  .new-sku__lead {
    margin-bottom: var(--space-5);
  }

  /* ---------- Codes: pool and the code card ---------- */
  td[data-col="files"] .truncate {
    display: block;
    max-width: 32ch;
  }
  .pool-tip {
    display: flex;
    align-items: center;
    gap: var(--space-1-5);
    margin-bottom: var(--space-3);
  }
  @media (max-width: 640px) {
    .pool-tip {
      display: none;
    }
  }
  .code-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: var(--stack-gap);
    align-items: start;
  }
  @media (max-width: 1100px) {
    .code-layout {
      grid-template-columns: minmax(0, 1fr);
    }
  }
  .code-id .card__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
  }
  .code-id__top {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .code-id__cis {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xl);
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
  }
  .code-id__tail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1-5);
    color: var(--text-subtle);
    font-size: var(--text-sm);
  }
  .timeline {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    margin: 0;
  }
  .timeline__item {
    position: relative;
    display: flex;
    gap: var(--space-3);
  }
  .timeline__item:not(:last-child)::before {
    position: absolute;
    top: 18px;
    bottom: calc(-1 * var(--space-5));
    left: 6px;
    width: 2px;
    background: var(--border);
    content: "";
  }
  .timeline__dot {
    width: 14px;
    height: 14px;
    flex: none;
    margin-top: 4px;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--chip-dot, var(--tone-neutral-dot));
    box-shadow: 0 0 0 1px var(--border);
  }
  .timeline__title {
    font-weight: var(--weight-semibold);
  }
  .timeline__meta {
    color: var(--text-subtle);
    font-size: var(--text-sm);
  }
  .timeline__note {
    margin-top: var(--space-1);
    color: var(--text-muted);
    font-size: var(--text-sm);
  }
}

/* Settings → Organization: the current logo on a checkerboard of the surface. */
@layer components {
  .org-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }
  .org-logo__picture {
    max-width: 160px;
    max-height: 64px;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
  }
}

/* The bureau's factories table: every count is a button that opens the factory on its page. */
@layer components {
  .bureau__open,
  .bureau__count {
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    color: inherit;
    cursor: pointer;
    font: inherit;
    padding: var(--space-1) var(--space-2);
    margin: calc(-1 * var(--space-1)) calc(-1 * var(--space-2));
  }
  .bureau__open {
    font-weight: var(--weight-semibold);
    text-align: start;
  }
  .bureau__count {
    font-variant-numeric: tabular-nums;
  }
  .bureau__open:hover,
  .bureau__count:hover {
    background: var(--accent-soft);
    color: var(--accent-text);
  }
  .bureau__bad {
    color: var(--danger-text);
  }
  .bureau th[scope="row"] .chip {
    margin-inline-start: var(--space-2);
  }
}
