:root {
  --paper: #ffffff;
  --ink: #243c4a;
  --ink-deep: #173140;
  --blue: #4f6f80;
  --blue-dark: #3d5b6a;
  --coral: #d8866d;
  --coral-soft: #e8cfc7;
  --sand: #d8ccc8;
  --sand-light: #f3ece9;
  --line: #d8927d;
  --white: #ffffff;
  --shadow: 0 18px 42px rgba(36,60,74,.18);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #aaa;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  background: var(--coral);
  color: white;
  padding: .75rem 1rem;
  cursor: pointer;
  font-weight: 800;
}
button.secondary { background: var(--sand-light); color: var(--ink); }
button.ghost { background: transparent; color: var(--blue-dark); border: 1px solid var(--sand); }
button.danger { background: #9b2c2c; }
button.small { padding: .45rem .7rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  width: 100%; border: 1px solid #d8ccc8; border-radius: 12px; background: white;
  padding: .85rem .9rem; color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
label { display: grid; gap: .4rem; font-weight: 800; color: var(--blue-dark); }

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: white;
  padding: max(.75rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  position: relative;
}
.loading-card, .auth-card, .welcome-card {
  width: min(560px, 100%); margin: 8vh auto; background: white; border: 3px solid var(--coral);
  box-shadow: var(--shadow); padding: 1.5rem; text-align: center;
}
.auth-logo { display: block; width: min(430px, 92%); margin: 0 auto 1rem; }
.auth-card p, .welcome-card p { color: var(--blue-dark); line-height: 1.4; }
.stack { display: grid; gap: 1rem; text-align: left; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.inline-grid { display: grid; grid-template-columns: 1fr .75fr; gap: .75rem; }

.topbar { display: grid; gap: .8rem; margin-bottom: .9rem; }
.brand-panel { text-align: center; padding-top: .2rem; }
.brand-logo { width: min(510px, 94%); max-height: 112px; object-fit: contain; }
.quick-actions {
  display: grid; grid-template-columns: repeat(3, 1fr); background: var(--coral); border-bottom: 14px solid var(--blue-dark);
  padding: .45rem .5rem 0; gap: .3rem; color: white;
}
.icon-action {
  background: transparent; border-radius: 0; padding: 0; color: white; display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto;
  justify-content: center; align-items: center; column-gap: .3rem; row-gap: .1rem; min-height: 58px;
}
.icon-action .plus { font-size: 1.75rem; font-weight: 900; line-height: 1; }
.icon-action img { height: 34px; width: 42px; object-fit: contain; }
.icon-action span:last-child { grid-column: 1 / -1; font-weight: 400; font-size: .82rem; margin-top: -.1rem; }
.muted-action { opacity: .92; }

.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.summary-card { border: 3px solid var(--coral); background: var(--sand); text-align: center; min-height: 64px; }
.summary-card span { display: block; background: var(--coral); color: white; font-size: .72rem; line-height: 1; padding: .28rem; text-transform: uppercase; font-weight: 900; }
.summary-card strong { display: block; color: white; font-weight: 500; font-size: clamp(1.15rem, 5vw, 1.45rem); padding: .65rem .35rem; }
.desktop-nav { display: none; align-items: center; justify-content: space-between; gap: 1rem; margin: .3rem 0 .6rem; }
.pill { display: inline-flex; align-items: center; border: 1px solid var(--sand); background: var(--sand-light); border-radius: 999px; color: var(--blue-dark); font-weight: 900; padding: .35rem .6rem; }

.week-strip { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 1rem; padding: .25rem 0 1rem; -webkit-overflow-scrolling: touch; }
.week-card { flex: 0 0 calc(100vw - 2rem); scroll-snap-align: start; min-height: calc(100vh - 300px); background: var(--sand); border: 4px solid var(--coral); padding: 1rem; position: relative; display: flex; flex-direction: column; gap: .8rem; }
.week-edit { position: absolute; right: 1rem; top: 1rem; z-index: 2; }
.edit-icon { width: 48px; height: 48px; border: 3px solid white; border-radius: 8px; background: transparent; padding: .4rem; display: grid; place-items: center; }
.edit-icon img { width: 100%; height: 100%; object-fit: contain; }
.week-hero { background: var(--blue); color: white; padding: 1.1rem 1.2rem .4rem; min-height: 86px; }
.week-hero h2 { margin: 0; font-size: clamp(2rem, 8vw, 2.6rem); line-height: .9; color: white; text-transform: uppercase; }
.week-hero .dates { color: white; font-size: 1.05rem; }
.hero-data { background: var(--blue); color: white; padding: .2rem 1.2rem 1rem; }
.hero-label { color: rgba(23,49,64,.55); text-transform: uppercase; font-weight: 1000; font-size: clamp(1.8rem, 8vw, 2.35rem); line-height: 1; margin-top: .3rem; }
.hero-value { color: white; font-size: clamp(1.35rem, 6vw, 1.65rem); line-height: 1.2; }
.measurement-icons { display: grid; grid-template-columns: repeat(2, 1fr); gap: .45rem; justify-items: center; padding: .25rem 0 .2rem; }
.measure-tile { min-height: 108px; display: grid; justify-items: center; align-content: center; color: var(--coral); text-align: center; }
.measure-tile img { max-height: 64px; max-width: 92px; object-fit: contain; margin-bottom: .2rem; }
.measure-tile span { font-size: .95rem; color: var(--coral); }
.measure-tile small { font-size: .72rem; color: var(--coral); opacity: .9; }
.week-details { margin-top: auto; }
details { color: var(--blue-dark); }
summary { cursor: pointer; font-weight: 900; }
.detail-sections { display: grid; gap: .65rem; margin-top: .7rem; }
.card-section { display: grid; gap: .45rem; }
.card-section h3 { margin: 0; color: var(--blue-dark); font-size: .95rem; }
.entry-list { display: grid; gap: .5rem; }
.entry-row { display: grid; gap: .35rem; border: 1px solid #dfc2ba; background: rgba(255,255,255,.55); border-radius: 14px; padding: .7rem; }
.entry-main { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.entry-main strong { font-size: 1rem; }
.entry-meta { color: #6a7780; font-size: .88rem; line-height: 1.35; }
.entry-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.empty { color: #6a7780; font-style: italic; }
.dose-day-prompt { background: rgba(255,255,255,.5); border: 2px dashed var(--coral); }
.optional-group { border: 1px solid #d8ccc8; border-radius: 18px; padding: .85rem; display: grid; gap: .65rem; background: rgba(255,255,255,.38); }
.optional-group legend { color: var(--blue-dark); font-weight: 900; padding: 0 .35rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-weight: 800; }
.checkbox-row input { width: auto; }
.compact-message { margin: -.35rem 0 0; min-height: 0; font-size: .9rem; }
.message { color: var(--blue-dark); min-height: 1.4rem; }
.error { color: #9b2c2c; font-weight: 800; }
.entry-dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 2rem)); background: white; color: var(--ink); box-shadow: var(--shadow); }
.entry-dialog::backdrop { background: rgba(23,49,64,.35); backdrop-filter: blur(4px); }
.dialog-inner { padding: 1.2rem; }
.dialog-inner h2 { margin: 0 0 .75rem; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.congrats-dialog h2 { font-size: clamp(1.8rem, 7vw, 2.6rem); margin-bottom: .25rem; color: var(--coral); }
.encouragement-line { color: var(--blue-dark); font-weight: 900; font-size: 1.1rem; margin: 0 0 1rem; }
.congrats-recap { display: grid; gap: .75rem; }
.congrats-recap p { margin: 0; border: 1px solid #d8ccc8; background: var(--sand-light); border-radius: 14px; padding: .85rem; color: var(--blue-dark); line-height: 1.4; }
.congrats-recap strong { color: var(--coral); }
.medical-note { color: #6a7780; font-size: .85rem; margin: .9rem 0 0; }
.floating-buttons { position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); display: grid; gap: .6rem; z-index: 5; }
.round-button { width: 58px; height: 58px; border-radius: 50%; padding: .65rem; background: var(--blue); border: 0; box-shadow: 0 8px 22px rgba(36,60,74,.25); }
.notes-button { background: var(--coral); }
.round-button img { width: 100%; height: 100%; object-fit: contain; }

@media (min-width: 760px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions { max-width: 620px; margin: 0 auto; width: 100%; }
}
@media (min-width: 980px) {
  body { background: #9f9f9f; }
  .app-shell { width: min(1180px, calc(100% - 2rem)); margin: 1rem auto; min-height: calc(100vh - 2rem); }
  .desktop-nav { display: flex; }
  .week-card { flex-basis: calc((100% - 2rem) / 3); min-height: 600px; }
  .week-hero h2 { font-size: 2.2rem; }
  .hero-label { font-size: 1.8rem; }
  .hero-value { font-size: 1.3rem; }
}

/* V2.1 measurement preferences */
.measurement-icons .measure-tile:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  justify-self: center;
  width: min(180px, 100%);
}
.measurement-empty {
  grid-column: 1 / -1;
  text-align: center;
  margin: .5rem 0;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem .85rem;
}
.settings-measurements .checkbox-row {
  background: rgba(255,255,255,.6);
  border: 1px solid #d8ccc8;
  border-radius: 12px;
  padding: .65rem .75rem;
}
.measurement-input-grid > label:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}
@media (max-width: 520px) {
  .checkbox-grid { grid-template-columns: 1fr; }
}
