/* ============ Rastreio — sistema de design ============
   Inspirado em "Morrow" (Al Helal Hadi, Behance): papel quente, pastéis, ilustrações a traço de tinta,
   títulos em serifa, muito espaço negativo, uma ação principal por cartão. */

:root {
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;

  --bg: #f7f0ec; --card: #ffffff; --ink: #1e1512; --muted: #7b6b64; --line: #ecdfd8; --field: #fbf6f3;
  --accent: #a8142f; --on-accent: #ffffff;
  --dark: #1e1512; --on-dark: #f8efea;
  --track: rgba(30, 21, 18, .09);
  --shadow: 0 10px 30px rgba(86, 40, 30, .12);

  --peach: #ffdac5;  --peach-d: #e6a07c;
  --rose: #f9cfd2;   --rose-d: #d9707c;
  --butter: #fbe9b9; --butter-d: #d4a233;
  --sage: #dde8d4;   --sage-d: #7da36a;
  --mist: #d9e7f0;   --mist-d: #5f93b5;

  --ok: #3f7a4f; --ok-bg: #dde8d4; --warn: #8a5a12; --warn-bg: #fbe9b9; --bad: #9b2335; --bad-bg: #f9cfd2;
  --red: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181110; --card: #241a17; --ink: #f6ece7; --muted: #aa9a92; --line: #3a2b28; --field: #2b201d;
    --accent: #e5506b; --on-accent: #1e0d10;
    --dark: #f1e5df; --on-dark: #1e1512;
    --track: rgba(246, 236, 231, .12);
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --peach: #4b3027;  --peach-d: #e29a78;
    --rose: #4d2a30;   --rose-d: #e77f8b;
    --butter: #4a3f22; --butter-d: #e0b64a;
    --sage: #2e3d2b;   --sage-d: #94bb80;
    --mist: #263644;   --mist-d: #7db0d1;
    --ok: #a9d29a; --ok-bg: #2e3d2b; --warn: #f1d28a; --warn-bg: #4a3f22; --bad: #f2a3ad; --bad-bg: #4d2a30;
    --red: #f2a3ad;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 var(--sans); min-height: 100vh; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font: 500 38px/1.05 var(--serif); letter-spacing: -.02em; }
h2 { font: 500 21px/1.15 var(--serif); letter-spacing: -.01em; }
h3 { font: 500 18px/1.2 var(--serif); }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 12px; }
.err { color: var(--red); font-size: 14px; min-height: 1.2em; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.ok { color: var(--ok); }
.low { color: var(--warn); }
@media (prefers-color-scheme: dark) { .low { color: var(--warn); } }

/* ---------- ilustrações ---------- */
.illo { display: grid; place-items: center; overflow: hidden; }
.illo img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.illo-fb { width: 58%; height: 58%; color: var(--ink); opacity: .5; }
@media (prefers-color-scheme: dark) { .illo img { filter: invert(1); mix-blend-mode: screen; } }

/* tons pastel reutilizados por tiles, cartões e barras */
.tone-peach { --tone: var(--peach); --tone-d: var(--peach-d); }
.tone-rose { --tone: var(--rose); --tone-d: var(--rose-d); }
.tone-butter { --tone: var(--butter); --tone-d: var(--butter-d); }
.tone-sage { --tone: var(--sage); --tone-d: var(--sage-d); }
.tone-mist { --tone: var(--mist); --tone-d: var(--mist-d); }

/* ---------- login ---------- */
#login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--peach); }
#loginForm { width: 100%; max-width: 340px; display: grid; gap: 14px; text-align: center; }
#loginArt { width: 220px; height: 170px; margin: 0 auto -6px; }
#loginArt .illo { width: 100%; height: 100%; }
.lede { color: var(--muted); font-size: 15px; }
input#pw { text-align: center; }

/* ---------- estrutura ---------- */
#app { padding-bottom: calc(168px + env(safe-area-inset-bottom)); }
#view { max-width: 560px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 18px 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
#view > * { min-width: 0; }

#tabs {
  position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: 528px; margin: 0 auto;
  display: flex; gap: 4px; padding: 6px; background: var(--card); border-radius: 30px; box-shadow: var(--shadow); z-index: 6;
}
#tabs button {
  flex: 1; min-height: 54px; border: 0; border-radius: 24px; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 600 11px/1 var(--sans);
}
#tabs button b { font-weight: 600; }
#tabs button.on { background: var(--rose); color: var(--ink); }

