:root{--navy:#102a43;--teal:#0b7285;--teal2:#0891a5;--bg:#f3f7fb;--card:#fff;--text:#172033;--muted:#667085;--line:#e4e7ec;--ok-bg:#e7f8ef;--ok:#087f3f;--l1-bg:#fff4d6;--l1:#9a6200;--l2-bg:#ffe1e1;--l2:#a11515}*{box-sizing:border-box}body{margin:0;background:radial-gradient(circle at top left,#dff7fb 0,#f3f7fb 34rem);color:var(--text);font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}.shell{width:min(1120px,calc(100% - 28px));margin:0 auto;padding:28px 0 48px}.hero{display:flex;justify-content:space-between;gap:24px;align-items:flex-end;padding:28px;border-radius:28px;background:linear-gradient(135deg,#082032,#0b7285 58%,#22b8cf);color:white;box-shadow:0 20px 50px rgba(8,32,50,.18)}.detail-hero{align-items:center}.eyebrow{text-transform:uppercase;letter-spacing:.16em;font-weight:800;font-size:.78rem;margin:0 0 8px;opacity:.82}.hero h1{font-size:clamp(2rem,5vw,4.5rem);line-height:.95;margin:0}.hero-copy{font-size:1.05rem;max-width:620px;margin:14px 0 0;color:#d7f9ff}.hero-actions{display:flex;gap:10px;flex-wrap:wrap}.button{border:1px solid rgba(255,255,255,.38);background:rgba(255,255,255,.12);color:white;border-radius:999px;padding:12px 18px;font-weight:800;cursor:pointer;backdrop-filter:blur(10px)}.button-primary{background:#fff;color:var(--teal);border-color:#fff}.button:disabled{opacity:.58;cursor:wait}.summary-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin:18px 0}.detail-metrics{grid-template-columns:repeat(4,1fr)}.metric,.card{background:rgba(255,255,255,.92);border:1px solid rgba(228,231,236,.82);box-shadow:0 10px 26px rgba(16,42,67,.08);border-radius:22px}.metric{padding:18px}.metric-label{display:block;color:var(--muted);font-size:.86rem;font-weight:700;margin-bottom:7px}.metric strong{font-size:1.35rem}.card{padding:0;overflow:hidden}.card-header{display:flex;justify-content:space-between;align-items:flex-start;gap:18px;padding:22px 24px;border-bottom:1px solid var(--line)}.card h2{margin:0;font-size:1.5rem}.card p{margin:5px 0 0;color:var(--muted)}.status-message{font-size:.88rem;color:var(--muted);font-weight:700}.status-message.error{color:var(--l2)}.sensor-list{display:grid}.sensor-row{display:grid;grid-template-columns:minmax(210px,1.25fr) minmax(130px,.65fr) minmax(170px,.85fr) minmax(300px,1.35fr) minmax(70px,auto);gap:20px;align-items:center;padding:18px 24px;color:inherit;text-decoration:none;border-bottom:1px solid var(--line);transition:background .15s,transform .15s}.sensor-row:hover{background:#f8fbfc;transform:translateY(-1px)}.sensor-row>div:last-child{justify-self:end}.sensor-row strong{display:block}.sensor-row span{display:block;color:var(--muted);font-size:.92rem;margin-top:3px}.big-value{font-size:2rem;font-weight:900;color:var(--navy)}.muted-label{font-size:.78rem;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)}.badge{display:inline-flex;align-items:center;justify-content:center;border-radius:999px;padding:7px 12px;font-weight:900;font-size:.86rem;white-space:nowrap}.badge.ok{background:var(--ok-bg);color:var(--ok)}.badge.level-1{background:var(--l1-bg);color:var(--l1)}.badge.level-2{background:var(--l2-bg);color:var(--l2)}.badge.no-data{background:#eef2f6;color:#475467}.back-link{display:inline-block;margin:0 0 14px;color:var(--teal);font-weight:900;text-decoration:none}#historyChart{display:block;width:100%;height:auto;max-height:440px;padding:16px}.reading-list{border-top:1px solid var(--line)}.reading-row{display:grid;grid-template-columns:1fr 1.5fr auto;gap:12px;align-items:center;padding:14px 24px;border-bottom:1px solid var(--line)}.empty{padding:28px;color:var(--muted);font-weight:700}@media (max-width:800px){.hero,.card-header{display:block}.hero-actions{margin-top:18px}.summary-grid,.detail-metrics{grid-template-columns:1fr}.sensor-row{grid-template-columns:1fr;gap:8px}.big-value{font-size:1.7rem}.reading-row{grid-template-columns:1fr}.shell{width:min(100% - 18px,1120px);padding-top:12px}.hero{border-radius:22px;padding:22px}.card,.metric{border-radius:18px}}


/* Sensor detail template redesign */
.sensor-detail-page {
  background: #f5f5f3;
  color: #1a1a1a;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
.sensor-template-shell {
  width: min(800px, 100%);
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem max(1rem, env(safe-area-inset-right)) 3rem max(1rem, env(safe-area-inset-left));
}
.sensor-back-link {
  display: inline-block;
  color: #555;
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 1rem;
}
.sensor-back-link:hover { color: #378ADD; }
.sensor-template-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.sensor-template-title {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.2;
  margin: 0;
}
.sensor-template-subtitle,
.sensor-template-device {
  font-size: 12px;
  color: #666;
  margin: 2px 0 0;
}
.sensor-status-row { display: flex; align-items: center; gap: 8px; }
.sensor-dot { width: 9px; height: 9px; border-radius: 50%; background: #999; flex-shrink: 0; }
.sensor-dot.online { background: #3B6D11; }
.sensor-dot.offline { background: #A32D2D; }
.sensor-status-text { font-size: 13px; color: #666; white-space: nowrap; }
.sensor-status-text.offline-text { color: #A32D2D; font-weight: 700; }
.offline-timestamp { color: #A32D2D !important; font-weight: 700; }
.sensor-meta-value.offline-timestamp { color: #A32D2D !important; }
.badge.offline { background: #FCEBEB; color: #A32D2D; }
.sensor-status-message {
  font-size: 12px;
  color: #666;
  margin: -0.75rem 0 1rem;
}
.sensor-status-message.error { color: #A32D2D; }
.sensor-error-box {
  font-size: 13px;
  color: #A32D2D;
  background: #FCEBEB;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: none;
}
.sensor-main-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 1.5rem;
  align-items: start;
  margin-bottom: 1rem;
}
.tank-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tank-svg { width: 110px; height: 180px; }
.tank-pct { font-size: 32px; font-weight: 500; }
.tank-sublabel { font-size: 12px; color: #888; }
.sensor-chart-wrap {
  background: #ebebea;
  border-radius: 8px;
  padding: 1rem;
}
.sensor-chart-title { font-size: 13px; color: #888; margin-bottom: 10px; }
.sensor-chart-canvas-wrap { position: relative; width: 100%; height: 220px; }
.sensor-meta-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 1.5rem;
}
.sensor-meta-card,
.sensor-recent-card {
  background: #ebebea;
  border-radius: 8px;
}
.sensor-meta-card { padding: 0.75rem 1rem; }
.sensor-meta-label { display: block; font-size: 12px; color: #555 !important; margin-bottom: 4px; }
.sensor-meta-value { font-size: 14px; font-weight: 500; color: #378ADD !important; overflow-wrap: anywhere; }
.sensor-recent-card { padding: 1rem; margin-bottom: 1rem; }
.sensor-recent-header { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.sensor-recent-header h2 { font-size: 15px; font-weight: 600; margin: 0 0 2px; }
.sensor-recent-header p { font-size: 12px; color: #888; margin: 0; }
.sensor-reading-list { display: grid; gap: 8px; }
.sensor-template-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.sensor-footer-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.sensor-tertiary { font-size: 12px; color: #999; }
.sensor-refresh-btn {
  font-size: 13px;
  color: #555;
  background: none;
  border: 0.5px solid #ccc;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
}
.sensor-refresh-btn:hover { background: #ebebea; }
.sensor-refresh-btn:disabled { opacity: .6; cursor: wait; }
.sensor-inline-edit {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  color: #555;
  background: rgba(255,255,255,0.35);
  border: 0.5px solid #ccc;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.sensor-inline-edit:hover { background: rgba(255,255,255,0.65); color: #378ADD; }
.threshold-editor-card {
  background: #ebebea;
  border-radius: 8px;
  padding: 1rem;
  margin: -0.5rem 0 1.5rem;
  border: 1px solid rgba(180,178,169,0.45);
}
.threshold-editor-card[hidden] { display: none; }
.threshold-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.threshold-editor-head h2 { font-size: 15px; font-weight: 600; margin: 0 0 3px; }
.threshold-editor-head p { font-size: 12px; color: #888; margin: 0; line-height: 1.35; }
.sensor-icon-btn {
  width: 28px;
  height: 28px;
  border: 0.5px solid #ccc;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  color: #555;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.sensor-icon-btn:hover { background: rgba(255,255,255,0.65); }
.threshold-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}
.threshold-form label { display: grid; gap: 5px; }
.threshold-form label span { font-size: 12px; color: #555; }
.threshold-form input {
  width: 100%;
  border: 0.5px solid #ccc;
  border-radius: 8px;
  background: #f8f8f6;
  color: #1a1a1a;
  padding: 8px 10px;
  font: inherit;
}
.threshold-save-btn { min-height: 36px; background: #f8f8f6; }
.threshold-edit-status { min-height: 1.2em; margin: 0.75rem 0 0; font-size: 12px; color: #555; }
.threshold-edit-status.error { color: #A32D2D; }
@media (max-width: 640px) {
  .sensor-template-shell {
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
  .sensor-back-link { margin-bottom: 0.75rem; }
  .sensor-template-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }
  .sensor-template-title { font-size: clamp(18px, 5.3vw, 22px); }
  .sensor-template-subtitle, .sensor-template-device { font-size: 13px; line-height: 1.35; }
  .sensor-status-row {
    align-self: flex-start;
    background: #ebebea;
    border-radius: 999px;
    padding: 6px 10px;
  }
  .sensor-status-message { margin: 0 0 0.85rem; }
  .sensor-main-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .tank-wrap {
    background: #ebebea;
    border-radius: 8px;
    padding: 1rem;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
  }
  .tank-svg { width: min(42vw, 136px); height: auto; max-height: 190px; }
  .tank-pct { font-size: clamp(28px, 9vw, 38px); }
  .sensor-chart-wrap { padding: 0.85rem; }
  .sensor-chart-canvas-wrap { height: 190px; }
  .sensor-meta-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 1rem;
  }
  .sensor-forecast-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sensor-meta-card { padding: 0.75rem; min-width: 0; }
  .sensor-meta-value { font-size: 13px; line-height: 1.3; }
  .sensor-inline-edit,
  .sensor-refresh-btn,
  .sensor-icon-btn { min-height: 40px; }
  .threshold-form { grid-template-columns: 1fr; }
  .threshold-form input { font-size: 16px; min-height: 42px; }
  .sensor-template-footer { align-items: flex-start; flex-direction: column; }
  .sensor-footer-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .sensor-footer-actions .sensor-refresh-btn { width: 100%; }
}
@media (max-width: 360px) {
  .sensor-meta-row { grid-template-columns: 1fr; }
  .sensor-footer-actions { grid-template-columns: 1fr; }
}
@media (prefers-color-scheme: dark) {
  .sensor-detail-page { background: #1a1a1a; color: #e8e8e6; }
  .sensor-chart-wrap, .sensor-meta-card, .sensor-recent-card, .threshold-editor-card, .sensor-forecast-card { background: #2a2a28; }
  .sensor-forecast-stats span { background: rgba(255,255,255,0.05); }
  .sensor-forecast-notes, .sensor-forecast-stats small { color: #999; }
  .sensor-meta-card, .threshold-editor-card { border: 1px solid #444; }
  .sensor-meta-label, .threshold-form label span { color: #999 !important; }
  .sensor-refresh-btn, .sensor-inline-edit, .sensor-icon-btn { border-color: rgba(255,255,255,0.2); color: #aaa; }
  .sensor-refresh-btn:hover, .sensor-inline-edit:hover, .sensor-icon-btn:hover { background: #333; }
  .threshold-form input { background: #1f1f1d; color: #e8e8e6; border-color: #444; }
  #tankPctSvg { fill: #e8e8e6; }
}

/* Forecast UI */
.forecast-summary { min-width: 190px; }
.forecast-summary strong { display: block; font-size: 0.95rem; line-height: 1.2; }
.forecast-summary small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 3px; line-height: 1.25; }
.sensor-forecast-card {
  background: #ebebea;
  border-radius: 8px;
  padding: 1rem;
  margin: 0 0 1rem;
  display: grid;
  grid-template-columns: 1.05fr 1.6fr;
  gap: 1rem;
  align-items: stretch;
}
.sensor-forecast-title {
  display: block;
  color: #378ADD;
  font-size: clamp(20px, 4vw, 30px);
  font-weight: 600;
  line-height: 1.1;
  margin-top: 4px;
}
.sensor-forecast-notes { margin: 8px 0 0; color: #666; font-size: 13px; line-height: 1.35; }
.sensor-forecast-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.sensor-forecast-stats span {
  background: rgba(255,255,255,0.45);
  border-radius: 8px;
  padding: 0.65rem;
  min-width: 0;
}
.sensor-forecast-stats b { display: block; color: #378ADD; font-size: 14px; overflow-wrap: anywhere; }
.sensor-forecast-stats small { display: block; color: #666; font-size: 11px; line-height: 1.2; margin-top: 3px; }
@media (max-width: 760px) {
  .sensor-row { grid-template-columns: 1fr; align-items: start; }
  .forecast-summary { min-width: 0; }
  .sensor-forecast-card { grid-template-columns: 1fr; }
  .sensor-forecast-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 360px) {
  .sensor-forecast-stats { grid-template-columns: 1fr; }
}

/* Home list responsive alignment fix */
@media (max-width: 800px) {
  .sensor-row { align-items: start; }
  .sensor-row > div:last-child { justify-self: start; }
  .forecast-summary strong,
  .forecast-summary small { max-width: 100%; }
}

/* Final home-table alignment: force five explicit desktop columns and named grid areas. */
.sensor-row {
  grid-template-columns: minmax(220px, 1.15fr) 150px 190px minmax(320px, 1.35fr) 84px !important;
  grid-template-areas: "name value received forecast status" !important;
  column-gap: 22px !important;
  row-gap: 8px !important;
  align-items: center !important;
}
.sensor-name-cell { grid-area: name; min-width: 0; }
.sensor-value-cell { grid-area: value; justify-self: end; text-align: right; white-space: nowrap; }
.sensor-received-cell { grid-area: received; min-width: 0; }
.sensor-forecast-cell { grid-area: forecast; min-width: 0; }
.sensor-status-cell { grid-area: status; justify-self: end !important; min-width: 0; }
.sensor-status-cell .badge { width: auto; min-width: 48px; }
@media (max-width: 980px) {
  .sensor-row {
    grid-template-columns: 1fr auto !important;
    grid-template-areas:
      "name value"
      "received status"
      "forecast forecast" !important;
    align-items: start !important;
  }
  .sensor-value-cell { justify-self: end; text-align: right; }
  .sensor-status-cell { justify-self: end !important; }
}
@media (max-width: 640px) {
  .sensor-row {
    grid-template-columns: 1fr !important;
    grid-template-areas:
      "name"
      "value"
      "received"
      "forecast"
      "status" !important;
  }
  .sensor-value-cell { justify-self: start; text-align: left; }
  .sensor-status-cell { justify-self: start !important; }
}
