:root {
  color-scheme: light;
  --bg: #edf1f7;
  --bg-top: #f8fafc;
  --bg-accent: radial-gradient(circle at top, rgba(3, 105, 161, 0.12), transparent 42%);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --surface-muted: #f1f5f9;
  --line: rgba(15, 23, 42, 0.12);
  --text: #020617;
  --text-muted: #475569;
  --brand: #0369a1;
  --brand-strong: #0c4a6e;
  --brand-soft: rgba(3, 105, 161, 0.10);
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.10);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --gap: 1rem;
  font-family: "Fira Sans", "Segoe UI", Roboto, Arial, sans-serif;
}

html[data-theme="dark"],
html.dark {
  color-scheme: dark;
  --bg: #020617;
  --bg-top: #0f172a;
  --bg-accent: radial-gradient(circle at top, rgba(56, 189, 248, 0.14), transparent 42%);
  --surface: rgba(15, 23, 42, 0.88);
  --surface-strong: #0f172a;
  --surface-muted: #111827;
  --line: rgba(148, 163, 184, 0.22);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --brand: #38bdf8;
  --brand-strong: #7dd3fc;
  --brand-soft: rgba(56, 189, 248, 0.18);
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.42);
}

/* ============================================================
   ACCESSIBILITY — skip-link, focus-visible, reduced-motion
   ============================================================ */

/* 1. Skip navigation link (WCAG 2.4.1 Bypass Blocks) */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  padding: 0.6rem 1rem;
  background: var(--brand);
  color: white;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

/* 2. Global focus-visible ring (WCAG 2.4.7 Focus Visible) */
:where(button, a, [role="button"], select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: inherit;
}

/* 3. Respect prefers-reduced-motion (WCAG 2.3.3 / user preference) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================ */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    var(--bg-accent),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
  color: var(--text);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 1.25rem;
}

.portal-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 1.25rem;
}

