/* Owner: P8a (UI shell and design system). Keep this Owner line.
   Shared components. Tokens only. Class vocabulary (stable, used by every view):

   .btn .btn-primary|secondary|quiet|danger .btn-icon .btn-block    [aria-busy="true"] shows a spinner
   .chip .chip-ok|warn|bad|unknown|info|peach|navy  .chip-dot  .count
   .card .card-head .card-body .card-foot .card-link  .panel
   .kpi .kpi-label .kpi-value .kpi-sub  (data-tone="ok|warn|bad|unknown")
   .notice .notice-ok|warn|bad|info    .tabs .tab    .segmented
   .table-wrap .table    .facts (dl)    .meter (progress/meter)  .meter-ok|warn|bad
   .field .field-label .field-hint .field-error  .switch  .choice  .form-actions
   dialog.dialog .dialog-head .dialog-body .dialog-actions  .dialog-drawer
   .toasts .toast  .state .state-icon   .skeleton   .spinner  .icon .icon-spin
   .steps .step[data-status]   .chart-figure .chart .chart-legend .s0 ... .s5  .is-stale */

/* Icons and spinner ------------------------------------------------------------------------- */
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  vertical-align: -0.2em;
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

/* Buttons ----------------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--hit);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-ctl);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--teal);
  color: var(--ink);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--surface);
}

.btn-primary:hover {
  background: var(--teal-700);
  border-color: var(--teal-700);
  color: var(--surface);
}

.btn-secondary {
  border-color: var(--navy);
  color: var(--navy);
  background: transparent;
}

.btn-secondary:hover {
  background: var(--navy-100);
  border-color: var(--navy);
  color: var(--navy);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--navy);
}

.btn-quiet:hover {
  background: var(--navy-100);
  border-color: transparent;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--ink);
  color: var(--surface);
}

.btn-icon {
  width: var(--hit);
  padding: 0;
  border-radius: 50%;
}

.btn-block {
  width: 100%;
}

.btn[aria-busy="true"] {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--surface);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-primary[aria-busy="true"]::after,
.btn-danger[aria-busy="true"]::after {
  border-color: var(--navy-line);
  border-top-color: var(--surface);
}

.btn-secondary[aria-busy="true"]::after,
.btn-quiet[aria-busy="true"]::after,
.btn:not(.btn-primary):not(.btn-danger)[aria-busy="true"]::after {
  border-color: var(--line-strong);
  border-top-color: var(--teal);
}

/* Chips and counts -------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 28px;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--unknown-bg);
  color: var(--unknown);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.chip-ok {
  background: var(--success-bg);
  color: var(--success);
}

.chip-warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.chip-bad {
  background: var(--danger-bg);
  color: var(--danger);
}

.chip-unknown {
  background: var(--unknown-bg);
  color: var(--unknown);
}

.chip-info {
  background: var(--info-bg);
  color: var(--info);
}

.chip-peach {
  background: var(--peach-200);
  color: var(--navy);
}

.chip-navy {
  background: var(--navy);
  color: var(--cream);
}

.chip-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--navy);
  color: var(--cream);
  font-size: var(--fs-xs);
  font-weight: 700;
}

/* Cards and panels -------------------------------------------------------------------------- */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.card-head h2,
.card-head h3 {
  font-size: var(--fs-lg);
  font-family: var(--font-ui);
  letter-spacing: 0;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

a.card-link {
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

a.card-link:hover {
  color: inherit;
  border-color: var(--teal);
  box-shadow: var(--shadow-2);
}

.panel {
  padding: var(--space-6);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

@media (max-width: 480px) {
  .card,
  .panel {
    padding: var(--space-4);
  }

  .kpi {
    padding: var(--space-4);
  }
}

/* KPI tiles --------------------------------------------------------------------------------- */
.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5) var(--space-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  min-width: 0;
}

.kpi-label {
  font-size: var(--fs-sm);
  color: var(--muted);
  font-weight: 700;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--fs-kpi);
  line-height: 1.1;
  letter-spacing: var(--tracking-display);
  font-variant-numeric: tabular-nums;
  color: var(--navy);
  overflow-wrap: anywhere;
}

.kpi-sub {
  font-size: var(--fs-sm);
  color: var(--muted);
}

.kpi[data-tone="ok"] .kpi-value {
  color: var(--success);
}

.kpi[data-tone="warn"] .kpi-value {
  color: var(--warning);
}

.kpi[data-tone="bad"] .kpi-value {
  color: var(--danger);
}

.kpi[data-tone="unknown"] .kpi-value,
.kpi.is-stale .kpi-value {
  color: var(--unknown);
}

/* Notices ----------------------------------------------------------------------------------- */
.notice {
  max-width: none;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-ctl);
  background: var(--info-bg);
  color: var(--info);
  font-size: var(--fs-sm);
  font-weight: 700;
}

