:root {
  color-scheme: dark;
  --bg: #071316;
  --card: #102126cc;
  --card-solid: #102126;
  --line: #274148;
  --text: #e8f4f1;
  --muted: #8ca8a7;
  --aqua: #35d7c0;
  --violet: #a886ff;
  --lime: #b8e26a;
  --amber: #ffbd66;
  --bad: #ff6f78;
  --sidebar: #09171aeb;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 90% -10%, #173c43 0, transparent 34%), radial-gradient(circle at 0 40%, #142b38 0, transparent 28%), var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.login-body { display: grid; min-height: 100vh; place-items: center; }
.login-main { width: min(520px, calc(100% - 24px)); padding: 32px 0; }
.login-card { margin-top: 22px; padding: 22px; }
.login-card label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.login-card input { width: 100%; border: 1px solid #38575e; border-radius: 12px; background: #0a181b; color: var(--text); padding: 12px; font: inherit; }
.login-card button { width: 100%; margin-top: 20px; border: 1px solid var(--aqua); border-radius: 12px; background: var(--aqua); color: #03201d; padding: 12px; font: inherit; font-weight: 800; cursor: pointer; }
.login-status { margin-top: 14px; border-radius: 12px; background: #0a181b; color: var(--muted); padding: 12px; }
.login-status.error { color: var(--bad); }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--aqua); outline-offset: 3px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  width: 220px;
  flex-direction: column;
  border-right: 1px solid #20383e;
  background: var(--sidebar);
  padding: 24px 16px;
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #3b665f; border-radius: 12px; background: #0d2828; color: var(--aqua); font-weight: 850; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.primary-nav { display: grid; gap: 6px; margin-top: 42px; }
.primary-nav a { display: flex; min-height: 44px; align-items: center; gap: 12px; border-radius: 12px; padding: 0 12px; color: var(--muted); text-decoration: none; }
.primary-nav a span { width: 20px; color: #7ba3a1; text-align: center; font-size: 17px; }
.primary-nav a:hover { background: #102126; color: var(--text); }
.primary-nav a.active { background: #16302f; color: var(--text); box-shadow: inset 3px 0 var(--aqua); }
.primary-nav a.active span { color: var(--aqua); }
.sidebar-status { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 12px; color: var(--muted); font-size: 12px; }
.live-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--aqua); box-shadow: 0 0 14px var(--aqua); }

.workspace { min-height: 100vh; padding-left: 220px; }
main { width: min(1220px, calc(100% - 40px)); margin: auto; padding: 25px 0 46px; }
.mobile-header, .mobile-nav { display: none; }
.breadcrumb { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover { color: var(--aqua); }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin: 23px 0 22px; }
.eyebrow, .section-kicker { color: var(--aqua); font-size: 10px; font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: .16em 0 .22em; font-size: clamp(32px, 5vw, 52px); line-height: 1; letter-spacing: -.035em; }
h2 { margin: 3px 0 0; font-size: 17px; }
.subtitle, .muted { color: var(--muted); }
.subtitle { margin: 0; }
.device-live { display: flex; align-items: center; gap: 9px; color: var(--muted); white-space: nowrap; }
.head-actions { display: grid; justify-items: end; gap: 10px; }
.refresh-button { border: 1px solid var(--aqua); border-radius: 11px; background: #12302e; color: var(--aqua); padding: 9px 13px; font: inherit; font-weight: 750; cursor: pointer; }
.refresh-button:disabled { cursor: wait; opacity: .6; }

.toolbar, .card { border: 1px solid var(--line); border-radius: 18px; background: var(--card); backdrop-filter: blur(12px); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; padding: 10px; }
.toolbar button, .quiet-action { min-height: 42px; border: 1px solid #35545b; border-radius: 11px; background: #0c191d; color: var(--text); padding: 9px 12px; font: inherit; text-decoration: none; cursor: pointer; }
.toolbar button.active { border-color: var(--aqua); background: var(--aqua); color: #03201d; font-weight: 800; }
.toolbar-spacer { flex: 1; }
.quiet-action { display: inline-flex; align-items: center; color: var(--aqua); }
.notice { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 13px; padding: 12px 15px; }
.notice.error { border-color: #693c41; background: #341c20; color: #ffb3b7; }

.metric-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card { padding: 17px; overflow: hidden; }
.metric-card { display: block; min-width: 0; text-decoration: none; transition: border-color .15s ease, transform .15s ease; }
.metric-card:hover { border-color: #3d666b; transform: translateY(-1px); }
.metric-card.metric-ok { box-shadow: inset 0 3px #35d7c055; }
.metric-card.metric-warning { border-color: #7a4c38; box-shadow: inset 0 3px var(--amber); }
.metric-card.range-desired { border-color: #285950; box-shadow: inset 0 3px #35d7c066; }
.metric-card.range-acceptable { border-color: #6e6235; box-shadow: inset 0 3px #eadb68aa; }
.metric-card.range-danger { border-color: #784149; background: #2a171bcc; box-shadow: inset 0 3px var(--bad); }
.metric-indicator { display: inline-flex; align-items: center; gap: 6px; margin-top: 9px; border: 1px solid #37535a; border-radius: 999px; padding: 3px 8px; color: var(--muted); font-size: 10px; }
.metric-indicator::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.metric-indicator.green { border-color: #2c685f; color: var(--aqua); }.metric-indicator.yellow { border-color: #746635; color: #eadb68; }.metric-indicator.orange { border-color: #765536; color: var(--amber); }.metric-indicator.red { border-color: #774149; color: var(--bad); }
.metric-label { display: block; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.metric-value { display: block; margin-top: 7px; font-size: clamp(25px, 3.5vw, 40px); font-weight: 750; letter-spacing: -.04em; white-space: nowrap; }
.metric-unit { margin-left: 4px; color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: 0; }
.metric-foot { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.dosing-summary { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 14px; margin-top: 10px; border: 1px solid #4b4432; border-radius: 14px; background: #201d16b8; padding: 11px 15px; text-decoration: none; }
.dosing-summary strong, .dosing-summary small { display: block; }.dosing-summary small { color: var(--muted); }.dosing-value { color: var(--amber); font-size: 20px; font-weight: 750; }.dosing-arrow { color: var(--muted); font-size: 24px; }

.chart-card { margin-top: 14px; padding: 10px 10px 6px; }
.card-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 7px 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 11px; }
.legend span::before { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; content: ""; }
.legend .kh::before { background: var(--violet); }.legend .ph::before { background: var(--aqua); }.legend .pho::before { background: var(--lime); }.legend .dose::before { background: var(--amber); }
canvas { display: block; width: 100%; height: 500px; }
.section-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 14px; margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 12px; }
.stat { border: 1px solid #20373d; border-radius: 12px; background: #0b1a1e; padding: 12px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { display: block; margin-top: 3px; font-size: 18px; }
.device-details { display: grid; gap: 0; margin: 10px 5px 0; }
.device-details div { display: flex; justify-content: space-between; gap: 15px; border-top: 1px solid #20363b; padding: 10px 0; }
.device-details div:first-child { border: 0; }
.device-details dt { color: var(--muted); }
.device-details dd { margin: 0; text-align: right; }
.status-online { color: var(--aqua); }
.collection-status { margin: 12px 5px 2px; border-top: 1px solid #20363b; padding-top: 12px; color: var(--muted); font-size: 12px; }
.collection-status strong { color: var(--text); }
footer { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }
.overview-metrics { margin-top: 10px; }
.devices-card { margin-top: 18px; }
.device-list { display: grid; margin-top: 10px; }
.device-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 13px; border-top: 1px solid #20363b; padding: 13px 7px; text-decoration: none; }
.device-row:first-child { border-top: 0; }
.device-row:hover { background: #13272b; }
.device-row strong, .device-row small { display: block; }
.device-row small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.device-icon { display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid #356159; border-radius: 13px; background: #0c2928; color: var(--aqua); font-size: 11px; font-weight: 850; }
.status-offline { color: var(--bad); }
.empty-state { grid-column: 1 / -1; color: var(--muted); }
.measurement-table { margin-top: 10px; }
.measurement-table > div { display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid #20363b; padding: 11px 7px; }
.measurement-table > div:first-child { border-top: 0; }
.measurement-table span small { display: block; color: var(--muted); font-size: 10px; }
.measurement-table strong { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 1000px) {
  .sidebar { width: 190px; }
  .workspace { padding-left: 190px; }
  .metric-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .workspace { padding: 0; }
  .mobile-header { position: sticky; top: 0; z-index: 9; display: flex; min-height: 62px; align-items: center; justify-content: space-between; border-bottom: 1px solid #20383e; background: #071316e8; padding: 0 16px; backdrop-filter: blur(16px); }
  .mobile-header .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
  .section-name { color: var(--muted); font-size: 12px; }
  main { width: min(100% - 24px, 720px); padding: 17px 0 98px; }
  .breadcrumb { display: none; }
  .page-head { align-items: start; flex-direction: column; margin-top: 10px; }
  .section-grid { grid-template-columns: 1fr; }
  canvas { height: 460px; }
  .mobile-nav { position: fixed; inset: auto 0 0; z-index: 12; display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid #29434a; background: #091719f2; padding: 6px max(7px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left)); backdrop-filter: blur(18px); }
  .mobile-nav a { display: grid; min-height: 52px; place-items: center; align-content: center; gap: 2px; border-radius: 10px; color: var(--muted); font-size: 10px; text-decoration: none; }
  .mobile-nav a span { font-size: 17px; }
  .mobile-nav a.active { background: #15302f; color: var(--aqua); }
}
@media (max-width: 480px) {
  main { width: calc(100% - 16px); }
  h1 { font-size: 34px; }
  .metric-cards { gap: 8px; }
  .card { padding: 13px; }
  .metric-value { font-size: 25px; }
  .toolbar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .toolbar-spacer, .quiet-action { display: none; }
  .toolbar button { flex: 0 0 auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .legend { max-width: 145px; justify-content: flex-end; gap: 5px 9px; }
  canvas { height: 430px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
