/* Shared components. Names follow the EMS frontend where EMS has them. */

/* ---------- Base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg-page); }
body {
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
}
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { color: var(--text-primary); line-height: 1.3; }
p { color: var(--text-secondary); }
ul, ol { padding-left: 1.2rem; color: var(--text-secondary); }
code, pre { font-family: var(--font-mono); }
::selection { background: var(--primary-action); color: #fff; }
:where(button, a, input, select, textarea, summary, [tabindex="0"]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
canvas, img, svg { max-width: 100%; }

/* ---------- Shell ---------- */
.page { min-height: 100vh; display: flex; align-items: stretch; }
.page > #nav-slot { flex: 0 0 var(--sidebar-width); }

.sidebar {
  position: sticky;
  top: 0;
  z-index: var(--z-sidebar);
  width: var(--sidebar-width);
  height: 100vh;
  padding: 1.5rem 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background: var(--bg-shell);
  border-right: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
}
.sidebar::-webkit-scrollbar { display: none; }

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 0.4rem;
  color: inherit;
  text-decoration: none;
}
.brand-logo { width: 38px; height: 38px; object-fit: contain; display: block; }
.brand-name { color: var(--text-primary); font-size: 1.1rem; font-weight: 700; letter-spacing: 0.06em; line-height: 1.05; }
.brand-name span { color: var(--text-muted); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.04em; }

.sidebar-label {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.project-switch {
  display: grid;
  gap: 0.3rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-inset);
}
.project-switch__name {
  overflow: hidden;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-switch__scenario {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
  color: var(--text-secondary);
  font-size: 0.8rem;
}
.project-switch__scenario > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-switch__link { font-size: 0.78rem; font-weight: 600; text-decoration: none; }

.nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav a:hover { color: var(--text-primary); background: var(--bg-elevated); }
.nav a.active { color: var(--text-primary); background: var(--primary-dim); box-shadow: inset 3px 0 0 var(--primary); }
.nav a[aria-disabled="true"] { color: var(--text-disabled); pointer-events: none; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 100%; height: 100%; }
.nav-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.65rem; padding-top: 0.5rem; }
.sidebar-identity { padding: 0 0.4rem; color: var(--text-muted); font-size: 0.78rem; line-height: 1.4; overflow-wrap: anywhere; }
.sidebar-identity strong { display: block; color: var(--text-secondary); font-size: 0.82rem; }
.sidebar-identity a { color: inherit; text-decoration: none; }
.sidebar-identity a:hover strong { color: var(--primary); }
.sidebar-link { padding: 0 0.4rem; color: var(--text-muted); font-size: 0.78rem; text-decoration: none; }