.notice > .icon {
  margin-top: 2px;
}

.notice p {
  max-width: none;
}

.notice-ok {
  background: var(--success-bg);
  color: var(--success);
}

.notice-warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.notice-bad {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Tabs and segmented control ---------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--hit);
  padding: 0 var(--space-4);
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
}

.tab:hover {
  color: var(--navy);
}

.tab[aria-selected="true"],
.tab[aria-current="page"] {
  color: var(--navy);
  border-bottom-color: var(--peach);
}

.segmented {
  display: inline-flex;
  align-self: flex-start;
  width: fit-content;
  max-width: 100%;
  padding: 2px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
}

.segmented > button,
.segmented > label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--hit);
  min-width: var(--hit);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  font-size: var(--fs-sm);
}

.segmented > button:hover {
  background: var(--navy-100);
}

.segmented > button[aria-pressed="true"],
.segmented > button[aria-selected="true"] {
  background: var(--navy);
  color: var(--cream);
}

/* Tables and facts -------------------------------------------------------------------------- */
.table-wrap {
  position: relative; /* containing block for .sr-only cells: they must not escape the scroll clip */
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.table-wrap > table th:first-child,
.table-wrap > table td:first-child {
  padding-left: var(--space-6);
}

.table-wrap > table th:last-child,
.table-wrap > table td:last-child {
  padding-right: var(--space-6);
}

.table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

.table-wrap tbody tr:hover {
  background: var(--surface-2);
}

.facts {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
  gap: var(--space-2) var(--space-6);
}

.facts dt {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .facts {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .facts dt {
    margin-top: var(--space-3);
  }
}

/* Meters (no inline width: use progress / meter) -------------------------------------------- */
.meter {
  -webkit-appearance: none;
  appearance: none;
  background: var(--line);
}

.meter::-webkit-progress-bar {
  background: var(--line);
}

.meter::-webkit-progress-value {
  background: var(--teal);
  border-radius: var(--radius-pill);
}

.meter::-moz-progress-bar {
  background: var(--teal);
  border-radius: var(--radius-pill);
}

.meter-ok::-webkit-progress-value {
  background: var(--success);
}

.meter-ok::-moz-progress-bar {
  background: var(--success);
}

.meter-warn::-webkit-progress-value {
  background: var(--warning);
}

.meter-warn::-moz-progress-bar {
  background: var(--warning);
}

.meter-bad::-webkit-progress-value {
  background: var(--danger);
}

.meter-bad::-moz-progress-bar {
  background: var(--danger);
}

/* Forms ------------------------------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.field-label {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-weight: 700;
  font-size: var(--fs-sm);
}

.field-optional {
  font-weight: 400;
  color: var(--muted);
}

.field-hint {
  font-size: var(--fs-sm);
  color: var(--muted);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--danger);
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border-color: var(--danger);
  border-width: 2px;
}

.field.is-valid input {
  border-color: var(--success);
}

.input-group {
  position: relative;
}

.input-group > input {
  padding-right: 96px;
}

.input-group > .btn {
  position: absolute;
  right: var(--space-1);
  top: 2px;
  min-height: 40px;
  padding: 0 var(--space-3);
  font-size: var(--fs-sm);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.form-error {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-ctl);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 700;
}

.switch {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--hit);
  cursor: pointer;
  font-weight: 700;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: var(--hit);
  height: var(--hit);
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--border-input);
  transition: background var(--dur-fast) var(--ease);
}

.switch-track::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform var(--dur-fast) var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--teal);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch-track {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
}

.switch input:disabled + .switch-track {
  opacity: 0.5;
}

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

.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-ctl);
  background: var(--surface);
  cursor: pointer;
  font-weight: 400;
  font-size: var(--fs-md);
}

.choice:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-100);
}

.choice input {
  margin-top: 2px;
}

.choice strong {
  display: block;
}

/* Dialog, drawer ---------------------------------------------------------------------------- */
dialog.dialog {
  width: min(var(--dialog-w), calc(100vw - 2 * var(--space-4)));
  max-height: calc(100dvh - 2 * var(--space-4));
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

dialog.dialog[open] {
  display: flex;
  flex-direction: column;
  animation: dialog-in var(--dur) var(--ease);
}

dialog.dialog::backdrop {
  background: var(--scrim);
}

dialog.dialog-lg {
  width: min(760px, calc(100vw - 2 * var(--space-4)));
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-6) var(--space-2);
}

.dialog-head h2 {
  font-family: var(--font-ui);
  font-size: var(--fs-xl);
  letter-spacing: 0;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-6) var(--space-4);
  overflow-y: auto;
  color: var(--ink);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6) var(--space-6);
}

