/* 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;
  /* Loop's presets tint (DerivedAssetsBase presets.colorset) */
  --presets: #117ca7;
  /* Clinical (AGP report v5), for History's report */
  --agp-vhigh: #d2823d;
  --agp-high: #fff051;
  --agp-target: #5ba151;
  --agp-low: #ac3432;
  --agp-vlow: #832828;
  --agp-outer: #dedee4;
  --agp-inner: #aaaac2;
  --agp-median: #2a3773;
  --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;
    --presets: #1388b8;
    --agp-outer: rgba(170, 170, 194, 0.18);
    --agp-inner: rgba(170, 170, 194, 0.42);
    --agp-median: #c3c8ff;
    --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; }
.section { font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.02em; margin: 18px 4px 6px; }
.person { padding: 12px 14px; border-top: 1px solid var(--separator); }
.person:first-child { border-top: 0; }
.person-head { display: flex; justify-content: space-between; align-items: baseline; }
.person-name { font-weight: 600; }
.person-detail { font-size: 14px; color: var(--secondary); margin-top: 2px; }
.you { font-size: 12px; font-weight: 600; color: var(--accent); margin-left: 4px; }
.areas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.area { font-size: 13px; padding: 3px 8px; border-radius: 999px; background: var(--bg); }
.circle-link { margin: 10px 0; color: var(--accent); }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--grid); border-radius: 9px; padding: 2px; margin: 6px 0 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 7px; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.daynav { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin: 4px 0; }
.daynav .navbtn { font-size: 26px; padding: 0 12px; }
.daynav .navbtn:disabled { opacity: 0.3; }
.card.pad h3 { margin: 0 0 10px; font-size: 17px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--separator); font-variant-numeric: tabular-nums; }
.stat:last-child { border-bottom: 0; }
.stat .l { font-size: 15px; }
.stat .l small { display: block; color: var(--secondary); font-size: 12px; }
.stat .v { font-size: 20px; font-weight: 700; white-space: nowrap; }
.stat .v small { font-size: 13px; color: var(--secondary); font-weight: 500; }
.tir { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: stretch; }
.tirstack { display: flex; flex-direction: column; gap: 2px; border-radius: 4px; overflow: hidden; min-height: 220px; }
.tirstack div { min-height: 3px; }
.tirrows { display: flex; flex-direction: column; justify-content: space-between; font-variant-numeric: tabular-nums; }
.tirrow { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; padding: 3px 0; }
.tirrow .n { font-size: 14px; }
.tirrow .n small { display: block; font-size: 11.5px; color: var(--secondary); }
.tirrow .p { font-size: 20px; font-weight: 700; text-align: right; }
.tirrow .p small { font-size: 11.5px; font-weight: 500; display: block; }
.ok-t { color: var(--ok); }
.miss-t { color: var(--bad); }
.agpwrap { position: relative; }
.agpwrap svg { display: block; touch-action: pan-y; }
.agptip { position: absolute; top: 8px; pointer-events: none; background: var(--surface); border: 1px solid var(--separator); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); font-variant-numeric: tabular-nums; white-space: nowrap; }
.agplegend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--secondary); margin-top: 6px; }
.agplegend span { display: inline-flex; align-items: center; gap: 6px; }
.agplegend .sq { width: 12px; height: 12px; border-radius: 2px; }
.agplegend .ln { width: 16px; height: 3px; border-radius: 2px; }
table.daily { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.daily th, table.daily td { padding: 8px 8px; text-align: right; border-top: 1px solid var(--separator); white-space: nowrap; }
table.daily th { font-size: 12px; color: var(--secondary); font-weight: 600; border-top: 0; }
table.daily th:first-child, table.daily td:first-child { text-align: left; }
.link.danger { color: var(--bad); padding-top: 6px; }
.person .pill.small { margin-top: 8px; }
.invite-form label { display: block; font-size: 14px; color: var(--secondary); margin-bottom: 12px; }
.invite-form input, .invite-form select { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--separator); background: var(--bg); color: var(--fg); }
/* Sheets: Add Carbs, Bolus, Presets. */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { position: sticky; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 52px; background: var(--bg); }
.sheet-head .navbtn { justify-self: start; font-size: 17px; }
.field { display: block; font-size: 14px; color: var(--secondary); margin: 12px 0; }
.field select { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--separator); background: var(--surface); color: var(--fg); }
.field .seg { margin-top: 6px; }
.unit-input { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; background: var(--surface); border-radius: 12px; padding: 8px 14px; }
.unit-input input { flex: 1; min-width: 0; border: 0; background: none; color: var(--fg); font: inherit; font-size: 34px; font-weight: 600; text-align: right; }
.unit-input input:focus { outline: none; }
.unit-input span { font-size: 20px; color: var(--secondary); }
.kv-list { background: var(--surface); border-radius: 12px; margin-top: 4px; }
.kv-list div { display: flex; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--separator); font-size: 15px; }
.kv-list div:first-child { border-top: 0; }
.kv-list span { color: var(--secondary); }
.btn.primary.bolus-btn { background: var(--insulin); }
.warn-text { color: #c77c00; }
.preset-row { display: flex; width: 100%; gap: 12px; align-items: center; padding: 12px 14px; border: 0; border-top: 1px solid var(--separator); background: none; text-align: left; cursor: pointer; }
.preset-row:first-child { border-top: 0; }
.preset-symbol { font-size: 26px; width: 34px; text-align: center; }
.preset-text { display: flex; flex-direction: column; }
.preset-text small { color: var(--secondary); font-size: 13px; }
.preset-active { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.preset-active .btn { width: auto; padding: 8px 14px; }
.status-row.command.refused, .status-row.command.failed, .status-row.command.denied { color: var(--bad); }
.status-row small { display: block; color: var(--secondary); }
.copyrow { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; margin: 8px 0; font-size: 13px; }
.copyrow span { color: var(--secondary); }
.copyrow code { font-size: 12px; overflow-wrap: anywhere; background: var(--bg); padding: 6px 8px; border-radius: 6px; }
.links { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.setting { padding: 12px 14px; border-top: 1px solid var(--separator); }
.setting:first-child { border-top: 0; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.setting .inline { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 30px; font-size: 15px; color: var(--secondary); }
.setting input[type="number"], .setting input[type="time"] { width: 76px; font: inherit; font-size: 16px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--separator); background: var(--bg); color: var(--fg); }
.setting input[type="time"] { width: auto; }
.setting .unit { color: var(--secondary); }
.loop-says p { margin: 0 0 8px; font-size: 15px; }
.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: 3px;
  background: none;
  border: 0;
  font-size: 10px;
  font-weight: 500;
  color: var(--tint, var(--accent));
  min-width: 64px;
}
/* Loop's toolbar icons, as single-color masks in each tab's tint. */
.tb-icon { width: 28px; height: 28px; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.i-carbs { --icon: url('icons/carbs.svg'); }
.i-bolus { --icon: url('icons/bolus.svg'); }
.i-presets { --icon: url('icons/presets.svg'); }
.i-presets-selected { --icon: url('icons/presets-selected.svg'); }
.i-settings { --icon: url('icons/settings.png'); }
/* Not yet available (remote commands): Loop's tints, dimmed. */
.toolbar button:disabled { opacity: 0.45; }

/* 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; } }