.view-toggle {
  display: flex;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.85);
}
.mode-pill {
  flex: 1;
  padding: 0.35rem 0.6rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: 600 0.8rem var(--font-sans);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.mode-pill:hover { color: var(--text-primary); }
.mode-pill[aria-pressed="true"] { background: var(--primary-action); color: #fff; box-shadow: var(--shadow-sm); }

.logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font: 500 0.9rem var(--font-sans);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.logout-btn:hover { background: rgba(230, 57, 70, 0.08); border-color: rgba(230, 57, 70, 0.3); color: #ff8a93; }

/* Job tray */
.job-tray { display: grid; gap: 0.45rem; }
.job-tray__head { display: flex; align-items: center; justify-content: space-between; padding: 0 0.4rem; }
.job-tray__count {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.38rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--primary-action);
  color: #fff;
  font: 700 0.72rem/1 var(--font-mono);
}
.job-tray__idle { padding: 0 0.4rem; color: var(--text-muted); font-size: 0.78rem; }
.job-tray__list { display: grid; gap: 0.45rem; list-style: none; padding: 0; }
.job-item {
  display: grid;
  gap: 0.35rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 0.8rem;
}
.job-item__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.job-item__title { min-width: 0; overflow: hidden; color: var(--text-primary); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.job-item__stage { color: var(--text-muted); font-size: 0.75rem; }
.job-item__actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.job-item--done { border-color: var(--success-border); }
.job-item--failed { border-color: var(--danger-border); }

/* Content column */
.content {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  max-width: calc(var(--content-standard) + (2 * var(--content-gutter)));
  margin: 0 auto;
  padding: var(--space-7) var(--content-gutter) var(--space-8);
}
.content--wide { max-width: calc(var(--content-wide) + (2 * var(--content-gutter))); }

/* ---------- Page anatomy ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}
.page-header--surface {
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}
.page-header__copy { min-width: 0; }
.page-header__actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-3); }
.page-eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.page-title {
  color: var(--text-primary);
  font-size: clamp(1.7rem, 2.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.page-subtitle { max-width: 75ch; margin-top: var(--space-2); color: var(--text-secondary); font-size: 0.95rem; line-height: 1.55; }
.page-section { min-width: 0; margin-bottom: var(--space-6); }
.content > :last-child { margin-bottom: 0; }

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.section-title, .card-title { color: var(--text-primary); font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.35; }
.section-description { margin-top: var(--space-1); color: var(--text-muted); font-size: var(--text-sm); }

.subsection { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px solid var(--border-subtle); }
.subsection__header { margin-bottom: var(--space-4); }
.subsection__header h3 { color: var(--text-primary); font-size: 0.92rem; }
.subsection__header p { margin-top: var(--space-1); color: var(--text-muted); font-size: 0.82rem; line-height: 1.45; }

/* ---------- Cards ---------- */
.card {
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.card--panel, .card--kpi { background: var(--bg-card); }
.card--interactive { cursor: pointer; }
.card--interactive:hover, .card--interactive:focus-within { border-color: var(--primary-border); box-shadow: var(--shadow-md); }
.card--warning { border-color: var(--warning-border); }
.card--danger { border-color: var(--danger-border); }
.card--inset { background: var(--bg-card-soft); border-color: var(--border-subtle); box-shadow: none; }
.card-label { color: var(--text-secondary); font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; }
.metric-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-sub { margin-top: var(--space-1); color: var(--text-secondary); font-size: 0.9rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: var(--space-4); }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  min-height: var(--control-height);
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font: 600 0.9rem/1.4 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.btn:hover { border-color: var(--primary-border); color: var(--text-primary); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; box-shadow: none; cursor: not-allowed; }
a.btn[aria-disabled="true"] { pointer-events: none; }
.btn.small { min-height: var(--control-height-sm); padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn.large { min-height: 46px; padding: 0.65rem 1.3rem; font-size: 0.95rem; }
.btn.icon-only { width: var(--control-height); padding: 0; }
.btn.icon-only.small { width: var(--control-height-sm); }
.btn.primary {
  border-color: var(--primary-action);
  background: var(--primary-action);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}
.btn.primary:hover { border-color: var(--primary-action-hover); background: var(--primary-action-hover); color: #fff; box-shadow: 0 5px 16px rgba(37, 99, 235, 0.34); }
.btn.ghost { border-color: var(--border); background: transparent; color: var(--text-secondary); }
.btn.ghost:hover { border-color: var(--primary); background: var(--bg-elevated); color: var(--text-primary); }
.btn.danger { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); color: var(--text-primary); }
.btn.link {
  min-height: 0;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--primary);
  font-size: 0.8rem;
}
.btn.link:hover { color: var(--primary-hover); }
.btn.link.danger { color: var(--danger); background: transparent; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

.spinner {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  display: inline-block;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn.is-loading { cursor: progress; }
.btn.is-loading:disabled { opacity: 0.8; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.input,
:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea) {
  min-height: var(--control-height);
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-control);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
:where(textarea) { min-height: 5rem; resize: vertical; line-height: 1.5; }
.input:focus,
:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input::placeholder, :where(input, textarea)::placeholder { color: var(--text-muted); }
.input:disabled, .input[readonly],
:where(input, select, textarea):disabled, :where(input, textarea)[readonly] {
  border-color: rgba(148, 163, 184, 0.22);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}
:where(input[type="file"]) {
  max-width: 100%;
  padding: 0.4rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-secondary);
  font: 0.84rem var(--font-sans);
}
:where(input[type="file"])::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: 600 0.8rem var(--font-sans);
  cursor: pointer;
}
:where(input[type="checkbox"], input[type="radio"]) {
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  accent-color: var(--primary-action);
}
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-elevated) inset;
  -webkit-text-fill-color: var(--text-primary);
}

.field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; color: var(--text-secondary); font-size: 0.86rem; font-weight: 600; }
.field > :is(input, select, textarea), .field .input { width: 100%; }
.label { color: var(--text-secondary); font-size: 0.86rem; font-weight: 600; }
.field-hint { color: var(--text-muted); font-size: 0.78rem; font-weight: 400; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-secondary); font-size: 0.88rem; cursor: pointer; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: var(--space-4); align-items: start; }
.field-grid--five { grid-template-columns: repeat(5, minmax(min(120px, 100%), 1fr)); }
.field-grid > .wide { grid-column: 1 / -1; }

