:root {
  color-scheme: light;
  --page: #f4f6f5;
  --surface: #ffffff;
  --surface-muted: #eef2f0;
  --border: #dce3df;
  --border-strong: #c6d0cb;
  --text: #18201d;
  --muted: #66716c;
  --accent: #176b4a;
  --accent-soft: #e5f2ec;
  --blue: #2869a7;
  --orange: #c15d2b;
  --gold: #a57a16;
  --red: #b73d4b;
  --violet: #7457a5;
  --cyan: #167d89;
  --shadow: 0 8px 24px rgba(24, 32, 29, 0.06);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  font-size: 15px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
}

.primary-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.primary-nav a {
  min-height: 34px;
  padding: 8px 13px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.primary-nav a:hover,
.primary-nav a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
}

.connection-state.live .connection-dot {
  background: var(--accent);
}

.connection-state.error .connection-dot {
  background: var(--red);
}

.account-link,
.quiet-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.account-link:hover,
.quiet-button:hover {
  color: var(--text);
}

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 36px 32px 64px;
}

.page-heading,
.section-heading,
.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.page-heading {
  margin-bottom: 28px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  line-height: 1.15;
}

h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.page-subtitle {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.period-control,
.access-switch {
  display: flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.period-control button {
  min-width: 54px;
  min-height: 34px;
  padding: 7px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.period-control button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.08);
}

.preview-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -12px 0 20px;
  padding: 11px 14px;
  border: 1px solid #d7b96d;
  border-radius: 6px;
  background: #fff9e8;
  color: #63501c;
  font-size: 12px;
}

.preview-banner[hidden] {
  display: none;
}

