:root {
  color-scheme: light;
  --page-bg: #f3f7fb;
  --card: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0284c7;
  --normal: #15803d;
  --normal-bg: #f0fdf4;
  --elevated: #b45309;
  --elevated-bg: #fffbeb;
  --high: #b91c1c;
  --high-bg: #fef2f2;
  --shadow: 0 5px 20px rgba(15, 23, 42, .055);
  font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--page-bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page-bg);
}

button, select { font: inherit; }

.soil-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(16px, 4vw, 56px);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.soil-brand, .soil-header-actions, .sensor-picker {
  display: flex;
  align-items: center;
}

.soil-brand {
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.soil-brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 13px;
  font-weight: 800;
}

.soil-brand strong, .soil-brand small { display: block; }
.soil-brand strong { font-size: 15px; letter-spacing: -.02em; }
.soil-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.soil-header-actions { gap: 16px; }
.sensor-picker { gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.sensor-picker[hidden] { display: none; }
.sensor-picker select {
  max-width: min(42vw, 240px);
  padding: 8px 28px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
}

.back-link {
  padding: 9px 13px;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  background: #f0f9ff;
  color: #075985;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.back-link:hover { background: #e0f2fe; }

.soil-main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 56px) 20px;
}

.page-intro, .panel-heading, .soil-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-intro { margin-bottom: 20px; }
.eyebrow {
  margin: 0 0 7px;
  color: #64748b;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.04em; }
.page-subtitle { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.refresh-indicator { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 11px; }
.refresh-dot { width: 8px; height: 8px; border-radius: 50%; background: #0d9488; }

.alert-banner {
  display: flex;
  min-height: 76px;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 15px 20px;
  border: 1px solid var(--border);
  border-left: 5px solid #94a3b8;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.alert-icon { font-size: 13px; }
.alert-banner > div { flex: 1; min-width: 0; }
.alert-banner h2 { margin: 0 0 3px; font-size: 14px; }
.alert-banner p { margin: 0; color: var(--muted); font-size: 12px; }
.alert-reading { font-size: clamp(20px, 3vw, 27px); font-weight: 800; white-space: nowrap; }
.alert-normal { border-left-color: var(--normal); background: var(--normal-bg); color: #166534; }
.alert-elevated { border-left-color: #d97706; background: var(--elevated-bg); color: #92400e; }
.alert-high { border-left-color: #dc2626; background: var(--high-bg); color: #991b1b; }
.alert-unavailable { border-left-color: #94a3b8; color: #334155; }

.soil-dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.panel-heading { align-items: flex-start; margin-bottom: 16px; }
.panel-heading h2 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.panel-heading .eyebrow { margin-bottom: 5px; }

.current-panel { grid-row: span 2; }
.moisture-reading { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 190px; }
.moisture-value { font-size: clamp(62px, 8vw, 92px); font-weight: 800; letter-spacing: -.075em; line-height: 1; }
.moisture-unit { margin-top: 12px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.gauge-wrap { margin: 4px 4px 0; }
.moisture-gauge { height: 14px; overflow: hidden; border-radius: 999px; background: linear-gradient(90deg, #dcfce7 0 60%, #fef3c7 60% 80%, #fee2e2 80% 100%); }
.gauge-fill { display: block; width: 0; height: 100%; border-right: 2px solid #0f172a; background: rgba(2, 132, 199, .28); transition: width .25s ease; }
.gauge-labels { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 10px; }
.current-note { min-height: 18px; margin: 16px 0 20px; color: var(--muted); font-size: 12px; text-align: center; }
.condition-row { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0 0; border-top: 1px solid #edf2f7; font-size: 12px; }
.condition-row span { color: var(--muted); }
.condition-row strong { text-align: right; }

.status-pill, .sensor-class, .decision-support-label, .chart-count {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  white-space: nowrap;
}
.status-online { background: #dcfce7; color: #166534; }
.status-stale { background: #fef3c7; color: #92400e; }
.status-offline, .status-unavailable { background: #f1f5f9; color: #475569; }
.status-no-data { background: #e2e8f0; color: #475569; }
.sensor-class, .chart-count { background: #f1f5f9; color: #475569; }

.details-list, .calibration-values { margin: 0; }
.details-list > div, .calibration-values > div { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; font-size: 11px; }
.details-list > div:last-child { border-bottom: 0; }
.details-list dt, .calibration-values dt { color: var(--muted); }
.details-list dd, .calibration-values dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.bench-note { margin-top: 13px; padding: 10px 11px; border-radius: 9px; background: #f0f9ff; color: #075985; font-size: 11px; font-weight: 700; line-height: 1.5; }
.calibration-values dd { font-family: "JetBrains Mono", monospace; }
.fine-print { margin: 12px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.alert-explainer > p:not(.fine-print) { min-height: 34px; margin-bottom: 10px; font-size: 13px; font-weight: 700; line-height: 1.5; }
.decision-support-label { background: #eff6ff; color: #1d4ed8; letter-spacing: 0; }
.threshold-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 15px; color: #475569; font-size: 10px; }
.threshold-legend span, .chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.threshold-dot { width: 8px; height: 8px; border-radius: 50%; }
.normal-dot { background: var(--normal); }
.elevated-dot { background: #d97706; }
.high-dot { background: #dc2626; }

.chart-panel, .history-panel { grid-column: 1 / -1; }
.chart-heading { align-items: center; }
.chart-heading .eyebrow { margin-bottom: 5px; }
.chart-wrap { position: relative; min-height: 270px; }
#moisture-chart { display: block; width: 100%; height: auto; min-height: 240px; overflow: visible; }
.chart-empty { position: absolute; inset: 40% 10px auto; margin: 0; color: var(--muted); font-size: 12px; text-align: center; }
.chart-has-data .chart-empty { display: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 9px 20px; margin-top: 6px; color: var(--muted); font-size: 10px; }
.legend-line { width: 19px; border-top: 2px solid; }
.reading-line { border-color: #0284c7; }
.elevated-line { border-color: #d97706; border-top-style: dashed; }
.high-line { border-color: #dc2626; border-top-style: dashed; }
.chart-grid-line { stroke: #e2e8f0; stroke-width: 1; }
.chart-axis-label { fill: #64748b; font: 11px "Plus Jakarta Sans", sans-serif; }
.chart-threshold-label { font: 10px "Plus Jakarta Sans", sans-serif; font-weight: 700; }
.chart-threshold-elevated { stroke: #d97706; }
.chart-threshold-high { stroke: #dc2626; }
.chart-series { fill: none; stroke: #0284c7; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: #fff; stroke: #0284c7; stroke-width: 3; }
.chart-no-data .chart-grid-line, .chart-no-data .chart-axis-label, .chart-no-data .chart-series, .chart-no-data .chart-point { opacity: .15; }

.history-note { margin: -5px 0 10px; }
.history-list { display: grid; gap: 0; }
.history-entry { display: grid; grid-template-columns: minmax(125px, .8fr) minmax(75px, .5fr) minmax(100px, .6fr) minmax(180px, 2fr); align-items: center; gap: 12px; padding: 11px 4px; border-top: 1px solid #f1f5f9; font-size: 11px; }
.history-time, .history-message { color: var(--muted); }
.history-moisture { font-family: "JetBrains Mono", monospace; font-weight: 700; }
.history-level { font-size: 9px; font-weight: 800; letter-spacing: .05em; }
.history-level-normal { color: var(--normal); }
.history-level-elevated { color: var(--elevated); }
.history-level-high { color: var(--high); }
.history-empty { margin: 0; padding: 12px 0; color: var(--muted); font-size: 12px; }
.soil-footer { padding: 16px 2px 0; color: var(--muted); font-size: 10px; }

@media (max-width: 760px) {
  .soil-dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .current-panel { grid-row: auto; }
  .chart-panel, .history-panel { grid-column: auto; }
  .page-intro { align-items: flex-start; flex-direction: column; gap: 10px; }
  .refresh-indicator { font-size: 10px; }
  .moisture-reading { min-height: 155px; }
  .history-entry { grid-template-columns: minmax(105px, 1fr) minmax(60px, .6fr) minmax(80px, .7fr); gap: 6px; }
  .history-message { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .soil-header { min-height: 62px; gap: 8px; padding: 9px 12px; }
  .soil-brand { gap: 8px; }
  .soil-brand-mark { width: 34px; height: 34px; }
  .soil-brand strong { font-size: 13px; }
  .soil-brand small { font-size: 9px; }
  .soil-header-actions { gap: 6px; }
  .back-link { padding: 8px 9px; font-size: 10px; }
  .sensor-picker { flex-direction: column; align-items: flex-start; gap: 3px; font-size: 9px; }
  .sensor-picker select { max-width: 105px; padding: 6px 20px 6px 6px; font-size: 10px; }
  .soil-main { padding: 20px 12px 14px; }
  .alert-banner { gap: 9px; min-height: 68px; padding: 12px; }
  .alert-banner h2 { font-size: 12px; }
  .alert-banner p { font-size: 10px; }
  .alert-reading { font-size: 20px; }
  .panel { padding: 15px; border-radius: 12px; }
  .panel-heading h2 { font-size: 14px; }
  .chart-wrap { min-height: 205px; }
  #moisture-chart { min-height: 180px; }
  .chart-legend { gap: 8px 12px; font-size: 9px; }
  .soil-footer { align-items: flex-start; flex-direction: column; gap: 5px; }
}
