/* ============================================================
   variáveis css cor e temas
   paleta inspirada na identidade visual SmartNutri
   ============================================================ */
:root {
  --g950: #0f2a26;
  --g900: #123b31;
  --g800: #16634d;
  --g750: #1c7a5e;
  --g700: #248b67;
  --g650: #2da875;
  --g600: #42bd7e;
  --g550: #5ccc83;
  --g500: #76d48a;
  --g450: #8ddb83;
  --g400: #a4d56b;
  --g350: #b8e182;
  --g300: #d0eda7;
  --g200: #e0f5c5;
  --g100: #eff9dc;
  --g50 : #f6fced;
  --g20 : #fbfef8;
  --blue-accent: #2d4b9a;

  --red     : #dc2626;
  --red-bg  : #fef2f2;
  --red-bdr : #fca5a5;
  --amber   : #b45309;
  --amber-bg: #fffbeb;
  --amber-bdr:#fcd34d;
  --ok-bg   : #eff9dc;
  --ok-bdr  : #b8e182;

  --bg      : #f3f9f3;
  --card    : #ffffff;
  --text    : #17372c;
  --muted   : #5d7869;
  --border  : #cce8d1;
  --radius  : 14px;
  --shadow  : 0 2px 16px rgba(36,139,103,0.10);
  --shadow-lg: 0 8px 32px rgba(36,139,103,0.14);
}

/* ============================================================
   reset e base para toda a interface
     - box-sizing para bordas não afetarem o tamanho
     - fonte principal 'DM Sans' para leitura confortável
     - fundo com padrão sutil de pontos para textura leve
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  background-image: radial-gradient(circle, #cce8d144 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ============================================================
   sidebar fixo à esquerda, com gradiente verde e itens de navegação
   ============================================================ */
#sidebar {
  width: 230px;
  min-height: 100vh;
  background: linear-gradient(160deg, var(--blue-accent) 0%, var(--g950) 30%, var(--g800) 100%);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 4px 0 24px rgba(0,0,0,0.18);
}

.brand { padding: 28px 22px 22px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 56px; height: 56px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(92,204,131,0.4);
  animation: pulse-green 3s ease-in-out infinite;
  background: transparent;
}
.brand-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 10px;
}
@keyframes pulse-green {
  0%,100% { box-shadow: 0 4px 12px rgba(92,204,131,0.4); }
  50%      { box-shadow: 0 4px 22px rgba(92,204,131,0.75); }
}
.brand-name { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: -0.3px; }
.brand-sub  { color: var(--g300); font-size: 11px; margin-top: 2px; }

nav { padding: 18px 12px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  margin-bottom: 5px;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-left: 3px solid transparent;
  user-select: none;
}
.nav-item:hover { color: #fff; border-left-color: var(--g400); transform: translateX(3px); background: rgba(255,255,255,0.05); }
.nav-item.active { background: linear-gradient(90deg, rgba(36,139,103,0.7), rgba(36,139,103,0.1)); color: #fff; border-left-color: var(--g400); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer { padding: 14px 22px; border-top: 1px solid rgba(255,255,255,0.07); color: rgba(255,255,255,0.25); font-size: 11px; }

/* ============================================================
   MAIN
   ============================================================ */
#main { margin-left: 230px; flex: 1; min-height: 100vh; }

.page { display: none; padding: 40px 44px; }
.page.active { display: block; animation: slideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   TIPOGRAFIA
   ============================================================ */
h1 { font-size: 28px; font-weight: 700; color: var(--g900); margin-bottom: 4px; letter-spacing: -0.4px; }
h2 { font-size: 17px; font-weight: 600; color: var(--g800); margin-bottom: 16px; }
h3 { font-size: 14px; font-weight: 600; color: var(--g800); }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 32px; }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); transition: box-shadow 0.3s; }
.card:hover { box-shadow: var(--shadow-lg); }
.card + .card { margin-top: 20px; }

/* ============================================================
   GRIDS
   ============================================================ */
.grid-2    { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3    { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4    { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; }

/* ============================================================
   CARDS SELECIONÁVEIS
   ============================================================ */
.sel-card {
  background: var(--card); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; cursor: pointer; user-select: none;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.sel-card:hover { border-color: var(--g400); transform: translateY(-2px); box-shadow: var(--shadow); }
.sel-card.selected { border-color: var(--g600); background: var(--g50); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(36,139,103,0.18); }
.sel-title { font-weight: 700; font-size: 15px; color: var(--g900); }
.sel-sub   { font-size: 12px; color: var(--muted); margin-top: 3px; }
.sel-meta  { font-size: 11.5px; color: var(--g650); margin-top: 10px; font-family: 'DM Mono', monospace; line-height: 1.7; }

/* ============================================================
   BOTÕES
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 10px; font-family: inherit;
  font-size: 14px; font-weight: 600; cursor: pointer; border: none;
  transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn:active { transform: scale(0.97) !important; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }
.btn-primary { background: linear-gradient(135deg, var(--g800), var(--g550)); color: #fff; box-shadow: 0 4px 14px rgba(36,139,103,0.35); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(36,139,103,0.45); }
.btn-outline { background: transparent; color: var(--g700); border: 2px solid var(--g300); }
.btn-outline:hover { background: var(--g50); border-color: var(--g500); transform: translateY(-1px); }

/* ============================================================
   INPUTS
   ============================================================ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--g700); margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 14px; color: var(--text); background: #fff; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.field input:focus, .field select:focus { border-color: var(--g500); box-shadow: 0 0 0 3px rgba(118,212,138,0.15); }

/* ============================================================
   TABELA
   ============================================================ */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 11px 16px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); border-bottom: 2px solid var(--g100); background: var(--g20); }
tbody td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--g50); transition: background 0.15s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--g20); }
.mono { font-family: 'DM Mono', monospace; font-size: 13px; }

/* ============================================================
   BADGES
   ============================================================ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-green { background: var(--g100); color: var(--g700); }
.badge-red   { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }

/* ============================================================
   CARDS DE VALIDAÇÃO
   ============================================================ */
.vcard { border: 1.5px solid; border-radius: 11px; padding: 14px 17px; margin-bottom: 11px; transition: transform 0.2s; }
.vcard:hover { transform: translateX(3px); }
.vcard.ok   { border-color: var(--ok-bdr);    background: var(--ok-bg); }
.vcard.fail { border-color: var(--red-bdr);   background: var(--red-bg); }
.vcard.warn { border-color: var(--amber-bdr); background: var(--amber-bg); }
.vcard .vt  { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.vcard .vb  { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ============================================================
   BARRAS DE PROGRESSO ANIMADAS
   ============================================================ */
.prog-wrap  { margin: 8px 0; }
.prog-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.prog       { height: 9px; background: var(--g100); border-radius: 5px; overflow: hidden; }
.prog-fill  { height: 100%; border-radius: 5px; width: 0%; transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1); }
.prog-fill.ok   { background: linear-gradient(90deg, var(--g700), var(--g400)); }
.prog-fill.fail { background: linear-gradient(90deg, var(--red), #f87171); }

/* ============================================================
   STAT BOXES
   ============================================================ */
.stat-box {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; box-shadow: var(--shadow);
  transition: all 0.3s; position: relative; overflow: hidden;
}
.stat-box::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, var(--g700), var(--g400)); }
.stat-box:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-value { font-size: 34px; font-weight: 700; color: var(--g700); font-family: 'DM Mono', monospace; animation: countUp 0.8s ease; }
@keyframes countUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 5px; }

/* ============================================================
   DASHBOARD CARDS
   ============================================================ */
.dash-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); cursor: default;
}
.dash-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.dash-icon  { font-size: 26px; margin-bottom: 12px; }
.dash-val   { font-size: 28px; font-weight: 700; color: var(--g800); font-family: 'DM Mono', monospace; }
.dash-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============================================================
   GRÁFICO DE PIZZA
   ============================================================ */
.pie-wrapper { position: relative; display: flex; justify-content: center; align-items: center; padding: 10px 0; }
#pie-canvas  { cursor: crosshair; filter: drop-shadow(0 6px 18px rgba(36,139,103,0.25)); transition: filter 0.3s; }
#pie-canvas:hover { filter: drop-shadow(0 8px 28px rgba(36,139,103,0.38)); }

