:root {
  --ink: #17202a;
  --quiet: #66717d;
  --rule: #e3e8ed;
  --grid: #edf0f3;
  --ground: #f3f5f7;
  --card: #ffffff;
  --soil: #2563a8;
  --soil-pale: #e6eef8;
  --brand: #17463a;
  --brand-pale: #e6efea;
  --predicted: #b8621c;
  --predicted-soft: #fbf0e6;
  --soil-temp: #b23a3a;
  --air-temp: #e0821c;
  --humidity: #0f9490;
  --rain: #5b4fb3;
  --light: #b08a12;
  --good: #1f8a4c;
  --warn: #b8741a;
  --warn-pale: #fbf3e6;
  --good-pale: #e8f5ed;
  --alert: #b42318;
  --alert-pale: #fdeceb;
  --side: 210px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --glide: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--ground); }

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-weight: 400;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}

.side {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--side);
  display: flex;
  flex-direction: column;
  padding: 24px 14px 20px;
  background: var(--card);
  border-right: 1px solid var(--rule);
  z-index: 20;
  transition: transform 0.5s var(--glide), box-shadow 0.5s;
}

body[data-side="closed"] .side { transform: translateX(-100%); }

.side-top { padding: 0 10px 18px; }
.brand { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--quiet); }

.pages { list-style: none; margin: 0; padding: 0; }
.pages li + li { margin-top: 2px; }

.pages a {
  display: block;
  padding: 8px 10px;
  font-size: 14.5px;
  color: var(--ink);
  text-decoration: none;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
}

.pages a:hover { background: var(--ground); }
.pages a[aria-current="page"] { background: var(--brand-pale); color: var(--brand); font-weight: 500; }
.pages a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(23, 32, 42, 0.3);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s, visibility 0s 0.45s;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 24px 96px;
  transition: margin-left 0.5s var(--glide);
}

body[data-side="open"] main { margin-left: var(--side); max-width: none; }
body[data-side="open"] main > * { max-width: 1080px; margin-left: auto; margin-right: auto; }

.pagehead {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.head-dot { display: block; }

.menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 7px;
  cursor: pointer;
}

.menu:hover { border-color: #c3c9cf; }
.bars { position: relative; width: 14px; height: 10px; }
.bars i { position: absolute; left: 0; width: 14px; height: 1.5px; background: var(--ink); transition: transform 0.45s var(--glide), opacity 0.3s; }
.bars i:nth-child(1) { top: 0; }
.bars i:nth-child(2) { top: 4.25px; }
.bars i:nth-child(3) { top: 8.5px; }
body[data-side="open"] .bars i:nth-child(1) { transform: translateY(4.25px) rotate(45deg); }
body[data-side="open"] .bars i:nth-child(2) { opacity: 0; }
body[data-side="open"] .bars i:nth-child(3) { transform: translateY(-4.25px) rotate(-45deg); }

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

h3 {
  margin: 0 0 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--quiet);
}

.sub {
  margin: 4px 0 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--quiet);
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 18px 20px 16px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.badge {
  flex: none;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--predicted);
  background: #fbf0e6;
  border-radius: 999px;
  white-space: nowrap;
}

.badge[data-state="busy"] { color: var(--quiet); background: #e9edf1; }

.login { max-width: 440px; }
.login p { margin: 0 0 16px; font-size: 15px; }
.login label { display: block; margin-bottom: 14px; }
.login label span { display: block; margin-bottom: 6px; font-size: 14px; color: var(--quiet); }

.login input,
.number,
select {
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  border: 1px solid #c3c9cf;
  border-radius: 6px;
  background: #fff;
}

.login input { width: 100%; }
.number { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
select { font-size: 14.5px; padding: 7px 10px; }

.login input:focus,
.number:focus,
select:focus,
button:focus-visible,
.switch input:focus-visible + .track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

button {
  padding: 10px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

button:disabled:not(.choice, .chat-send) { opacity: 0.45; cursor: default; }

.quiet-button {
  padding: 7px 12px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--ink);
  background: var(--card);
  border: 1px solid #c3c9cf;
}

.error { margin: 12px 0 0; font-size: 14px; color: var(--warn); }

.pagehead { flex-wrap: wrap; }
.strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 20px;
  margin-left: auto;
  font-size: 13.5px;
  color: var(--quiet);
}
.pagehead:has(.strip:not([hidden])) .head-dot { display: none; }

.strip .status { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); }