.topbar,
.panel,
.info-card {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: var(--radius-xl);
  padding: 1.25rem;
  display: flex;
  gap: 1.5rem;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: grid;
  gap: 1rem;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.brand__logo {
  display: block;
  width: 100%;
  max-width: 120pt;
  height: auto;
}

.brand__portal {
  min-width: 0;
  padding-right: 0.35rem;
}

.brand__eyebrow,
.info-card__label,
.detail-card__label,
.field__label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.brand__eyebrow {
  display: grid;
  gap: 0.1rem;
  line-height: 1.2;
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
}

.brand__title {
  margin: 0;
  text-transform: uppercase;
  font-weight: 700;
  font-size: clamp(1.2rem, 1.6vw, 1.6rem);
  letter-spacing: 0.04em;
  line-height: 1.25;
  color: var(--brand-strong);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.9rem;
  margin-left: auto;
}

.toolbar__brand {
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.toolbar__controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.help-trigger {
  font-size: 1.05rem;
  font-weight: 700;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.lang-pill,
.theme-icon,
.primary-action,
.secondary-action {
  border: 1px solid transparent;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.lang-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  min-width: 3rem;
  justify-content: center;
}

.lang-pill.is-active,
.lang-pill:hover {
  background: var(--surface-strong);
  color: var(--brand-strong);
  border-color: rgba(3, 105, 161, 0.22);
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.theme-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
}

.theme-icon.is-active,
.theme-icon:hover {
  background: var(--surface-strong);
  color: var(--brand-strong);
  border-color: rgba(3, 105, 161, 0.22);
}

html[data-theme="dark"] .lang-pill.is-active,
html[data-theme="dark"] .lang-pill:hover,
html[data-theme="dark"] .theme-icon.is-active,
html[data-theme="dark"] .theme-icon:hover,
html.dark .lang-pill.is-active,
html.dark .lang-pill:hover,
html.dark .theme-icon.is-active,
html.dark .theme-icon:hover {
  background: rgba(15, 23, 42, 0.96);
  color: var(--brand-strong);
  border-color: rgba(125, 211, 252, 0.35);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
}

.info-grid--summary {
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 0.95fr);
}

.info-card {
  border-radius: var(--radius-lg);
  padding: 0.95rem 1rem;
  display: grid;
  gap: 0.35rem;
  min-height: 84px;
  border-top: 2px solid rgba(3, 105, 161, 0.18);
}

html[data-theme="dark"] .info-card,
html.dark .info-card {
  border-top-color: rgba(56, 189, 248, 0.22);
}

.info-card__value {
  font-size: clamp(0.95rem, 1.2vw, 1.05rem);
  line-height: 1.35;
  font-weight: 600;
  font-family: "Fira Code", monospace;
  font-variant-numeric: tabular-nums;
}

.help-dialog {
  width: min(760px, calc(100vw - 2rem));
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.help-dialog::backdrop {
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(6px);
}

.help-dialog__surface {
  display: grid;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.help-dialog__header,
.help-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.help-dialog__title,
.help-dialog__section h3 {
  margin: 0;
}

.help-dialog__close {
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
}

.help-dialog__body {
  display: grid;
  gap: 1rem;
}

.help-dialog__section {
  display: grid;
  gap: 0.5rem;
}

.help-dialog__section p,
.help-dialog__list {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.6;
}

.help-dialog__list {
  padding-left: 1.1rem;
}

.help-dialog__hint {
  font-size: 0.95rem;
}

.help-dialog__link {
  color: var(--brand-strong);
  word-break: break-word;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.workspace--stations {
  grid-template-columns: 1fr;
}

.panel {
  border-radius: var(--radius-xl);
  padding: 1rem;
}

.panel__header,
.detail-block__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.panel__title,
.detail-block__header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.station-list {
  position: sticky;
  top: 1.25rem;
}

.workspace--stations .station-list {
  position: static;
  top: auto;
}

.station-list__table-wrap {
  margin-top: 1rem;
  overflow-x: auto;
}

.station-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.station-table th,
.station-table td {
  padding: 0.8rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.station-table th {
  color: var(--text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.station-table__row {
  transition: background 140ms ease;
  cursor: pointer;
}

.station-table__row:hover {
  background: rgba(3, 105, 161, 0.05);
}

html[data-theme="dark"] .station-table__row:hover,
html.dark .station-table__row:hover {
  background: rgba(56, 189, 248, 0.08);
}

.station-table__row.is-selected {
  background: linear-gradient(180deg, rgba(3, 105, 161, 0.09) 0%, rgba(3, 105, 161, 0.04) 100%);
}

html[data-theme="dark"] .station-table__row.is-selected,
html.dark .station-table__row.is-selected {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.18) 0%, rgba(14, 116, 144, 0.10) 100%);
}

.station-table__row.is-selected td {
  background: transparent;
}

.station-table__row.is-selected td:first-child {
  border-left: 3px solid var(--brand);
  padding-left: calc(0.85rem - 3px);
}

.station-table__row td:first-child {
  border-left: 3px solid transparent;
  padding-left: calc(0.85rem - 3px);
}

.station-table__link {
  display: block;
  width: 100%;
  min-height: 100%;
  color: inherit;
  text-decoration: none;
}

.station-table__link:hover,
.station-table__link:focus-visible {
  color: inherit;
  text-decoration: none;
}

.station-table__link--numeric,
.station-table td:last-child,
.station-table th:last-child {
  text-align: right;
}

.station-table__link--numeric {
  font-family: "Fira Code", monospace;
}

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

.station-table__expanded-row td {
  padding: 0;
  border-bottom: 0;
  background: transparent;
}

.station-expanded {
  display: grid;
  gap: 1rem;
  margin: 0.85rem 0 0.35rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(3, 105, 161, 0.18);
  background: linear-gradient(180deg, rgba(3, 105, 161, 0.06) 0%, var(--surface-strong) 100%);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] .station-expanded,
html.dark .station-expanded {
  border-color: rgba(56, 189, 248, 0.24);
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.16) 0%, rgba(15, 23, 42, 0.98) 100%);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.42);
}

.station-expanded__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.station-expanded__eyebrow,
.station-expanded__title {
  margin: 0;
}

.station-expanded__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.station-expanded__title {
  margin-top: 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.station-expanded__close {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--brand-strong);
  text-decoration: none;
}

.station-expanded__meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.detail-card__value {
  font-weight: 650;
  font-family: "Fira Code", monospace;
  font-size: 0.92rem;
}

.summary-empty,
.field--action .field__label {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.detail-card {
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  padding: 0.85rem;
  display: grid;
  gap: 0.35rem;
}

.detail-block {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.95rem;
  display: grid;
  gap: 1rem;
}

.detail-block--results {
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  gap: 0.9rem;
  align-items: end;
}

.form-grid--modal {
  grid-template-columns: 1fr;
}

.modal-action-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 0.9fr) auto;
  gap: 0.9rem;
  align-items: end;
}

.modal-action-row__field,
.modal-action-row__actions {
  min-width: 0;
}

.modal-action-row__actions {
  display: flex;
  align-items: flex-end;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field__control {
  width: 100%;
  min-height: 46px;
  padding: 0.75rem 2.25rem 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230369a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
}

.field__control option {
  color: var(--text);
}

.field--action {
  min-width: 140px;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  text-decoration: none;
}

.primary-action {
  background: var(--brand);
  color: #fff;
}

.secondary-action {
  background: var(--surface-muted);
  color: var(--brand-strong);
  border-color: var(--line);
  white-space: nowrap;
}

.primary-action:disabled,
.secondary-action:disabled,
.field__control:disabled {
  cursor: not-allowed;
  opacity: 0.75;
}

.summary-empty {
  border-radius: var(--radius-md);
  border: 1px dashed var(--line);
  min-height: 112px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
}

.empty-state {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(3, 105, 161, 0.05) 0%, rgba(3, 105, 161, 0.02) 100%);
  padding: 1rem;
  display: grid;
  gap: 0.45rem;
}

.empty-state--selection {
  background: linear-gradient(180deg, rgba(3, 105, 161, 0.07) 0%, rgba(3, 105, 161, 0.02) 100%);
}

.empty-state--nodata {
  background: linear-gradient(180deg, rgba(116, 132, 150, 0.08) 0%, rgba(116, 132, 150, 0.04) 100%);
}

html[data-theme="dark"] .empty-state--selection,
html.dark .empty-state--selection {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.14) 0%, rgba(15, 23, 42, 0.95) 100%);
}