dialog.dialog-drawer {
  width: min(var(--drawer-w), 100vw);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  border-radius: var(--radius-card) 0 0 var(--radius-card);
}

dialog.dialog-drawer[open] {
  animation: drawer-in var(--dur) var(--ease);
}

@keyframes drawer-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 480px) {
  dialog.dialog:not(.dialog-drawer) {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }

  .dialog-actions .btn {
    flex: 1 1 auto;
  }

  dialog.dialog-drawer {
    border-radius: 0;
  }
}

/* Toasts ------------------------------------------------------------------------------------ */
.toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--navy);
  color: var(--cream);
  border-radius: var(--radius-ctl);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: dialog-in var(--dur) var(--ease);
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  padding-top: var(--space-2);
}

.toast-ok {
  border-left: 6px solid var(--success-bg);
}

.toast-warn {
  border-left: 6px solid var(--peach);
}

.toast-error {
  border-left: 6px solid var(--danger-bg);
}

.toast .btn-quiet {
  color: var(--cream);
  min-height: 40px;
  width: 40px;
}

.toast .btn-quiet:hover {
  background: var(--navy-hover);
}

@media (max-width: 800px) {
  .toasts {
    bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px) + var(--space-3));
    right: var(--space-3);
  }
}

/* States: empty, error, loading ------------------------------------------------------------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.state h2,
.state h3 {
  font-size: var(--fs-xl);
}

.state p {
  color: var(--muted);
}

.state-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--peach-100);
  color: var(--navy);
}

.state-icon .icon {
  width: 28px;
  height: 28px;
}

.state-bad .state-icon {
  background: var(--danger-bg);
  color: var(--danger);
}

.skeleton {
  display: block;
  min-height: 1em;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }

  to {
    background-position: -200% 0;
  }
}

/* Steps (job steps, provisioning timeline) -------------------------------------------------- */
.steps {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 30px;
  bottom: -6px;
  width: 2px;
  background: var(--line-strong);
}

.step-mark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  display: grid;
  place-items: center;
}

.step[data-status="ok"] .step-mark {
  background: var(--success);
  border-color: var(--success);
}

.step[data-status="ok"] .step-mark::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid var(--surface);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.step[data-status="failed"] .step-mark {
  background: var(--danger);
  border-color: var(--danger);
}