.has-error, .field.has-error { color: var(--danger); }
.has-error :is(input, select, textarea), [aria-invalid="true"] {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-soft) !important;
}
.field-error-message { color: var(--danger); font-size: 0.78rem; font-weight: 600; }
.field-error-message:empty { display: none; }

/* ---------- Inline messages ---------- */
.inline-message {
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-secondary);
  font-size: 0.86rem;
}
.inline-message:empty { display: none; }
.inline-message.info { border-color: var(--primary-border); background: var(--primary-soft); color: var(--primary-light); }
.inline-message.success { border-color: var(--success-border); background: var(--success-soft); color: var(--success-text); }
.inline-message.warning { border-color: var(--warning-border); background: var(--warning-soft); color: #fcd34d; }
.inline-message.error { border-color: var(--danger-border); background: var(--danger-soft); color: #fecaca; }
/* EMS status line: hidden while empty. */
.status { display: none; padding: 0.875rem 1rem; border-radius: var(--radius); color: var(--text-muted); font-size: 0.9rem; text-align: center; }
.status:not(:empty) { display: block; }
.status.error { border: 1px solid var(--danger-border); background: var(--danger-soft); color: #f5b0b5; }
.status.success { border: 1px solid var(--success-border); background: var(--success-soft); color: #9ee8e2; }
.code-block {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-inset);
  color: var(--text-muted);
  font: 0.84rem/1.5 var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Tables ---------- */
.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); }
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table :is(th, td) { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border-subtle); text-align: left; }
.data-table th { color: var(--text-muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.data-table td { color: var(--text-primary); font-size: 0.88rem; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--hover); }
.data-table .num { text-align: right; }

/* ---------- Status pills ---------- */
.status-pill {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--hover);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.3;
  white-space: nowrap;
}
.status-pill:is(.selected, .blue, .info) { border-color: var(--primary-border); background: var(--primary-soft); color: var(--primary); }
.status-pill:is(.ok, .success, .healthy) { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.status-pill:is(.warning, .alarm) { border-color: var(--warning-border); background: var(--warning-soft); color: var(--warning); }
.status-pill:is(.danger, .fault, .critical) { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.status-pill.muted { color: var(--text-muted); }

/* ---------- Progress ---------- */
.progress-bar {
  width: 100%;
  height: 8px;
  display: block;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  appearance: none;
}
.progress-bar::-webkit-progress-bar { background: var(--bg-input); border-radius: var(--radius-pill); }
.progress-bar::-webkit-progress-value { background: linear-gradient(90deg, var(--primary-action), var(--accent)); border-radius: var(--radius-pill); transition: width var(--transition-base); }
.progress-bar::-moz-progress-bar { background: linear-gradient(90deg, var(--primary-action), var(--accent)); border-radius: var(--radius-pill); }
.progress-bar.large { height: 10px; }
.progress-bar.small { height: 5px; }
.progress-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem var(--space-3);
  margin: var(--space-3) 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
}
.progress-stage__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); color: var(--text-secondary); font-size: 0.86rem; }
.progress-stage__value { color: var(--text-primary); font: 600 0.82rem var(--font-mono); }
.progress-stage .progress-bar { grid-column: 1; }
.progress-stage > .btn { grid-column: 2; grid-row: 1 / span 2; }

/* ---------- Skeleton ---------- */
.skeleton {
  display: block;
  border-radius: var(--radius-xs);
  background: linear-gradient(90deg, var(--bg-elevated) 0%, #263850 50%, var(--bg-elevated) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}
.skeleton-text { height: 0.8rem; margin: 0.45rem 0; }
.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 70%; }
.skeleton-title { width: 55%; height: 1.2rem; margin-bottom: 0.8rem; }
.skeleton-block { height: 7rem; border-radius: var(--radius); }
.skeleton-card { min-height: 12rem; }
@keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Loading and auth gate ---------- */
.loading-state { min-height: 60vh; display: grid; place-content: center; justify-items: center; gap: var(--space-3); color: var(--text-muted); font-size: var(--text-sm); }
.loading-state .spinner { width: 32px; height: 32px; border-width: 3px; color: var(--primary); }
.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); }
.auth-card { width: min(420px, 100%); display: grid; gap: var(--space-4); justify-items: center; padding: 2.25rem; text-align: center; }
.auth-card .brand-logo { width: 52px; height: 52px; }
.auth-card .btn { width: 100%; }

