:root,
html[data-theme="light"] {
  --bg: #f5f3ee;
  --surface: rgba(255, 252, 247, 0.92);
  --surface-2: #f1ede6;
  --surface-3: #e7e1d8;
  --surface-4: #ddd6ca;
  --text: #27231d;
  --muted: #706b64;
  --border: #d7d0c6;
  --primary: #0d6f79;
  --primary-strong: #0a8793;
  --primary-soft: rgba(13, 111, 121, 0.12);
  --accent: #c88a13;
  --accent-strong: #a66f09;
  --accent-soft: rgba(200, 138, 19, 0.14);
  --success: #4d8a2d;
  --success-strong: #3f7324;
  --success-soft: rgba(77, 138, 45, 0.14);
  --danger: #b14b46;
  --danger-strong: #933934;
  --danger-soft: rgba(177, 75, 70, 0.14);
  --shadow: 0 12px 32px rgba(44, 34, 20, 0.12);
  --radius: 18px;
  --radius-sm: 10px;
  --group-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(245, 240, 232, 0.82));
  --group-border: rgba(13, 111, 121, 0.16);
  --group-head-bg: rgba(13, 111, 121, 0.08);
  --group-head-border: rgba(13, 111, 121, 0.12);
  --button-text-strong: #ffffff;
}

html[data-theme="dark"] {
  --bg: #171614;
  --surface: rgba(34, 33, 31, 0.92);
  --surface-2: #22211f;
  --surface-3: #2a2927;
  --surface-4: #353432;
  --text: #cdccca;
  --muted: #8a8883;
  --border: #393836;
  --primary: #4f98a3;
  --primary-strong: #6ab6c1;
  --primary-soft: rgba(79, 152, 163, 0.14);
  --accent: #e8af34;
  --accent-strong: #f2bf57;
  --accent-soft: rgba(232, 175, 52, 0.12);
  --success: #6daa45;
  --success-strong: #84be5e;
  --success-soft: rgba(109, 170, 69, 0.16);
  --danger: #d77a72;
  --danger-strong: #e59790;
  --danger-soft: rgba(215, 122, 114, 0.16);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  --group-surface: linear-gradient(180deg, rgba(42, 41, 39, 0.74), rgba(28, 27, 25, 0.92));
  --group-border: rgba(79, 152, 163, 0.18);
  --group-head-bg: rgba(79, 152, 163, 0.09);
  --group-head-border: rgba(79, 152, 163, 0.18);
  --button-text-strong: #0f1416;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--primary) 18%, transparent), transparent 30%),
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent) 10%, transparent), transparent 24%),
    var(--bg);
  transition: background-color 180ms ease, color 180ms ease;
}

a,
button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
}

.topbar,
.layout {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding: 32px 0 20px;
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
h4,
h5,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 3rem);
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1.05rem;
}

h4 {
  font-size: 1rem;
}

h5 {
  font-size: 0.96rem;
}

.layout {
  padding-bottom: 40px;
}

.stats-grid,
.sensor-grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 24px;
}

.sensor-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.stat-card,
.sensor-card,
.chart-wrap,
.range-form,
.empty-state,
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.stat-card,
.sensor-card,
.empty-state {
  padding: 20px;
}

.stat-card span,
.sensor-card span,
.meta-row,
.timestamp,
.range-form label,
.sensor-avg-state,
.group-count,
.field-stack label,
.group-average-note,
.ventilation-meta,
.ventilation-card p {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  color: var(--text);
}

.stat-card--outdoor {
  border-color: color-mix(in srgb, var(--primary) 20%, var(--border));
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--primary) 6%, var(--surface)), var(--surface));
}

.section-head {
  margin: 28px 0 16px;
}

.sensor-group {
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--group-border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--group-surface);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 10px 24px rgba(0, 0, 0, 0.04);
}

.group-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--group-head-border);
  border-radius: 14px;
  background: var(--group-head-bg);
}