.step[data-status="failed"] .step-mark::after {
  content: "!";
  color: var(--surface);
  font-weight: 700;
  font-size: var(--fs-sm);
  line-height: 1;
}

.step[data-status="running"] .step-mark {
  border-color: var(--line-strong);
  border-top-color: var(--teal);
  animation: spin 0.8s linear infinite;
}

.step[data-status="skipped"] .step-mark,
.step[data-status="undone"] .step-mark {
  background: var(--unknown-bg);
  border-color: var(--unknown);
}

.step[data-status="pending"] {
  color: var(--muted);
}

.step-meta {
  font-size: var(--fs-sm);
  color: var(--muted);
  white-space: nowrap;
}

/* Charts (svgchart.js; colours from classes, no style attributes) --------------------------- */
.chart-figure {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: var(--font-ui);
}

.s0 {
  --c: var(--chart-1);
}

.s1 {
  --c: var(--chart-2);
}

.s2 {
  --c: var(--chart-3);
}

.s3 {
  --c: var(--chart-4);
}

.s4 {
  --c: var(--chart-5);
}

.s5 {
  --c: var(--chart-6);
}

.chart-type-donut {
  max-width: 260px;
  margin-inline: auto;
}

.chart-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-grid .chart-baseline {
  stroke: var(--line-strong);
}

.chart-axis text,
.chart-label {
  fill: var(--chart-axis);
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke: var(--c);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: var(--c);
  fill-opacity: 0.12;
  stroke: none;
}

.chart-bar,
.chart-slice {
  fill: var(--c);
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--c);
  stroke-width: 2;
}

.chart-dot-end {
  fill: var(--c);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart-value {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.chart-center {
  fill: var(--navy);
  font-family: var(--font-display);
  font-size: 28px;
}

.chart-center-sub {
  fill: var(--chart-axis);
  font-size: 12px;
}

.chart-empty {
  fill: var(--muted);
  font-size: 14px;
}

.chart-spark {
  display: inline-flex;
  width: 120px;
  max-width: 100%;
  vertical-align: middle;
}

.chart-spark .chart {
  height: 32px;
}

.chart-spark .chart-line {
  stroke-width: 2;
}

.chart-slice {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
}

.chart-legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--c);
  flex: none;
}

.chart-legend .legend-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-figure.is-stale .chart-line,
.chart-figure.is-stale .chart-dot,
.chart-figure.is-stale .chart-dot-end {
  stroke: var(--chart-stale);
}

.chart-figure.is-stale .chart-area,
.chart-figure.is-stale .chart-bar,
.chart-figure.is-stale .chart-slice,
.chart-figure.is-stale .chart-legend .swatch {
  fill: var(--chart-stale);
  background: var(--chart-stale);
}

.chart-figure.is-stale .chart-dot-end {
  fill: var(--chart-stale);
}

.chart-figure.is-stale .chart-center {
  fill: var(--muted);
}

/* Stale data in general */
.is-stale {
  filter: grayscale(1);
}

.chart-figure.is-stale {
  filter: none;
}

/* Shared helpers added at integration (lead): used in drawers and dialogs, which live outside the page
   outlet and therefore cannot use page-scoped CSS. ---------------------------------------------- */
.code-block {
  margin: 0;
  padding: var(--space-3);
  max-height: 24rem;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.subhead {
  margin-bottom: var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  letter-spacing: 0;
  color: var(--navy);
}

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

.warn-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.diff-list {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-1) var(--space-4);
  font-size: var(--fs-sm);
}

.diff-list .diff-head {
  font-weight: 700;
  color: var(--muted);
}

.diff-list .diff-old {
  color: var(--danger);
  overflow-wrap: anywhere;
}

.diff-list .diff-new {
  color: var(--success);
  overflow-wrap: anywhere;
}

.step > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* Phone layer (<= 800 px) ------------------------------------------------------------------- */
/* shell.js labels every body cell with its column header (data-label) and marks the table
   .is-labelled; on a phone each row becomes a card of "label: value" lines, so no table scrolls
   sideways. Tables without the mark keep their normal layout. */
