:root {
  --sage: #78947b;
  --sage-dark: #476654;
  --sage-ink: #25382f;
  --mint: #e9f2ec;
  --cream: #fbf7ef;
  --paper: #fffdf8;
  --white: #ffffff;
  --terracotta: #c86f59;
  --amber: #e4bd72;
  --blue: #7aa7b4;
  --rose: #d89a8c;
  --danger: #a43f33;
  --ink: #1f2c28;
  --muted: #66736e;
  --line: #dce5df;
  --soft-line: #edf2ee;
  --shadow: 0 20px 56px rgba(30, 48, 40, .12);
  --shadow-soft: 0 12px 32px rgba(30, 48, 40, .08);
  --radius: 8px;
  --sidebar: 292px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(145deg, rgba(233, 242, 236, .72) 0%, rgba(251, 247, 239, .96) 38%, rgba(255, 253, 248, .98) 100%),
    var(--cream);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

a {
  color: inherit;
}

svg {
  display: block;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px;
  background: rgba(255, 253, 248, .94);
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 40px rgba(47, 66, 56, .05);
  overflow: auto;
}

.brand {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.brand-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--sage-dark), var(--sage));
  color: #fff;
  box-shadow: var(--shadow-soft);
}

.brand-logo svg {
  width: 31px;
  fill: currentColor;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.16rem;
  line-height: 1.05;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: .79rem;
  font-weight: 750;
}

.patient-chip,
.storage-meter {
  display: grid;
  gap: 6px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}

.patient-chip strong,
.storage-meter strong {
  font-size: .96rem;
}

.patient-chip span,
.storage-meter span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.nav-list {
  display: grid;
  gap: 5px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 830;
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--mint);
  color: var(--sage-dark);
  font-size: .84rem;
}

.nav-item.active {
  color: var(--sage-ink);
  background: #fff;
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

.nav-item.active .nav-icon {
  color: #fff;
  background: var(--sage-dark);
}

.nav-progress {
  width: 28px;
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--soft-line);
}

.nav-progress span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: var(--terracotta);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.mobile-topbar {
  display: none;
}

.workspace {
  min-width: 0;
  padding: 26px clamp(16px, 4vw, 42px) 46px;
}

.page {
  max-width: 1460px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.page-title {
  max-width: 900px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--sage-dark);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 9px;
  font-size: clamp(2.1rem, 5vw, 4.25rem);
  line-height: .98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(1.35rem, 3vw, 2.05rem);
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 9px;
  font-size: 1.05rem;
  letter-spacing: 0;
}

h4 {
  margin-bottom: 8px;
  font-size: .92rem;
}

p {
  color: var(--muted);
  line-height: 1.62;
}

.lead {
  color: var(--sage-ink);
  font-size: 1.05rem;
  font-weight: 760;
}

.muted {
  color: var(--muted);
}

.fine {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(320px, .94fr);
  min-height: min(740px, calc(100vh - 72px));
  gap: 28px;
  align-items: stretch;
}

.hero-copy {
  display: grid;
  align-content: center;
  padding: clamp(18px, 4vw, 34px) 0;
}

.hero-copy h1 {
  max-width: 850px;
}

.hero-actions,
.toolbar,
.actions,
.button-row,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hero-visual {
  position: relative;
  display: grid;
  align-content: stretch;
  min-height: 520px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .86), rgba(233, 242, 236, .86) 52%, rgba(248, 238, 222, .94)),
    var(--paper);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.demo-board {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  min-height: 100%;
}