.daybar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 14px;
}

.daybar .quiet-button { padding: 6px 12px; font-size: 18px; line-height: 1; }
.daybar select { min-width: 180px; }
.kpi .horizons:empty::before { content: "Nothing recorded"; font-size: 13.5px; color: var(--quiet); }
.strip span:empty { display: none; }
body[data-node="offline"] .tile-value b,
body[data-node="offline"] .trace .now { color: var(--quiet); }
body[data-node="offline"] .spark { opacity: 0.4; }

.tiles {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  padding: 14px 14px 10px 16px;
  background: var(--card);
  border: 1.5px solid color-mix(in srgb, var(--accent, var(--soil)) 55%, #fff);
  border-radius: 12px;
  overflow: hidden;
}

.tile[data-kind="soil"], .trace[data-kind="soil"] { --accent: var(--soil); }
.tile[data-kind="soil-temp"], .trace[data-kind="soil-temp"] { --accent: var(--soil-temp); }
.tile[data-kind="air-temp"], .trace[data-kind="air-temp"] { --accent: var(--air-temp); }
.tile[data-kind="humidity"], .trace[data-kind="humidity"] { --accent: var(--humidity); }
.tile[data-kind="rain"], .trace[data-kind="rain"] { --accent: var(--rain); }
.tile[data-kind="light"], .trace[data-kind="light"] { --accent: var(--light); }
.trace[data-kind="valve"] { --accent: var(--ink); }

.tile-label {
  display: block;
  font-size: 12.5px;
  color: var(--quiet);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 4px 0 2px;
}

.tile-value b {
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--accent, var(--ink));
}

.tile-value small { font-size: 12.5px; color: var(--quiet); }

.spark { margin: 0; height: 30px; }
.spark svg { display: block; width: 100%; height: 30px; overflow: hidden; }
.spark path.line { fill: none; stroke: var(--accent, var(--soil)); stroke-width: 1.5; stroke-linejoin: round; }
.spark path.fill { fill: var(--accent, var(--soil)); opacity: 0.1; }

.hero-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 20px;
  align-items: stretch;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--ground);
  border-radius: 10px;
}

.kpi-label { font-size: 12.5px; color: var(--quiet); }