html[data-theme="dark"] .empty-state--nodata,
html.dark .empty-state--nodata {
  background: linear-gradient(180deg, rgba(71, 85, 105, 0.26) 0%, rgba(15, 23, 42, 0.96) 100%);
}

.empty-state__eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.empty-state__title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 650;
}

.empty-state__text {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.summary-card,
.series-summary,
.chart-frame,
.export-panel {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 1rem;
}

.chart-frame {
  gap: 0.85rem;
}


.chart-frame__subtitle,
.chart-frame__caption {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.measurement-chart-shell {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.75rem;
}

.measurement-chart {
  width: 100%;
  min-height: 320px;
  height: clamp(320px, 42vw, 420px);
}

html[data-theme="dark"] .summary-card,
html[data-theme="dark"] .chart-frame,
html[data-theme="dark"] .export-panel,
html.dark .summary-card,
html.dark .chart-frame,
html.dark .export-panel {
  background: rgba(15, 23, 42, 0.9);
}

html[data-theme="dark"] .measurement-chart-shell,
html.dark .measurement-chart-shell {
  background: rgba(2, 6, 23, 0.92);
}

.summary-card__header,
.chart-frame__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
}

.summary-card__eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.summary-card__title {
  margin: 0.25rem 0 0;
  font-size: 1.05rem;
}

.summary-card__badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(3, 105, 161, 0.09);
  color: var(--brand-strong);
  font-size: 0.82rem;
  font-family: "Fira Code", monospace;
  letter-spacing: 0.02em;
}