/* Tooltip flutuante do gráfico */
#pie-tooltip {
  position: fixed; background: var(--g900); color: #fff;
  padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
  pointer-events: none; display: none; z-index: 9999;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3); white-space: nowrap;
}

/* Legenda */
.legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 16px; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; transition: transform 0.2s; cursor: default; }
.legend-item:hover { transform: scale(1.05); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* ============================================================
   HISTÓRICO
   ============================================================ */
.hist-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; margin-bottom: 14px; box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  animation: slideIn 0.4s ease both;
  border-left: 4px solid var(--g300);
}
.hist-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); border-left-color: var(--g500); }
.hist-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hist-title { font-weight: 700; font-size: 17px; color: var(--g900); }
.hist-date  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hist-cost-val { font-size: 22px; font-weight: 700; color: var(--g700); font-family: 'DM Mono', monospace; }
.hist-meta { display: flex; gap: 30px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.hist-meta-item { font-size: 13px; color: var(--muted); }
.hist-meta-item span { font-weight: 600; color: var(--text); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(21,27,43,0.45); backdrop-filter: blur(4px); z-index: 999; align-items: center; justify-content: center; }
.modal-bg.open { display: flex; animation: fadeOverlay 0.2s ease; }
@keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }
.modal { background: #fff; border-radius: 18px; padding: 32px; width: 440px; max-width: 92vw; box-shadow: 0 24px 64px rgba(0,0,0,0.22); animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes modalIn { from { opacity: 0; transform: scale(0.85) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal h3 { margin-bottom: 20px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; justify-content: flex-end; }

/* Botões da tabela */
.edit-btn { background: none; border: none; cursor: pointer; color: var(--g500); font-size: 15px; padding: 5px 8px; border-radius: 7px; transition: all 0.2s; }
.edit-btn:hover { background: var(--g100); transform: scale(1.15); }
.edit-btn.del:hover { background: var(--red-bg); color: var(--red); }

/* Rótulo de seção */
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 12px; margin-top: 22px; }

/* Box de requisitos */
.req-box { background: linear-gradient(90deg, var(--g50), var(--g20)); border: 1.5px solid var(--g200); border-radius: 11px; padding: 16px 22px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; transition: all 0.3s; }
.req-box:hover { border-color: var(--g400); }
.req-item { font-size: 14px; color: var(--muted); }
.req-item strong { color: var(--g800); font-size: 16px; }

/* Checkboxes de ingredientes */
.ing-check { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; padding: 10px 13px; border: 1.5px solid var(--border); border-radius: 9px; background: #fff; user-select: none; transition: all 0.2s; }
.ing-check:hover { border-color: var(--g400); background: var(--g20); }
.ing-check input[type="checkbox"] { accent-color: var(--g600); width: 15px; height: 15px; cursor: pointer; }

/* Animação de entrada em cascata */
.stagger > * { animation: slideIn 0.4s ease both; }
.stagger > *:nth-child(1)  { animation-delay: 0.05s; }
.stagger > *:nth-child(2)  { animation-delay: 0.10s; }
.stagger > *:nth-child(3)  { animation-delay: 0.15s; }
.stagger > *:nth-child(4)  { animation-delay: 0.20s; }
.stagger > *:nth-child(5)  { animation-delay: 0.25s; }
.stagger > *:nth-child(6)  { animation-delay: 0.30s; }
.stagger > *:nth-child(7)  { animation-delay: 0.35s; }
.stagger > *:nth-child(8)  { animation-delay: 0.40s; }
.stagger > *:nth-child(9)  { animation-delay: 0.45s; }
.stagger > *:nth-child(10) { animation-delay: 0.50s; }
.stagger > *:nth-child(11) { animation-delay: 0.55s; }


/* ============================================================
   MOBILE APP — navegação inferior, áreas seguras e responsividade
   ============================================================ */
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--bg);
}

button, input, select { touch-action: manipulation; }
button, .nav-item, .sel-card, .ing-check { -webkit-tap-highlight-color: transparent; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: inherit;
}

.install-app-btn {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 8px 12px;
  color: #fff;
  background: rgba(255,255,255,.12);
  font: 600 12px 'DM Sans', sans-serif;
  cursor: pointer;
}

