:root {
  --bg: #0a0f1a;
  --surface: #121a2b;
  --surface-2: #1a2540;
  --border: rgba(148, 163, 184, 0.12);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Auth */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #1e293b 0%, var(--bg) 60%);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}

.auth-card label { display: block; font-size: .85rem; color: var(--muted); margin: 16px 0 6px; }
.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.brand { text-align: center; margin-bottom: 8px; }
.brand-icon { color: var(--accent-2); font-size: 1.5rem; }
.brand h1 { font-size: 1.75rem; font-weight: 700; margin-top: 8px; }
.brand p { color: var(--muted); font-size: .9rem; }

/* App layout */
.app { max-width: 720px; margin: 0 auto; padding-bottom: 40px; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  background: rgba(10, 15, 26, .85);
  backdrop-filter: blur(12px);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.brand-sm { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.live-dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.main { padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }

/* Kind-modus */
.kid-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: .9rem;
  color: var(--text);
  user-select: none;
}

.kid-mode-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.kid-mode-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--muted);
  background: var(--bg);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: border-color .2s, background .2s;
}

.kid-mode-toggle input:checked + .kid-mode-check {
  border-color: var(--accent);
  background: var(--accent);
}

.kid-mode-toggle input:checked + .kid-mode-check::after {
  content: "";
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.kid-mode-label { font-weight: 500; }

.kid-smiley {
  margin: 8px auto 16px;
  padding: 16px;
  max-width: 280px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  animation: kid-pop .35s ease;
}

@keyframes kid-pop {
  from { transform: scale(.92); opacity: .6; }
  to { transform: scale(1); opacity: 1; }
}

.kid-smiley.kid-low { border-color: rgba(251, 191, 36, .5); background: rgba(251, 191, 36, .08); }
.kid-smiley.kid-ok { border-color: rgba(52, 211, 153, .5); background: rgba(52, 211, 153, .08); }
.kid-smiley.kid-high { border-color: rgba(56, 189, 248, .5); background: rgba(56, 189, 248, .08); }

.kid-face-wrap {
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.kid-face {
  width: 100%;
  height: 100%;
  display: none;
}

.kid-face.active { display: block; }

.kid-hint {
  margin-top: 12px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.hero.hero--kid .glucose-value {
  font-size: clamp(2.5rem, 12vw, 4rem);
}

.hero.hero--kid .trend {
  font-size: 1.75rem;
}

/* Hero glucose */
.hero {
  text-align: center;
  padding: 28px 16px 8px;
}

.hero-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.glucose-value {
  font-size: clamp(4rem, 18vw, 6.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--ok);
  transition: color .3s;
}

.glucose-value.warn { color: var(--warn); }
.glucose-value.danger { color: var(--danger); }

.unit { font-size: 1.25rem; color: var(--muted); font-weight: 500; }
.trend { font-size: 2.5rem; opacity: .85; }

.meta { color: var(--muted); margin-top: 8px; font-size: .95rem; }

.alert-banner {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(248, 113, 113, .15);
  border: 1px solid rgba(248, 113, 113, .35);
  color: #fecaca;
  font-size: .9rem;
  text-align: left;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 12px; }

.predict-msg { font-size: .95rem; line-height: 1.5; margin-bottom: 12px; }

.predict-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.predict-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.predict-item .time { font-size: .75rem; color: var(--muted); }
.predict-item .val { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }
.predict-item.risk { border: 1px solid var(--danger); }

.chart-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 12px; }
.chart-header h2 { margin: 0; }
.chart-legend-hint { font-size: .75rem; color: var(--muted); margin-top: 4px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.range-btns { display: flex; gap: 4px; }
.range-btns .range {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8rem;
}
.range-btns .range.active { background: var(--accent); color: #fff; }

#chart { max-height: 260px; }

#treatment-list { list-style: none; }
#treatment-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
#treatment-list li:last-child { border: none; }
#treatment-list .time { color: var(--muted); font-size: .8rem; }

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
}
.btn.primary { background: var(--accent); color: #fff; width: 100%; margin-top: 16px; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

/* Dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  max-width: 400px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog label { display: block; font-size: .8rem; color: var(--muted); margin: 12px 0 4px; }
dialog input, dialog select, dialog textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.dialog-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }
.dialog-actions .btn.primary { width: auto; margin-top: 0; }
