:root {
  color-scheme: dark;
  --bg: #080c12;
  --surface: #111821;
  --surface-raised: #17212d;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f7fb;
  --muted: #8e9bac;
  --green: #48d597;
  --green-soft: rgba(72, 213, 151, 0.13);
  --amber: #ffb95c;
  --red: #ff6b73;
  --blue: #70a7ff;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(
      circle at 85% -10%,
      rgba(44, 125, 102, 0.22),
      transparent 34rem
    ),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px
    calc(104px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 26px;
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 3px;
  font-size: clamp(32px, 9vw, 48px);
  line-height: 1;
  letter-spacing: -0.045em;
}

h2 {
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.eyebrow {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted { color: var(--muted); }
.app-header .muted { margin-top: 8px; font-size: 14px; }

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  font-size: 25px;
  cursor: pointer;
}

.icon-button.busy { animation: rotate 0.8s linear infinite; }

.state-card {
  min-height: 310px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 36px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 24, 33, 0.86);
}

.state-card .muted {
  max-width: 300px;
  font-size: 14px;
  line-height: 1.5;
}

.state-card button {
  margin-top: 10px;
  padding: 11px 22px;
  border: 0;
  border-radius: 14px;
  background: var(--green);
  color: #06110c;
  font-weight: 800;
}

.state-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 107, 115, 0.14);
  color: var(--red);
  font-size: 24px;
  font-weight: 800;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: rotate 0.85s linear infinite;
}

@keyframes rotate { to { transform: rotate(360deg); } }

.overall-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 150px;
  padding: 24px;
  border: 1px solid rgba(72, 213, 151, 0.18);
  border-radius: 26px;
  background: linear-gradient(135deg, #14271f 0%, #101a20 68%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
}

.overall-card::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  right: -85px;
  bottom: -110px;
  border-radius: 50%;
  background: rgba(72, 213, 151, 0.12);
}

.overall-card h2 { margin: 10px 0 8px; font-size: 28px; }
.overall-card .muted { font-size: 13px; }

.status-orb {
  z-index: 1;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border: 6px solid rgba(72, 213, 151, 0.17);
  border-radius: 50%;
  background: var(--green);
  background-clip: padding-box;
  box-shadow: 0 0 28px rgba(72, 213, 151, 0.58);
}

.overall-card.problem {
  border-color: rgba(255, 107, 115, 0.28);
  background: linear-gradient(135deg, #2c181d 0%, #17151b 68%);
}

.overall-card.problem .eyebrow { color: var(--red); }

.overall-card.problem .status-orb {
  background: var(--red);
  box-shadow: 0 0 28px rgba(255, 107, 115, 0.48);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.summary-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
}

.summary-card strong {
  display: block;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.summary-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.summary-card.alert strong { color: var(--red); }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin: 30px 2px 14px;
}

.section-heading h2 { margin-top: 6px; }

.count-badge {
  min-width: 31px;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.count-alert:not(:empty) {
  color: var(--red);
  background: rgba(255, 107, 115, 0.12);
}

.reading-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.reading-card {
  min-width: 0;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
}

.reading-card.wide { grid-column: 1 / -1; }
.reading-card.unavailable { opacity: 0.56; }
.reading-card .reading-name { color: var(--muted); font-size: 12px; }

.reading-card .reading-value {
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: 25px;
  font-weight: 780;
  letter-spacing: -0.04em;
}

.reading-card .reading-value small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.reading-card .reading-device {
  margin-top: 10px;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reading-card .reading-place {
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sparkline { width: 100%; height: 40px; margin-top: 10px; }

.sparkline polyline {
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 20px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
}

.search-field input {
  width: 100%;
  padding: 14px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.location-group { margin-bottom: 25px; }

.location-title {
  margin: 0 2px 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stack-list { display: grid; gap: 10px; }

.list-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.list-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(72, 213, 151, 0.38);
}

.list-dot.warning { background: var(--amber); box-shadow: none; }

.list-dot.error,
.list-dot.critical { background: var(--red); box-shadow: none; }

.list-body { min-width: 0; flex: 1; }

.list-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.list-top strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-top span { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.list-body p { margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.list-body .resolved { color: var(--green); }

.empty-card {
  padding: 30px 20px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.read-only-note {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 22px;
  padding: 18px;
  border: 1px solid rgba(112, 167, 255, 0.2);
  border-radius: 18px;
  background: rgba(112, 167, 255, 0.08);
}

.read-only-note strong { color: var(--blue); font-size: 13px; }
.read-only-note span { color: var(--muted); font-size: 12px; line-height: 1.5; }

.bottom-nav {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 696px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(17, 24, 33, 0.92);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.bottom-nav button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 3px 7px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}

.bottom-nav button > span { font-size: 20px; line-height: 1; }
.bottom-nav button.active { background: var(--green-soft); color: var(--green); }

.bottom-nav i {
  position: absolute;
  top: 6px;
  right: 24%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}

[hidden] { display: none !important; }

@media (min-width: 540px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .reading-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .reading-card.wide { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
  }
}
