:root {
  --ink: #132238;
  --muted: #61708a;
  --diabetes-blue: #578ad6;
  --primary: #2d63ad;
  --primary-strong: #174a8b;
  --primary-soft: #eef4fc;
  --nav: #123b6d;
  --nav-soft: #ddeaf9;
  --sky: #0284c7;
  --sky-soft: #e6f6ff;
  --violet: #7c3aed;
  --violet-soft: #f2edff;
  --coral: #d94f70;
  --coral-soft: #fff0f4;
  --gold: #b96708;
  --gold-soft: #fff6df;
  --aqua: #087f8c;
  --aqua-soft: #e8f8f8;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --line: #d9e2f1;
  --line-strong: #b9c8dd;
  --amber: #fff6dd;
  --red: #b42318;
  --shadow: 0 12px 34px rgba(23, 74, 139, .09);
  --shadow-lg: 0 24px 65px rgba(15, 35, 70, .18);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 92% 3%, rgba(124, 58, 237, .055), transparent 27rem),
    radial-gradient(circle at 8% 96%, rgba(2, 132, 199, .06), transparent 30rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Avenir Next", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.has-overlay { overflow: hidden; }

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(87, 138, 214, .32);
  outline-offset: 2px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 220px;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 16px 18px;
  background: linear-gradient(180deg, #123b6d 0%, #0b2a51 100%);
  color: #fff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 20px;
  font-weight: 760;
  letter-spacing: -.02em;
  text-decoration: none;
}

.brand > span,
.login-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 3px solid var(--diabetes-blue);
  border-radius: 50%;
  background: #f7faff;
  color: var(--primary-strong);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.03em;
}

.patient-pill {
  display: flex;
  flex-direction: column;
  margin: 24px 0 18px;
  padding: 12px 13px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 13px;
  background: rgba(255, 255, 255, .08);
}