/* ---------- Empty states ---------- */
.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-7);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-passive);
  color: var(--text-muted);
  text-align: center;
}
.empty-state__icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.4rem;
}
.empty-state__title { color: var(--text-primary); font-size: 1.05rem; font-weight: 700; }
.empty-state__text { max-width: 52ch; color: var(--text-muted); font-size: 0.9rem; }
.empty-state .btn { margin-top: var(--space-2); }
.empty-state--error { border-color: var(--danger-border); }
.empty-state--error .empty-state__icon { background: var(--danger-soft); color: var(--danger); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  overflow-x: auto;
  margin-bottom: var(--space-6);
  padding: var(--space-2) var(--space-2) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--bg-card);
  box-shadow: inset 0 -1px 0 var(--border), var(--shadow-sm);
  scrollbar-width: thin;
}
.tab {
  position: relative;
  flex: 0 0 auto;
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.58rem 1rem 0.65rem;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font: 600 0.86rem var(--font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast), transform var(--transition-fast);
}
.tab:hover { color: var(--text-primary); background: var(--bg-elevated); transform: translateY(-1px); }
.tab:is(.active, [aria-selected="true"]) {
  z-index: 1;
  margin-bottom: -1px;
  padding-bottom: calc(0.65rem + 1px);
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: inset 0 3px 0 var(--primary-action), 0 -5px 14px rgba(2, 8, 23, 0.18);
  transform: translateY(-1px);
}
.tab:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- Collapsible sections ---------- */
details.collapsible {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-inset);
}
details.collapsible > summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.8rem 1rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  flex: 0 0 auto;
  border-right: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  transform: rotate(-45deg);
  transition: transform var(--transition-fast);
}
details.collapsible[open] > summary::before { transform: rotate(45deg); }
details.collapsible > summary:hover { color: var(--text-primary); }
.collapsible__summary-text { margin-left: auto; color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }
.collapsible__body { padding: 0 1rem 1rem; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-xl);
}
.dialog.wide { width: min(720px, calc(100vw - 32px)); }
.dialog::backdrop { background: var(--bg-backdrop); backdrop-filter: blur(4px); }
.dialog__form { display: grid; gap: var(--space-5); padding: var(--space-6); }
.dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.dialog__title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.dialog__message { color: var(--text-secondary); font-size: 0.92rem; white-space: pre-line; }
.dialog__footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--space-5);
  bottom: var(--space-5);
  width: min(380px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-3);
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 0.88rem;
  pointer-events: auto;
  animation: toast-in 0.18s ease;
}
.toast__icon { width: 1.3rem; height: 1.3rem; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 0.75rem; font-weight: 800; }
.toast__body { display: grid; gap: 0.2rem; }
.toast__action { width: fit-content; font-weight: 600; font-size: 0.82rem; }
.toast__close { padding: 0 0.2rem; border: 0; background: transparent; color: var(--text-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.toast__close:hover { color: var(--text-primary); }
.toast--success { border-left-color: var(--success); }
.toast--success .toast__icon { background: var(--success-soft); color: var(--success); }
.toast--warning { border-left-color: var(--warning); }
.toast--warning .toast__icon { background: var(--warning-soft); color: var(--warning); }
.toast--error { border-left-color: var(--danger); }
.toast--error .toast__icon { background: var(--danger-soft); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Cookie notice ---------- */
.cookie-notice {
  position: fixed;
  z-index: calc(var(--z-toast) + 1);
  left: calc(var(--sidebar-width) + var(--space-5));
  bottom: var(--space-5);
  width: min(430px, calc(100vw - 40px));
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-xl);
}
.cookie-notice h2 { font-size: 1rem; }
.cookie-notice p { color: var(--text-secondary); font-size: 0.86rem; }
.cookie-notice__actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }

/* ---------- Utilities ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stack { display: grid; gap: var(--space-4); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.font-mono { font-family: var(--font-mono); }

/* The product is desktop-first; below this width the sidebar stacks above the content. */
@media (max-width: 900px) {
  .page { flex-direction: column; }
  .page > #nav-slot { flex: 0 0 auto; }
  .sidebar { position: static; width: 100%; height: auto; }
  .cookie-notice { left: var(--space-5); }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header__actions { justify-content: flex-start; }
  .field-grid--five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { width: 100%; }
}

/* Long button labels wrap rather than widen a phone-width page. */
@media (max-width: 560px) {
  .btn { max-width: 100%; white-space: normal; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
