:root {
  color-scheme: light;
  --page: #f1f5f6;
  --surface: #ffffff;
  --surface-raised: #f7fafb;
  --surface-tint: #e4f0f2;
  --border: #c7d6da;
  --text: #172a30;
  --muted: #435b63;
  --accent: #12677b;
  --accent-hover: #0c5263;
  --accent-action: #12677b;
  --accent-action-hover: #0c5263;
  --accent-on-action: #ffffff;
  --selection-background: #12677b;
  --selection-foreground: #ffffff;
  --chart-ph: #176f9a;
  --chart-oxygen: #28714e;
  --chart-grid: #d7e1e4;
  --ok-bg: #e6f4eb;
  --ok-text: #155e35;
  --ok-border: #8ebba0;
  --warn-bg: #fff3d8;
  --warn-text: #704700;
  --warn-border: #d7b76b;
  --critical-bg: #fbe9e8;
  --critical-text: #852d2b;
  --critical-border: #d89c99;
  --info-bg: #e8f0f2;
  --info-text: #344f58;
  --radius: 12px;
  --shadow: 0 3px 12px rgba(20, 50, 60, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #101b20;
    --surface: #18262d;
    --surface-raised: #1d2e36;
    --surface-tint: #213941;
    --border: #354b54;
    --text: #edf4f5;
    --muted: #b6c8cc;
    --accent: #70bfd0;
    --accent-hover: #a0d8e2;
    --accent-action: #12677b;
    --accent-action-hover: #0c5263;
    --accent-on-action: #ffffff;
    --selection-background: #70bfd0;
    --selection-foreground: #102329;
    --chart-ph: #71c1e6;
    --chart-oxygen: #88d3a6;
    --chart-grid: #31434a;
    --ok-bg: #183728;
    --ok-text: #a5e0b8;
    --ok-border: #477458;
    --warn-bg: #423512;
    --warn-text: #f5d485;
    --warn-border: #806b31;
    --critical-bg: #421f20;
    --critical-text: #f2aaa5;
    --critical-border: #85504e;
    --info-bg: #263b42;
    --info-text: #c2d6da;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scrollbar-color: var(--border) var(--page);
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

::selection {
  background: var(--selection-background);
  color: var(--selection-foreground);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  accent-color: var(--accent);
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.container {
  width: min(100% - 2rem, 1240px);
  margin-inline: auto;
}

.app-header {
  padding: 1.5rem 0 1.35rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.header-titles {
  min-width: 0;
}

.header-titles h1 {
  max-width: 22ch;
  margin: 0;
  font-size: clamp(1.55rem, 2.8vw, 2.2rem);
  line-height: 1.14;
  letter-spacing: -0.025em;
}

.subtitle {
  margin: 0.45rem 0 0.8rem;
  color: var(--muted);
  font-size: 1rem;
}

.standard-note {
  display: grid;
  gap: 0.12rem;
  flex: 0 0 min(340px, 36%);
  padding: 0.85rem 1rem;
  background: var(--surface-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.standard-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.standard-note strong {
  font-size: 1rem;
}

.standard-note > span:not(.standard-label),
.standard-note small {
  color: var(--muted);
}

.standard-note small {
  margin-top: 0.35rem;
  line-height: 1.4;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 1.85rem;
  padding: 0.24rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.3;
}

.badge-demo {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.badge-standard,
.badge-sim {
  background: var(--info-bg);
  color: var(--info-text);
}

.main-grid {
  display: grid;
  gap: 1.15rem;
  padding-top: 1.25rem;
  padding-bottom: 2rem;
}

.panel {
  min-width: 0;
  padding: clamp(1rem, 2.5vw, 1.45rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.panel-header h2 {
  margin: 0;
  font-size: clamp(1.08rem, 1.6vw, 1.28rem);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.panel-desc {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.criteria-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0;
}

.criteria-list > div {
  min-width: 0;
  padding: 0.7rem 0.8rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.criteria-list dt {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.criteria-list dd {
  margin: 0.2rem 0 0;
  font-size: 0.96rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.criteria-list .criteria-complement {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--info-bg);
}

.criteria-footnote {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.metric-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.9rem 1rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.metric-card.status-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.metric-card.status-critico {
  background: var(--critical-bg);
  border-color: var(--critical-border);
}

.metric-card.status-informativo {
  background: var(--info-bg);
}

.metric-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
  line-height: 1.35;
}

.metric-value {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 1.8rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.metric-unit {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0;
}

.metric-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.4;
}

.metric-footer > span:first-child {
  flex: 1 1 130px;
}

.status-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 0.17rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1.35;
}

.status-pill.status-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.status-pill.status-atencion {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.status-pill.status-critico {
  background: var(--critical-bg);
  border-color: var(--critical-border);
  color: var(--critical-text);
}

.status-pill.status-informativo {
  background: var(--info-bg);
  border-color: var(--border);
  color: var(--info-text);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.32rem;
}

.form-group label {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.form-group input,
.form-group select,
.filter-bar select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 0.68rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
}

.form-group input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.field-hint {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.form-feedback {
  min-height: 1.4rem;
  margin-top: 0.9rem;
  font-size: 0.86rem;
}

.form-feedback.error,
.form-feedback.success {
  padding: 0.62rem 0.75rem;
  border: 1px solid;
  border-radius: 7px;
}

.form-feedback.error {
  background: var(--critical-bg);
  border-color: var(--critical-border);
  color: var(--critical-text);
}

.form-feedback.success {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.25rem;
}

.btn {
  min-height: 2.8rem;
  padding: 0.62rem 1rem;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.btn-primary {
  background: var(--accent-action);
  color: var(--accent-on-action);
}

.btn-primary:hover {
  background: var(--accent-action-hover);
  color: var(--accent-on-action);
}

.btn-secondary {
  background: var(--surface-raised);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-tint);
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.filter-bar label {
  flex: 0 0 auto;
  font-weight: 700;
}

.filter-bar select {
  width: auto;
  min-width: min(100%, 250px);
  min-height: 2.5rem;
}

.chart-container {
  width: 100%;
  min-width: 0;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-gridline {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-label,
.chart-axis-title,
.chart-legend {
  fill: var(--muted);
  font-family: inherit;
}

.chart-label-ph {
  fill: var(--chart-ph);
}

.chart-label-oxygen {
  fill: var(--chart-oxygen);
}

.chart-threshold {
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  opacity: 0.9;
}

.chart-threshold-ph {
  stroke: var(--chart-ph);
}

.chart-threshold-oxygen {
  stroke: var(--chart-oxygen);
}

.chart-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-line-ph,
.chart-point-ph {
  stroke: var(--chart-ph);
}

.chart-line-ph {
  fill: none;
}

.chart-line-oxygen,
.chart-point-oxygen {
  stroke: var(--chart-oxygen);
}

.chart-line-oxygen {
  stroke-dasharray: 7 4;
  fill: none;
}

.chart-point-ph {
  fill: var(--surface);
  stroke-width: 2;
}

.chart-point-oxygen {
  fill: var(--surface);
  stroke-width: 2;
}

.chart-empty {
  padding: 1rem;
  background: var(--surface-raised);
  border: 1px dashed var(--border);
  border-radius: 7px;
}

.table-wrapper {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  scrollbar-color: var(--border) var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 0.62rem 0.72rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-tint);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 750;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: var(--surface-raised);
}

.origin-tag {
  color: var(--muted);
  font-size: 0.76rem;
}

.app-footer {
  padding: 1.2rem 0 1.4rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}

.app-footer p {
  max-width: 100ch;
  margin: 0.45rem 0;
}

.footer-note {
  font-size: 0.78rem;
}

@media (max-width: 900px) {
  .header-content {
    align-items: flex-start;
    flex-direction: column;
    gap: 1rem;
  }

  .standard-note {
    flex-basis: auto;
    width: 100%;
  }

  .criteria-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cards-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .container {
    width: min(100% - 1.25rem, 1240px);
  }

  .app-header {
    padding: 1.15rem 0;
  }

  .header-titles h1 {
    max-width: 18ch;
  }

  .main-grid {
    gap: 0.85rem;
    padding-top: 0.85rem;
  }

  .criteria-list,
  .cards-grid,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .criteria-list .criteria-complement {
    grid-column: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 0.15rem;
  }

  .metric-footer {
    align-items: center;
  }

  .filter-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-bar select {
    width: 100%;
  }

  .form-actions .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .metric-card,
  .panel,
  .criteria-list > div,
  .form-group input,
  .form-group select,
  .filter-bar select,
  .data-table th,
  .data-table td {
    border: 1px solid CanvasText;
  }
}