@media (max-width: 820px) {
  :root {
    --radius: 16px;
    --shadow: 0 4px 18px rgba(15,42,38,.08);
    --shadow-lg: 0 8px 24px rgba(15,42,38,.12);
  }

  body {
    display: block;
    min-height: 100dvh;
    padding-top: calc(68px + env(safe-area-inset-top));
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    background-size: 22px 22px;
    overflow-x: hidden;
  }

  #sidebar {
    width: 100%;
    min-height: 0;
    height: 0;
    inset: 0 0 auto 0;
    background: transparent;
    box-shadow: none;
    z-index: 1000;
    pointer-events: none;
  }

  .brand {
    position: fixed;
    inset: 0 0 auto 0;
    height: calc(68px + env(safe-area-inset-top));
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    display: flex;
    align-items: center;
    border: 0;
    background: linear-gradient(125deg, var(--blue-accent), var(--g950) 45%, var(--g800));
    box-shadow: 0 4px 20px rgba(0,0,0,.18);
    pointer-events: auto;
  }

  .brand-row { gap: 10px; }
  .brand-icon { width: 50px; height: 50px; border-radius: 13px; }
  .brand-name { font-size: 18px; }
  .brand-sub { font-size: 11px; }

  #pwa-install-wrap {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top));
    right: 14px;
    z-index: 1010;
    pointer-events: auto;
  }

  #sidebar nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(76px + env(safe-area-inset-bottom));
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    display: flex;
    align-items: stretch;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    background: linear-gradient(125deg, var(--blue-accent), var(--g950) 45%, var(--g800));
    border-top: 1px solid rgba(255,255,255,.09);
    box-shadow: 0 -5px 24px rgba(0,0,0,.18);
    pointer-events: auto;
  }
  #sidebar nav::-webkit-scrollbar { display: none; }

  .nav-item {
    flex: 1 0 70px;
    min-width: 70px;
    height: 60px;
    margin: 0;
    padding: 7px 5px;
    border: 0;
    border-top: 3px solid transparent;
    border-radius: 12px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    text-align: center;
    font-size: 10px;
    line-height: 1.05;
    color: rgba(255,255,255,.65);
    white-space: normal;
  }
  .nav-item:hover { transform: none; border-left-color: transparent; }
  .nav-item.active {
    border-left-color: transparent;
    border-top-color: var(--g400);
    background: rgba(255,255,255,.13);
    color: #fff;
  }
  .nav-icon { width: auto; font-size: 22px; line-height: 1; }
  .sidebar-footer { display: none; }

  #main { margin-left: 0; width: 100%; min-height: auto; }
  .page { padding: 22px 16px 26px; scroll-margin-top: 76px; }
  .page.active { animation-duration: .22s; }

  h1 { font-size: clamp(24px, 7vw, 30px); line-height: 1.12; }
  h2 { font-size: 17px; }
  .page-sub { margin-bottom: 22px; line-height: 1.5; }

  .card { padding: 19px 16px; border-radius: 16px; }
  .card + .card { margin-top: 16px; }

  .grid-2, .grid-3, .grid-4, .grid-auto { grid-template-columns: 1fr; gap: 12px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-auto { grid-template-columns: repeat(2, minmax(0,1fr)); }

  .dash-card, .stat-box { padding: 17px 12px; min-width: 0; }
  .dash-icon { font-size: 23px; margin-bottom: 8px; }
  .dash-val, .stat-value { font-size: clamp(22px, 7vw, 30px); overflow-wrap: anywhere; }
  .dash-label, .stat-label { line-height: 1.25; }

  .sel-card { padding: 16px; }
  .req-box { padding: 14px; align-items: flex-start; flex-direction: column; gap: 10px; }
  .req-item { width: 100%; }

  .ing-check { min-height: 48px; padding: 11px; align-items: flex-start; }
  .ing-check input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }

  .btn {
    min-height: 46px;
    padding: 11px 16px;
    justify-content: center;
    border-radius: 12px;
  }
  #btn-calcular, #btn-clima, #btn-qr-start, #btn-qr-stop { width: 100%; }
  .page > div[style*="justify-content:space-between"],
  .card > div[style*="justify-content:space-between"] {
    gap: 12px;
    flex-wrap: wrap;
  }
  .page > div[style*="justify-content:space-between"] > .btn,
  .page > div[style*="justify-content:space-between"] > button {
    width: 100%;
  }

  .field input, .field select {
    min-height: 48px;
    padding: 12px 13px;
    font-size: 16px; /* impede zoom automático no iOS */
  }

  .table-scroll { margin: 0; }
  table { min-width: 720px; }
  thead th { padding: 11px 12px; white-space: nowrap; }
  tbody td { padding: 13px 12px; }
  .edit-btn { min-width: 42px; min-height: 42px; font-size: 17px; }

  .hist-top { gap: 14px; }
  .hist-title { font-size: 16px; }
  .hist-cost-val { font-size: 19px; }
  .hist-meta { gap: 9px 14px; flex-wrap: wrap; }
  .hist-meta-item { flex: 1 1 145px; }

  .modal-bg {
    align-items: flex-end;
    padding-top: env(safe-area-inset-top);
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 88dvh;
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    padding: 24px 18px calc(22px + env(safe-area-inset-bottom));
    animation-name: mobileSheetIn;
  }
  @keyframes mobileSheetIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }

  #pie-canvas { width: min(100%, 280px); height: auto; }
  #pie-tooltip { display: none !important; }
  .legend { justify-content: flex-start; }

  #qr-video { aspect-ratio: 3 / 4; object-fit: cover; }
  #qr-placeholder { min-height: 280px; display: flex; align-items: center; justify-content: center; }

  @media (hover: none) {
    .card:hover, .sel-card:hover, .dash-card:hover, .stat-box:hover, .hist-card:hover,
    .vcard:hover, .req-box:hover, .legend-item:hover { transform: none; box-shadow: var(--shadow); }
  }
}