html[data-theme="dark"] .summary-card__badge,
html.dark .summary-card__badge {
  background: rgba(56, 189, 248, 0.16);
  color: #d9f5ff;
}

.summary-metrics,
.series-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.summary-metric,
.series-summary__item {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.85rem;
  display: grid;
  gap: 0.25rem;
}

.summary-metric__label,
.series-summary__label {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-metric__value,
.series-summary__value {
  font-size: 1rem;
  font-weight: 650;
  font-family: "Fira Code", monospace;
}

.table-collapse {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.75rem;
}

.table-collapse__summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  cursor: pointer;
  font-weight: 650;
  color: var(--brand-strong);
}

.table-collapse__summary::-webkit-details-marker {
  display: none;
}

.table-scroll {
  margin-top: 0.85rem;
  overflow-x: auto;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
}

.result-table th,
.result-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.result-table th {
  color: var(--text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-table td {
  color: var(--text);
  font-family: "Fira Code", monospace;
  font-size: 0.87rem;
  font-variant-numeric: tabular-nums;
}

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

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.export-actions--disabled .secondary-action {
  opacity: 0.8;
}

html[data-theme="dark"] .secondary-action,
html.dark .secondary-action {
  background: rgba(15, 23, 42, 0.96);
  color: #d9f5ff;
  border: 1px solid rgba(125, 211, 252, 0.28);
}

/* WCAG fix: light blue bg (#38bdf8) + white text = 2.1:1 (fail). Use dark blue bg instead. */
html[data-theme="dark"] .primary-action,
html.dark .primary-action {
  background: #0c4a6e;
}

/* Higher specificity needed to override html.dark .secondary-action color */
html[data-theme="dark"] .secondary-action.secondary-action--active,
html.dark .secondary-action.secondary-action--active {
  background: #0c4a6e;
  color: #7dd3fc;
  border-color: rgba(125, 211, 252, 0.35);
}

html[data-theme="dark"] .field__control,
html.dark .field__control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2338bdf8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

html[data-theme="dark"] .field__control option,
html.dark .field__control option {
  color: var(--text);
}

.export-panel__note {
  margin: -0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.export-panel {
  display: grid;
  gap: 0.9rem;
}

.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-1px);
}

body.station-modal-open {
  overflow: hidden;
}

.station-modal {
  width: min(1360px, calc(100vw - 1rem));
  max-width: 1360px;
  max-height: calc(100vh - 1.5rem);
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.station-modal::backdrop {
  background: rgba(2, 6, 23, 0.56);
  backdrop-filter: blur(14px);
}

.station-modal__surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 1rem;
  min-height: min(720px, calc(100vh - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: 0 28px 80px rgba(2, 6, 23, 0.28);
  overflow: hidden;
}

.station-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.2rem 0;
}

.station-modal__heading {
  min-width: 0;
  flex: 1 1 auto;
}

.station-modal__eyebrow,
.station-modal-state__eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.station-modal__title,
.station-modal-state__title {
  margin: 0.3rem 0 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.station-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--brand-strong);
}

.station-modal__header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.station-modal__location {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--brand-strong);
  text-decoration: none;
}

.station-modal__body {
  min-height: 0;
  overflow: auto;
  padding: 0 1.2rem 1.2rem;
}

.station-modal-state {
  display: grid;
  gap: 0.75rem;
  min-height: 320px;
  padding: 1rem 0 0;
}

.station-modal-state__text {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 42rem;
}

.station-modal-state__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.station-modal-skeleton {
  display: grid;
  gap: 1rem;
  margin-top: 0.35rem;
}

.station-modal-skeleton__row,
.station-modal-skeleton__grid,
.station-modal-skeleton__panel {
  display: grid;
  gap: 0.9rem;
}