.kpi-value {
  font-size: 40px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-value small { font-size: 16px; font-weight: 400; color: var(--quiet); margin-left: 4px; }

.pill {
  align-self: flex-start;
  margin-top: 4px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 999px;
  color: var(--good);
  background: #e7f4ec;
}

.pill[data-state="irrigate"] { color: var(--warn); background: var(--warn-pale); }
.pill[data-state="waiting"] { color: var(--quiet); background: #e9edf1; }

.kpi-note { margin: 8px 0 0; font-size: 13.5px; line-height: 1.45; }
.horizons { list-style: none; margin: 10px 0 0; padding: 8px 0 0; border-top: 1px solid var(--rule); font-size: 13px; }
.horizons li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; color: var(--quiet); }
.horizons b { font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-note.quiet { color: var(--quiet); font-size: 12.5px; margin-top: 4px; }

.chart { margin: 0; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: hidden; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--quiet); font-size: 12px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .series.soil, .chart .marker.soil { stroke: var(--soil); }
.chart .area.soil { fill: var(--soil); }
.chart .series.predicted { stroke: var(--predicted); stroke-dasharray: 5 4; }
.chart .series.persist { stroke: var(--quiet); stroke-width: 1.5; stroke-dasharray: 2 4; }
.chart .series.accent { stroke: var(--accent, var(--soil)); }
.chart .area.accent { fill: var(--accent, var(--soil)); }
.chart .marker { stroke: #fff; stroke-width: 2; }
.chart .marker.soil { fill: var(--soil); }
.chart .marker.predicted { fill: var(--predicted); }
.chart .marker.accent { fill: var(--accent, var(--soil)); }
.chart .threshold { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .band { fill: var(--warn); opacity: 0.06; }
.chart .shade { fill: var(--ground); }
.chart .now { stroke: var(--quiet); stroke-width: 1; }
.chart .crosshair { stroke: var(--ink); stroke-width: 1; opacity: 0.4; pointer-events: none; }
.chart .hover { fill: transparent; cursor: crosshair; }
.chart .empty { fill: var(--quiet); font-size: 14px; }
.chart .title { fill: var(--ink); font-size: 13px; font-weight: 500; }
.chart .bar { fill: var(--soil); }
.chart .bar.neg { fill: var(--warn); }
.chart .bar-label { fill: var(--ink); font-size: 12.5px; font-weight: 500; }
.chart .baseline { stroke: var(--quiet); stroke-width: 1; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--quiet);
}

.legend span { display: flex; align-items: center; gap: 7px; }
.swatch { display: inline-block; width: 18px; height: 0; border-top: 2px solid; }
.swatch.soil { border-color: var(--soil); }
.swatch.predicted { border-color: var(--predicted); border-top-style: dashed; }
.swatch.persist { border-color: var(--quiet); border-top-style: dotted; }
.swatch.threshold { border-color: var(--warn); border-top-style: dotted; }
.swatch.shaded { height: 10px; border: 1px solid var(--rule); background: var(--ground); border-radius: 2px; }

.tooltip {
  position: fixed;
  z-index: 30;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd5db;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  pointer-events: none;
  white-space: nowrap;
}

.tooltip .when { color: var(--quiet); }

.table-wrap { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
th { font-weight: 500; color: var(--quiet); }
th:first-child, td:first-child { text-align: left; }
td.none { color: var(--quiet); }
td.neg { color: var(--warn); }

.traces {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.traces .card { margin: 0; }
.trace .card-head { align-items: baseline; margin-bottom: 4px; }
.trace .now { font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--accent, var(--ink)); }
.chart.small { padding: 2px 0 0; }

.valve-card .sub { margin-top: 12px; }
.watered { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); }
.watered b { font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.check-line { font-size: 13.5px; color: var(--quiet); }
.check-line[data-state="failed"] { color: var(--alert); }
.check-line[data-state="ok"] { color: var(--good); }

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 14.5px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
}
.notice p { margin: 0; }
.notice[data-state="ok"] { background: var(--good-pale); border-color: var(--good); }
.notice[data-state="failed"] { background: var(--alert-pale); border-color: var(--alert); color: var(--alert); }
.notice[data-state="failed"] p { font-weight: 500; }
.notice:not([data-state="failed"]) button { display: none; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 15px; flex: none; }
.switch.big { margin-top: 14px; font-size: 18px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #cfd5db;
  transition: background 0.2s;
  flex: none;
}

.track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:disabled + .track { opacity: 0.5; cursor: default; }

.scenario-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin: 4px 0 14px;
}

.choices { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; }
.choices-label { font-size: 13.5px; color: var(--quiet); margin-right: 4px; }

.sim-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 24px;
  align-items: end;
  margin: 8px 0 14px;
}

.range { display: block; }
.range > span { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--quiet); margin-bottom: 4px; }
.range output { color: var(--ink); font-variant-numeric: tabular-nums; }
.range input { display: block; width: 100%; margin: 0; accent-color: var(--brand); }
.sim-controls .field { padding-bottom: 2px; }

.chart .series.previous { stroke: var(--predicted); stroke-dasharray: 5 4; opacity: 0.35; }
.chart .marker.previous { fill: var(--predicted); opacity: 0.35; }
.swatch.previous { border-top: 2px dashed var(--predicted); opacity: 0.4; }
.pill[data-state="waiting"] { color: var(--quiet); background: #e9edf1; }
h3.spaced { margin-top: 18px; }

.weather-now {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 16px;
}

.wx {
  padding: 10px 12px 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
}

.wx .tile-value b { font-size: 22px; }

.weather-charts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 8px;
}

