/* Functional web app shell — builds on the mockup design system */
html, body { height: 100%; }
body {
  display: flex;
  justify-content: center;
  background: #dfe7e9;
}
@media (min-width: 560px) {
  body { background: radial-gradient(circle at 50% 0%, #eef4f5 0, #d7e1e3 70%); }
}
.screen {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  border-left: 1px solid rgba(16, 24, 40, .06);
  border-right: 1px solid rgba(16, 24, 40, .06);
}
@media (min-width: 560px) {
  .screen { box-shadow: 0 24px 80px rgba(16, 24, 40, .18); }
}
.content {
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 20px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5d7 transparent;
}
.content::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-thumb { background: #cbd5d7; border-radius: 999px; }
.content.has-fab { padding-bottom: 84px; }
.bottomnav { padding-bottom: max(8px, env(safe-area-inset-bottom)); height: auto; min-height: 76px; }
.bottom-actions { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.fab { bottom: calc(92px + env(safe-area-inset-bottom)); }
.screen > .content.grow-main { flex: 1; }

/* app utilities */
.hidden { display: none !important; }
.grow-main { flex: 1; min-height: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack-8 { display: flex; flex-direction: column; gap: 8px; }
.stack-12 { display: flex; flex-direction: column; gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.link { color: var(--accent); font-weight: 700; cursor: pointer; }
.link:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  width: 100%;
}
.input input, .input select { min-width: 0; }
.input textarea { resize: none; }
textarea.input-area {
  min-height: 70px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); padding: 11px 12px; font-size: 13.5px;
}
.input:focus-within, .input-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; -webkit-appearance: none; padding-right: 22px; }
.select-wrap::after {
  content: ""; position: absolute; right: 10px; top: 50%; width: 7px; height: 7px;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.ghost-btn {
  border: 0; background: transparent; color: var(--accent); font-weight: 750;
  font-size: 12px; padding: 6px 4px;
}
.icon-text {
  display: inline-flex; align-items: center; gap: 5px;
}
.empty {
  text-align: center; padding: 34px 20px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty .icon { width: 34px; height: 34px; opacity: .5; }
.empty b { color: var(--text); font-size: 15px; }
.empty span { font-size: 12px; max-width: 260px; line-height: 1.5; }
.empty .btn { margin-top: 8px; height: 44px; padding: 0 20px; }
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.4px; margin: 0; }
.page-sub { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.bar { transition: height .2s ease; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #101828; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 12.5px; font-weight: 650; z-index: 100; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* dialogs */
dialog {
  border: 0; padding: 0; border-radius: 22px; width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 30px 90px rgba(16,24,40,.35);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
.dialog-body { padding: 20px 20px 14px; }
.dialog-title { font-size: 18px; font-weight: 800; letter-spacing: -.3px; margin: 0 0 12px; }
.dialog-actions { display: flex; gap: 8px; padding: 0 20px 20px; }
.dialog-actions .btn { flex: 1; height: 44px; font-size: 13.5px; }
.dialog-close {
  position: absolute; right: 12px; top: 12px; width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted);
}

/* meal editor */
.foodrow { grid-template-columns: 1fr 92px 30px; align-items: start; }
.foodrow .food-cell { position: relative; }
.foodrow .input { overflow: hidden; }
.foodrow .food-name { font-weight: 750; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foodrow .food-sub { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foodrow .qty-wrap { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.foodrow .unit-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 100%; }
.foodrow .unit-toggle button {
  border: 0; border-radius: 8px; background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 750; padding: 5px 2px; line-height: 1.2; min-height: 24px;
}
.foodrow .unit-toggle button.active { background: var(--accent-soft); color: var(--accent); }
.foodrow .rm { border: 0; margin-top: 8px; }
.autocomplete {
  position: absolute; left: 0; right: 0; top: 50px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 40px rgba(16,24,40,.2); overflow: hidden; max-height: 210px; overflow-y: auto;
}
.autocomplete .option { cursor: pointer; }
.autocomplete .option:hover, .autocomplete .option.active { background: var(--accent-soft); }
.autocomplete .option:active { background: var(--accent-soft); }
.autocomplete .none { padding: 12px; font-size: 12px; color: var(--muted); }
.pinned { position: sticky; bottom: 0; }
.insulin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.actual-row { display: flex; gap: 10px; align-items: center; }
.extra-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.extra-item { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.extra-item b { color: var(--text); }

/* history / trends */
.calendar .day { cursor: pointer; }
.calendar .day:hover { background: var(--surface-2); }
.calendar .day.selected:hover { background: var(--accent); }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; gap: 2px; align-items: flex-end; height: 88px; }
.bar-pair .bar { width: 8px; }
.bar-label { font-size: 8.5px; color: var(--muted); font-weight: 700; }
.chart-svg { width: 100%; height: auto; display: block; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 4px; }

/* food editor */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.form-grid .field.full { grid-column: 1 / -1; }
.form-grid .field.third { grid-column: span 1; }
.derived-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.derived-table th { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: right; padding: 0 0 6px; font-weight: 750; }
.derived-table th:first-child { text-align: left; }
.derived-table td { padding: 6px 0; border-top: 1px solid var(--line); }
.derived-table td:not(:first-child) { text-align: right; font-weight: 750; }
.derived-table td:first-child { color: var(--muted); }

/* settings */
.settings-group { display: flex; flex-direction: column; gap: 6px; }
.cir-row { display: grid; grid-template-columns: 1fr 88px 76px; gap: 6px; align-items: center; }
.cir-row .input { min-height: 38px; padding: 0 7px; }
.cir-row .input input { flex: 1; min-width: 0; }
.cir-row .suffix { font-size: 8px; }
.cir-row .cir-value { text-align: right; }
.card .section-label { margin-bottom: 5px; }

/* print / desktop */
@media (min-width: 560px) {
  .screen { border-radius: 0; }
}

/* ---------- functional additions ---------- */
button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
}
.navitem { text-decoration: none; }
.chip-btn {
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
}
.chip-btn:active { transform: translateY(1px); }
.day {
  border: 0;
  background: transparent;
  font-family: inherit;
  padding: 0;
  width: 100%;
}
.day.today { color: var(--text); }
.option {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font-family: inherit;
}
.option:last-child { border-bottom: 0; }
.chart-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 10px 18px;
}
.form-error {
  color: var(--red);
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.4;
  margin-top: 8px;
  min-height: 0;
}
.form-error:empty { display: none; }
.foodrow .food-sub:empty { display: none; }
.foodrow .food-sub {
  font-size: 10px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.foodrow .input input[type="text"] { font-size: 13px; font-weight: 700; }
.foodrow .qty-wrap .input { padding: 0 8px; }
.foodrow .qty-wrap .input input { text-align: right; font-weight: 700; font-size: 13px; }
.foodrow .unit-toggle button { min-width: 0; }
.autocomplete .none {
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.autocomplete .none:hover { background: var(--accent-soft); }
.checkbox { padding: 0; }
.screen > .content:first-child { padding-top: 8px; }


/* ---------- Google Drive sync ---------- */
.sync-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 2px;
  min-height: 28px;
}
.sync-row .sync-chip { max-width: 100%; }
.sync-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 750;
}
.sync-chip.green { border-color: transparent; background: var(--green-soft); color: var(--green); }
.sync-chip.amber { border-color: transparent; background: var(--amber-soft); color: var(--amber); }
.sync-chip.blue { border-color: transparent; background: var(--blue-soft); color: var(--blue); }
.sync-chip.red { border-color: transparent; background: var(--red-soft); color: var(--red); }
.sync-chip.accent { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.sync-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 6px;
}
.sync-progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .2s ease;
}
.drive-test {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  padding: 4px 10px;
}
.drive-test-step {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 7px;
  align-items: start;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.drive-test-step:first-child { border-top: 0; }
.drive-test-mark {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  margin-top: 1px;
}
.drive-test-step.running .drive-test-mark { background: var(--blue-soft); color: var(--blue); }
.drive-test-step.ok .drive-test-mark { background: var(--green-soft); color: var(--green); }
.drive-test-step.fail .drive-test-mark { background: var(--red-soft); color: var(--red); }
.drive-test-step.skipped { opacity: .6; }
.drive-test-copy { min-width: 0; }
.drive-test-label {
  font-size: 11.5px;
  font-weight: 750;
  line-height: 1.35;
}
.drive-test-message {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.4;
  margin-top: 1px;
  overflow-wrap: anywhere;
}
.drive-test-exact {
  color: var(--red);
  font-size: 10.5px;
  line-height: 1.4;
  margin-top: 1px;
  overflow-wrap: anywhere;
}
.drive-test-step.fail .drive-test-label { color: var(--red); }
.drive-test-step.fail .drive-test-message { color: var(--red); }
