/* CarbCal AU on the web — the iPhone app's look: system colours, rounded
   grouped cards, glass bars, and one blue for every carb figure. */

:root {
  --bg: #ffffff;                      /* a plain list page */
  --grouped: #f2f2f7;                 /* behind grouped cards */
  --card: #ffffff;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --label: #000000;
  --label2: rgba(60, 60, 67, 0.6);
  --label3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.2);
  --accent: #0088ff;
  --accent-tint: rgba(0, 136, 255, 0.12);
  --red: #ff383c;
  --orange: #ff8d28;
  --glass: rgba(255, 255, 255, 0.74);
  --glass-edge: rgba(255, 255, 255, 0.7);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  --backdrop: rgba(0, 0, 0, 0.22);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, system-ui, sans-serif;
  --rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --grouped: #000000;
    --card: #1c1c1e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.34);
    --label: #ffffff;
    --label2: rgba(235, 235, 245, 0.6);
    --label3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.6);
    --accent: #0091ff;
    --accent-tint: rgba(0, 145, 255, 0.2);
    --red: #ff4245;
    --orange: #ff9230;
    --glass: rgba(44, 44, 48, 0.72);
    --glass-edge: rgba(255, 255, 255, 0.12);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
    --backdrop: rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.sheet-open { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.3 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg.icon {
  width: 1em;
  height: 1em;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg.icon .f { fill: currentColor; stroke: none; }
svg.icon.xfill .x { stroke: var(--card); stroke-width: 2.2; }
svg.icon.i-plus, svg.icon.i-chevron-right, svg.icon.i-chevron-left, svg.icon.i-chevron-up { stroke-width: 2.6; }
.accessory .circle { width: 42px; height: 42px; box-shadow: none; background: none; border: 0; color: var(--accent); font-size: 20px; }

/* ---------- layout ---------- */

.app { display: flex; min-height: 100dvh; }
.pages { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding-bottom: 24px; }

.panel { display: none; }

@media (min-width: 900px) {
  /* iPad and an open iPhone Duo: the meal stays open beside the pages. */
  .panel {
    display: flex;
    flex-direction: column;
    flex: none;
    width: clamp(340px, 33vw, 420px);
    height: 100dvh;
    position: sticky;
    top: 0;
    background: var(--grouped);
    border-left: 0.5px solid var(--sep);
  }
  .accessory { display: none !important; }
}

/* ---------- top bar and search ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: env(safe-area-inset-top) 0 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.bar > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.bar-row {
  position: relative;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 60px;
}
.bar-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bar-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { border-radius: 6px; }
.back {
  position: absolute;
  left: 12px;
  top: 4px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  color: var(--label);
  background: var(--glass);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  margin: 4px 16px 10px;
  padding: 0 12px 0 16px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06), inset 0 0 0 0.5px var(--sep);
}
.search-icon { color: var(--label2); font-size: 18px; }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 17px;
}
.search input::placeholder { color: var(--label3); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  border: 0;
  background: none;
  padding: 4px;
  color: var(--label3);
  font-size: 19px;
  display: grid;
  place-items: center;
}

/* ---------- lists ---------- */

.section-title {
  margin: 0;
  padding: 18px 16px 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--label2);
}
.list { margin: 0; padding: 0; list-style: none; }
.row {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border: 0;
  background: none;
  text-align: left;
  min-height: 56px;
}
.row::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: bottom;
}
li:last-child > .row::after, .row:last-child::after { display: none; }
.row:active, .row.pressed { background: var(--fill); }
@media (hover: hover) { button.row:hover { background: var(--fill); } }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 500; }
.row .sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--label2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .figure { flex: none; max-width: 150px; text-align: right; }
.row .figure b { display: block; color: var(--accent); font-weight: 600; font-size: 17px; }
.row .figure small {
  display: block;
  font-size: 11px;
  color: var(--label3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .count { color: var(--label2); font-size: 15px; font-variant-numeric: tabular-nums; }
.row .chev { color: var(--label3); font-size: 13px; }
.row .lead { color: var(--accent); font-size: 22px; }

/* ---------- empty and error states ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 16vh 32px 8vh;
}
.empty .big { font-size: 52px; color: var(--label2); margin-bottom: 14px; }
.empty h2 { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.empty p { margin: 0; color: var(--label2); font-size: 15px; max-width: 26em; }
.suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.chip {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-tint);
}
.spinner {
  width: 26px;
  height: 26px;
  margin: 18vh auto;
  border-radius: 50%;
  border: 2.5px solid var(--fill-strong);
  border-top-color: var(--label2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.about {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px calc(110px + env(safe-area-inset-bottom));
  color: var(--label2);
  font-size: 12px;
  line-height: 1.45;
}
.about p { margin: 0 0 6px; }
.about a { color: var(--label2); }
@media (min-width: 900px) { .about { padding-bottom: 32px; } }

/* ---------- the bar at the bottom (phones) ---------- */

.accessory {
  position: fixed;
  z-index: 10;
  left: 16px;
  right: 16px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 0;
  border-radius: 999px;
  background: var(--glass);
  border: 0.5px solid var(--glass-edge);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}
.accessory .open {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 0 20px;
  border: 0;
  background: none;
  text-align: left;
  border-radius: 999px;
}
.accessory .fork { color: var(--label2); font-size: 18px; }
.accessory .none { color: var(--label2); font-size: 15px; font-weight: 500; }
.accessory .what { flex: 1; min-width: 0; }
.accessory .what small { display: block; font-size: 11px; color: var(--label2); }
.accessory .what b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.accessory .review { display: flex; align-items: center; gap: 4px; color: var(--accent); font-size: 15px; font-weight: 600; }
.accessory .review .icon { font-size: 12px; }

/* ---------- this meal ---------- */

.meal { display: flex; flex-direction: column; min-height: 0; flex: 1; background: var(--grouped); }
.meal-bar {
  flex: none;
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 64px;
  font-weight: 600;
}
.meal-bar .lead-btn { position: absolute; left: 12px; top: 8px; }
.meal-bar .trail-btn { position: absolute; right: 12px; top: 8px; }
.circle {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--glass);
  border: 0.5px solid var(--glass-edge);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.capsule {
  height: 40px;
  padding: 0 16px;
  border: 0.5px solid var(--glass-edge);
  border-radius: 999px;
  font-size: 16px;
  font-weight: 500;
  background: var(--glass);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.capsule.strong { font-weight: 600; color: var(--accent); }
.capsule:disabled { color: var(--label3); }

.meal-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 20px; }

.total {
  text-align: center;
  padding: 26px 16px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0)),
    color-mix(in srgb, var(--accent) 16%, var(--card));
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.55), 0 1px 3px rgba(0, 0, 0, 0.05);
}
@media (prefers-color-scheme: dark) {
  .total {
    background: color-mix(in srgb, var(--accent) 22%, var(--card));
    box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  }
}
.total .k { font-size: 15px; font-weight: 500; color: var(--label2); }
.total .v {
  margin: 4px 0;
  font: 700 50px/1.1 var(--rounded);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.total .of { font-size: 15px; color: var(--label2); }
.total .per100 { margin-top: 8px; font-size: 13px; font-weight: 500; color: var(--label2); }

.group {
  margin-top: 20px;
  border-radius: 22px;
  background: var(--card);
  overflow: hidden;
}
.group .row { min-height: 60px; }
.hint {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  color: var(--label2);
  font-size: 15px;
}
.hint .icon { font-size: 20px; }
.row .portion-label { font-size: 12px; color: var(--label2); margin-top: 2px; }
.row .line-carbs { color: var(--accent); font-weight: 600; font-size: 16px; white-space: nowrap; }
.row .zero-sub { font-size: 11px; color: var(--label2); margin-top: 1px; }
.row .plus { color: var(--accent); font-size: 14px; }
.row .muted-icon { color: var(--label2); font-size: 18px; }

.meal-actions {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--grouped) 85%, transparent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.panel .meal-actions { padding-bottom: 16px; }
.btn {
  flex: 1;
  height: 52px;
  border: 0;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 500;
  white-space: nowrap;
}
.btn.prominent { background: var(--accent); color: #fff; }
.btn.glass { background: var(--card); box-shadow: inset 0 0 0 0.5px var(--sep), 0 2px 8px rgba(0, 0, 0, 0.06); }
.btn:disabled { opacity: 0.4; }
.btn.bin { flex: 0 0 66px; color: var(--label2); }
.btn.bin .icon {
  font-size: 20px;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.3s;
  transform-origin: 10% 90%;
}
.btn.bin.armed { color: var(--red); background: color-mix(in srgb, var(--red) 12%, var(--card)); }
.btn.bin.armed .icon { transform: rotate(-22deg); }

/* ---------- menus ---------- */

.menu {
  position: fixed;
  z-index: 80;
  min-width: 230px;
  padding: 6px;
  border-radius: 20px;
  background: var(--glass);
  border: 0.5px solid var(--glass-edge);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
}
.menu button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 14px;
  border: 0;
  border-radius: 14px;
  background: none;
  font-size: 17px;
  text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--fill); outline: none; }