#weather-temp { --accent: var(--air-temp); }
#weather-rain { --accent: var(--rain); }
#weather-sun { --accent: var(--light); }

.warn-text { color: var(--warn); }

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

.input-group .horizons { margin-top: 6px; }
.input-group .sub { margin-top: 8px; font-size: 12.5px; }
#change-chart { max-width: 640px; }
.check-tables { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.check-tables .table-wrap { margin-top: 14px; }

.choice {
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  background: var(--card);
  border: 1px solid #c3c9cf;
  border-radius: 999px;
}

.choice:hover { border-color: var(--brand); }
.choice[aria-pressed="true"] { color: var(--brand); background: var(--brand-pale); border-color: var(--brand); font-weight: 500; }
.choice:disabled { color: var(--quiet); border-color: var(--rule); cursor: default; }

.field { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--quiet); }

.trained-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.trained-body .table-wrap { margin-top: 0; }
.stations td, .stations th { padding: 6px 6px; font-size: 13.5px; }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}

.setting.wide { grid-column: 1 / -1; }
.setting .label { font-size: 14.5px; }
.setting .value { font-size: 14.5px; color: var(--quiet); }
.usb-note { margin: 4px 0 0; font-size: 13.5px; color: var(--quiet); }
.key-row { display: flex; flex-wrap: wrap; gap: 8px; }
.key-input { width: 220px; padding: 7px 10px; font: inherit; font-size: 14px; border: 1px solid #c3c9cf; border-radius: 6px; -webkit-text-security: disc; }
.key-input:focus { outline: 2px solid var(--brand); outline-offset: 2px; }
.settings .sub { margin-top: 12px; }

@media (max-width: 900px) {
  body[data-side="open"] main { margin-left: 0; }
  body[data-side="open"] .side { box-shadow: 0 0 24px rgba(0, 0, 0, 0.15); }
  body[data-side="open"] .backdrop { opacity: 1; visibility: visible; transition: opacity 0.45s; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .traces { grid-template-columns: repeat(2, 1fr); }
  .hero-body { grid-template-columns: 1fr; }
  .kpi { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 18px; }
  .kpi-note { flex-basis: 100%; }
  .horizons { flex-basis: 100%; }
  .trained-body { grid-template-columns: 1fr; }
  .check-tables { grid-template-columns: 1fr; }
  .weather-now { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .weather-charts { grid-template-columns: 1fr; }
  .input-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sim-controls { grid-template-columns: repeat(2, 1fr); }
}


@media (max-width: 560px) {
  main { padding: 16px 16px 96px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .traces { grid-template-columns: 1fr; }
  .weather-now { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .input-groups { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .sim-controls { grid-template-columns: 1fr; }
  .card { padding: 14px 14px 12px; }
  .strip { flex-basis: 100%; justify-content: flex-start; margin-left: 0; }
}


.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 25;
  width: 56px;
  height: 56px;
  padding: 0;
  color: #fff;
  background: var(--brand);
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(23, 70, 58, 0.35);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}

.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(23, 70, 58, 0.4); }
.chat-fab svg { position: absolute; inset: 16px; width: 24px; height: 24px; transition: transform 0.25s var(--ease), opacity 0.2s; }
.fab-chat { fill: currentColor; }
.fab-close { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: rotate(-90deg) scale(0.6); }
body[data-chat="open"] .fab-chat { opacity: 0; transform: rotate(90deg) scale(0.6); }
body[data-chat="open"] .fab-close { opacity: 1; transform: none; }

.chat-unread {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  color: #fff;
  background: var(--alert);
  border: 2px solid var(--ground);
  border-radius: 10px;
  box-sizing: content-box;
}

.chat {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 24;
  display: flex;
  flex-direction: column;
  width: 480px;
  height: min(780px, calc(100vh - 116px));
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 18px;
  box-shadow: 0 18px 48px rgba(23, 32, 42, 0.16);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.18s, transform 0.24s var(--ease), visibility 0s 0.24s, width 0.3s var(--ease), height 0.3s var(--ease), right 0.3s var(--ease), bottom 0.3s var(--ease), border-radius 0.3s;
}

.chat[data-open="true"] { opacity: 1; visibility: visible; transform: none; transition: opacity 0.18s, transform 0.24s var(--ease), width 0.3s var(--ease), height 0.3s var(--ease), right 0.3s var(--ease), bottom 0.3s var(--ease), border-radius 0.3s; }

/* full screen grows the panel from its corner to the whole window, the content keeps a reading width */
.chat[data-full="true"] { right: 0; bottom: 0; width: 100%; height: 100%; border-radius: 0; border: 0; z-index: 30; }
.chat[data-full="true"] .chat-head { padding-left: max(16px, calc(50% - 400px)); padding-right: max(10px, calc(50% - 406px)); }
.chat[data-full="true"] .chat-log, .chat[data-full="true"] .chat-chips { padding-left: max(16px, calc(50% - 400px)); padding-right: max(16px, calc(50% - 400px)); }
.chat[data-full="true"] .chat-form { width: min(800px, calc(100% - 32px)); margin: 10px auto 20px; }
.chat[data-full="true"] .msg { max-width: 72%; }
.chat[data-full="true"] .msg.card-msg { align-self: flex-start; width: 460px; max-width: 100%; }
.full-out, .chat[data-full="true"] .full-in { display: none; }
.chat[data-full="true"] .full-out { display: block; }


.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--rule);
}

.chat-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4f8273, var(--brand));
}