.demo-board-head,
.report-brand,
.split-head,
.card-head,
.panel-head,
.row-between {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.plate-map {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: center;
}

.plate-tile {
  min-height: 132px;
  display: grid;
  align-content: end;
  padding: 14px;
  border-radius: 14px;
  background: var(--white);
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: var(--shadow-soft);
}

.plate-tile strong {
  font-size: 1.8rem;
}

.plate-tile.protein { background: #fdf4ef; }
.plate-tile.veg { background: #edf5eb; }
.plate-tile.carbs { background: #fff6df; }
.plate-tile.fats { background: #edf3f6; }

.insight-stream {
  display: grid;
  gap: 9px;
}

.stream-line {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,.84);
  border: 1px solid var(--line);
  color: var(--sage-ink);
  font-weight: 790;
}

.surface,
.card,
.metric,
.chart-panel,
.patient-row,
.form-section,
.report-page,
.education-card,
.rec-card,
.plan-item,
.timeline-item {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.surface {
  padding: clamp(16px, 2vw, 22px);
  margin-bottom: 16px;
}

.surface.flush {
  padding: 0;
  overflow: hidden;
}

.card,
.education-card,
.rec-card,
.plan-item {
  padding: 15px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.auto {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.patient-list {
  display: grid;
  gap: 10px;
}

.patient-row {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 13px;
  color: var(--ink);
  text-align: left;
}

.patient-row.active {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px rgba(120, 148, 123, .16);
}

.patient-row span {
  color: var(--muted);
  font-size: .82rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 13px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 830;
}

.field.full {
  grid-column: 1 / -1;
}

.field input,
.field textarea,
.field select,
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.field textarea,
.text-input.area {
  min-height: 96px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.text-input:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px rgba(120, 148, 123, .16);
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 9px;
}

.check-card {
  min-height: 44px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  font-size: .9rem;
  font-weight: 760;
}

.check-card input {
  width: 20px;
  height: 20px;
  accent-color: var(--sage-dark);
}

.primary,
.secondary,
.ghost,
.danger,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  gap: 8px;
  padding: 0 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 860;
  line-height: 1.15;
  text-decoration: none;
}

.primary {
  color: #fff;
  background: var(--sage-dark);
  box-shadow: 0 10px 24px rgba(71, 102, 84, .22);
}

.primary:hover {
  background: #385544;
}

.secondary {
  color: var(--sage-dark);
  background: #fff;
  border-color: var(--line);
}

.ghost {
  color: var(--sage-ink);
  background: var(--mint);
  border-color: transparent;
}

.danger {
  color: #fff;
  background: var(--danger);
}

.icon-button {
  width: 42px;
  padding: 0;
  color: var(--sage-ink);
  background: #fff;
  border-color: var(--line);
  font-size: 1.1rem;
}

.full {
  width: 100%;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  overflow-x: auto;
}

.tab-button,
.seg-button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-weight: 840;
}

.tab-button.active,
.seg-button.active {
  color: #fff;
  border-color: var(--sage-dark);
  background: var(--sage-dark);
}

.badge,
.status,
.confidence,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.badge {
  color: var(--sage-dark);
  background: var(--mint);
}

.badge.warn {
  color: #7b4c0f;
  background: #fff1ca;
}

.badge.alert {
  color: #8d342a;
  background: #ffe2dc;
}

.badge.info {
  color: #315a64;
  background: #e6f3f6;
}

.metric {
  display: grid;
  gap: 9px;
  min-height: 118px;
  padding: 15px;
}

.metric span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 880;
}

.metric strong {
  font-size: clamp(1.3rem, 3vw, 2rem);
  line-height: 1;
}

.metric small {
  color: var(--muted);
  line-height: 1.4;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft-line);
}

.progress-track span {
  display: block;
  width: var(--value, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sage-dark), var(--terracotta));
}

.score-ring {
  --score: 0;
  width: 148px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, #fff 0 59%, transparent 60%),
    conic-gradient(var(--sage-dark) calc(var(--score) * 1%), #edf2ee 0);
}

.score-ring strong {
  font-size: 2.1rem;
}

.axis-card {
  display: grid;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}

.axis-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.axis-examples {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.meal-entry {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.meal-grid {
  display: grid;
  grid-template-columns: 96px 130px minmax(0, 1fr) 120px;
  gap: 10px;
}

.plate-viz {
  width: min(260px, 100%);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  overflow: hidden;
  border: 10px solid #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-soft);
  background: #fff;
}

.plate-viz span {
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--ink);
  font-size: .78rem;
  font-weight: 900;
  text-align: center;
}

.plate-viz .veg { background: #dbeed9; }
.plate-viz .protein { background: #f5d1c5; }
.plate-viz .carbs { background: #f9e2a5; }
.plate-viz .fat { background: #cfe5eb; }

.glycemic-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
}

.food-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 90px 90px 42px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.table-lite {
  width: 100%;
  border-collapse: collapse;
}

.table-lite th,
.table-lite td {
  padding: 10px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: top;
}

.table-lite th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}

.chart-panel {
  padding: 15px;
}

.chart-panel canvas {
  width: 100%;
  height: 250px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 12px;
  padding: 13px;
}

.rec-card {
  display: grid;
  gap: 12px;
}

.rec-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 14px;
}

.rec-actions {
  display: grid;
  gap: 8px;
}

.education-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
}

.education-card {
  display: grid;
  gap: 10px;
}

.education-card ul,
.clean-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.48;
}

.signature-pad {
  display: grid;
  gap: 10px;
}

.signature-pad canvas {
  width: 100%;
  min-height: 180px;
  border: 1px dashed var(--sage);
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
}

.pdf-drop {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px dashed var(--sage);
  border-radius: var(--radius);
  background: rgba(255,255,255,.72);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(31, 44, 40, .58);
  overflow: auto;
}

.modal.active {
  display: grid;
}

.modal-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 28px 80px rgba(0,0,0,.22);
}

.modal-panel.wide {
  width: min(1080px, 100%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 80;
  transform: translateX(-50%) translateY(90px);
  width: min(560px, calc(100% - 24px));
  padding: 13px 15px;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.report-modal {
  align-items: start;
}

.report-toolbar {
  position: sticky;
  top: 10px;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.report-shell {
  width: min(980px, 100%);
  margin: 0 auto 24px;
  display: grid;
  gap: 18px;
}

.report-page {
  min-height: 1122px;
  padding: 38px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
  break-after: page;
}

.report-page:last-child {
  break-after: auto;
}

.report-page h1 {
  font-size: 2.8rem;
}

.report-page h2 {
  font-size: 1.55rem;
  margin-top: 20px;
}

.report-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}

.callout {
  padding: 13px;
  border-radius: var(--radius);
  background: var(--mint);
  border: 1px solid #d7e6db;
}

.callout.warn {
  background: #fff5dc;
  border-color: #f0d99c;
}

.callout.alert {
  background: #ffeae5;
  border-color: #efc8be;
}

.print-only {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(330px, 88vw);
    transform: translateX(-105%);
    transition: transform .22s ease;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 35;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(255,253,248,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }

  .brand.mini {
    width: auto;
  }

  .brand.mini .brand-logo {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .workspace {
    padding-top: 18px;
  }

  .home-hero,
  .dashboard-grid,
  .rec-grid,
  .glycemic-builder {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .page-head,
  .demo-board-head,
  .split-head,
  .card-head,
  .panel-head,
  .row-between {
    display: grid;
    justify-items: start;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .form-grid,
  .meal-grid {
    grid-template-columns: 1fr;
  }

  .hero-visual {
    min-height: auto;
  }

  .plate-map {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 1fr;
  }

  .food-row {
    grid-template-columns: 1fr 1fr;
  }

  .food-row .icon-button {
    width: 100%;
  }

  h1 {
    font-size: clamp(2rem, 12vw, 3.2rem);
  }
}

@media (max-width: 460px) {
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

  .surface,
  .card,
  .education-card,
  .rec-card,
  .plan-item {
    padding: 13px;
  }

  .primary,
  .secondary,
  .ghost,
  .danger {
    width: 100%;
  }

  .metric strong {
    font-size: 1.45rem;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  .app-shell,
  .toast,
  .no-print {
    display: none !important;
  }

  .modal.report-modal {
    position: static;
    display: block !important;
    padding: 0;
    background: #fff;
  }

  #reportPreview,
  .report-shell {
    width: 100%;
    margin: 0;
    display: block;
  }

  .report-page {
    min-height: auto;
    padding: 0;
    border: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }

  .report-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .print-only {
    display: block;
  }
}
