/* Nomios web UI: components (notices, pills, tiles, cards, charts). Design system: docs/design/DESIGN_SYSTEM.md.
   The four stylesheets are linked in this order: tokens, base, shell, components. */

@layer components {
  /* Page header: title, one quiet line of context, and the page's primary action. */
  .back-link {
    margin: 0 0 var(--space-3);
    font-size: var(--text-sm);
  }

  .page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3) var(--space-6);
    margin-bottom: var(--space-6);
  }

  .page-heading {
    flex: 1 1 22rem;
    min-width: 0;
  }

  .page-header h1 {
    margin: 0;
  }

  .page-subtitle {
    margin: var(--space-1) 0 0;
    max-width: 62ch;
    color: var(--color-text-muted);
  }

  .page-actions {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  /* Key figures at the top of a detail page: the few numbers to read first. */
  .figures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: var(--space-3);
    margin: 0 0 var(--space-6);
  }

  .figure {
    display: grid;
    align-content: start;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    background: var(--glass-raised-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: inset 0 1px 0 var(--glass-highlight);
  }

  .figure dt {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .figure dd {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: 650;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
  }

  .figure .pill {
    font-size: var(--text-base);
  }

  .figure .badge,
  .figure-note {
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--color-text-muted);
  }

  /* The sections of the run page are cards on the page's glass. */
  #run-live > section {
    overflow-x: auto; /* a wide table scrolls inside its card instead of poking out */
    margin-bottom: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--color-column);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
  }

  #run-live > section > h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-lg);
  }

  #run-live > section > :last-child {
    margin-bottom: 0;
  }

  /* Label and value tables: labels muted, values in the normal colour. */
  .facts th {
    width: 14rem;
    font-weight: 600;
    color: var(--color-text-muted);
  }

  /* Status pill: a word, a dot and a tint in one of the fixed status colours. The text keeps the
     normal text colour so contrast never depends on the status colour. */
  .pill {
    --pill: var(--status-neutral);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3) 0 var(--space-2);
    min-height: 1.5rem;
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1.5rem;
    white-space: nowrap;
    color: var(--color-text);
    background: color-mix(in srgb, var(--pill) calc(var(--pill-alpha) * 100%), transparent);
    border: 1px solid color-mix(in srgb, var(--pill) 55%, transparent);
    border-radius: var(--radius-pill);
  }

  .pill::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    flex: none;
    background: var(--pill);
    border-radius: 50%;
  }

  .pill-running {
    --pill: var(--status-running);
  }

  .pill-awaiting {
    --pill: var(--status-awaiting);
  }

  .pill-succeeded {
    --pill: var(--status-succeeded);
  }

  .pill-failed {
    --pill: var(--status-failed);
  }

  .pill-neutral {
    --pill: var(--status-neutral);
  }

  /* Notices: neutral by default; a coloured edge marks info, warning or error. */
  .notice {
    --notice: var(--color-border-strong);
    padding: var(--space-3) var(--space-4);
    background: var(--color-sunken);
    border: 1px solid var(--color-border);
    border-inline-start: 3px solid var(--notice);
    border-radius: var(--radius-md);
  }

  .notice-info {
    --notice: var(--status-running);
  }

  .notice-warn {
    --notice: var(--status-awaiting);
  }

  .notice-error {
    --notice: var(--status-failed);
  }

  .error {
    color: var(--status-failed);
    font-weight: 600;
  }

  .note,
  .gap-note,
  .empty,
  .paging {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  /* Empty states: say what is missing and, where there is one, what to do next. */
  .empty {
    padding: var(--space-3) var(--space-4);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
  }

  .empty-state {
    margin-bottom: var(--space-4);
    padding: var(--space-8) var(--space-6);
    text-align: center;
    color: var(--color-text-muted);
    background: var(--color-column);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
  }

  .empty-state p {
    margin: 0 0 var(--space-3);
  }

  .empty-title {
    font-size: var(--text-lg);
    font-weight: 650;
    color: var(--color-text);
  }

  .gap-reason {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  /* New run: starting a pipeline and the orders in one panel. */
  .new-run {
    margin-bottom: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: var(--color-column);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
  }

  .new-run > h2 {
    margin: 0 0 var(--space-3);
  }

  .new-run h3 {
    margin: 0 0 var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
  }

  .new-run .entries,
  .new-run .fields {
    display: grid;
    gap: var(--space-3);
    margin: 0 0 var(--space-3);
    padding: 0;
    list-style: none;
  }

  .new-run .entries li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .new-run .fields li {
    display: grid;
    gap: var(--space-1);
  }

  /* The cost panel: the same key figures, one under the other. */
  .figures-stack {
    grid-template-columns: minmax(0, 1fr);
    margin-bottom: var(--space-3);
  }

  #cost-counter > h2 {
    margin: 0 0 var(--space-3);
  }

  .figures-stack dd {
    display: grid;
    gap: var(--space-1);
    font-size: var(--text-base);
  }

  .figure-line {
    display: block;
  }

  .figure-empty {
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--color-text-muted);
  }

  /* The team view's person list (a plain form): a wrapped row of checkboxes. */
  .team-form .choices {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    margin: 0 0 var(--space-3);
    padding: 0;
    list-style: none;
  }

  .gap {
    color: var(--status-awaiting);
  }

  .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: center;
    margin: var(--space-4) 0;
  }

  /* As many columns as fit with room for a card (4 on a wide screen, 2 beside the cost panel). */
  .columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
    gap: var(--space-4);
  }

  .column {
    min-width: 0;
    padding: var(--space-3);
    background: var(--color-column);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
  }

  .column > h2 {
    margin: var(--space-1) var(--space-2) var(--space-3);
    font-size: var(--text-base);
  }

  .columns-single {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Summary tiles: the size of each column, and a plain link that filters the board to it. */
  .tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-5);
  }

  .tile {
    --tile: var(--status-neutral);
    display: grid;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    color: var(--color-text);
    text-decoration: none;
    background: var(--glass-raised-bg);
    border: 1px solid var(--color-border);
    border-inline-start: 3px solid var(--tile);
    border-radius: var(--radius-md);
    box-shadow: inset 0 1px 0 var(--glass-highlight);
    transition:
      transform var(--dur-fast) var(--ease-spring),
      border-color var(--dur-fast) var(--ease-standard),
      background-color var(--dur-fast) var(--ease-standard);
  }

  .tile:hover {
    transform: translateY(var(--lift));
    border-color: var(--color-border-strong);
    border-inline-start-color: var(--tile);
  }

  .tile:active {
    transform: scale(var(--press-scale));
  }

  .tile.is-active {
    border-color: var(--color-accent);
    border-inline-start-color: var(--tile);
    background: var(--glass-bg);
  }

  .tile-running {
    --tile: var(--status-running);
  }

  .tile-awaiting {
    --tile: var(--status-awaiting);
  }

  .tile-succeeded {
    --tile: var(--status-succeeded);
  }

  .tile-failed {
    --tile: var(--status-failed);
  }

  .tile-count {
    font-size: var(--text-2xl);
    font-weight: 650;
    line-height: 1;
    font-variant-numeric: tabular-nums;
  }

  .tile-title {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  .count {
    font-weight: 400;
    color: var(--color-text-muted);
  }

  .cards {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: var(--space-3);
  }

  .card {
    min-width: 0;
    background: var(--glass-raised-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    box-shadow: inset 0 1px 0 var(--glass-highlight);
  }

  .card h3 {
    font-size: 0.95rem;
    margin: 0 0 var(--space-1);
  }

  /* A run card: title, status and date, then four small figures. Compact, never wider than it is. */
  .run {
    display: grid;
    gap: var(--space-2);
  }

  .run-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-2);
  }

  .run-head h3 {
    margin: 0;
    overflow-wrap: anywhere;
  }

  .run-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
  }

  .run-time {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
  }

  .run-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2) var(--space-3);
    margin: 0;
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
  }

  .run-stats div {
    min-width: 0;
  }

  .run-stats dt {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .run-stats dd {
    margin: 0;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
  }

  /* One column chosen: the figures spread over the card's width; on a wide card the whole run is
     one line (a container query, so it follows the card, not the window). */
  .columns-single .card {
    container-type: inline-size;
  }

  .columns-single .run-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  @container (min-width: 46rem) {
    .columns-single .run {
      grid-template-columns: minmax(6rem, 1fr) 16rem minmax(0, 3fr); /* fixed: rows align */
      align-items: center;
      gap: var(--space-2) var(--space-5);
    }

    .columns-single .run-stats {
      padding-top: 0;
      border-top: 0;
    }
  }

  .badge {
    font-size: var(--text-xs);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-pill);
    padding: 0 var(--space-2);
  }

  .badge-mock {
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .period-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: center;
    margin: var(--space-2) 0;
  }

  .period-nav a[aria-current="page"] {
    font-weight: 700;
    text-decoration: none;
    border-bottom: 2px solid currentcolor;
  }

  .tabs {
    display: flex;
    gap: var(--space-4);
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    list-style: none;
    padding: 0;
    margin: var(--space-3) 0;
  }

  .swatch {
    display: inline-block;
    width: 0.8rem;
    height: 0.8rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 3px;
    vertical-align: baseline;
  }

  .chart {
    max-width: 100%;
    height: auto;
    margin: var(--space-2) 0;
  }

  .chart-label,
  .chart-value,
  .chart-tick {
    font-size: 12px;
    fill: currentcolor;
    font-family: var(--font-sans);
  }

  .chart-tick {
    text-anchor: middle;
  }

  .axis {
    stroke: currentcolor;
    stroke-width: 1;
    opacity: 0.5;
  }

  .bar {
    stroke: var(--color-border-strong);
    stroke-width: 1;
  }

  .bar-project {
    fill: var(--chart-neutral);
  }

  /* One fixed colour per client; the values live in the tokens layer. */
  .client-1 {
    fill: var(--client-1);
    background-color: var(--client-1);
  }

  .client-2 {
    fill: var(--client-2);
    background-color: var(--client-2);
  }

  .client-3 {
    fill: var(--client-3);
    background-color: var(--client-3);
  }

  .client-4 {
    fill: var(--client-4);
    background-color: var(--client-4);
  }

  .client-5 {
    fill: var(--client-5);
    background-color: var(--client-5);
  }

  .client-6 {
    fill: var(--client-6);
    background-color: var(--client-6);
  }

  .client-7 {
    fill: var(--client-7);
    background-color: var(--client-7);
  }

  .client-na {
    fill: var(--client-na);
    background-color: var(--client-na);
  }

  /* --- The dictation pill: on screen whenever the microphone is open (docs/design/DICTATION.md). --- */
  .dictation-pill {
    --level: 0.1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    align-self: center;
    max-width: calc(100% - var(--space-6));
    margin: var(--space-3) var(--space-4) 0;
    padding: var(--space-2) var(--space-4);
    background: var(--glass-raised-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-2);
  }

  .dictation-pill[hidden],
  .dictation-pill [hidden] {
    display: none;
  }

  .dictation-pill .btn {
    padding-block: var(--space-1);
  }

  .dictation-label {
    font-weight: 600;
  }

  .dictation-dot {
    width: 0.7rem;
    height: 0.7rem;
    background: var(--status-failed);
    border-radius: var(--radius-pill);
  }

  .dictation-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--color-border-strong);
    border-top-color: var(--color-accent);
    border-radius: var(--radius-pill);
  }

  .dictation-time {
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted);
  }

  /* Five short bars that follow the input level; with reduced motion the script keeps the level
     steady, so nothing moves. */
  .dictation-meter {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 1.1rem;
  }

  .dictation-meter i {
    width: 3px;
    height: calc(25% + var(--level) * 75%);
    background: var(--color-accent);
    border-radius: var(--radius-xs);
  }

  .dictation-meter i:nth-child(2),
  .dictation-meter i:nth-child(4) {
    height: calc(20% + var(--level) * 100%);
  }

  .dictation-meter i:nth-child(3) {
    height: calc(15% + var(--level) * 85%);
  }

  @media (prefers-reduced-motion: no-preference) {
    .dictation-pill {
      animation: rise var(--dur-base) var(--ease-out);
    }

    .dictation-spinner {
      animation: spin 0.9s linear infinite;
    }

    .dictation-dot {
      animation: breathe 1.6s var(--ease-standard) infinite;
    }

    .dictation-meter i {
      transition: height var(--dur-fast) var(--ease-standard);
    }
  }

  /* The code of a refusal, for a colleague: closed, small and quiet; support can ask for it. */
  .error-code {
    margin-top: var(--space-1);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  .error-code summary {
    cursor: pointer;
  }
}