.station-modal-skeleton__row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.station-modal-skeleton__grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.station-modal-skeleton__panel {
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.station-modal-skeleton__block {
  display: block;
  width: 100%;
  min-height: 74px;
  border-radius: 16px;
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.16) 0%, rgba(148, 163, 184, 0.3) 50%, rgba(148, 163, 184, 0.16) 100%);
  background-size: 220% 100%;
  animation: station-modal-skeleton-pulse 1.3s ease-in-out infinite;
}

.station-modal-skeleton__block--title {
  min-height: 26px;
  max-width: 20rem;
}

.station-modal-skeleton__block--action {
  min-height: 42px;
  width: 7rem;
  border-radius: 999px;
}

.station-modal-skeleton__block--wide {
  min-height: 48px;
}

.station-modal-skeleton__block--chart {
  min-height: 260px;
}

html[data-theme="dark"] .station-modal__surface,
html.dark .station-modal__surface {
  background: rgba(15, 23, 42, 0.94);
}

html[data-theme="dark"] .station-modal__close,
html.dark .station-modal__close {
  background: rgba(2, 6, 23, 0.88);
}

html[data-theme="dark"] .station-modal__location,
html.dark .station-modal__location {
  background: rgba(2, 6, 23, 0.88);
}

html[data-theme="dark"] .station-modal-skeleton__panel,
html.dark .station-modal-skeleton__panel {
  background: rgba(2, 6, 23, 0.72);
}

.modal-station-detail {
  display: grid;
  gap: 1rem;
}

.field--actions {
  grid-column: 1 / -1;
}

.action-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: flex-start;
}

.modal-action-row__actions .action-group > * {
  flex: 0 0 auto;
}

/* Visual separator between view toggles and export buttons */
.action-group button:not([data-export-action]) + button[data-export-action] {
  margin-left: 0.3rem;
  padding-left: calc(0.75rem + 0.55rem);
  border-left: 1px solid var(--line);
  border-radius: 0 12px 12px 0;
}

.secondary-action--active {
  background: var(--brand);
  border-color: transparent;
  color: #fff;
}

.station-modal-detail__selectors,
.station-modal-detail__results {
  position: relative;
  display: grid;
  gap: 1rem;
}

.station-modal-detail__selectors.is-updating,
.station-modal-detail__results.is-updating {
  pointer-events: none;
}

.station-modal-detail__selectors.is-updating > *,
.station-modal-detail__results.is-updating > * {
  opacity: 0.42;
}

.station-modal-detail__selectors.is-updating::after,
.station-modal-detail__results.is-updating::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.1) 0%, rgba(148, 163, 184, 0.22) 50%, rgba(148, 163, 184, 0.1) 100%);
  background-size: 220% 100%;
  animation: station-modal-skeleton-pulse 1.1s ease-in-out infinite;
}

.table-modal-panel {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.table-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.table-pager__button {
  min-width: 7.5rem;
}

.table-pager__status {
  color: var(--text-muted);
  font-size: 0.92rem;
}

html[data-theme="dark"] .table-modal-panel,
html.dark .table-modal-panel {
  background: rgba(15, 23, 42, 0.9);
}

html[data-theme="dark"] .station-modal-detail__selectors.is-updating::after,
html[data-theme="dark"] .station-modal-detail__results.is-updating::after,
html.dark .station-modal-detail__selectors.is-updating::after,
html.dark .station-modal-detail__results.is-updating::after {
  background: linear-gradient(90deg, rgba(51, 65, 85, 0.28) 0%, rgba(100, 116, 139, 0.34) 50%, rgba(51, 65, 85, 0.28) 100%);
  background-size: 220% 100%;
}

@keyframes station-modal-skeleton-pulse {
  0% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0 50%;
  }
}