.group-head__title {
  display: grid;
  gap: 8px;
}

.group-head h3 {
  color: var(--text);
}

.group-count {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-3) 65%, transparent);
  border: 1px solid var(--border);
  font-size: 0.92rem;
}

.group-averages {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: stretch;
}

.group-average-card {
  min-width: 160px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.group-average-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.group-average-card strong {
  color: var(--text);
  font-size: 1.1rem;
}

.group-average-note {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  font-size: 0.85rem;
  white-space: nowrap;
}

.sensor-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sensor-card--outdoor {
  border-color: color-mix(in srgb, var(--primary) 22%, var(--border));
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--primary) 5%, var(--surface)), var(--surface));
}

.sensor-card-head,
.reading-row,
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.sensor-card-head {
  align-items: flex-start;
}

.sensor-card-head__title-wrap {
  min-width: 0;
  flex: 1 1 auto;
}

.sensor-card-title {
  display: block;
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.35;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.sensor-card-head__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.reading-row {
  margin-top: 4px;
}

.reading-block {
  min-width: 0;
  flex: 1 1 0;
  padding: 14px 14px 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-2) 84%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 86%, transparent);
}

.reading-block span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.reading-row strong {
  display: block;
  margin-top: 6px;
  font-size: 1.75rem;
  color: var(--text);
}

.meta-row {
  padding-top: 14px;
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.timestamp {
  font-size: 0.85rem;
}

.badge,
.ventilation-badge {
  display: inline-flex;
  align-items: center;
  align-self: start;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  border: 1px solid transparent;
}

.badge {
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: var(--success-soft);
  color: color-mix(in srgb, var(--success) 82%, white 18%) !important;
}

.badge--muted {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-soft);
  color: var(--accent) !important;
}

.ventilation-badge--ok {
  background: var(--success-soft);
  color: var(--success-strong) !important;
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.ventilation-badge--ventilate,
.ventilation-badge--cool {
  background: var(--primary-soft);
  color: var(--primary-strong) !important;
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
}

.ventilation-badge--wait,
.ventilation-badge--warm,
.ventilation-badge--dry,
.ventilation-badge--cold {
  background: var(--accent-soft);
  color: var(--accent-strong) !important;
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.range-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

select {
  appearance: none;
  min-height: 40px;
  padding: 8px 36px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    var(--surface-2);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px),
    0 0;
  background-size: 6px 6px, 6px 6px, 100% 100%;
  background-repeat: no-repeat;
  color: var(--text);
  font-size: 1rem;
}

.chart-wrap {
  height: 440px;
  padding: 16px;
}

.empty-state {
  text-align: center;
}

.sensor-disclosure {
  margin-top: 2px;
  display: grid;
  gap: 12px;
}

.sensor-disclosure__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
  color: var(--text);
  font-weight: 600;
  text-align: left;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.sensor-disclosure__toggle:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: color-mix(in srgb, var(--surface-3) 92%, transparent);
}

.sensor-disclosure__toggle[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--primary) 55%, transparent);
  background: color-mix(in srgb, var(--primary) 10%, var(--surface-2));
}

.sensor-disclosure__label {
  color: var(--text);
}

.sensor-disclosure__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  color: var(--muted);
  transition: transform 180ms ease;
}

.sensor-disclosure__toggle[aria-expanded="true"] .sensor-disclosure__icon {
  transform: rotate(180deg);
}

.sensor-disclosure__content {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.ventilation-card {
  margin-top: 4px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
  display: grid;
  gap: 10px;
}

.ventilation-card--ok {
  border-color: color-mix(in srgb, var(--success) 26%, var(--border));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--success) 8%, var(--surface)),
    var(--surface-2)
  );
}

.ventilation-card--ventilate,
.ventilation-card--cool {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--primary) 10%, var(--surface)),
    var(--surface-2)
  );
}

