:root {
  --ink: #14181F;
  --ink-2: #2A303B;
  --paper: #F4F1EA;
  --card: #FBF9F4;
  --line: #E2DCCF;
  --muted: #6A665E;
  --body: #3E3C37;
  --accent: #9A5512;
  --accent-2: #E3A04A;
  --ok: #2F6B4F;
  --ok-bg: #E4EFE7;
  --bad: #A23B2A;
  --bad-bg: #F6E3DE;
  --warn-bg: #FBEBD3;
  --radius: 12px;
  --side: 248px;
  --display: 'Space Grotesk', system-ui, sans-serif;
  --text: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--text); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 8px; line-height: 1.15; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.neg { color: var(--bad); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }

/* ---------- Estrutura ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--ink); color: #EDE9E0; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px; }
.brand strong { font-family: var(--display); font-size: 16px; display: block; letter-spacing: -0.015em; white-space: nowrap; }
.brand strong span { font-weight: 500; color: #A39E93; }
.brand.big strong span { color: var(--muted); }
.brand small { display: block; color: #9C978C; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.brand-mark { display: block; flex: none; }
.brand.big { justify-content: center; padding: 0 0 6px; }
.brand.big strong { font-size: 24px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: #C9C4B9; text-decoration: none; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #1E242E; color: #fff; }
.sidebar nav a.active { background: #262D38; color: #fff; box-shadow: inset 3px 0 0 var(--accent-2); }
.me { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 20px; border-top: 1px solid #262D38; }
.me strong { display: block; font-size: 14px; }
.me small { color: #9C978C; font-size: 12px; }
.me a { color: #C9C4B9; }
.main { padding: 32px 40px 64px; margin-left: var(--side); max-width: 1280px; }
body.no-nav .main { margin: 0 auto; padding: 24px 16px; }
.topbar, .scrim { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card.dark { background: var(--ink); color: #EDE9E0; border-color: var(--ink); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.cols > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 20px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.kpi span { display: block; font-size: 13px; color: var(--muted); }
.kpi strong { display: block; font: 600 28px/1.2 var(--display); margin-top: 6px; }
.kpi small { color: var(--muted); }
.kpi.alert { border-color: #E6C08C; background: #FCF3E4; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--ink); color: #F4F1EA; border: 0; border-radius: 9px; padding: 11px 18px; font: 600 14px var(--text); text-decoration: none; cursor: pointer; min-height: 42px; }
.btn:hover { background: var(--ink-2); }
.btn.accent { background: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #ECE7DC; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid #E5C2BA; }
.btn.sm { padding: 6px 12px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.linkbtn.danger { color: var(--bad); }

.flash { padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; background: var(--ok-bg); color: var(--ok); border: 1px solid #C5DCCB; }
.flash.err { background: var(--bad-bg); color: var(--bad); border-color: #E5C2BA; }
.flash.warn { background: var(--warn-bg); color: #7A4A10; border-color: #EBCF9F; }
.banner { padding: 10px 16px; border-radius: 9px; margin-bottom: 12px; background: #E9E4D8; color: var(--body); font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: #7A4A10; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #E9E4D8; color: var(--body); white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.warn { background: var(--warn-bg); color: #7A4A10; }
.tag.dark { background: var(--ink); color: #F4F1EA; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -20px; padding: 0 20px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 10px; border-bottom: 1px solid #ECE7DC; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t td.num, .t th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.t tr.low td { background: #FCF3E4; }
.t input { min-height: 38px; }
.t .qty-in { width: 110px; text-align: right; }

/* ---------- Formulários ---------- */
.form label { display: block; font-weight: 600; font-size: 13px; color: var(--body); margin-bottom: 14px; }
.form label > input, .form label > select, .form label > textarea { margin-top: 6px; }
input, select, textarea { width: 100%; font: 15px var(--text); color: var(--ink); background: #fff; border: 1px solid #D6CFC0; border-radius: 8px; padding: 10px 12px; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
.form .check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.form .hint { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 4px; margin: 0 0 18px; }
legend { font: 600 14px var(--display); padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { margin-bottom: 0; }
.inline-form > * { flex: 1 1 160px; }
.inline-form > .btn { flex: 0 0 auto; }
.search { max-width: 340px; }

.conv-preview { background: var(--ink); color: #EDE9E0; border-radius: 9px; padding: 12px 16px; font-size: 14px; margin-bottom: 14px; }
.conv-preview strong { color: var(--accent-2); }

/* linhas dinâmicas (entradas, ficha) */
.rows .row-line { display: grid; grid-template-columns: 2.4fr 1fr 1fr auto; gap: 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid #ECE7DC; }
.rows .row-line label { margin: 0; }
.rows .row-line .conv { font-size: 12px; color: var(--muted); grid-column: 1 / -1; margin-top: -4px; }
.rows.recipe .row-line { grid-template-columns: 2.5fr 1fr auto; }
.rm { background: none; border: 1px solid var(--line); border-radius: 8px; width: 42px; height: 42px; cursor: pointer; color: var(--bad); font-size: 20px; }

/* ---------- Login / cadastro ---------- */
.auth-wrap { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; }
.auth-card.wide { max-width: 640px; }
.auth-card > .muted { text-align: center; }
.plan-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.plan-opt { position: relative; margin: 0 !important; }
.plan-opt input { position: absolute; opacity: 0; }
.plan-opt span { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; cursor: pointer; height: 100%; }
.plan-opt strong { display: block; font-family: var(--display); }
.plan-opt em { font-style: normal; color: var(--accent); font-weight: 600; display: block; }
.plan-opt small { font-weight: 400; color: var(--muted); }
.plan-opt input:checked + span { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

.empty { text-align: center; padding: 56px 16px; }
.empty p { color: var(--muted); }

.bar { height: 8px; background: #E9E4D8; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar.low i { background: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-color: var(--accent); }

.copy-box { display: flex; gap: 8px; }
.copy-box input { font-size: 13px; }

/* ---------- Celular ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 270px; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20,24,31,.45); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; background: var(--ink); color: #F4F1EA; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar strong { font-family: var(--display); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-btn { background: none; border: 0; width: 36px; height: 36px; display: flex; flex-direction: column; justify-content: center; gap: 5px; cursor: pointer; padding: 6px; }
  .menu-btn span { display: block; height: 2px; background: #F4F1EA; border-radius: 2px; }
  .main { margin-left: 0; padding: 20px 16px 48px; }
  .page-head h1 { display: none; }
  .page-head { margin-bottom: 16px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .rows .row-line { grid-template-columns: 1fr 1fr; }
  .rows .row-line > :first-child { grid-column: 1 / -1; }
  .rows.recipe .row-line { grid-template-columns: 1fr auto; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi strong { font-size: 22px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .hide-sm { display: none; }
  .search { max-width: none; }
}
@media print {
  .sidebar, .topbar, .actions, .banner, .btn { display: none !important; }
  .main { margin: 0; padding: 0; }
}

/* ajustes finos */
.kpi strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 26px; }
.kpi strong .tag { display: inline-block; width: auto; }
@media (max-width: 900px) { .kpi strong { font-size: 20px; } }

/* ---------- Celular ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  input, select, textarea { font-size: 16px; } /* evita zoom automático no iPhone */
  .tabs { scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 0 16px; }
  .tabs::-webkit-scrollbar { display: none; }
  .actions .btn { flex: 1 1 auto; }
  body.has-nav .main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--ink); border-top: 1px solid #262D38; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; color: #9C978C; text-decoration: none; font: 600 11px var(--text); background: none; border: 0; cursor: pointer; min-width: 0; }
  .tabbar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tabbar a.active { color: #F4F1EA; }
  .tabbar a.active svg { color: var(--accent-2); }
  body.nav-open .tabbar { display: none; }
}
@media (max-width: 700px) {
  table.t.stack, .t.stack tbody, .t.stack tr, .t.stack td { display: block; width: 100%; }
  .t.stack thead, .t.stack tr.stack-head { display: none; }
  .t.stack tr { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 6px 12px; margin-bottom: 10px; }
  .t.stack tr.low { background: #FCF3E4; }
  .t.stack tr.low td { background: transparent; }
  .t.stack td { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 4px 6px; text-align: right; padding: 8px 0; border-bottom: 1px solid #F0EBE1; white-space: normal; }
  .t.stack td:last-child { border-bottom: 0; }
  .t.stack td.stack-empty { display: none; }
  .t.stack td::before { content: attr(data-label); flex: none; margin-right: auto; padding-right: 12px; max-width: 45%; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .t.stack td[data-label=""]::before { display: none; }
  .t.stack td[data-label=""] { justify-content: flex-end; }
  .t.stack td.stack-title { display: block; text-align: left; font-size: 15px; padding-top: 10px; }
  .t.stack td.stack-title::before { display: none; }
  .t.stack td.hide-sm { display: none; }
  .t.stack td input, .t.stack td select { max-width: 60%; }
  .t.stack .qty-in { width: 120px; }
  .table-wrap { overflow-x: visible; }
}

/* Cadastro de produto: jeito de controlar */
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 18px; }
.preset { position: relative; display: block; cursor: pointer; }
.preset input { position: absolute; opacity: 0; pointer-events: none; }
.preset span { display: block; height: 100%; border: 1px solid #D6CFC0; border-radius: 10px; padding: 10px 12px; background: #fff; }
.preset strong { display: block; font-size: 14px; }
.preset small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
.preset input:checked + span { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: #FBF9F4; }
.preset input:focus-visible + span { outline: 2px solid var(--accent-2); }
input[readonly] { background: #F4F1EA; color: var(--muted); }
@media (max-width: 700px) { .presets { grid-template-columns: 1fr 1fr; } }

/* Seletor de produto com busca */
.combo { position: relative; }
.combo-native { position: absolute !important; opacity: 0; pointer-events: none; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; bottom: 0; left: 0; }
.combo-input { padding-right: 34px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236A665E' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") no-repeat right 12px center; }
.combo-panel { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40; background: #fff; border: 1px solid #D6CFC0; border-radius: 10px; box-shadow: 0 16px 32px rgba(20,24,31,.14); overflow: hidden; min-width: 260px; }
.combo-cats { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid #ECE7DC; overflow-x: auto; scrollbar-width: none; }
.combo-cats::-webkit-scrollbar { display: none; }
.combo-cats button { flex: none; border: 1px solid #D6CFC0; background: #fff; border-radius: 999px; padding: 5px 11px; font: 600 12px var(--text); color: var(--body); cursor: pointer; }
.combo-cats button.on { background: var(--ink); border-color: var(--ink); color: #F4F1EA; }
.combo-list { max-height: 280px; overflow-y: auto; padding: 4px 0; }
.combo-group { padding: 8px 12px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.combo-opt { padding: 9px 12px; cursor: pointer; font-size: 14px; font-weight: 400; }
.combo-opt.active { background: #F4F1EA; }
.combo-opt.sel { font-weight: 600; }
.combo-empty { padding: 14px 12px; color: var(--muted); font-size: 14px; font-weight: 400; }
@media (max-width: 900px) { .combo-opt { padding: 12px; font-size: 15px; } .combo-list { max-height: 50vh; } }

/* iPhone/Safari: campos de data e busca no mesmo padrão dos outros */
input[type=date], input[type=month], input[type=time], input[type=search] { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; display: block; }
input[type=date]::-webkit-date-and-time-value, input[type=month]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type=search]::-webkit-search-decoration { -webkit-appearance: none; }
.inline-form > * { min-width: 0; }
.form label, .inline-form label { min-width: 0; }
@media (max-width: 600px) {
  .inline-form { flex-direction: column; align-items: stretch; gap: 12px; }
  .inline-form > * { flex: 1 1 auto; width: 100%; }
  .inline-form > .btn { width: 100%; }
}

/* Menu agrupado por momento do dia */
.sidebar .nav-group { margin: 10px 12px 2px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #8E897F; }
.sidebar nav a.has-desc { align-items: flex-start; padding-top: 6px; padding-bottom: 6px; }
.sidebar nav a.has-desc svg { margin-top: 1px; flex: none; }
.sidebar nav a span small { display: block; font-size: 12px; font-weight: 400; color: #8E897F; margin-top: 1px; line-height: 1.3; }
.sidebar nav a.active span small, .sidebar nav a:hover span small { color: #B9B4AA; }