@media (max-width: 800px) {
  .table-wrap:has(> table.is-labelled) {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .main table.is-labelled,
  .main table.is-labelled > tbody,
  .main table.is-labelled > tbody > tr,
  .main table.is-labelled > tbody > tr > th,
  .main table.is-labelled > tbody > tr > td {
    display: block;
  }

  .main table.is-labelled {
    width: 100%;
    min-width: 0;
    background: transparent;
  }

  .main table.is-labelled > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .main table.is-labelled > tbody > tr {
    margin-bottom: var(--space-3);
    padding: var(--space-2) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-1);
  }

  .main table.is-labelled > tbody > tr:hover {
    background: var(--surface);
  }

  .main table.is-labelled > tbody > tr > th,
  .main table.is-labelled > tbody > tr > td {
    display: grid;
    grid-template-columns: minmax(6rem, 38%) minmax(0, 1fr);
    align-items: baseline;
    gap: var(--space-3);
    min-width: 0;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .main table.is-labelled > tbody > tr > :last-child {
    border-bottom: 0;
  }

  .main table.is-labelled > tbody > tr > :is(th, td) > * {
    grid-column: 2;
    justify-self: start;
    max-width: 100%;
  }

  .main table.is-labelled > tbody > tr > :is(th, td)::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--fs-sm);
    font-weight: 700;
    line-height: 1.3;
  }

  /* Card title (row header), empty-label cells (actions) and single-cell rows (empty states). */
  .main table.is-labelled > tbody > tr > th[scope="row"],
  .main table.is-labelled > tbody > tr > [data-label=""],
  .main table.is-labelled > tbody > tr > :only-child {
    grid-template-columns: minmax(0, 1fr);
  }

  .main table.is-labelled > tbody > tr > th[scope="row"] > *,
  .main table.is-labelled > tbody > tr > [data-label=""] > *,
  .main table.is-labelled > tbody > tr > :only-child > * {
    grid-column: 1;
  }

  .main table.is-labelled > tbody > tr > th[scope="row"]::before,
  .main table.is-labelled > tbody > tr > [data-label=""]::before,
  .main table.is-labelled > tbody > tr > :only-child::before {
    display: none;
  }

  .main table.is-labelled > tbody > tr > th[scope="row"] {
    font-size: var(--fs-md);
    color: var(--ink);
  }

  .main table.is-labelled > tbody > tr > th[scope="row"] a {
    display: inline-flex;
    align-items: center;
    min-height: var(--hit);
  }

  .main table.is-labelled > tbody > tr > [data-label=""]:not(:empty) {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .main table.is-labelled > tbody > tr > [data-label=""] .btn {
    flex: 1 1 auto;
  }

  .main table.is-labelled > tbody > tr > [data-label=""]:empty {
    display: none;
  }
}

/* Touch targets on phones: buttons in table cards and text links in headings and breadcrumbs get a
   44 px hit area (padding offset by a negative margin, so the layout does not move). */
@media (max-width: 800px) {
  .main table.is-labelled .btn {
    min-height: var(--hit);
  }

  .main :is(h2, h3) > a,
  .main .eyebrow a {
    display: inline-block;
    padding-block: var(--space-3);
    margin-block: calc(-1 * var(--space-3));
  }

  .topbar-brand {
    display: inline-grid;
    place-items: center;
    min-width: var(--hit);
    min-height: var(--hit);
  }

  .page-newsite .ns-step {
    min-height: var(--hit);
  }
}