.ventilation-card--wait,
.ventilation-card--warm,
.ventilation-card--dry,
.ventilation-card--cold {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 10%, var(--surface)),
    var(--surface-2)
  );
}

.ventilation-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.ventilation-card__head h5 {
  color: var(--text);
}

.ventilation-card p {
  line-height: 1.55;
}

.ventilation-card p strong {
  color: var(--text);
}

.ventilation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.85rem;
}

.ventilation-meta span {
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
}

.sensor-settings-form {
  position: relative;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.field-stack {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field-stack input[type="text"] {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.field-stack input[type="text"]::placeholder {
  color: var(--muted);
}

.field-stack input[type="text"]:focus {
  border-color: color-mix(in srgb, var(--primary) 75%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 12%, transparent);
  background: var(--surface-3);
}

.switch-field {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 12px;
  cursor: pointer;
  user-select: none;
}

.switch-input {
  position: absolute;
  inline-size: 54px;
  block-size: 30px;
  margin: 0;
  opacity: 0.0001;
  cursor: pointer;
}

.switch-ui {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 54px;
  height: 30px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.switch-knob {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f7f7f5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transform: translateX(0);
  transition: transform 180ms ease, background-color 180ms ease;
}

.switch-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.switch-title {
  color: var(--text) !important;
  font-size: 0.96rem;
  line-height: 1.35;
}

.switch-subtitle {
  color: var(--muted) !important;
  font-size: 0.85rem;
  line-height: 1.4;
}

.switch-input:checked + .switch-ui {
  background: color-mix(in srgb, var(--primary) 22%, var(--surface-3));
  border-color: color-mix(in srgb, var(--primary) 80%, transparent);
}

.switch-input:checked + .switch-ui .switch-knob {
  transform: translateX(24px);
  background: #ffffff;
}

.switch-field:hover .switch-ui {
  border-color: color-mix(in srgb, var(--primary) 45%, transparent);
}

.switch-input:focus-visible + .switch-ui {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.button,
.theme-toggle {
  appearance: none;
  border: 1px solid transparent;
  min-height: 42px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    color 160ms ease;
}

.button {
  border-radius: 10px;
}

.button:hover,
.theme-toggle:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--primary);
  color: var(--button-text-strong);
  font-weight: 700;
}

.button-primary:hover {
  background: var(--primary-strong);
}

.button-primary:active,
.theme-toggle:active {
  transform: translateY(0);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.theme-toggle__icon {
  font-size: 1rem;
  line-height: 1;
}

.theme-toggle__label {
  font-weight: 600;
}

.sensor-avg-state {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.5;
}

.sensor-avg-state--active {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  border-color: color-mix(in srgb, var(--primary) 28%, transparent);
  color: color-mix(in srgb, var(--primary) 55%, var(--text) 45%);
}

.sensor-avg-state--inactive {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-color: color-mix(in srgb, var(--accent) 24%, transparent);
  color: color-mix(in srgb, var(--accent) 55%, var(--text) 45%);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .group-head {
    flex-direction: column;
    align-items: stretch;
  }

  .group-averages {
    justify-content: stretch;
  }

  .group-average-card,
  .group-average-note {
    flex: 1 1 160px;
  }

  .ventilation-card__head {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
  }

  .range-form {
    justify-content: space-between;
  }

  .sensor-card-head,
  .reading-row,
  .meta-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .sensor-card-head__badges {
    justify-content: flex-start;
  }

  .reading-row strong {
    font-size: 1.5rem;
  }

  .reading-block {
    width: 100%;
  }

  .settings-actions {
    justify-content: stretch;
  }

  .settings-actions .button,
  .theme-toggle {
    width: 100%;
  }

  .group-averages {
    flex-direction: column;
  }

  .group-average-card,
  .group-average-note {
    min-width: 0;
  }

  .ventilation-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .ventilation-meta span {
    width: 100%;
  }
}