.menu .icon { font-size: 18px; }

/* ---------- sheets ---------- */

.layer { position: fixed; inset: 0; z-index: 50; }
.backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 0.3s;
}
.layer.shown .backdrop { opacity: 1; }

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100dvh - 44px - env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  background: var(--grouped);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 0.34s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.sheet.tall { height: calc(100dvh - 44px - env(safe-area-inset-top)); }
.sheet.open { transform: none; }
.sheet.under { transform: scale(0.96) translateY(-8px); filter: brightness(0.92); }
.grabber {
  flex: none;
  width: 36px;
  height: 5px;
  margin: 6px auto 0;
  border-radius: 3px;
  background: var(--label3);
}
.sheet-bar {
  flex: none;
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 96px;
  font-weight: 600;
}
.sheet-bar .left { position: absolute; left: 12px; top: 8px; }
.sheet-bar .right { position: absolute; right: 12px; top: 8px; }
.sheet-bar .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 16px; }

@media (min-width: 700px) {
  /* A form sheet in the middle, as on iPad. */
  .sheet {
    left: 50%;
    top: 50%;
    bottom: auto;
    width: min(560px, 92vw);
    max-height: min(760px, 90dvh);
    border-radius: 28px;
    transform: translate(-50%, -46%) scale(0.98);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1), opacity 0.2s;
  }
  .sheet.tall { height: min(760px, 90dvh); }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet.under { transform: translate(-50%, -50%) scale(0.96); opacity: 1; }
  .grabber { display: none; }
}