/* Scrolling strips (tabs, wizard steps) on touch screens: no scrollbar, snap, fade on the edge. */
@media (max-width: 800px) {
  .tabs,
  .page-offers .of-nav,
  .page-newsite .ns-nav {
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-mask-image: linear-gradient(to right, var(--ink) calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, var(--ink) calc(100% - 28px), transparent);
  }

  .tabs::-webkit-scrollbar,
  .page-offers .of-nav::-webkit-scrollbar,
  .page-newsite .ns-nav::-webkit-scrollbar {
    display: none;
  }

  .tabs > *,
  .page-offers .of-steps > *,
  .page-newsite .ns-steps > * {
    scroll-snap-align: start;
  }

  .segmented {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  dialog.dialog:not(.dialog-drawer) {
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - var(--space-4));
  }

  .dialog-actions {
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  }

  dialog.dialog-drawer .dialog-head {
    padding-top: calc(var(--space-6) + env(safe-area-inset-top, 0px));
  }

  .chart-figure,
  .main img,
  .main video {
    max-width: 100%;
  }
}

/* IT/EN language switch (header and login page; core/i18n.js langSwitch). */
.lang-switch {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
}
.lang-btn {
  min-width: 34px;
  min-height: 30px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.lang-btn:hover { color: var(--text); }
.lang-btn[aria-pressed="true"] {
  background: var(--navy);
  color: var(--surface);
}
.lang-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.login-lang {
  align-self: flex-end;
  margin-bottom: var(--space-2);
}

/* Premium layer (design upgrade) ------------------------------------------------------------
   Surfaces with subtle depth, refined controls and micro-interactions. Same class vocabulary;
   motion is neutralised by the prefers-reduced-motion rule in base.css.

   Utilities for dashboards and clickable tiles (markup):

     Skeleton loader (decorative; the container carries role="status" + a .sr-only text):
       <div role="status" aria-busy="true"><span class="sr-only">Loading…</span>
         <span class="skeleton skeleton-line"></span>          one text line (width: .w-60 / .w-40 helpers)
         <span class="skeleton skeleton-block"></span>         a 120 px block (chart / card body)
         <span class="skeleton skeleton-circle"></span></div>  40 px avatar / icon
     Clickable card with lift on hover and a visible focus ring:
       <a class="card card-elevated tile-link" href="#/statistiche"> ... </a>
       (.tile-link resets link colour/underline; .card-elevated adds hover lift + focus-visible ring;
        both also work on <button> or on a <div> that contains a stretched link)
     Delta pill (direction is in the text, never colour only):
       <span class="delta delta-up">▲ 12%</span>   <span class="delta delta-down">▼ 4%</span>
       <span class="delta delta-flat">= 0%</span>  <span class="delta delta-na">n/a</span>
     Segmented control: <div class="segmented" role="group"><button aria-pressed="true">7d</button>…</div> */

.btn {
  box-shadow: var(--shadow-0);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn:hover {
  box-shadow: var(--shadow-1);
}

.btn-primary {
  background-image: linear-gradient(180deg, var(--teal) 0%, var(--teal-700) 140%);
  box-shadow: var(--shadow-0), var(--highlight-top);
}

.btn-primary:hover {
  background-image: none;
  box-shadow: var(--shadow-1);
}

.btn-quiet,
.btn-quiet:hover {
  box-shadow: none;
}

.btn:focus-visible {
  box-shadow: var(--ring);
}

.chip {
  letter-spacing: 0.005em;
  box-shadow: inset 0 0 0 1px var(--border-1);
}

.chip-ok,
.chip-warn,
.chip-bad,
.chip-info,
.chip-unknown,
.chip-peach,
.chip-navy {
  box-shadow: none;
}

.card,
.kpi {
  border-color: var(--border-1);
  box-shadow: var(--shadow-1), var(--highlight-top);
}

.card-head h2,
.card-head h3 {
  letter-spacing: -0.005em;
}

a.card-link {
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease-out);
}

a.card-link:hover {
  transform: var(--lift);
  box-shadow: var(--shadow-3);
}

.panel {
  border-color: var(--border-1);
}

/* KPI tiles: a short peach rule on top, quieter label */
.kpi {
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--space-6);
  width: 32px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--grad-card-accent);
}

