:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface2: #eef1f8; --text: #1b2033; --muted: #687089;
  --line: #dde2ee; --primary: #3d5afe; --primary-soft: #e6eaff; --danger: #e5484d; --ok: #22a06b; --warn: #e5793b;
  --radius: 14px; --shadow: 0 1px 3px rgba(20,30,60,.08), 0 4px 14px rgba(20,30,60,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11131a; --surface: #1a1d27; --surface2: #232736; --text: #e8eaf2; --muted: #9aa1b8;
    --line: #2d3244; --primary: #7c8cff; --primary-soft: #262c4d; --shadow: none; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: flex; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

/* Layout */
#sidebar { width: 232px; flex: none; background: var(--surface); border-right: 1px solid var(--line); height: 100vh; position: sticky; top: 0; overflow-y: auto; padding: 14px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 8px 16px; }
.brand img { width: 34px; height: 34px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
#nav a:hover { background: var(--surface2); }
#nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
#nav .ico { width: 22px; text-align: center; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
#topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); }
#topbar h1 { font-size: 21px; margin: 0; flex: 1; }
#actions { display: flex; gap: 8px; }
#view { padding: 4px 20px 90px; max-width: 1200px; width: 100%; }
#menuBtn { display: none; }
#bottomnav { display: none; }
#scrim { display: none; }

@media (max-width: 820px) {
  #sidebar { position: fixed; z-index: 30; left: 0; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  body.drawer #sidebar { transform: none; }
  body.drawer #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  #menuBtn { display: inline-flex; }
  #topbar { padding: 10px 16px; }
  #view { padding: 4px 16px 96px; }
  #bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  #bottomnav a { flex: 1; text-align: center; padding: 7px 2px 6px; font-size: 11px; color: var(--muted); text-decoration: none; }
  #bottomnav a .ico { display: block; font-size: 20px; line-height: 1.2; }
  #bottomnav a.active { color: var(--primary); font-weight: 600; }
}

/* Componentes */
.btn { border: 0; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.secondary { background: var(--surface2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: var(--surface2); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 17px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn.ghost { background: transparent; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .more { margin-left: auto; font-size: 13px; font-weight: 500; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; background: var(--surface2); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; flex: none; color: #fff; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.input, select.input, textarea.input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; }
.input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.seg { display: inline-flex; background: var(--surface2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
ul.plain { list-style: none; margin: 0; padding: 0; }
.li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .t { overflow: hidden; text-overflow: ellipsis; }
.li.done .t { text-decoration: line-through; color: var(--muted); }
.clickable { cursor: pointer; }
.check { width: 22px; height: 22px; accent-color: var(--ok); flex: none; cursor: pointer; }
.bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar.over > i { background: var(--danger); }
.big { font-size: 26px; font-weight: 700; }
.pos { color: var(--ok); } .neg { color: var(--danger); }

/* Calendário */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal .hd { background: var(--surface2); padding: 6px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal .day { background: var(--surface); min-height: 96px; padding: 4px; cursor: pointer; overflow: hidden; }
.cal .day.other { background: var(--bg); color: var(--muted); }
.cal .day.sel { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal .num { font-size: 12px; font-weight: 600; display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 50%; }
.cal .today .num { background: var(--primary); color: #fff; }
.cal .ev { font-size: 11px; padding: 1px 5px; border-radius: 5px; color: #fff; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 820px) { .cal .day { min-height: 58px; } .cal .ev { font-size: 0; height: 6px; padding: 0; } }
.split { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* Listas */
.lists-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .lists-layout { grid-template-columns: 1fr; } }
.listsel a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; cursor: pointer; }
.listsel a.on { background: var(--primary-soft); font-weight: 600; }
.quickadd { display: flex; gap: 8px; margin-bottom: 10px; }

/* Semana (refeições/horários) */
.week { display: grid; grid-template-columns: 110px repeat(7, minmax(120px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.week > div { background: var(--surface); padding: 6px; min-height: 64px; }
.week .hd { background: var(--surface2); font-size: 12px; font-weight: 600; min-height: 0; text-align: center; }
.week .hd.today { color: var(--primary); }
.week .rowhd { background: var(--surface2); font-size: 12px; font-weight: 600; display: flex; align-items: center; }
.week .slot { cursor: pointer; }
.week .slot:hover { background: var(--surface2); }
.chip { display: block; font-size: 12px; padding: 4px 6px; border-radius: 7px; background: var(--primary-soft); margin-bottom: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.daycol { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; }
.daycol .col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 200px; }
.daycol .col h4 { margin: 0 0 8px; font-size: 13px; text-align: center; }
.tt { border-left: 4px solid var(--primary); background: var(--surface2); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }

/* Receitas / galeria */
.rcard { cursor: pointer; padding: 0; overflow: hidden; }
.rcard .img { height: 130px; background: var(--surface2) center/cover; display: flex; align-items: center; justify-content: center; font-size: 44px; }
.rcard .body { padding: 12px; }
.photos { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: pointer; display: block; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 8px; }
.lightbox .row { margin-top: 12px; color: #fff; }

/* Mural */
.post { margin-bottom: 12px; }
.post .txt { white-space: pre-wrap; margin-top: 8px; }

/* Modal */
dialog#modal { border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); max-height: 90vh; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog#modal::backdrop { background: rgba(10,15,30,.45); }
#modalForm { display: flex; flex-direction: column; max-height: 90vh; }
.mh { padding: 16px 20px 6px; font-size: 18px; font-weight: 700; }
.mb { padding: 8px 20px; overflow-y: auto; display: grid; gap: 12px; }
.mf { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field.inline { display: flex; align-items: center; gap: 8px; }
.field.inline label { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors label { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.colors input { display: none; }
.colors input:checked + label { border-color: var(--text); }
.mlist { display: flex; flex-wrap: wrap; gap: 6px; }
.mlist label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--surface2); cursor: pointer; font-size: 13px; }

/* Novos módulos */
#nav a .grow { flex: 1; }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.pill .x { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0 0 0 4px; }
.pill.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.pill.warnp { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.warn { color: var(--warn); }
.info { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.qty { display: flex; align-items: center; gap: 6px; flex: none; }
.qty .icon-btn { width: 28px; height: 28px; font-size: 15px; }
.qty strong { min-width: 22px; text-align: center; }
.stockrow .who { display: flex; gap: 2px; flex: none; }
.stockrow .bula { display: flex; gap: 4px; flex: none; }
.pill a, a.pill { text-decoration: none; color: inherit; }
.alerts { border-left: 4px solid var(--warn); }
.seg { flex-wrap: wrap; }
@media (max-width: 820px) {
  .stockrow { flex-wrap: wrap; }
  .stockrow .grow { flex-basis: 100%; }
}

/* Gráficos de peso e altura */
.graficos { display: grid; gap: 14px; }
.graficos.dois { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
svg.grafico { width: 100%; max-width: 620px; height: auto; display: block; }
svg.grafico .g { stroke: var(--line); stroke-width: 1; }
svg.grafico .eixo { stroke: var(--muted); stroke-width: 1; }
svg.grafico .t { fill: var(--muted); font-size: 12px; }
svg.grafico .v { fill: var(--text); font-size: 13px; font-weight: 600; }
svg.grafico .linha { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.grafico .marca { fill: var(--primary); stroke: var(--surface); stroke-width: 2; }
svg.grafico .alvo { fill: transparent; }
svg.grafico .ponto:hover .marca { r: 6.5; }
table.tabela { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.tabela th { text-align: left; color: var(--muted); font-weight: 600; }
table.tabela th, table.tabela td { padding: 5px 6px; border-bottom: 1px solid var(--line); }

/* Login e conta */
body.auth > aside, body.auth > main, body.auth > #bottomnav, body.auth > #scrim { display: none !important; }
#authscreen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); overflow-y: auto; }
.authbox { width: min(400px, 100%); display: grid; gap: 12px; }
.authbox h2 { margin: 0 0 4px; font-size: 20px; }
.authbox form { display: grid; gap: 12px; }
#userbox { border-top: 1px solid var(--line); margin-top: 12px; padding: 12px 8px 4px; display: grid; gap: 4px; }
.qr { display: flex; justify-content: center; }
.qr svg { width: 220px; height: 220px; border-radius: 8px; }
code.chave { font-size: 15px; letter-spacing: 1px; word-break: break-all; }
pre.codigos { font-size: 17px; line-height: 1.7; background: var(--surface2); padding: 12px 16px; border-radius: 10px; columns: 2; }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }
