/* Reset + Tokens */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --fg: #0f172a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.06);
  --primary: #e11d48; /* red-600 */
  --primary-700: #be123c;
  --primary-50: #fff1f2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }

/* Layout base */
.container { width: 100%; max-width: 420px; margin: 0 auto; padding: 20px; }
.auth-body { min-height: 100dvh; display: grid; place-items: center; background: radial-gradient(1200px 500px at 50% -10%, var(--primary-50), #fff 50%); }
.auth-container { width: 100%; }

/* Tipografia utilitária */
.brand { text-align: center; color: var(--primary); margin: 0 0 14px; font-size: 28px; letter-spacing: .2px; font-weight: 900; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.link { color: var(--primary); text-decoration: none; font-weight: 700; }
.link:hover { text-decoration: underline; }

/* Cartões e formulários */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.card label { display: grid; gap: 6px; font-size: 14px; }
.card input, .card select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); font-size: 16px; background: #fff; transition: border-color .15s ease, box-shadow .15s ease; }
.card input:focus, .card select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225,29,72,.15); }

/* Acessibilidade: esconder visualmente o nativo quando usamos dropdown custom */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Dropdown custom (vermelho/branco) usado em Perfil e Relatório */
.select-wrap { position: relative; }
.select-display { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 12px; border: 1px solid transparent; background: linear-gradient(#ffffff, #ffffff) padding-box, linear-gradient(180deg, #ffe4e6, #fecdd3) border-box; color: var(--fg); box-shadow: var(--shadow); cursor: pointer; }
.select-display .chev { color: var(--primary); transition: transform .15s ease; }
.select-display[aria-expanded="true"] .chev { transform: rotate(180deg); }
.select-display:hover { background: linear-gradient(#ffffff, #ffffff) padding-box, linear-gradient(180deg, #fecdd3, #fda4af) border-box; }
.select-display:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(225,29,72,.14); }
.select-value { font-size: 16px; }

.select-list { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #ffffff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px 0; z-index: 40; }
.select-list li { list-style: none; padding: 10px 14px; cursor: pointer; }
.select-list li:hover { background: #fff1f2; }
.select-list li.active { background: #fee2e2; color: #be123c; font-weight: 800; }

/* Botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; padding: 12px 16px; border: 1px solid var(--border); background: #f9fafb; color: var(--fg); text-decoration: none; font-weight: 700; transition: transform .06s ease, background .15s ease, box-shadow .15s ease; box-shadow: var(--shadow); }
.btn:hover { background: #f3f4f6; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-700); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.danger { color: #b91c1c; border-color: #fecaca; background: #fff5f5; }
.btn.danger:hover { background: #fee2e2; }

/* Alertas */
.alert { border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; border: 1px solid var(--border); }
.alert.success { background: #ecfeff; color: #155e75; border-color: #a5f3fc; }
.alert.error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* Topbar/Chat */
.topbar { position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--border); padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; backdrop-filter: saturate(140%) blur(4px); }
.topbar { flex-direction: row-reverse; }
.topbar-left { display: flex; gap: 10px; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 999px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; box-shadow: var(--shadow); }
.user-meta { line-height: 1.1; }
.user-name { font-weight: 800; font-size: 14px; }
.user-sub { font-size: 12px; color: var(--muted); }

.menu-toggle { display: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border); background: linear-gradient(#ffffff, #ffffff); align-items: center; justify-content: center; box-shadow: var(--shadow); transition: box-shadow .15s ease, transform .06s ease, background .2s ease; position: relative; overflow: hidden; }
.menu-toggle:hover { box-shadow: 0 6px 22px rgba(16,24,40,.18), 0 1px 2px rgba(16,24,40,.12); }
.menu-toggle:active { transform: translateY(1px); }
.menu-toggle .bar { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: block; width: 18px; height: 2px; background: var(--fg); border-radius: 2px; transition: background .2s ease; }
.menu-toggle .bar::before, .menu-toggle .bar::after { content: ""; position: absolute; left: 50%; width: 18px; height: 2px; background: var(--fg); border-radius: 2px; transition: transform .2s ease, top .2s ease, opacity .2s ease; transform: translateX(-50%); }
.menu-toggle .bar::before { top: -6px; }
.menu-toggle .bar::after { top: 6px; }
.menu-toggle.open .bar { background: transparent; }
.menu-toggle.open .bar::before { top: 0; transform: translateX(-50%) rotate(45deg); }
.menu-toggle.open .bar::after { top: 0; transform: translateX(-50%) rotate(-45deg); }
.menu-panel { position: fixed; pointer-events: none; }
/* Drawer lateral (desktop e mobile) */
.menu-panel { top: 0; left: 0; height: 100dvh; background: #fff; border-right: none; border-radius: 0; box-shadow: none; display: grid; align-content: start; width: 280px; z-index: 3000; padding: 8px; gap: 2px; overflow-y: auto; opacity: 1; transform: translateX(-105%); transition: none; }
.menu-panel:not([hidden]) { pointer-events: auto; }
.menu-panel[data-open="true"] { transform: translateX(0); border-right: 1px solid var(--border); box-shadow: 10px 0 24px rgba(16,24,40,.16); }
.menu-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 10px; background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%); border-bottom: 1px solid var(--border); border-radius: 0; z-index: 1; }
.menu-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, rgba(225,29,72,.65), rgba(225,29,72,.22)); }
.menu-title { font-weight: 900; font-size: 15px; color: #0b1220; letter-spacing: .2px; }
/* Botão de fechar mais objetivo (30% menor do anterior) */
.menu-close { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: linear-gradient(#ffffff, #f8fafc); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); }
.menu-close:hover { box-shadow: 0 6px 22px rgba(16,24,40,.18), 0 1px 2px rgba(16,24,40,.12); }
.menu-close .x { position: relative; width: 18px; height: 2px; background: transparent; }
.menu-close .x::before, .menu-close .x::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: #0f172a; border-radius: 2px; }
.menu-close .x::before { transform: rotate(45deg); }
.menu-close .x::after { transform: rotate(-45deg); }
/* Visual mais moderno para a barra lateral */
.menu-panel { background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%); }
.menu-item { border-color: #e6e8ee; background: linear-gradient(#ffffff, #ffffff); border-left: 3px solid transparent; }
/* alterna um destaque vermelho mais forte, coerente com a paleta do site */
.menu-panel .menu-item:nth-of-type(2n) { background: linear-gradient(180deg, var(--primary-50) 0%, #ffffff 100%); border-left-color: rgba(225,29,72,.45); }
.menu-item:hover { border-color: #fecaca; background: #fff1f2; border-left-color: var(--primary); }
.menu-item:focus-visible { outline: 0; box-shadow: 0 0 0 2px rgba(225,29,72,.20), 0 0 0 4px rgba(225,29,72,.30); }
.menu-item::before { content: ""; display: none; }
.menu-item:hover::before { content: ""; display: block; width: 3px; height: 100%; background: var(--primary); border-radius: 3px; margin-right: 6px; }
.menu-item { display: flex; align-items: center; gap: 6px; min-height: 58px; padding: 8px 10px; text-decoration: none; color: var(--fg); font-size: 12.5px; line-height: 1.1; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.menu-panel a.menu-item, .menu-panel button.menu-item {
  padding: 6px 10px !important;
  min-height: 54px !important;
  line-height: 1.1 !important;
  border-radius: 4px !important;
  border: 1px solid var(--border) !important;
}
.menu-item:last-child { margin-bottom: 0; }
.menu-item:hover { background: #f3f4f6; }
.menu-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.25); backdrop-filter: blur(2px); z-index: 2999; transition: opacity .2s ease; }
.menu-backdrop[hidden] { display: none; }

.chat-body { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.chat-container { padding: 14px 12px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; height: calc(100dvh - 140px); background: radial-gradient(1000px 500px at 100% -10%, var(--primary-50), #fff 40%); }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.from-user { align-items: flex-end; }
.msg.from-bot { align-items: flex-start; }
.bubble { max-width: 86%; padding: 12px 14px; border-radius: 18px; background: #f8fafc; border: 1px solid var(--border); font-size: 15px; line-height: 1.35; white-space: pre-wrap; box-shadow: var(--shadow); }
.bubble.bot { background: #fff; border-color: #ffe4e6; box-shadow: 0 1px 2px rgba(225,29,72,.12), 0 6px 20px rgba(225,29,72,.10); }
.msg-image { max-width: 100%; max-height: 300px; object-fit: contain; display: block; border-radius: 14px; border: 1px solid var(--border); box-shadow: var(--shadow); margin-left: auto; margin-right: auto; }
.msg.draft .msg-image { border-style: dashed; }
.draft-note { margin-top: 6px; display: inline-block; padding: 6px 10px; border-radius: 999px; border: 1px solid #fecaca; background: #fff1f2; color: #b91c1c; font-size: 12px; box-shadow: var(--shadow); }

/* Scanner overlay quando imagem está sendo analisada */
.scan-wrap { position: relative; display: block; max-width: 100%; margin-left: auto; }
.scan-wrap.scanning::after { content: ""; position: absolute; inset: 0; border-radius: 14px; box-shadow: inset 0 0 0 2px rgba(225,29,72,.35); pointer-events: none; }
.scan-wrap.scanning::before { content: ""; position: absolute; left: 0; right: 0; height: 64px; top: -64px; background: linear-gradient(180deg, rgba(225,29,72,0) 0%, rgba(225,29,72,.18) 50%, rgba(225,29,72,0) 100%); border-radius: 12px; animation: scanY 1.4s linear infinite; pointer-events: none; }
@keyframes scanY { from { top: -64px; } to { top: 100%; } }

/* Garantir alinhamento à direita imediato para imagens do usuário */
.msg.from-user .scan-wrap { align-self: flex-end; margin-left: auto; }
/* Pré-visualização (imagem direta dentro da mensagem) alinhada à direita */
.msg.from-user > .msg-image { display: block; margin-left: auto; }
/* Quando a imagem estiver dentro do scan-wrap, igualar largura ao container */
.scan-wrap > .msg-image { max-width: 100%; display: block; }

.composer { position: sticky; bottom: 0; display: grid; grid-template-columns: auto 1fr auto; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: #fff; backdrop-filter: saturate(140%) blur(4px); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.composer textarea { width: 100%; padding: 12px 16px; border-radius: 16px; border: 1px solid var(--border); font-size: 16px; background: #fff; transition: border-color .15s ease, box-shadow .15s ease; min-height: 44px; max-height: 140px; resize: none; overflow-y: hidden; line-height: 1.35; }
.composer textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225,29,72,.15); }
.composer .file-btn { width: 42px; height: 42px; border-radius: 999px; display: grid; place-items: center; border: 1px solid var(--border); background: #fff; cursor: pointer; box-shadow: var(--shadow); }
.composer .file-btn input { display: none; }

/* Modal global (confirmações) - overlay fixo e centralizado */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.7); backdrop-filter: blur(2px) saturate(120%); z-index: 9999; }
.modal[hidden] { display: none; }
.modal-box { width: min(92vw, 380px); border-radius: 14px; border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow); padding: 16px; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal-pill { width: 10px; height: 10px; border-radius: 999px; background: var(--primary); }
.modal-title { margin: 0; font-size: 16px; color: #111; font-weight: 900; }
.modal-msg { margin: 0 0 12px; color: #374151; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Cartela Nutricional */
.nutri-card { margin-top: 8px; background: #ffffff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.nutri-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 12px; font-size: 14px; }
.nutri-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.nutri-row span { color: var(--muted); }
.nutri-row strong { color: var(--fg); }

@media (min-width: 480px) {
  .chat-container { height: calc(100dvh - 128px); }
}

/* Sempre usar menu tipo "hambúrguer"; esconder ações do topo em todas as telas */
.topbar-actions { display: none; }
.menu-toggle { display: inline-flex; }
/* Inverter ordem no mobile para manter menu à esquerda */
@media (max-width: 767px) {
  .topbar { flex-direction: row-reverse; }
}