.chat-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-who b { font-size: 15px; font-weight: 600; }
#chat-sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--quiet); white-space: nowrap; }
.chat-live { width: 7px; height: 7px; border-radius: 50%; background: #c3c9cf; }
#chat-sub[data-state="live"] .chat-live { background: var(--good); }
#chat-sub[data-state="busy"] { color: var(--brand); }
#chat-sub[data-state="busy"] .chat-live { background: var(--brand); animation: blink 1.2s infinite; }

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  flex: none;
  color: var(--quiet);
  background: transparent;
  border-radius: 8px;
}

.icon-button:hover { color: var(--ink); background: var(--ground); }
.icon-button svg, .chat-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: #eceff3;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
}

.chat-chips, .chat-form { background: var(--card); }
.chat-chips { padding-top: 10px; border-top: 1px solid var(--rule); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg { max-width: 88%; font-size: 14.5px; line-height: 1.5; animation: rise 0.25s var(--ease); }
.msg p { margin: 0 0 6px; }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 6px; padding-left: 20px; }
.msg code { font-size: 13px; padding: 1px 4px; background: var(--brand-pale); border-radius: 4px; }
.msg.user { align-self: flex-end; padding: 9px 13px; color: #fff; background: var(--brand); border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; padding: 10px 14px; background: var(--card); border: 1px solid var(--rule); border-radius: 16px 16px 16px 4px; }
.msg.note { align-self: center; max-width: 100%; font-size: 13px; color: var(--quiet); text-align: center; }
.msg.note a { color: var(--brand); }
.msg.bot.alert { color: var(--alert); background: var(--alert-pale); border: 1px solid var(--alert); }
.msg.error { align-self: flex-start; padding: 9px 13px; color: var(--alert); background: var(--alert-pale); border-radius: 12px; }
.msg.card-msg { align-self: stretch; max-width: 100%; }

.typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--quiet); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink {
  0%, 60%, 100% { opacity: 0.25; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-chips { display: flex; gap: 6px; padding: 6px 14px 0; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 400;
  color: var(--brand);
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--brand) 35%, #fff);
  border-radius: 999px;
}

.chip:hover { background: var(--brand-pale); }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 10px 12px 12px;
  padding: 6px 6px 6px 14px;
  border: 1px solid #c3c9cf;
  border-radius: 22px;
  transition: border-color 0.15s;
}

.chat-form:focus-within { border-color: var(--brand); }