#dock {
  position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); max-width: 528px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 22px; z-index: 5;
  background: var(--dark); color: var(--on-dark); box-shadow: var(--shadow); font-size: 13px;
}
#dock .dk { flex: 1; min-width: 0; display: grid; gap: 5px; }
#dock .dk span { display: flex; justify-content: space-between; gap: 8px; }
#dock b { font: 500 15px/1 var(--serif); }
#dock .mini { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .18); overflow: hidden; }
@media (prefers-color-scheme: dark) { #dock .mini { background: rgba(0, 0, 0, .15); } }
#dock .mini i { display: block; height: 100%; border-radius: 2px; background: var(--rose-d); }
#dock .dk.w .mini i { background: var(--mist-d); }
#dock .sep { width: 1px; align-self: stretch; background: currentColor; opacity: .18; }

.card { background: var(--card); border-radius: 24px; padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; box-shadow: 0 1px 0 var(--line); }
.card.tone-peach, .card.tone-rose, .card.tone-butter, .card.tone-sage, .card.tone-mist { background: var(--tone); box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-art { width: 56px; height: 56px; flex: none; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 2px -4px; }

.daynav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.daynav .title { flex: 1; font: 500 34px/1.05 var(--serif); letter-spacing: -.02em; }
.daynav .title::first-letter { text-transform: uppercase; }
.daynav .title small { display: block; font: 400 14px/1.3 var(--sans); letter-spacing: 0; color: var(--muted); margin-top: 4px; }
.daynav .nav-btns { display: flex; gap: 8px; }

/* ---------- botões ---------- */
.btn {
  min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: 600 15px/1 var(--sans); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--red); }
.btn.small { min-height: 44px; min-width: 44px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .45; }
.round {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.round.dark { background: var(--dark); border-color: var(--dark); color: var(--on-dark); }
.round:disabled { opacity: .35; }

/* ---------- Hoje ---------- */
.badge { align-self: start; justify-self: start; font-size: 13px; font-weight: 600; background: var(--rose); color: var(--ink); border-radius: 999px; padding: 7px 14px; }

.hero { position: relative; min-height: 236px; padding: 20px; border-radius: 28px; background: var(--tone); display: grid; align-content: space-between; overflow: hidden; box-shadow: none; }
.hero .pill { justify-self: start; font-size: 12px; font-weight: 600; background: var(--card); border-radius: 999px; padding: 6px 12px; position: relative; z-index: 1; }
.hero p { font: 500 24px/1.18 var(--serif); letter-spacing: -.015em; max-width: 52%; position: relative; z-index: 1; }
/* a metade esquerda das cenas é em branco (some pelo multiply): a imagem ocupa o cartão todo e o texto fica por cima */
.hero .hero-art { position: absolute; right: 0; bottom: 0; width: 80%; height: 100%; }
.hero .hero-art img { object-position: right bottom; }

.next { gap: 14px; }
.next .next-row { display: flex; align-items: center; gap: 14px; }
.tile { width: 64px; height: 64px; flex: none; border-radius: 20px; background: var(--tone); display: grid; place-items: center; overflow: hidden; }
.tile .illo { width: 100%; height: 100%; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat { position: relative; background: var(--tone); border-radius: 22px; padding: 16px; display: grid; gap: 6px; min-height: 118px; align-content: start; overflow: hidden; }
.stat.wide { grid-column: span 2; min-height: 96px; }
.stat .label { font-size: 13px; font-weight: 600; opacity: .75; }
.stat .val { font: 500 28px/1 var(--serif); letter-spacing: -.02em; position: relative; z-index: 1; display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 4px; }
.stat .val small { font: 400 13px/1 var(--sans); opacity: .65; letter-spacing: 0; }
.stat .hint { font-size: 12px; opacity: .7; }
/* sem opacity aqui: ela isolaria o mix-blend-mode e deixaria um quadrado branco atrás do desenho */
.stat .stat-art { position: absolute; right: 4px; top: 4px; width: 54px; height: 54px; }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--tone-d); border-radius: 3px; }
.bar.t-rose { --tone-d: var(--rose-d); } .bar.t-mist { --tone-d: var(--mist-d); } .bar.t-sage { --tone-d: var(--sage-d); }
.bar.t-butter { --tone-d: var(--butter-d); } .bar.t-peach { --tone-d: var(--peach-d); }

.slot { background: var(--card); border-radius: 24px; padding: 14px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; box-shadow: 0 1px 0 var(--line); }
.slot.done { background: var(--card); }
.slot-head { display: flex; align-items: center; gap: 12px; }
.slot-head .tile { width: 56px; height: 56px; border-radius: 18px; }
.slot-head h3 { font-size: 18px; }
.slot-head .acts { display: flex; gap: 8px; flex: none; }
.meal { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--field); border-radius: 18px; padding: 8px 12px 8px 8px; color: inherit; font: inherit; cursor: pointer; min-height: 56px; }
.thumb { width: 44px; height: 44px; border-radius: 14px; background: var(--line); object-fit: cover; flex: none; }
.meal .d { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bottle { background: rgba(255, 255, 255, .55); border-radius: 18px; padding: 12px 14px; display: grid; gap: 10px; }
@media (prefers-color-scheme: dark) { .bottle { background: rgba(0, 0, 0, .18); } }
.item { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; font-size: 15px; border-top: 1px solid rgba(0, 0, 0, .07); }
@media (prefers-color-scheme: dark) { .item { border-top-color: rgba(255, 255, 255, .08); } }
.item:first-of-type { border-top: 0; }
.item.check { cursor: pointer; }
.item.check input { width: 26px; height: 26px; accent-color: var(--accent); }

/* ---------- chips, avisos, análises ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px; background: var(--track); }
.chip.conf-alta, .chip.st-ok { background: var(--ok-bg); color: var(--ok); }
.chip.conf-media, .chip.st-warn { background: var(--warn-bg); color: var(--warn); }
.chip.conf-baixa { background: var(--bad-bg); color: var(--bad); }
.chip.st-na { background: var(--track); color: var(--muted); }
.chip.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.chip.tag .x { border: 0; background: none; color: var(--muted); font-size: 18px; min-width: 28px; min-height: 28px; cursor: pointer; }
.notice { font-size: 14px; background: var(--warn-bg); color: var(--warn); border-radius: 14px; padding: 10px 12px; }
.question { display: grid; gap: 8px; background: var(--sage); border-radius: 16px; padding: 12px 14px; }
.question input { min-height: 46px; padding: 8px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 16px; }
.rv { display: grid; gap: 10px; }
.rv p { margin: 0; }
.rv-head { font: 500 19px/1.25 var(--serif); }
.doctor { background: var(--rose); color: var(--ink); border-radius: 16px; padding: 10px 14px; font-size: 14px; }
.bul { margin: 2px 0 0; padding-left: 20px; font-size: 15px; }
details.hist { border-top: 1px solid var(--line); padding: 8px 0; }
details > summary { cursor: pointer; min-height: 32px; }
.review { white-space: pre-wrap; font-size: 15px; }

.item-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.item-row .d { white-space: normal; }
.portion { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); }
.portion input { width: 76px; min-height: 46px; padding: 6px 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; font-size: 16px; }

/* check-in */
.ck { display: grid; gap: 8px; }
.segs { display: flex; gap: 6px; }
.seg { flex: 1; min-height: 46px; border-radius: 16px; border: 0; background: rgba(255, 255, 255, .6); color: var(--ink); font: 600 15px var(--sans); cursor: pointer; }
.card:not([class*="tone-"]) .seg { background: var(--field); }
@media (prefers-color-scheme: dark) { .seg { background: rgba(0, 0, 0, .2); } }
.seg.on { background: var(--accent) !important; color: var(--on-accent); }

/* ---------- campos e folhas ---------- */
input[type=text], input[type=number], input[type=time], input[type=date], input[type=password], select, textarea { font-size: 16px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.field input, .field textarea, .field select, input#pw, .inp, .secbody input[type=text], .secbody input[type=number], .secbody input[type=time], .secbody select {
  width: 100%; min-height: 48px; padding: 8px 14px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--field); color: var(--ink); font: inherit; font-size: 16px;
}
input#pw { background: var(--card); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 20px; }

