/* LoopCare web app: Loop's main screen (next-dev) in iOS's grouped style.
 * Glucose, insulin and carbs colors are Loop's (LoopKit DerivedAssetsBase);
 * carbs are darkened in light mode to read on white (LoopSight docs/colors.md). */

:root {
  color-scheme: light;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --fg: #000000;
  --secondary: #6c6c70;
  --separator: rgba(60, 60, 67, 0.18);
  --grid: rgba(60, 60, 67, 0.12);
  --accent: #007aff;
  --glucose: #00b0ff;
  --glucose-band: rgba(0, 176, 255, 0.16);
  --glucose-band-preset: rgba(0, 176, 255, 0.32);
  --insulin: #ff9500;
  --carbs: #3d9a22;
  --ok: #34c759;
  --warn: #ffcc00;
  --bad: #ff3b30;
  --warning-bg: #fff4d6;
  --critical-bg: #ffe1df;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #000000;
    --surface: #1c1c1e;
    --fg: #ffffff;
    --secondary: #98989f;
    --separator: rgba(84, 84, 88, 0.6);
    --grid: rgba(235, 235, 245, 0.12);
    --accent: #0a84ff;
    --glucose: #63baff;
    --glucose-band: rgba(99, 186, 255, 0.16);
    --glucose-band-preset: rgba(99, 186, 255, 0.32);
    --insulin: #ff9f0a;
    --carbs: #59e433;
    --ok: #30d158;
    --warn: #ffd60a;
    --bad: #ff453a;
    --warning-bg: #3a2f00;
    --critical-bg: #4a1512;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
canvas { display: block; width: 100%; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}
.page.center { max-width: 460px; padding-top: 12vh; text-align: center; }
.large-title { font-size: 34px; font-weight: 700; margin: 24px 0 16px; letter-spacing: 0.01em; }
.note { color: var(--secondary); font-size: 13px; text-align: center; margin: 12px 8px; }
.muted { color: var(--secondary); }
.error { color: var(--bad); }

.navbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 44px;
  margin: 0 -16px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.nav-title { font-weight: 600; }
.back { justify-self: start; background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; }

/* Active preset banner, as Loop's. */
.preset {
  margin: 4px 0 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--glucose-band-preset);
  font-weight: 600;
  font-size: 15px;
}

.alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warning-bg);
  font-weight: 600;
}
.alert-row.urgent { background: var(--critical-bg); }
.pill {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* HUD: loop ring, glucose, devices. */
.hud {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 12px;
}
.ring { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ring-circle { width: 34px; height: 34px; border-radius: 50%; border: 5px solid var(--secondary); }
.ring.small .ring-circle { width: 18px; height: 18px; border-width: 3px; }
.ring.small { flex-direction: row; gap: 6px; }
.ring-label { font-size: 13px; color: var(--secondary); font-variant-numeric: tabular-nums; }
.ring.fresh .ring-circle { border-color: var(--ok); }
.ring.aging .ring-circle { border-color: var(--warn); }
.ring.stale .ring-circle { border-color: var(--bad); }

.bg { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: baseline; column-gap: 6px; }
.bg-value { font-size: 40px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.bg-trend { font-size: 28px; }
.bg-sub { grid-column: 1 / -1; font-size: 13px; color: var(--secondary); }
.bg.stale .bg-value, .bg.stale .bg-trend { color: var(--secondary); text-decoration: line-through; text-decoration-thickness: 2px; }
.slot { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pump-slot { align-items: flex-end; text-align: right; max-width: 130px; }
.pump-slot .progress { width: 100%; }

/* Device status, after LoopKit's DeviceStatusHighlight and DeviceLifecycleProgress. */
.highlight { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; line-height: 1.2; }
.pump-slot .highlight { flex-direction: row-reverse; text-align: right; }
.hl-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: var(--secondary);
}
.highlight.small { font-size: 15px; }
.highlight.small .hl-icon { width: 20px; height: 20px; font-size: 12px; }
.highlight.normalCGM .hl-icon { background: var(--glucose); }
.highlight.normalPump .hl-icon { background: var(--insulin); }
.highlight.warning .hl-icon { background: var(--warn); color: #000; }
.highlight.critical .hl-icon { background: var(--bad); }
.highlight.critical .hl-text { color: var(--bad); }
.progress { height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--secondary); }
.progress.normalCGM span { background: var(--glucose); }
.progress.normalPump span { background: var(--insulin); }
.progress.warning span { background: var(--warn); }
.progress.critical span { background: var(--bad); }
.progress.dimmed span { background: var(--secondary); opacity: 0.5; }
.life { font-size: 13px; font-weight: 600; }
.life.warning { color: var(--secondary); }
.life.critical { color: var(--bad); }
.unseen { display: inline-block; width: 8px; height: 8px; margin-left: 5px; border-radius: 50%; background: var(--bad); vertical-align: super; }
.navbtn { justify-self: end; background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; font-size: 17px; }
.card-head .navbtn { font-size: 15px; padding: 0; }

/* Activity: the shared timeline. */
.activity { list-style: none; margin: 0; padding: 0 0 4px; }
.activity .day { padding: 12px 14px 4px; font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.02em; }
.item { display: grid; grid-template-columns: 66px 12px 1fr auto; align-items: start; gap: 8px; padding: 9px 14px; border-top: 1px solid var(--separator); }
.activity .day + .item { border-top: 0; }
.item-time { white-space: nowrap; font-size: 13px; color: var(--secondary); font-variant-numeric: tabular-nums; padding-top: 2px; }
.item-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--secondary); }
.item.k-food .item-dot { background: var(--carbs); }
.item.k-insulin .item-dot { background: var(--insulin); }
.item.k-preset .item-dot { background: var(--glucose); }
.item.k-alert .item-dot { background: var(--bad); }
.item.k-response .item-dot { background: var(--ok); }
.item-title { font-size: 15px; }
.item-detail { font-size: 13px; color: var(--secondary); margin-top: 2px; }
.pill.small { padding: 5px 10px; font-size: 13px; }
.compose { display: flex; gap: 8px; margin: 6px 0 10px; }
.compose input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--separator); background: var(--surface); color: var(--fg); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chip { flex: none; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px; background: var(--surface); color: var(--fg); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; }
.phone { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--secondary); font-variant-numeric: tabular-nums; }
.batt { position: relative; width: 20px; height: 10px; border: 1.5px solid currentColor; border-radius: 3px; padding: 1px; }
.batt::after { content: ''; position: absolute; right: -4px; top: 2px; width: 2px; height: 4px; border-radius: 0 1px 1px 0; background: currentColor; }
.batt span { display: block; height: 100%; border-radius: 1px; background: currentColor; }
.phone.warning { color: #c77c00; }
.phone.critical { color: var(--bad); font-weight: 600; }
.tile-device { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.device-value { font-size: 17px; font-weight: 600; display: block; }
.device-sub { font-size: 13px; color: var(--secondary); }

.status-row {
  margin: 6px 0;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface);
  font-size: 15px;
}
.status-row.bad { color: var(--bad); }
.status-row small { color: var(--secondary); }

.card { background: var(--surface); border-radius: 12px; margin: 10px 0; overflow: hidden; }
.card.pad { padding: 18px; text-align: left; }
.card h2 { margin: 0 0 8px; font-size: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px 4px; }
.card-title { font-weight: 600; font-size: 15px; }
.card-sub { color: var(--secondary); font-size: 15px; }
.card canvas { margin: 0 0 6px 8px; width: calc(100% - 8px); }
.card-foot { border-top: 1px solid var(--separator); padding: 10px 14px; font-size: 15px; }

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--separator);
}
.toolbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 0;
  font-size: 10px;
  color: var(--accent);
  min-width: 64px;
}
.toolbar button span { font-size: 22px; }
.toolbar button:disabled { color: var(--secondary); opacity: 0.6; }

/* Overview: a tile per child. */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tile {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--surface);
  cursor: pointer;
}
.tile.alerting { box-shadow: inset 0 0 0 2px var(--bad); }
.tile-head { display: flex; justify-content: space-between; align-items: center; }
.tile-name { font-size: 20px; font-weight: 700; }
.tile-body { display: grid; grid-template-columns: 116px 1fr; gap: 12px; align-items: center; margin-top: 4px; }
.tile .bg-value { font-size: 34px; }
.spark { min-width: 0; }
.tile-onboard { display: flex; gap: 18px; margin-top: 8px; font-size: 15px; font-variant-numeric: tabular-nums; }
.onboard-label { font-weight: 600; margin-right: 4px; }
.onboard-label.insulin { color: var(--insulin); }
.onboard-label.carbs { color: var(--carbs); }
.tile-alert { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--critical-bg); font-weight: 600; font-size: 15px; }
.tile-note { margin-top: 6px; color: var(--secondary); font-size: 15px; }

.all-clear { display: flex; flex-direction: column; margin: 10px 0 4px; font-size: 24px; font-weight: 600; color: var(--ok); }
.all-clear small { font-size: 13px; color: var(--secondary); font-weight: 400; }
.all-clear.big { align-items: center; font-size: 34px; margin-top: 15vh; }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font-weight: 600; cursor: pointer; background: var(--surface); }
.btn.primary { background: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.6; }
.btn + .btn, .note + .btn { margin-top: 10px; }
.link { background: none; border: 0; color: var(--accent); padding: 10px 0 0; cursor: pointer; font-size: 15px; }
.spinner { width: 22px; height: 22px; margin: 16px auto 0; border: 3px solid var(--separator); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