/* ---------- forms inside sheets ---------- */

.form-group {
  margin-top: 18px;
  border-radius: 22px;
  background: var(--card);
  overflow: hidden;
}
.form-group:first-child { margin-top: 4px; }
.form-head { margin: 22px 16px 6px; font-size: 13px; color: var(--label2); }
.form-head + .form-group { margin-top: 0; }
.form-foot { margin: 8px 16px 0; font-size: 13px; color: var(--label2); line-height: 1.4; }
.cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 10px 16px;
}
.cell + .cell::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 0;
  top: 0;
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: top;
}
.cell .grow { flex: 1; min-width: 0; }
.cell .dim { color: var(--label2); }
.cell.small { min-height: 40px; font-size: 13px; color: var(--label2); }
.summary .name { font-weight: 600; }
.summary .sub { font-size: 12px; color: var(--label2); margin-top: 3px; }
.summary .rate { font-size: 12px; color: var(--accent); margin-top: 4px; }
.cell input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0;
}
.cell input.big { font-size: 22px; font-weight: 500; }
.cell input.right { text-align: right; }
.cell input::placeholder { color: var(--label3); }
.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  text-align: left;
}
.danger {
  width: 100%;
  border: 0;
  background: none;
  color: var(--red);
  font-size: 17px;
  min-height: 50px;
}

.seg {
  display: flex;
  width: 100%;
  padding: 2px;
  border-radius: 999px;
  background: var(--fill);
}
.seg button {
  flex: 1;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.seg button[aria-pressed="true"] {
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  .seg button[aria-pressed="true"] { background: #636366; }
}

.stepper { display: flex; flex: none; border-radius: 999px; background: var(--fill); }
.stepper button {
  width: 48px;
  height: 34px;
  border: 0;
  background: none;
  font-size: 20px;
  display: grid;
  place-items: center;
}
.stepper button:disabled { color: var(--label3); }
.stepper button + button { border-left: 0.5px solid var(--sep); }
.count-text { font-variant-numeric: tabular-nums; }

.quick { display: flex; gap: 8px; padding: 4px 16px 14px; }
.quick button {
  flex: 1;
  border: 0;
  border-radius: 14px;
  padding: 8px 4px;
  color: var(--accent);
  background: var(--accent-tint);
  line-height: 1.2;
}
.quick b { display: block; font-size: 15px; }
.quick small { display: block; font-size: 11px; opacity: 0.8; }

.missing { color: var(--orange); font-size: 15px; }
.cell .portion-label { font-size: 12px; margin-top: 2px; }

.total-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 16px calc(10px + env(safe-area-inset-bottom));
  padding: 14px 20px;
  border-radius: 22px;
  background: var(--glass);
  border: 0.5px solid var(--glass-edge);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}
@media (min-width: 700px) { .total-bar { margin-bottom: 14px; } }
.total-bar span { font-size: 15px; color: var(--label2); }
.total-bar b { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.total-bar b.quiet { font-size: 15px; font-weight: 500; color: var(--label2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