.analysis-controls,
.time-navigator {
  margin-bottom: 24px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.analysis-heading,
.time-navigator-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.analysis-heading h2,
.time-navigator-heading h2 {
  font-size: 15px;
}

#timeWindowLabel,
.weather-state {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.time-navigator {
  margin-bottom: 12px;
  padding: 14px 18px 12px;
}

.time-navigator-heading {
  margin-bottom: 10px;
}

.time-navigator-controls {
  display: grid;
  grid-template-columns: max-content minmax(260px, 1fr);
  align-items: center;
  gap: 20px;
}

.timeline-control {
  min-width: 0;
}

.dual-range {
  --range-start: 0%;
  --range-end: 100%;
  position: relative;
  height: 24px;
}

.dual-range::before,
.dual-range::after {
  position: absolute;
  top: 10px;
  height: 4px;
  border-radius: 2px;
  content: "";
}

.dual-range::before {
  right: 0;
  left: 0;
  background: var(--border-strong);
}

.dual-range::after {
  right: calc(100% - var(--range-end));
  left: var(--range-start);
  background: var(--accent);
}

.dual-range input[type="range"] {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 24px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
  pointer-events: none;
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  appearance: none;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 5px rgba(24, 32, 29, 0.18);
  pointer-events: auto;
}

.dual-range input[type="range"]::-moz-range-track {
  height: 4px;
  background: transparent;
}

.dual-range input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 5px rgba(24, 32, 29, 0.18);
  pointer-events: auto;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}

.summary-item {
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.summary-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
}

.summary-value {
  display: block;
  overflow: hidden;
  font-size: 24px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-detail {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.sensor-section,
.readings-section {
  margin-bottom: 36px;
}

.analysis-controls {
  margin-bottom: 12px;
}

.analysis-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 36px minmax(180px, 1fr) repeat(3, auto);
  align-items: end;
  gap: 10px;
}

.analysis-fields > label:not(.toggle-control) {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.analysis-fields select {
  width: 100%;
  min-height: 38px;
  padding: 8px 34px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.swap-button {
  width: 36px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.toggle-control input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.demo-action {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-top: 10px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
}

.section-heading {
  margin-bottom: 14px;
}

.selection-actions {
  display: flex;
  gap: 4px;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.sensor-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 174px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.sensor-card:hover,
.sensor-card.selected {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.sensor-card:not(.selected) {
  opacity: 0.58;
}

.sensor-card input {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.sensor-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding-right: 28px;
}

.sensor-swatch,
.legend-swatch {
  flex: 0 0 auto;
  border-radius: 50%;
}

.sensor-swatch {
  width: 9px;
  height: 9px;
}

.sensor-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sensor-location {
  overflow: hidden;
  margin: 5px 0 14px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sensor-temperature {
  align-self: end;
  font-size: 31px;
  font-weight: 600;
}

.sensor-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 36px;
}

.chart-panel,
.detail-panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.chart-panel-wide {
  grid-row: span 2;
}

.panel-heading {
  align-items: center;
  margin-bottom: 14px;
}

.panel-unit,
.table-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.chart-frame {
  position: relative;
  width: 100%;
  height: 390px;
}

.chart-frame-small {
  height: 210px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  margin: 0;
  color: var(--muted);
}

.empty-state.visible {
  display: grid;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  min-height: 18px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.legend-swatch {
  width: 8px;
  height: 8px;
}

.weather-swatch {
  background: #49545f;
}

.difference-swatch {
  background: var(--red);
}

.empty-grid {
  grid-column: 1 / -1;
}

.detail-list {
  display: grid;
  gap: 0;
  margin: 0;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.detail-list div:last-child {
  border-bottom: 0;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  font-weight: 650;
  text-align: right;
}

.readings-section {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.admin-only[hidden] {
  display: none;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

td {
  font-size: 12px;
}

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

.table-sensor {
  font-weight: 650;
}

.audit-status {
  display: inline-flex;
  min-width: 62px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}

.audit-status.success {
  border-color: #afd3c1;
  background: var(--accent-soft);
  color: var(--accent);
}

.audit-status.failure {
  border-color: #e4bac0;
  background: #faecee;
  color: var(--red);
}

.audit-ip {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.empty-grid,
.empty-table {
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

.login-view {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.login-view[hidden] {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-context {
  margin: 10px 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.access-switch {
  margin: 0 0 20px;
  padding: 4px;
}

.access-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.access-switch label {
  flex: 1;
  cursor: pointer;
}

.access-switch input {
  position: absolute;
  opacity: 0;
}

.access-switch span {
  display: grid;
  min-height: 38px;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.access-switch input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.08);
}

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 650;
}

input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
}

.primary-button {
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

.primary-button:hover {
  background: #12583d;
}

.form-error {
  min-height: 20px;
  margin: 8px 0;
  color: var(--red);
  font-size: 12px;
}

.chart-tooltip {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  max-width: 280px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 11px;
  line-height: 1.6;
  pointer-events: none;
}

.color-0 { background: var(--accent); }
.color-1 { background: var(--blue); }
.color-2 { background: var(--orange); }
.color-3 { background: var(--violet); }
.color-4 { background: var(--red); }
.color-5 { background: var(--cyan); }
.color-6 { background: var(--gold); }
.color-7 { background: #4d6f24; }

@media (max-width: 1050px) {
  .app-header {
    grid-template-columns: auto 1fr auto;
  }

  .primary-nav {
    justify-self: center;
  }

  .connection-state {
    display: none;
  }

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

  .analysis-fields {
    grid-template-columns: minmax(180px, 1fr) 36px minmax(180px, 1fr);
  }

  .time-navigator-controls {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .toggle-control {
    justify-content: center;
  }
}

@media (max-width: 780px) {
  .app-header {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  .brand {
    margin-right: auto;
  }

  .primary-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .primary-nav a {
    flex: 1;
    text-align: center;
  }

  .page-shell {
    padding: 28px 16px 48px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .analysis-fields {
    grid-template-columns: 1fr 36px 1fr;
  }

  .toggle-control {
    grid-column: span 1;
  }

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

  .chart-panel-wide {
    grid-row: auto;
  }

  .chart-frame {
    height: 300px;
  }

  .chart-frame-small {
    height: 240px;
  }
}

@media (max-width: 520px) {
  .header-actions {
    gap: 8px;
  }

  .account-link,
  .quiet-button {
    font-size: 11px;
  }

  h1 {
    font-size: 26px;
  }

  .period-control {
    width: 100%;
  }

  .period-control button {
    flex: 1;
  }

  .preview-banner,
  .time-navigator-heading,
  .analysis-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  #timeWindowLabel,
  .weather-state {
    text-align: left;
  }

  .analysis-fields {
    grid-template-columns: 1fr;
  }

  .swap-button {
    justify-self: center;
    transform: rotate(90deg);
  }

  .toggle-control {
    justify-content: flex-start;
  }

  .summary-grid,
  .sensor-grid {
    grid-template-columns: 1fr;
  }

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

  .summary-item {
    padding: 15px;
  }

  .summary-value {
    font-size: 21px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .selection-actions {
    width: 100%;
    justify-content: space-between;
  }

  .login-panel {
    padding: 24px 20px;
  }
}
