:root {
  color-scheme: light;
  --ink: #1d2b24;
  --muted: #718078;
  --line: #e3eae4;
  --surface: #ffffff;
  --background: #f4f7f2;
  --green: #4b8d5f;
  --green-dark: #32734a;
  --green-pale: #e8f3e9;
  --red: #b83e46;
  --red-pale: #fff0ef;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--ink); }
button, input { font: inherit; }
[hidden] { display: none !important; }

.app-shell { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 28px; }
.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login-panel { width: min(420px, 100%); display: grid; gap: 16px; }
.login-panel h1 { margin: 0; font-size: 1.8rem; letter-spacing: -0.04em; }
.login-panel .muted { margin: -8px 0 4px; }
.login-panel .message { margin: 0; }
.topbar, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar { margin-bottom: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.8rem, 4vw, 2.45rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.18rem; letter-spacing: -0.02em; }
.eyebrow { margin-bottom: 7px; color: var(--green-dark); font-size: 0.69rem; font-weight: 800; letter-spacing: 0.12em; }
.muted, .small-muted, .stat-note { color: var(--muted); }
.muted { margin-bottom: 0; line-height: 1.5; }
.small-muted, .stat-note { font-size: 0.82rem; }
.mode-badge { display: inline-flex; align-items: center; gap: 9px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #d29d3f; }
.mode-badge.connected .status-dot { background: var(--green); }
.panel, .stat-card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 26px rgb(34 65 44 / 4%); }
.panel { padding: 22px; margin-bottom: 18px; }
.section-heading { margin-bottom: 20px; }
.notice { margin: 0 0 18px; padding: 13px 15px; border: 1px solid #e8d9ad; border-radius: 12px; background: #fff9e9; color: #725d26; font-size: 0.86rem; line-height: 1.45; }
.notice.live { border-color: #bcdac3; background: var(--green-pale); color: var(--green-dark); }
.import-form { display: grid; grid-template-columns: minmax(150px, 0.8fr) minmax(260px, 1.5fr) auto; align-items: end; gap: 14px; }
.field { display: grid; gap: 8px; color: #435249; font-size: 0.84rem; font-weight: 650; }
.field input { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #d5dfd7; border-radius: 9px; background: #fff; color: var(--ink); }
.field input:focus { outline: 3px solid rgb(75 141 95 / 18%); border-color: var(--green); }
.field input:disabled { background: #f4f6f4; color: #9aa49d; }
.button { min-height: 42px; padding: 0 16px; border: 0; border-radius: 9px; cursor: pointer; font-weight: 700; transition: background 120ms ease, transform 120ms ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.55; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { background: var(--green-pale); color: var(--green-dark); }
.button-quiet { min-height: 36px; padding: 0 10px; background: transparent; color: var(--muted); font-size: 0.82rem; }
.button-quiet:hover { background: #f1f5f1; }
.message { min-height: 1.1em; margin: 13px 0 0; color: var(--muted); font-size: 0.84rem; }
.message.error { color: var(--red); }
.message.success { color: var(--green-dark); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { display: grid; gap: 9px; padding: 18px; }
.stat-label { color: var(--muted); font-size: 0.8rem; font-weight: 650; }
.stat-card strong { font-size: 1.8rem; letter-spacing: -0.04em; }
.stat-card strong.alert-value { color: var(--red); }
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.device-tools { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.location-filter { width: min(250px, 100%); }
.location-filter select { min-height: 42px; padding: 9px 11px; border: 1px solid #d5dfd7; border-radius: 9px; background: #fff; color: var(--ink); }
.download-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.add-device { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.add-device summary { width: fit-content; color: var(--green-dark); font-weight: 750; cursor: pointer; }
.device-form { display: grid; grid-template-columns: repeat(2, minmax(170px, 1fr)); align-items: end; gap: 12px; margin: 16px 0 10px; }
.device-form .button { justify-self: start; }
.device-card { width: 100%; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); text-align: left; cursor: pointer; }
.device-card:hover, .device-card.selected { border-color: var(--green); background: #fbfefb; }
.device-card.selected { box-shadow: inset 0 0 0 1px var(--green); }
.device-card.alert { border-color: #efc3c0; background: var(--red-pale); }
.device-topline, .device-reading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.device-name { overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.device-location { margin: 7px 0 14px; color: var(--muted); font-size: 0.82rem; }
.device-reading strong { font-size: 1.4rem; letter-spacing: -0.03em; }
.device-time { margin-top: 5px; color: var(--muted); font-size: 0.78rem; }
.device-status { padding: 5px 8px; border-radius: 999px; background: var(--green-pale); color: var(--green-dark); font-size: 0.72rem; font-weight: 750; white-space: nowrap; }
.device-card.alert .device-status { background: #ffe0dd; color: var(--red); }
.empty-state { grid-column: 1 / -1; margin: 0; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }
.details-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.9fr); gap: 18px; }
.chart-panel, .limits-panel { min-width: 0; }
.chart-panel { min-height: 345px; }
.chart-panel canvas { display: none; width: 100%; height: 245px; }
.chart-empty { display: grid; min-height: 245px; place-items: center; color: var(--muted); text-align: center; }
.limits-panel h2 { margin-bottom: 12px; }
.limits-form { display: grid; gap: 13px; margin: 19px 0; }
.limits-form .button { justify-self: start; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 10px; border-bottom: 1px solid #edf1ed; }
th { color: var(--muted); font-size: 0.76rem; font-weight: 700; }
td { font-size: 0.86rem; }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { padding: 24px 10px; color: var(--muted); text-align: center; }
.reading-alert { color: var(--red); font-weight: 750; }
.reading-ok { color: var(--green-dark); font-weight: 700; }
.alerts-panel { margin-top: 0; }
.alert-list { display: grid; gap: 9px; }
.alert-row { display: flex; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid #f0d7d4; border-radius: 10px; background: var(--red-pale); font-size: 0.84rem; }
.alert-main { display: grid; gap: 4px; }
.alert-main strong { color: var(--red); }
.alert-delivery { align-self: center; color: var(--muted); font-size: 0.78rem; text-align: right; }
.footer-note { padding: 4px 2px; color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
@media (max-width: 760px) {
  .app-shell { width: min(100% - 24px, 620px); padding-top: 24px; }
  .topbar, .section-heading { align-items: flex-start; }
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .import-form { grid-template-columns: 1fr; }
  .device-tools { align-items: stretch; flex-direction: column; }
  .location-filter { width: 100%; }
  .download-actions { justify-content: flex-start; }
  .device-form { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 1.5rem; }
  .details-grid { grid-template-columns: 1fr; gap: 0; }
  .panel { padding: 17px; }
  .small-muted { text-align: right; }
  .alert-row { align-items: flex-start; flex-direction: column; }
  .alert-delivery { text-align: left; }
}
