:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #17211c;
  --muted: #647067;
  --line: #d8ded8;
  --blue: #2673b8;
  --blue-soft: #d9ecfb;
  --green: #178052;
  --green-soft: #dff3e9;
  --red: #b73632;
  --red-soft: #f8dddd;
  --amber: #b56c12;
  --amber-soft: #f8ead1;
  --shadow: 0 18px 50px rgba(22, 32, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(38, 115, 184, 0.08), transparent 260px),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.status-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.pill.ok {
  border-color: rgba(23, 128, 82, 0.25);
  background: var(--green-soft);
  color: var(--green);
}

.pill.warn {
  border-color: rgba(181, 108, 18, 0.28);
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.bad {
  border-color: rgba(183, 54, 50, 0.25);
  background: var(--red-soft);
  color: var(--red);
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 310px;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.controls-panel,
.log-panel {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.switch-row span {
  display: grid;
  gap: 3px;
}

.switch-row small,
.range-note,
.metric-card small,
.dose-row span {
  color: var(--muted);
  font-size: 12px;
}

.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.slider-block {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.slider-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.process-panel {
  min-width: 0;
  overflow: hidden;
}

.pool-visual {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  background: linear-gradient(180deg, #eef7fc 0%, #e9f3ed 100%);
}

.water {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 28px;
  height: 190px;
  border: 1px solid rgba(38, 115, 184, 0.25);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #7dc8ec, #2c86c8);
}

.wave {
  position: absolute;
  left: -10%;
  width: 120%;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  animation: drift 6s linear infinite;
}

.wave-a {
  top: -28px;
}

.wave-b {
  top: 14px;
  opacity: 0.5;
  animation-duration: 8s;
}

@keyframes drift {
  from { transform: translateX(-30px); }
  to { transform: translateX(30px); }
}

.unit {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(22, 32, 27, 0.14);
  font-size: 12px;
  font-weight: 900;
}

.unit.active {
  border-color: rgba(23, 128, 82, 0.35);
  background: var(--green-soft);
  color: var(--green);
}

.unit.blocked {
  border-color: rgba(183, 54, 50, 0.25);
  background: var(--red-soft);
  color: var(--red);
}

.filter {
  top: 42px;
  left: 46px;
  width: 112px;
  height: 72px;
}

.pump {
  top: 44px;
  width: 118px;
  height: 62px;
}

.pump.ph {
  right: 178px;
}

.pump.chlorine {
  right: 36px;
}

.pipe {
  position: absolute;
  background: #9aa8a2;
  border-radius: 999px;
}

.pipe-main {
  left: 112px;
  right: 88px;
  top: 136px;
  height: 14px;
}

.pipe-dose-a,
.pipe-dose-b {
  top: 106px;
  width: 12px;
  height: 70px;
}

.pipe-dose-a {
  right: 228px;
}

.pipe-dose-b {
  right: 86px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.metric-card {
  display: grid;
  gap: 5px;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-card strong {
  font-size: 28px;
}

.metric-card.ok {
  background: var(--green-soft);
  border-color: rgba(23, 128, 82, 0.18);
}

.metric-card.warn {
  background: var(--amber-soft);
  border-color: rgba(181, 108, 18, 0.18);
}

.dose-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 0 14px 16px;
}

.dose-row > div,
.mix-row > div {
  display: grid;
  gap: 7px;
}

.mix-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 14px 16px;
}

.mix-row > div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eee9;
}

.bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 500px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.log-list li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}

.log-list strong {
  display: block;
  margin-bottom: 3px;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

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

  .status-cluster {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 16px, 1180px);
    padding: 12px 0;
  }

  .pool-visual {
    min-height: 300px;
  }

  .water {
    left: 14px;
    right: 14px;
    height: 150px;
  }

  .filter {
    left: 16px;
  }

  .pump.ph {
    right: 144px;
  }

  .pump.chlorine {
    right: 14px;
  }

  .pump {
    width: 112px;
  }

  .metrics-grid,
  .dose-row,
  .mix-row {
    grid-template-columns: 1fr;
  }
}