.patient-pill small { color: #b9cbed; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.patient-pill strong { font-size: 17px; }

.nav-main { display: flex; flex: 1; flex-direction: column; gap: 5px; }

.nav-main a,
.sidebar > .help-link {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding: 10px 11px;
  border-radius: 11px;
  color: #dce8fb;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.nav-main a svg,
.sidebar > .help-link svg {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.nav-main a:hover,
.sidebar > .help-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.nav-main a.active {
  background: rgba(255, 255, 255, .13);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--diabetes-blue);
}

.nav-main .calc-nav { color: #dce8fb; }
.nav-main .calc-nav:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-main .calc-nav.active { background: #fff; color: var(--primary-strong); box-shadow: none; }

.sidebar > .help-link {
  margin-top: 16px;
  border: 1px solid rgba(255, 214, 163, .22);
  color: #ffdda8;
}

.sidebar > .help-link.active { background: rgba(255, 255, 255, .1); }

.main-area { min-height: 100vh; margin-left: 220px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: flex-end;
  padding: 0 28px;
  border-bottom: 1px solid rgba(217, 226, 241, .9);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }
.top-actions button,
.top-more {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.top-actions svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.8; }
.top-more { display: none; }
.mobile-brand { display: none; }

.page-wrap { width: min(100%, 1180px); margin: auto; padding: 32px 28px 104px; }

h1, h2, h3, p { overflow-wrap: break-word; }
h1 { margin: 5px 0 9px; font-size: clamp(30px, 4vw, 43px); font-weight: 760; letter-spacing: -.035em; line-height: 1.08; }
h2 { font-weight: 740; letter-spacing: -.02em; }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 24px;
}

.page-heading p,
.page-intro { margin: 0; color: var(--muted); }

.eyebrow {
  margin: 0;
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.card,
.metrics section {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metrics section:nth-child(1) { border-top: 4px solid var(--sky); background: linear-gradient(160deg, #fff, var(--sky-soft)); }
.metrics section:nth-child(2) { border-top: 4px solid var(--violet); background: linear-gradient(160deg, #fff, var(--violet-soft)); }
.metrics section:nth-child(3) { border-top: 4px solid var(--aqua); background: linear-gradient(160deg, #fff, var(--aqua-soft)); }

.card h2 { margin: 0 0 15px; font-size: 20px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); gap: 20px; }
.narrow { width: min(100%, 680px); margin: 0 auto; }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; gap: 14px; margin: 22px 0; }
.metrics section { display: grid; min-height: 178px; grid-template-rows: minmax(29px, auto) minmax(88px, auto) minmax(38px, auto); align-content: start; }
.metrics small { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .045em; text-transform: uppercase; }
.metrics strong { margin: 5px 0; color: var(--primary); font-size: 40px; font-weight: 760; line-height: 1.1; }
.metrics b { margin: 8px 0; font-size: 20px; }
.metric-content { display: grid; min-width: 0; grid-template-rows: minmax(54px, auto) minmax(30px, auto); align-content: start; }
.metric-value-row { display: flex; min-width: 0; align-items: center; gap: 9px; }
.metric-value-row > strong,
.metric-value-row > b { margin: 0; }
.metric-meta-row { display: flex; min-width: 0; flex-wrap: wrap; align-items: flex-start; gap: 4px 8px; color: var(--ink); }
.metric-meta-row > span { min-width: 0; }
.metric-footer { min-height: 38px; }
.done, .status-good { color: #187653; }

.primary-btn,
.save-log-btn {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff !important;
  font-size: 15px;
  font-weight: 720;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease, transform .15s ease;
}

.primary-btn:hover,
.save-log-btn:hover { background: var(--primary-strong); box-shadow: 0 8px 20px rgba(23, 74, 139, .22); }
.primary-btn:active,
.save-log-btn:active { transform: translateY(1px); }
.full-btn { width: 100%; }

.secondary-btn {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 11px 14px;
  border: 1px solid #abc0df;
  border-radius: 11px;
  background: #fff;
  color: var(--primary-strong);
  font-weight: 680;
  text-decoration: none;
  cursor: pointer;
}

.message,
.confirmed-banner {
  margin-bottom: 18px;
  padding: 13px 16px;
  border: 1px solid #bfd4f7;
  border-radius: 13px;
  background: var(--primary-soft);
  color: #173d7f;
}

.next-step,
.calm-note {
  margin-bottom: 12px;
  padding: 14px 15px;
  border-left: 4px solid var(--primary);
  border-radius: 11px;
  background: var(--primary-soft);
}

.task-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.task-row time { color: var(--primary-strong); font-weight: 740; }
.task-row div { display: flex; min-width: 0; flex-direction: column; }
.task-row small,
.journal-row small { color: var(--muted); }
.task-row button {
  padding: 7px 11px;
  border: 1px solid #b4c6df;
  border-radius: 9px;
  background: #fff;
  color: var(--primary-strong);
  font-weight: 680;
}
.task-row.complete { opacity: .6; }
.task-controls { display: flex; align-items: center; flex-direction: column; gap: 7px; }
.task-controls form { margin: 0; }
.task-row .task-controls,
.task-row .record-actions { flex-direction: row; flex-wrap: wrap; }
.daily-plan-list .task-controls { justify-content: flex-end; }
.daily-plan-list .record-actions a { min-height: 34px; padding: 6px 9px; font-size: 12px; }
.task-row.category-glucose { border-left: 3px solid var(--sky); padding-left: 12px; }
.task-row.category-meal { border-left: 3px solid var(--coral); padding-left: 12px; }
.task-row.category-rapid,
.task-row.category-basal { border-left: 3px solid var(--violet); padding-left: 12px; }
.task-row.category-ketone { border-left: 3px solid var(--gold); padding-left: 12px; }
.task-row.category-activity { border-left: 3px solid var(--aqua); padding-left: 12px; }

.journal-row { display: flex; flex-direction: column; padding: 13px 0; border-bottom: 1px solid var(--line); }
.journal-row:last-child { border-bottom: 0; }
.journal-main { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.journal-card .journal-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.tag { align-self: flex-start; padding: 3px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-strong); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.journal-row.kind-glucose .tag { background: var(--sky-soft); color: var(--sky); }
.journal-row.kind-meal .tag { background: var(--coral-soft); color: var(--coral); }
.journal-row.kind-insulin .tag { background: var(--violet-soft); color: var(--violet); }
.journal-row.kind-ketones .tag { background: var(--gold-soft); color: var(--gold); }
.journal-row.kind-activity .tag { background: var(--aqua-soft); color: var(--aqua); }
.action-row { display: flex; flex-wrap: wrap; gap: 9px; margin: 17px 0; }
.action-row a { padding: 9px 13px; border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--primary-strong); font-weight: 680; text-decoration: none; }

.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { min-width: 0; color: var(--ink); font-weight: 690; line-height: 1.35; }
.field-label-row { display: flex; min-width: 0; align-items: center; gap: 3px; }
.field-label-row label { width: auto; min-width: 0; margin: 0; word-break: normal; overflow-wrap: normal; }
.field small { color: var(--muted); font-size: 13px; }
.field-error { color: var(--red); font-size: 13px; font-weight: 650; }

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

input::placeholder,
textarea::placeholder { color: #8996aa; font-weight: 450; opacity: 1; }
input:focus,
select:focus,
textarea:focus { border-color: var(--diabetes-blue); outline: 3px solid rgba(87, 138, 214, .18); }
textarea { resize: vertical; }

input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  flex: none;
  padding: 0;
  border-radius: 5px;
  accent-color: var(--primary);
}

.check-field {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  grid-template-areas: "check label" ". help" ". error";
  gap: 4px 10px;
  align-items: start;
}

.check-field > input[type="checkbox"] {
  grid-area: check;
  float: none;
  margin: 1px 0 0;
}

.check-field > .field-label-row {
  grid-area: label;
  width: auto;
  word-break: normal;
  overflow-wrap: normal;
}

.check-field > small { grid-area: help; }
.check-field > .field-error { grid-area: error; }

.choice-field > div {
  display: grid;
  width: 100% !important;
  height: auto !important;
  min-height: 0;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 8px;
  float: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.choice-field > div > div > label {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fbff;
  font-size: 14px;
  font-weight: 620;
}

.choice-field input[type="checkbox"] { float: none; margin: 0; }

.login-shell { width: min(100%, 440px); margin: 0 auto; padding-top: 7vh; text-align: center; }
.login-logo { width: 62px; height: 62px; margin: auto; font-size: 20px; }
.login-shell .card { text-align: left; }
.login-shell label { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; font-weight: 690; }
.login-shell .primary-btn { width: 100%; }

.error-box,
.safety-block,
.danger-box {
  margin: 13px 0;
  padding: 14px 15px;
  border: 1px solid #e6aaa5;
  border-radius: 13px;
  background: #fff0ef;
  color: #7c2925;
}

.quick-fab {
  position: fixed;
  right: 25px;
  bottom: 25px;
  z-index: 50;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #3a70bc, #174a8b);
  box-shadow: 0 13px 30px rgba(23, 74, 139, .35);
  color: #fff;
  font-size: 36px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}

.quick-fab:hover { box-shadow: 0 16px 35px rgba(23, 74, 139, .42); transform: translateY(-2px); }
.quick-fab[aria-expanded="true"] { transform: rotate(45deg); }

.quick-menu {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 49;
  width: min(390px, calc(100vw - 30px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 21px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}

.quick-menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.quick-menu-head strong { font-size: 18px; }
.quick-menu-head button,
.close-panel {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #eef3fb;
  color: var(--ink);
  font-size: 23px;
  cursor: pointer;
}

.quick-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-menu-grid a {
  display: flex;
  min-height: 58px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-weight: 680;
  text-decoration: none;
}
.quick-menu-grid a > span { display: grid; width: 34px; height: 34px; flex: none; place-items: center; border-radius: 9px; background: var(--primary-soft); color: var(--primary); }
.quick-menu-grid svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.quick-menu-grid .primary { grid-column: 1 / -1; background: var(--primary); color: #fff; }
.quick-menu-grid .primary > span { background: rgba(255, 255, 255, .16); color: #fff; }
.quick-menu-grid .urgent { color: #982e27; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 26, 53, .52);
  backdrop-filter: blur(4px);
}
.overlay[hidden],
.quick-menu[hidden] { display: none; }

.learn-panel,
.term-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 27px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
}
.close-panel { position: absolute; top: 15px; right: 15px; }
.learn-panel h2 { margin: 4px 44px 15px 0; }
.learn-term { width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; text-align: left; cursor: pointer; }
.learn-term:hover { border-color: #a8c2ee; background: #f8fbff; }
.learn-term small { display: block; color: var(--muted); }

.info-dot {
  display: inline-grid;
  width: 21px;
  height: 21px;
  place-items: center;
  margin: 0 0 0 3px;
  padding: 0;
  border: 1px solid #b9d2fb;
  border-radius: 50%;
  background: #eff6ff;
  box-shadow: 0 1px 2px rgba(23, 74, 139, .08);
  color: var(--primary);
  vertical-align: -4px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.info-dot:hover { border-color: #7eabf5; background: #dceaff; transform: scale(1.06); }
.info-dot svg,
.term-icon svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }

.term-icon { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 15px; background: var(--primary-soft); color: var(--primary); }
.term-icon svg { width: 25px; height: 25px; stroke-width: 1.8; }
.term-definition { font-size: 19px; line-height: 1.55; }
.visual-card { padding: 14px; border: 1px solid #d4e3fb; border-radius: 12px; background: #f2f7ff; color: #1e4f9f; font-weight: 680; text-align: center; }

.calc-page { width: min(100%, 900px); margin: auto; }
.calc-heading { margin-bottom: 20px; text-align: center; }
.calc-heading h1 { font-size: clamp(34px, 5vw, 49px); }
.calc-heading p:last-child { margin: 0; color: var(--muted); }

.recent-dose { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 18px; align-items: center; margin-bottom: 13px; padding: 12px 15px; border: 1px solid #e4ca83; border-radius: 14px; background: var(--amber); }
.recent-dose strong { justify-self: end; }
.recent-dose small { grid-column: 1 / -1; color: var(--muted); }
.calc-card { padding: clamp(18px, 3vw, 26px); border: 1px solid var(--line); border-radius: 23px; background: #fff; box-shadow: 0 18px 52px rgba(23, 74, 139, .1); }
.calc-workspace { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(255px, .65fr); gap: 18px; align-items: stretch; }
.calc-input-panel { display: flex; min-width: 0; flex-direction: column; justify-content: center; }
.calc-fields { display: grid; grid-template-columns: 1fr 42px 1fr; gap: 10px; align-items: end; }
.calc-fields .calc-field { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.calc-fields .calc-field label { font-size: 18px; font-weight: 720; }
.calc-fields .calc-field > small { color: var(--muted); }
.calc-input { padding: 15px !important; border-radius: 14px !important; font-size: clamp(24px, 3vw, 30px) !important; font-weight: 650; text-align: center; }
.calc-input::placeholder { font-size: .84em; font-weight: 500; }
.math-symbol { display: grid; height: 66px; place-items: center; color: var(--primary); font-size: 28px; }

.target-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0 0; padding: 0; border: 0; }
.target-toggle legend { grid-column: 1 / -1; margin-bottom: 8px; font-weight: 720; text-align: center; }
.target-toggle label { cursor: pointer; }
.target-toggle input { position: absolute; width: 1px; opacity: 0; }
.target-toggle label span { display: flex; flex-direction: column; align-items: center; padding: 11px; border: 2px solid var(--line); border-radius: 14px; background: #fbfcff; }
.target-toggle label span b { font-size: 18px; }
.target-toggle input:focus-visible + span { outline: 3px solid rgba(87, 138, 214, .28); outline-offset: 2px; }
.target-toggle input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }

.live-result { display: flex; min-width: 0; min-height: 270px; flex-direction: column; justify-content: center; padding: 20px; border-radius: 19px; background: linear-gradient(145deg, #174a8b, #2d63ad); color: #fff; text-align: center; }
.live-result p { margin: 0; opacity: .82; }
.live-result > div:first-of-type { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.live-result > div strong { font-size: 64px; font-weight: 760; line-height: 1.08; }
.live-result > div span { font-size: 19px; }
.breakdown { display: flex !important; flex-wrap: wrap; justify-content: center; gap: 8px 18px !important; margin: 10px 0; }
.breakdown span { font-size: 13px !important; }
.calc-workspace .breakdown { flex-direction: column; gap: 4px !important; }
.live-result > small { display: block; max-width: 660px; margin: 4px auto 0; opacity: .84; }
.live-safety { margin-top: 13px; padding: 12px 14px; border: 1px solid #e0a7a3; border-radius: 12px; background: #fff0ef; color: #7c2925; font-weight: 680; }

.save-dose { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(260px, 1.2fr); gap: 10px; margin-top: 17px; }
.save-dose > label:first-child { display: flex; grid-row: 1 / 4; flex-direction: column; }
.save-dose > label:first-child > span { font-weight: 720; }
.save-dose > label:first-child > small { color: var(--muted); }
.save-dose > label:first-child input { height: 100%; min-height: 105px; font-size: 27px; font-weight: 680; text-align: center; }
.save-summary { display: flex; flex-direction: column; justify-content: center; padding: 12px 14px; border: 1px solid #c8dafa; border-radius: 12px; background: linear-gradient(135deg, var(--primary-soft), #f7f4ff); }
.save-summary strong { color: var(--primary-strong); font-size: 13px; }
.save-summary span { color: var(--muted); font-size: 13px; line-height: 1.4; }
.dose-time { display: flex; flex-direction: column; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.dose-time > span { color: var(--ink); font-size: 13px; font-weight: 720; }
.dose-time > small { margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.dose-time input { padding: 9px 10px; }
.dose-time em { margin-top: 5px; color: var(--red); font-size: 12px; font-style: normal; font-weight: 650; }
.save-log-btn:disabled { cursor: not-allowed; opacity: .45; box-shadow: none; }

.formula-strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; margin: 18px 0; color: var(--muted); font-size: 13px; text-align: center; }
.formula-strip b { color: var(--ink); }

.plan-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 11px; margin: 19px 0; }
.plan-grid div { display: flex; flex-direction: column; padding: 14px; border-radius: 12px; background: var(--primary-soft); }
.plan-grid strong { color: var(--primary-strong); font-size: 24px; }
.plan-grid div:nth-child(1) { background: var(--coral-soft); }
.plan-grid div:nth-child(1) strong { color: var(--coral); }
.plan-grid div:nth-child(2) { background: var(--sky-soft); }
.plan-grid div:nth-child(2) strong { color: var(--sky); }
.plan-grid div:nth-child(3) { background: var(--violet-soft); }
.plan-grid div:nth-child(3) strong { color: var(--violet); }
.plan-grid div:nth-child(4) { background: var(--gold-soft); }
.plan-grid div:nth-child(4) strong { color: var(--gold); }
.calculation-order li { margin-bottom: 8px; }
.danger-box { margin-top: 20px; font-weight: 700; }

.simple-chart { display: flex; height: 230px; align-items: flex-end; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); }
.simple-chart i { display: block; min-width: 3px; flex: 1; border-radius: 4px 4px 0 0; background: var(--primary); }
.inline-form { display: flex; gap: 8px; }

.verification-banner,
.setup-box,
.dexcom-strip { margin-bottom: 20px; padding: 15px; border: 1px solid #bfd4f7; border-radius: 14px; background: #f0f6ff; }
.photo-record { display: grid; grid-template-columns: 105px 1fr; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.photo-record img { width: 105px; height: 90px; border-radius: 11px; object-fit: cover; }
.flow-steps { display: flex; align-items: center; justify-content: center; gap: 15px; margin-top: 22px; text-align: center; }
.flow-steps div { display: flex; flex-direction: column; }
.flow-steps b { display: grid; width: 32px; height: 32px; place-items: center; margin: auto; border-radius: 50%; background: var(--primary); color: #fff; }
.connection-card { display: flex; align-items: center; gap: 20px; }
.connection-icon,
.connection-ok { display: grid; min-width: 76px; height: 76px; place-items: center; border-radius: 21px; background: var(--primary-soft); color: var(--primary); font-size: 24px; font-weight: 760; }
.privacy-note { color: var(--muted); }
code { padding: 2px 6px; border-radius: 6px; background: #edf2fb; }
.dexcom-strip { display: flex; align-items: center; justify-content: space-between; }
.dexcom-strip button { padding: 7px 11px; border: 1px solid var(--primary); border-radius: 9px; background: #fff; color: var(--primary); font-weight: 680; }

.log-choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.log-choice { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 13px; align-items: center; min-height: 100px; padding: 18px; border: 1px solid var(--line); border-radius: 17px; background: #fff; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease; }
.log-choice:hover { border-color: #9bbbf0; box-shadow: 0 16px 36px rgba(23, 74, 139, .13); transform: translateY(-2px); }
.log-choice.featured { grid-column: 1 / -1; min-height: 112px; border-color: #9ebdf3; background: linear-gradient(135deg, #f5f9ff, #eaf2ff); }
.choice-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 13px; background: var(--primary-soft); color: var(--primary-strong); font-size: 13px; font-weight: 780; }
.featured .choice-icon { background: var(--primary); color: #fff; font-size: 25px; font-weight: 450; }
.log-choice:nth-child(2) .choice-icon { background: var(--sky-soft); color: var(--sky); }
.log-choice:nth-child(3) .choice-icon { background: var(--coral-soft); color: var(--coral); }
.log-choice:nth-child(4) .choice-icon { background: var(--violet-soft); color: var(--violet); }
.log-choice:nth-child(5) .choice-icon { background: var(--gold-soft); color: var(--gold); }
.log-choice:nth-child(6) .choice-icon { background: var(--aqua-soft); color: var(--aqua); }
.log-choice b { font-size: 18px; }
.log-choice p { margin: 2px 0 0; color: var(--muted); }
.choice-arrow { color: var(--primary); font-size: 22px; }

.back-link { display: inline-flex; margin-bottom: 15px; color: var(--primary-strong); font-weight: 680; text-decoration: none; }
.care-moment-page > h1 { margin-bottom: 7px; }
.care-moment-form { margin-top: 20px; }
.moment-section { margin: 22px 0; padding-top: 20px; border-top: 1px solid var(--line); }
.moment-heading { display: flex; align-items: flex-start; gap: 11px; margin-bottom: 14px; }
.moment-heading > span { display: grid; width: 28px; height: 28px; flex: none; place-items: center; border-radius: 9px; background: var(--primary-soft); color: var(--primary-strong); font-size: 13px; font-weight: 760; }
.moment-heading h2 { margin: 0; font-size: 19px; }
.moment-heading p { margin: 1px 0 0; color: var(--muted); font-size: 13px; }
.moment-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.moment-wide { grid-column: 1 / -1; }

.more-groups { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.more-groups > .card { position: relative; overflow: hidden; }
.more-groups > .card::before { position: absolute; inset: 0 0 auto; height: 4px; background: var(--sky); content: ""; }
.more-groups > .card:nth-child(2)::before { background: linear-gradient(90deg, var(--coral), var(--gold)); }
.more-groups > .card:nth-child(3)::before { background: linear-gradient(90deg, var(--violet), var(--aqua)); }
.more-links { display: flex; flex-direction: column; }
.more-links a { display: flex; flex-direction: column; padding: 13px 4px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.more-links a:last-child { border-bottom: 0; }
.more-links a:hover span { color: var(--primary-strong); }
.more-links span { font-weight: 700; }
.more-links small { color: var(--muted); }
.more-links .more-help span { color: #982e27; }

.food-layout { grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); align-items: start; }
.manual-food { position: sticky; top: 86px; }
.food-search { margin-bottom: 12px; }
.food-search input { min-height: 46px; }
.food-search .primary-btn { min-width: 96px; flex: none; border-color: transparent; background: linear-gradient(135deg, var(--primary), var(--primary-strong)); color: #fff !important; }
.food-search .primary-btn:hover { border-color: transparent; background: var(--primary-strong); color: #fff !important; }
.search-results, .saved-foods { margin-top: 24px; }
.search-results h3 { margin-bottom: 10px; font-size: 16px; }
.food-result, .saved-food { margin-bottom: 9px; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.food-result[open], .saved-food[open] { border-color: #abc4ee; box-shadow: 0 8px 22px rgba(23, 74, 139, .07); }

.usda-access { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px; margin: 14px 0; padding: 14px; border: 1px solid #c8dafa; border-radius: 14px; background: var(--primary-soft); }
.usda-access-icon { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 50%; background: #fff; color: var(--primary-strong); box-shadow: inset 0 0 0 2px var(--diabetes-blue); }
.usda-access-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.usda-access strong { display: block; margin-bottom: 3px; }
.usda-access p { margin: 0; color: var(--muted); font-size: 14px; }
.usda-access a { color: var(--primary-strong); font-weight: 700; }
.cache-pill { display: inline-flex; margin-top: 9px; padding: 5px 9px; border: 1px solid #bfd2f0; border-radius: 999px; background: #fff; color: var(--primary-strong); font-size: 12px; font-weight: 700; }
.food-result summary, .saved-food summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 14px; cursor: pointer; list-style: none; }
.food-result summary::-webkit-details-marker, .saved-food summary::-webkit-details-marker { display: none; }
.food-result summary::before, .saved-food summary::before { content: "+"; display: grid; width: 24px; height: 24px; flex: none; place-items: center; border-radius: 8px; background: var(--primary-soft); color: var(--primary-strong); font-weight: 720; }
.food-result[open] summary::before, .saved-food[open] summary::before { content: "−"; }
.food-result summary > span:first-of-type, .saved-food summary > span:first-of-type { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.food-result summary small, .saved-food summary small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.carb-badge, .saved-food summary > span:last-child { flex: none; color: var(--primary-strong); font-weight: 720; text-align: right; }
.food-detail { padding: 0 14px 15px 52px; border-top: 1px solid var(--line); }
.nutrient-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.nutrient-grid div { display: flex; flex-direction: column; padding: 10px; border-radius: 10px; background: #f4f7fc; }
.nutrient-grid small { color: var(--muted); font-size: 11px; }
.nutrient-grid strong { color: var(--ink); }
.nutrient-grid div:nth-child(1) { background: var(--sky-soft); }
.nutrient-grid div:nth-child(2) { background: var(--aqua-soft); }
.nutrient-grid div:nth-child(3) { background: var(--violet-soft); }
.nutrient-grid div:nth-child(4) { background: var(--gold-soft); }
.food-facts { margin: 12px 0; }
.food-facts > div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.food-facts dt { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.food-facts dd { margin: 0; font-size: 13px; }
.basis-note { padding: 10px 11px; border-radius: 10px; background: var(--amber); font-size: 13px; }
.food-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.food-actions form { display: flex; flex-wrap: wrap; gap: 8px; }
.food-actions > a { color: var(--primary-strong); font-size: 13px; font-weight: 650; }

.record-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.record-actions a { display: inline-flex; min-height: 32px; align-items: center; padding: 6px 9px; border: 1px solid #bfd0e8; border-radius: 9px; background: #fff; color: var(--primary-strong); font-size: 12px; font-weight: 700; line-height: 1; text-decoration: none; }
.record-actions a:hover { border-color: #8fb0e3; background: var(--primary-soft); }
.record-actions .reuse-action { border-color: #b9def0; background: var(--sky-soft); color: #076a9c; }
.record-actions .delete-link { border-color: #f0c9c5; background: #fff8f7; color: #a52b24; }
.reuse-banner { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; padding: 12px 14px; border: 1px solid #c7d7f5; border-left: 4px solid var(--violet); border-radius: 12px; background: linear-gradient(135deg, #f5f8ff, var(--violet-soft)); }
.reuse-banner span { color: var(--muted); font-size: 13px; }
.list-controls { display: flex; flex: none; align-items: flex-end; flex-direction: column; gap: 7px; }
.list-controls form { margin: 0; }
.food-record-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.food-record-controls form { margin: 0; }
.supply-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.supply-row.is-low { margin: 5px 0; padding: 13px; border: 1px solid #f0d294; border-radius: 12px; background: var(--gold-soft); }
.contact-actions { display: flex !important; align-items: flex-end; flex-direction: column !important; gap: 6px; }
.heading-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }

.manage-plan-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.manage-plan-card h2 { margin-bottom: 5px; }
.manage-plan-card p { margin: 3px 0; color: var(--muted); }
.manage-actions { display: flex; flex: none; flex-direction: column; align-items: stretch; gap: 8px; }
.danger-link, .delete-link { color: #a52b24; font-weight: 650; text-decoration: none; }
.danger-link { text-align: center; }
.manage-groups { display: grid; gap: 12px; }
.manage-group { padding: 0; overflow: hidden; }
.manage-group > summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; cursor: pointer; list-style: none; }
.manage-group > summary::-webkit-details-marker { display: none; }
.manage-group > summary > span { display: flex; min-width: 0; flex-direction: column; }
.manage-group > summary strong { font-size: 18px; }
.manage-group > summary small { color: var(--muted); }
.manage-group > summary b { display: grid; min-width: 32px; height: 32px; place-items: center; border-radius: 10px; background: var(--primary-soft); color: var(--primary-strong); }
.manage-group-body { padding: 0 20px 16px; border-top: 1px solid var(--line); }
.manage-create { padding: 13px 0 5px; }
.manage-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.manage-row > div:first-child { display: flex; min-width: 0; flex-direction: column; }
.manage-row small { color: var(--muted); }
.row-actions { display: flex; flex: none; gap: 13px; }
.row-actions a { color: var(--primary-strong); font-weight: 650; text-decoration: none; }
.row-actions .delete-link { color: #a52b24; }
.empty-state { color: var(--muted); }
.standalone-delete { display: inline-block; margin-top: 15px; }
.delete-confirm .card { margin-top: 18px; }
.danger-button { width: 100%; min-height: 46px; padding: 12px 18px; border: 0; border-radius: 12px; background: #b42318; color: #fff; font-weight: 720; cursor: pointer; }
.plan-revision { width: min(100%, 760px); }

@media (max-width: 1000px) {
  .more-groups { grid-template-columns: 1fr 1fr; }
  .more-groups > :last-child { grid-column: 1 / -1; }
  .daily-plan-list .task-row { grid-template-columns: 72px minmax(0, 1fr); }
  .daily-plan-list .task-controls { grid-column: 2; justify-content: flex-start; }
}

@media (max-width: 800px) {
  .sidebar { display: none; }
  .main-area { margin-left: 0; }
  .topbar { height: 58px; padding: 0 15px; }
  .mobile-brand { display: inline-flex; align-items: center; gap: 7px; margin-right: auto; color: var(--primary-strong); font-weight: 760; text-decoration: none; }
  .mobile-brand span { display: grid; width: 30px; height: 30px; place-items: center; border: 2px solid var(--diabetes-blue); border-radius: 50%; background: #fff; font-size: 11px; }
  .top-more { display: inline-flex; }
  .page-wrap { padding: 22px 15px 100px; }
  .two-col, .metrics { grid-template-columns: 1fr; }
  .page-heading { flex-direction: column; }
  .metrics section { min-height: 154px; }
  .calc-workspace { grid-template-columns: 1fr; }
  .calc-fields { grid-template-columns: 1fr; }
  .math-symbol { height: 24px; }
  .recent-dose { display: flex; flex-direction: column; align-items: flex-start; }
  .recent-dose strong { justify-self: auto; }
  .recent-dose small { grid-column: auto; }
  .live-result { min-height: 220px; }
  .save-dose { grid-template-columns: 1fr; }
  .save-dose > label:first-child { grid-row: auto; }
  .save-dose > label:first-child input { min-height: 72px; }
  .plan-grid { grid-template-columns: 1fr 1fr; }
  .quick-fab { right: 17px; bottom: 17px; }
  .quick-menu { right: 15px; bottom: 87px; }
  .task-row { grid-template-columns: 72px minmax(0, 1fr); }
  .task-row > .task-controls { grid-column: 2; align-items: flex-start; }
  .calc-card { border-radius: 19px; }
  .live-result > div strong { font-size: 56px; }
  .more-groups { grid-template-columns: 1fr; }
  .more-groups > :last-child { grid-column: auto; }
  .food-layout { grid-template-columns: 1fr; }
  .manual-food { position: static; }
}

@media (max-width: 650px) {
  .top-actions { gap: 5px; }
  .top-actions button, .top-more { padding: 7px 9px; font-size: 13px; }
  .top-actions .learn-button span { display: none; }
  .log-choice-grid { grid-template-columns: 1fr; }
  .log-choice.featured { grid-column: auto; }
  .moment-grid { grid-template-columns: 1fr; }
  .moment-wide { grid-column: auto; }
  .formula-strip { gap: 7px 9px; font-size: 11px; }
  .flow-steps { display: grid; grid-template-columns: 1fr; }
  .flow-steps > div:nth-child(even) { transform: rotate(90deg); }
  .connection-card { align-items: flex-start; }
  .photo-record { grid-template-columns: 80px 1fr; }
  .photo-record img { width: 80px; height: 75px; }
  .nutrient-grid { grid-template-columns: 1fr 1fr; }
  .food-detail { padding-left: 14px; }
  .food-result summary, .saved-food summary { align-items: flex-start; }
  .manage-plan-card, .manage-row { align-items: stretch; flex-direction: column; }
  .manage-actions { width: 100%; }
  .row-actions { justify-content: flex-end; }
  .journal-card .journal-row,
  .supply-row { grid-template-columns: 1fr; }
  .journal-card .record-actions { margin-top: 3px; }
  .list-controls,
  .contact-actions { align-items: flex-start; }
  .heading-actions { justify-content: flex-start; }
}

@media (max-width: 420px) {
  h1 { font-size: 31px; }
  .quick-menu-grid { grid-template-columns: 1fr; }
  .quick-menu-grid .primary { grid-column: auto; }
  .target-toggle { grid-template-columns: 1fr 1fr; }
  .card, .metrics section { padding: 18px; }
}

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