@media (max-width: 1120px) {
  .topbar {
    flex-direction: column;
  }

  .toolbar {
    margin-left: 0;
    justify-content: flex-start;
    width: 100%;
  }

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

  /* summary grid keeps 3 columns — don't let the generic 2-col rule override it */
  .info-grid--summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .summary-metrics,
  .series-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .station-expanded__meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .station-modal-skeleton__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1121px) {
  .brand {
    grid-template-columns: 120pt minmax(10rem, 11.5rem) minmax(0, 1fr);
    column-gap: 1.75rem;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0.75rem;
  }

  .topbar,
  .panel,
  .info-card {
    border-radius: 20px;
  }

  .toolbar,
  .toolbar__controls {
    flex-wrap: wrap;
  }

  /* info-grid stays 2 cols on mobile; form-grid goes to 1 col */
  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .info-grid--summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-action-row {
    grid-template-columns: 1fr;
  }

  .panel__header,
  .detail-block__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .station-expanded__header {
    flex-direction: column;
  }

  .summary-card__header,
  .chart-frame__header,
  .table-collapse__summary {
    flex-direction: column;
    align-items: flex-start;
  }

  /* keep 2-col grid for metric summaries on mobile */
  .summary-metrics,
  .series-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .station-expanded__meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* hide network column on small screens to reduce table min-width */
  .station-table th:nth-child(4),
  .station-table td:nth-child(4) {
    display: none;
  }

  .station-table {
    min-width: 420px;
  }

  /* scroll shadow hint: fades out content at right edge */
  .station-list__table-wrap {
    background:
      linear-gradient(to right, transparent 85%, var(--surface-muted)),
      linear-gradient(to right, var(--surface-muted) 0%, transparent 15%);
    background-attachment: local, scroll;
    background-repeat: no-repeat;
    -webkit-overflow-scrolling: touch;
  }

  .station-modal {
    width: calc(100vw - 0.75rem);
    max-height: calc(100vh - 0.75rem);
  }

  .station-modal__surface {
    min-height: calc(100vh - 0.75rem);
    max-height: calc(100vh - 0.75rem);
    gap: 0.75rem;
  }

  .station-modal__header,
  .station-modal__body {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .station-modal__body {
    padding-bottom: 0.9rem;
  }

  .station-modal__header {
    align-items: flex-start;
  }

  .station-modal__header,
  .station-modal__header-actions,
  .table-pager {
    flex-direction: column;
    align-items: flex-start;
  }

  .station-modal__header-actions,
  .action-group,
  .modal-action-row {
    width: 100%;
  }

  /* action group: view buttons 2-per-row, export buttons 3-per-row */
  .action-group {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .action-group > *:not([data-export-action]) {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
  }

  .action-group [data-export-action] {
    flex: 1 1 calc(33.33% - 0.35rem);
    min-width: 0;
  }

  /* export separator on mobile: top border + full-width first export button */
  .action-group button:not([data-export-action]) + button[data-export-action] {
    flex-basis: 100%;
    margin-left: 0;
    padding-left: 0.75rem;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 12px;
    padding-top: calc(0.75rem + 0.2rem);
    margin-top: 0.1rem;
  }

  /* after the first export btn, revert flex-basis to 1/3 */
  .action-group [data-export-action] + [data-export-action] {
    flex: 1 1 calc(33.33% - 0.35rem);
    border-top: none;
    padding-top: 0.75rem;
    margin-top: 0;
  }

  .station-modal__title,
  .station-modal-state__title {
    font-size: 1.05rem;
  }

  .station-modal-skeleton__row,
  .station-modal-skeleton__grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  /* very small screens: also hide component count column */
  .station-table th:nth-child(5),
  .station-table td:nth-child(5) {
    display: none;
  }

  .station-table {
    min-width: 300px;
  }

  /* info-grid--summary: stack to 2 col on small screens */
  .info-grid--summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  /* info-grid--summary: full 1-col reflow on very narrow viewports (360px phones) */
  .info-grid--summary {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   PORTAL FOOTER
   ============================================================ */

.portal-footer {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 1.25rem 0;
  border-top: 1px solid var(--line);
  text-align: center;
}

.portal-footer__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.portal-footer__link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.14s;
}

.portal-footer__link:hover {
  color: var(--brand);
}

.portal-footer__brand {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}
