:root {
  --bg: #0a0a0c;
  --bg-glow: #0f0f12;
  --card: #161619;
  --card-2: #0e0e11;
  --border: #2a2a30;
  --border-soft: #202026;
  --text: #f1f1f4;
  --muted: #9999a2;
  --muted-2: #60606a;
  --accent: #ff2e45;
  --accent-soft: #ff5a6b;
  --accent-deep: #8f0f1e;
  --teal: #ff5a6b;
  --amber: #ffb454;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

img, svg { max-width: 100%; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 460px at 12% -8%, rgba(255, 46, 69, 0.16), transparent 60%),
    radial-gradient(800px 460px at 88% -10%, rgba(143, 15, 30, 0.4), transparent 60%),
    var(--bg-glow);
  z-index: -1;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { width: 100%; max-width: 1180px; min-width: 0; margin: 0 auto; padding: 0 20px 90px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 26px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 38px; width: auto; display: block; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(255, 90, 107, 0.18); }

.topbar-right { display: flex; align-items: center; min-width: 0; gap: 18px; }

.user { color: var(--muted); font-size: 13px; }

.sync {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.sync .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.sync .pulse.idle { background: var(--amber); }

.btn {
  font: 600 13.5px var(--font);
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--accent-soft); background: #1d1d22; text-decoration: none; }

.grid { display: grid; gap: 16px; }

.hero { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.hero .key-stats { grid-column: 1 / -1; }

.card {
  min-width: 0;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.gauge-card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; padding: 16px; }
.gauge-card svg { width: 132px; height: 132px; }
.gauge-card .g-title { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600; }
.gauge-card .g-sub { color: var(--muted-2); font-size: 12.5px; }
.gauge-center { font-size: 42px; font-weight: 750; letter-spacing: -0.02em; }
.gauge-center small { font-size: 16px; color: var(--muted); font-weight: 500; }

.key-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}
.kstat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 18px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-soft);
}
.kstat .k-label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kstat .k-value { font-size: 26px; font-weight: 720; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kstat .k-unit { font-size: 13px; color: var(--muted-2); font-weight: 500; }
.kstat .k-sub { color: var(--muted-2); font-size: 12px; margin-top: 4px; }
.kstat .k-bar { height: 5px; border-radius: 4px; background: var(--border); margin-top: 10px; overflow: hidden; }
.kstat .k-bar span { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--amber)); }