.chat-form textarea {
  flex: 1;
  max-height: 120px;
  padding: 7px 0;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
}

.chat-send { width: 34px; height: 34px; padding: 0; flex: none; color: #fff; background: var(--brand); border-radius: 50%; display: grid; place-items: center; }
.chat-send:disabled { background: #c3c9cf; cursor: default; }

.cc {
  --tone: var(--brand);
  padding: 12px 14px 14px;
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--tone) 28%, var(--rule));
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.04), 0 6px 16px rgba(23, 32, 42, 0.06);
}

/* each kind of card has its own colour, on its icon and its border */
.cc[data-kind="readings"], .cc[data-kind="valve"] { --tone: var(--brand); }
.cc[data-kind="forecast"] { --tone: var(--predicted); }
.cc[data-kind="weather"] { --tone: var(--air-temp); }
.cc[data-kind="model"] { --tone: var(--rain); }
.cc[data-kind="accuracy"] { --tone: var(--humidity); }
.cc[data-kind="history"] { --tone: var(--light); }
.cc[data-kind="setting"] { --tone: var(--quiet); }

.cc-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  flex: none;
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 14%, #fff);
  border-radius: 7px;
}

.cc-icon svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cc-title { display: inline-flex; align-items: center; }

.cc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
.cc-title { font-size: 14px; font-weight: 600; }
.cc-sub { font-size: 12.5px; color: var(--quiet); }
.cc .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0; }
.cc .tile { padding: 10px 12px 6px; }
.cc .tile-value b { font-size: 22px; }
.cc .weather-now { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 8px; }
.cc .wx { padding: 8px 10px 6px; }
.cc .wx .tile-value b { font-size: 18px; }
.cc .chart.small { margin-top: 4px; }
.cc .horizons { margin-top: 6px; }
.cc table { font-size: 13px; }
.cc th, .cc td { padding: 6px 4px; }
.cc[data-tone="alert"] { background: var(--alert-pale); border-color: var(--alert); color: var(--alert); }
.cc[data-tone="good"] { background: var(--good-pale); border-color: var(--good); }

.cc-valve { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: center; }
.cc-valve .cc-head { grid-column: 1 / -1; margin: 0 0 4px; }
.ring { position: relative; width: 78px; height: 78px; }
.ring svg { width: 78px; height: 78px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring .ring-bg { stroke: var(--brand-pale); }
.ring .ring-fg { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring-text b { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.ring-text small { font-size: 11px; color: var(--quiet); }
.cc-valve .switch { margin: 0; }
.cc-check { grid-column: 1 / -1; margin: 4px 0 0; font-size: 13px; color: var(--quiet); }
.cc-check[data-state="ok"] { color: var(--good); }
.cc-check[data-state="failed"] { color: var(--alert); }
.cc-valve[data-live="false"] .switch { opacity: 0.5; pointer-events: none; }
.cc-forecast .kpi-line { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.cc-forecast .kpi-value { font-size: 28px; }
.cc-forecast .pill { margin: 0; }
.cc-sensor .sensor-now { margin: 2px 0 6px; }
.cc-sensor .kpi-value { font-size: 40px; color: var(--tone); }
.sensor-range { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--quiet); }
.sensor-range b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.cc-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.cc-setting .quiet-button { padding: 5px 10px; font-size: 13px; }
.cc-setting .cc-title { font-weight: 400; flex-wrap: wrap; }

@media (max-width: 560px) {
  .chat, .chat[data-full="true"] { right: 0; bottom: 0; width: 100%; height: 100%; border-radius: 0; border: 0; transform-origin: bottom center; }
  #chat-full { display: none; }
  .chat-fab { right: 16px; bottom: 16px; }
  body[data-chat="open"] .chat-fab { opacity: 0; pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  .track, .track::after, .side, main, .bars i, .backdrop, .chat, .chat-fab, .chat-fab svg, .ring .ring-fg { transition: none; }
  .msg, .typing i { animation: none; }
  .dot.tick, .kpi.fresh { animation: none; }
}