#sheet { position: fixed; inset: 0; background: rgba(30, 15, 12, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
#sheet .panel {
  position: relative; background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 30px 30px 0 0; padding: 26px 20px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 14px;
}
#sheet .panel::before { content: ""; position: absolute; top: 9px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line); }

#spinner { position: fixed; inset: 0; background: rgba(30, 15, 12, .55); z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px; color: #fff; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.spin { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: r .8s linear infinite; }
@keyframes r { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(160px + env(safe-area-inset-bottom)); background: var(--dark); color: var(--on-dark); padding: 12px 18px; border-radius: 18px; z-index: 40; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); }

/* ---------- Painel ---------- */
.chart { display: grid; gap: 8px; }
.bars { position: relative; display: flex; align-items: flex-end; gap: 7px; height: 118px; }
.bars .col { flex: 1; display: grid; align-items: end; height: 100%; }
.bars .col i { display: block; background: var(--rose-d); border-radius: 8px 8px 3px 3px; min-height: 3px; }
.bars.blue .col i { background: var(--mist-d); }
.bars.amber .col i { background: var(--peach-d); }
.bars .goal { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--muted); opacity: .6; pointer-events: none; }
.labels { display: flex; gap: 7px; font-size: 11px; color: var(--muted); text-align: center; }
.labels span { flex: 1; }