.kpi-label {
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.kpi-value {
  color: var(--text-brand);
  font-weight: 400;
}

/* Tabs: the peach underline grows in */
.tab {
  position: relative;
  border-bottom-color: transparent;
  transition: color var(--dur-fast) var(--ease);
}

.tab::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--peach);
  transform: scaleX(0);
  transition: transform var(--dur) var(--ease-out);
}

.tab[aria-selected="true"],
.tab[aria-current="page"] {
  border-bottom-color: transparent;
}

.tab[aria-selected="true"]::after,
.tab[aria-current="page"]::after {
  transform: scaleX(1);
}

.segmented {
  background: var(--bg-subtle);
  border-color: var(--border-1);
  box-shadow: var(--shadow-inset);
}

.segmented > button {
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease);
}

.segmented > button[aria-pressed="true"],
.segmented > button[aria-selected="true"] {
  box-shadow: var(--shadow-1);
}

/* Tables: quiet uppercase header band */
.table-wrap {
  border-color: var(--border-1);
  box-shadow: var(--shadow-1);
}

.table-wrap > table > thead th {
  background: var(--bg-subtle);
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table-wrap tbody tr {
  transition: background var(--dur-fast) var(--ease);
}

/* Dialogs and toasts */
dialog.dialog {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
}

dialog.dialog::backdrop {
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.toast {
  background: var(--bg-chrome);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-3);
}

/* Empty / error / loading states: warm gradient, soft frame, ringed icon */
.state {
  background: var(--grad-state);
  border: 1px solid var(--border-1);
  box-shadow: var(--shadow-1);
}

.state-icon {
  box-shadow: 0 0 0 8px var(--peach-50), 0 0 0 9px var(--peach-200);
}

.state-bad .state-icon {
  box-shadow: 0 0 0 8px var(--danger-bg), 0 0 0 9px var(--border-1);
}

.state p {
  max-width: 52ch;
}

/* Skeleton loaders */
.skeleton {
  display: block;
  min-height: 1em;
  border-radius: var(--radius-sm);
  background-color: var(--skeleton-base);
  background-image: linear-gradient(90deg, var(--skeleton-base) 0%, var(--skeleton-shine) 50%, var(--skeleton-base) 100%);
  background-size: 200% 100%;
  background-repeat: no-repeat;
  animation: shimmer 1.6s var(--ease) infinite;
}

.skeleton-line {
  height: 0.875rem;
  min-height: 0;
  width: 100%;
}

.skeleton-line.w-60 {
  width: 60%;
}

.skeleton-line.w-40 {
  width: 40%;
}

.skeleton-title {
  height: 1.75rem;
  width: 45%;
  border-radius: var(--radius-ctl);
}

.skeleton-block {
  height: 120px;
  border-radius: var(--radius-ctl);
}

.skeleton-circle {
  width: 40px;
  height: 40px;
  min-height: 0;
  border-radius: 50%;
}

.state-loading {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.skel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: var(--space-4);
}

.skel-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background-image: none;
  }
}

/* Clickable tiles */
.tile-link,
.tile-link:hover {
  color: inherit;
  text-decoration: none;
}

.tile-link {
  display: flex;
  cursor: pointer;
  text-align: inherit;
  font: inherit;
}

.card-elevated {
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.card-elevated:hover {
  transform: var(--lift);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-3);
}

.card-elevated:active {
  transform: translateY(0);
  box-shadow: var(--shadow-1);
}

.card-elevated:focus-visible,
.card-elevated:focus-within:has(a:focus-visible) {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
  box-shadow: var(--shadow-2), var(--ring);
}

/* Delta pills: direction is written (▲ ▼ =), colour only reinforces it */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: var(--delta-flat-bg);
  color: var(--delta-flat);
}

.delta-up {
  background: var(--delta-up-bg);
  color: var(--delta-up);
}

.delta-down {
  background: var(--delta-down-bg);
  color: var(--delta-down);
}

.delta-flat,
.delta-na {
  background: var(--delta-flat-bg);
  color: var(--delta-flat);
}

.delta-na {
  font-weight: 400;
}