.panel { margin-bottom: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; min-width: 0; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.panel-head .hint { min-width: 0; color: var(--muted-2); font-size: 12.5px; text-align: right; overflow-wrap: anywhere; }

.chart { width: 100%; height: 300px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart .tip {
  position: absolute;
  pointer-events: none;
  background: #1c1c21;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
  white-space: nowrap;
  transform: translate(-50%, -115%);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.08s ease;
}
.chart .tip b { font-size: 15px; font-variant-numeric: tabular-nums; }

.sensors { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.sensor { display: flex; flex-direction: column; padding: 14px; border-radius: 16px; background: rgba(255, 255, 255, 0.02); border: 1px solid var(--border-soft); }
.sensor .s-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.sensor .s-value { font-size: 24px; font-weight: 720; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.sensor .s-unit { font-size: 13px; color: var(--muted-2); font-weight: 500; }
.sensor .s-time { color: var(--muted-2); font-size: 12px; margin-top: auto; padding-top: 8px; }

@media (min-width: 720px) {
  .sensors { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
  .sensor { padding: 18px; }
  .sensor .s-label { font-size: 12.5px; }
  .sensor .s-value { font-size: 26px; }
}

@media (max-width: 719px) {
  .sensor:last-child { grid-column: span 2; }
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border-soft); }
.list li:last-child { border-bottom: 0; }
.list .li-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 15px; background: rgba(255, 90, 107, 0.1); color: var(--teal); flex-shrink: 0; }
.list .li-ico.red { background: rgba(255, 46, 69, 0.12); color: var(--accent-soft); }
.list .li-main { flex: 1; min-width: 0; }
.list .li-title { font-weight: 600; font-size: 14px; }
.list .li-sub { color: var(--muted-2); font-size: 12.5px; }
.list .li-val { font-weight: 650; font-size: 14px; font-variant-numeric: tabular-nums; }

.sleep-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 8px; background: var(--border); }
.sleep-bar .seg { height: 100%; }
.sleep-bar .seg.deep { background: #ff2e45; }
.sleep-bar .seg.rem { background: #ffb454; }
.sleep-bar .seg.light { background: #ff7a86; }
.sleep-bar .seg.wake { background: #3a3a42; }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
table { border-collapse: collapse; width: 100%; min-width: 640px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; white-space: nowrap; }
td { font-size: 14px; }
tbody tr:hover { background: rgba(255, 255, 255, 0.015); }
td .pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.good { background: rgba(255, 90, 107, 0.14); color: var(--accent-soft); }
.pill.mid { background: rgba(255, 180, 84, 0.14); color: var(--amber); }
.pill.low { background: rgba(255, 46, 69, 0.16); color: var(--accent-soft); }

.empty { text-align: center; color: var(--muted-2); padding: 42px 20px; }
.empty .e-ico { font-size: 34px; margin-bottom: 10px; opacity: 0.6; }

.offline {
  margin-bottom: 16px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 180, 84, 0.35);
  background: rgba(255, 180, 84, 0.08);
  color: var(--amber);
  font-size: 14px;
}

footer { color: var(--muted-2); font-size: 12px; text-align: center; margin-top: 34px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: min(400px, 92vw);
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 38px 34px 34px;
  box-shadow: var(--shadow);
}
.login-card .logo { text-align: center; margin-bottom: 8px; }
.login-card .logo img { height: 52px; width: auto; }
.login-card .tagline { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.login-card label { display: block; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 8px; }
.login-card input {
  width: 100%;
  font: 16px var(--font);
  color: var(--text);
  background: #0a0a0d;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  margin-bottom: 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 4px rgba(255, 46, 69, 0.14); }
.login-card button {
  width: 100%;
  font: 650 15px var(--font);
  color: #fff;
  background: linear-gradient(180deg, var(--accent-soft), var(--accent));
  border: 0;
  border-radius: 12px;
  padding: 13px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card button:active { transform: translateY(1px); }
.login-card .error { color: #ff8a94; font-size: 13.5px; text-align: center; margin: 14px 0 0; }
.login-card .foot { color: var(--muted-2); font-size: 12px; text-align: center; margin: 22px 0 0; }

@media (max-width: 560px) {
  .shell { padding-inline: 12px; }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px 12px;
    padding: 16px 0 20px;
  }
  .brand { flex: 0 0 auto; }
  .brand img { max-width: 132px; height: 34px; }
  .topbar-right {
    flex: 1 1 176px;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px 12px;
  }
  .topbar-right .user {
    flex: 0 0 100%;
    min-width: 0;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .sync, .btn { white-space: nowrap; }

  .card { padding: 18px; }
  .hero { gap: 10px; }
  .hero .gauge-card { padding: 12px 8px; border-radius: 14px; }
  .gauge-card svg { width: 108px; height: 108px; }
  .gauge-card .g-title { font-size: 11.5px; }
  .gauge-card .g-sub { font-size: 10.5px; line-height: 1.3; }
  .key-stats { min-width: 0; gap: 10px; }
  .kstat { min-width: 0; padding: 14px; }
  .kstat .k-value { font-size: 23px; }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }
  .panel-head .hint { text-align: left; }

  .list li { min-width: 0; }
  .list .li-title, .list .li-sub { overflow-wrap: anywhere; }
  .list .li-val { flex-shrink: 0; }
}

@media (max-width: 900px) {
  .key-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 340px) {
  .gauge-card svg { width: 92px; height: 92px; }
  .gauge-card .g-sub { font-size: 9.5px; }
}