/* ---------- Ajustes ---------- */
.sec > summary { list-style: none; min-height: 44px; display: flex; align-items: center; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary h2::after { content: ' ▾'; color: var(--muted); font-size: 16px; }
.secbody { display: grid; gap: 12px; margin-top: 8px; }
.sub { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 20px; padding: 12px; }
.savebar { position: sticky; bottom: calc(92px + env(safe-area-inset-bottom)); display: flex; padding: 8px 0; z-index: 4; }
.savebar:has(button:disabled) { display: none; } /* só aparece quando há alterações para salvar */

/* ---------- relatório para a médica: sempre claro, imprimível em A4 ---------- */
#report { --bg: #fff; --card: #fff; --ink: #111; --muted: #555; --line: #ccc; --field: #fff; --accent: #15803d; --on-accent: #fff; --track: rgba(0,0,0,.1);
  --serif: ui-serif, Georgia, serif;
  position: fixed; inset: 0; z-index: 50; background: #fff; color: #111; overflow: auto; padding: calc(12px + env(safe-area-inset-top)) 16px 40px; }
.rp-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.rp-doc { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; font-size: 14px; }
.rp-doc h2 { font-size: 20px; margin-bottom: 4px; }
.rp-doc h3 { font: 700 15px/1.2 var(--sans); border-bottom: 2px solid #111; padding-bottom: 2px; margin: 0 0 6px; }
.rp-sec { break-inside: avoid; }
.rp-t { width: 100%; border-collapse: collapse; font-size: 13px; }
.rp-t th, .rp-t td { border: 1px solid #bbb; padding: 4px 6px; text-align: left; vertical-align: top; }
.rp-t th { background: #eee; }
.rp-alert { margin-top: 8px; border: 1px solid #c2410c; background: #fff7ed; padding: 6px 10px; border-radius: 6px; }
.rp-alert ul, .rp-ver ul { margin: 2px 0 0; padding-left: 18px; }
.rp-ver { margin-bottom: 6px; }
.rp-foot { font-size: 12px; color: #555; border-top: 1px solid #ccc; padding-top: 6px; }
.rp-doc .bars { height: 70px; margin-top: 6px; }
.rp-doc .bars .col i { background: #444; }
@media print {
  body > :not(#report) { display: none !important; }
  #report { position: static; overflow: visible; padding: 0; }
  .noprint { display: none !important; }
  @page { size: A4; margin: 14mm; }
}