@media (max-width: 390px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .grid-auto { grid-template-columns: 1fr; }
  .nav-item { flex-basis: 66px; min-width: 66px; }
  .install-app-btn span { display: none; }
}



/* ============================================================
   AUTENTICAÇÃO LOCAL — SmartNutri
   Mantém o aplicativo bloqueado até o usuário entrar.
   As credenciais ficam somente neste dispositivo/navegador.
   ============================================================ */
body.auth-locked #sidebar,
body.auth-locked #main,
body.auth-locked #pie-tooltip,
body.auth-locked #auth-user-chip { display: none !important; }

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(66,189,126,.28), transparent 34%),
    radial-gradient(circle at 82% 82%, rgba(45,75,154,.35), transparent 38%),
    linear-gradient(145deg, #0f2a26 0%, #123b31 38%, #1d266c 100%);
  font-family: 'DM Sans', sans-serif;
}
.auth-screen[hidden] { display: none !important; }
.auth-shell {
  width: min(920px, 100%);
  min-height: 560px;
  background: #fff;
  border-radius: 26px;
  overflow: hidden;
  display: grid;
  grid-template-columns: .92fr 1.08fr;
  box-shadow: 0 32px 90px rgba(0,0,0,.32);
  border: 1px solid rgba(255,255,255,.22);
}
.auth-brand-panel {
  padding: 42px 36px;
  background: linear-gradient(160deg, #2d4b9a 0%, #123b31 52%, #16634d 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-brand-panel::before,
.auth-brand-panel::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.auth-brand-panel::before { width: 260px; height: 260px; right: -110px; top: -90px; background: rgba(118,212,138,.14); }
.auth-brand-panel::after  { width: 190px; height: 190px; left: -90px; bottom: -70px; background: rgba(255,255,255,.08); }
.auth-logo-wrap { position: relative; z-index: 1; }
.auth-logo {
  width: 124px;
  height: 124px;
  object-fit: cover;
  border-radius: 24px;
  display: block;
  box-shadow: 0 14px 34px rgba(0,0,0,.24);
  margin-bottom: 24px;
}
.auth-brand-title { font-size: 31px; font-weight: 700; letter-spacing: -.7px; line-height: 1.05; }
.auth-brand-sub { color: #d0eda7; font-weight: 600; margin-top: 7px; font-size: 14px; }
.auth-brand-copy { position: relative; z-index: 1; color: rgba(255,255,255,.76); font-size: 13px; line-height: 1.65; max-width: 290px; }
.auth-form-panel { padding: 42px 44px 34px; display: flex; flex-direction: column; justify-content: center; }
.auth-heading { font-size: 28px; color: var(--g900); font-weight: 700; letter-spacing: -.5px; margin-bottom: 6px; }
.auth-caption { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin-bottom: 22px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; background: var(--g50); border: 1px solid var(--g200); border-radius: 12px; margin-bottom: 22px; }
.auth-tab { border: 0; background: transparent; padding: 10px 12px; border-radius: 9px; font: 600 13px 'DM Sans', sans-serif; color: var(--muted); cursor: pointer; transition: .2s; }
.auth-tab.active { background: #fff; color: var(--g800); box-shadow: 0 3px 12px rgba(36,139,103,.13); }
.auth-form { display: none; }
.auth-form.active { display: block; animation: authFade .22s ease; }
@keyframes authFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.auth-field { margin-bottom: 14px; }
.auth-field label { display: block; color: var(--g700); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-bottom: 6px; }
.auth-field input {
  width: 100%;
  height: 46px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0 13px;
  font: 400 14px 'DM Sans', sans-serif;
  color: var(--text);
  outline: none;
  transition: .2s;
}
.auth-field input:focus { border-color: var(--g500); box-shadow: 0 0 0 3px rgba(118,212,138,.16); }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 16px; }
.auth-remember { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; user-select: none; }
.auth-remember input { accent-color: var(--g600); width: 16px; height: 16px; }
.auth-submit { width: 100%; justify-content: center; min-height: 46px; }
.auth-message { min-height: 22px; margin-top: 11px; font-size: 12.5px; line-height: 1.45; border-radius: 9px; padding: 0; }
.auth-message.show { padding: 9px 11px; }
.auth-message.error { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; }
.auth-message.success { color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; }
.auth-note { margin-top: 19px; padding-top: 16px; border-top: 1px solid var(--g100); font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.auth-user-chip {
  position: fixed;
  z-index: 1500;
  top: 14px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-user-button {
  border: 1px solid rgba(23,55,44,.12);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  min-height: 40px;
  padding: 5px 11px 5px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(15,42,38,.12);
  font-family: inherit;
  color: var(--g900);
}
.auth-avatar { width: 29px; height: 29px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg,var(--blue-accent),var(--g600)); color: #fff; font-size: 11px; font-weight: 700; }
.auth-user-name { font-size: 12px; font-weight: 700; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.auth-user-menu { position: absolute; top: 47px; right: 0; width: 220px; background: #fff; border: 1px solid var(--border); border-radius: 13px; box-shadow: 0 14px 38px rgba(0,0,0,.17); padding: 11px; display: none; }
.auth-user-menu.open { display: block; animation: authFade .18s ease; }
.auth-menu-name { font-weight: 700; font-size: 13px; color: var(--g900); overflow-wrap: anywhere; }
.auth-menu-email { font-size: 11.5px; color: var(--muted); margin: 3px 0 10px; overflow-wrap: anywhere; }
.auth-logout { width: 100%; border: 1px solid var(--red-bdr); background: var(--red-bg); color: var(--red); border-radius: 9px; padding: 9px 10px; font: 600 12px 'DM Sans',sans-serif; cursor: pointer; }

@media (max-width: 720px) {
  .auth-screen { padding: 14px; align-items: flex-start; overflow-y: auto; }
  .auth-shell { grid-template-columns: 1fr; min-height: 0; margin: max(18px, env(safe-area-inset-top)) 0 max(18px, env(safe-area-inset-bottom)); border-radius: 20px; }
  .auth-brand-panel { min-height: 190px; padding: 26px 24px; }
  .auth-logo { width: 76px; height: 76px; border-radius: 18px; margin-bottom: 12px; }
  .auth-brand-title { font-size: 25px; }
  .auth-brand-copy { display: none; }
  .auth-form-panel { padding: 27px 22px 25px; }
  .auth-heading { font-size: 24px; }
  .auth-field input { font-size: 16px; }
  .auth-user-chip { top: calc(14px + env(safe-area-inset-top)); right: 72px; }
  .auth-user-name { display: none; }
  .auth-user-button { padding-right: 6px; }
}
