/* ============================================================
   base.css — Sistema de design Ice Beer (Fase 2)
   Camadas: tokens -> reset/base -> componentes -> classes-hook
            -> utilitarios -> responsivo
   Classes-hook (active/hidden/show/low-stock/scanning/...) são
   ligadas pelo JS — ver DOM-CONTRACT.md. Não renomear.
   ============================================================ */

/* ---------- TOKENS: tema claro (default) ---------- */
:root {
  --brand: #1e3a5f;
  --brand-light: #2d5a87;
  --brand-dark: #0f2744;
  --brand-contrast: #ffffff;
  --accent: #f59e0b;
  --accent-light: #fbbf24;
  --accent-dark: #d97706;
  --accent-contrast: #1e3a5f;

  --success: #10b981; --success-bg: #d1fae5; --success-fg: #065f46;
  --danger: #ef4444;  --danger-bg: #fee2e2;  --danger-fg: #991b1b;
  --warning: #f59e0b; --warning-bg: #fef3c7; --warning-fg: #92400e;
  --info: #3b82f6;    --info-bg: #dbeafe;    --info-fg: #1e40af;

  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --bg-page: #f8fafc;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.12);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --tap: 44px;
}

/* ---------- TOKENS: tema escuro ---------- */
[data-theme="dark"] {
  --brand: #2d5a87;
  --brand-light: #3b6ea5;
  --brand-dark: #1e3a5f;
  --brand-contrast: #ffffff;
  --accent: #fbbf24;
  --accent-light: #fcd34d;
  --accent-dark: #f59e0b;
  --accent-contrast: #0f1722;

  --success: #34d399; --success-bg: #064e3b; --success-fg: #a7f3d0;
  --danger: #f87171;  --danger-bg: #7f1d1d;  --danger-fg: #fecaca;
  --warning: #fbbf24; --warning-bg: #78350f; --warning-fg: #fde68a;
  --info: #60a5fa;    --info-bg: #1e3a8a;    --info-fg: #bfdbfe;

  --surface: #1a2433;
  --surface-2: #0f1722;
  --bg-page: #0b121c;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #2b3648;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.5);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.6);
}

/* ---------- RESET / BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 700; line-height: 1.2; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); }
img { max-width: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- LAYOUT SHELL ---------- */
.app-bar {
  background: var(--brand); color: var(--brand-contrast);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; gap: 10px;
}
.toolbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.container { max-width: 1280px; margin: 0 auto; }

/* ---------- BOTOES ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px; border-radius: var(--r-md);
  border: 1px solid transparent; font-weight: 600; font-size: .9rem;
  background: var(--surface-2); color: var(--text); transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--brand-contrast); }
.btn-accent  { background: var(--accent); color: var(--accent-contrast); }
.btn-outline { background: transparent; border-color: var(--brand); color: var(--brand); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info    { background: var(--info); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); }
.btn-icon { min-width: var(--tap); padding: 0; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- BUSCA ---------- */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0 12px; min-height: var(--tap);
  position: sticky; top: 0; z-index: 5;
}
.search-bar input { flex: 1; border: none; background: transparent; color: var(--text); font-size: .95rem; outline: none; min-height: var(--tap); }

/* ---------- ABAS / CHIPS DE FILTRO (hook: .tab-btn / .tab-content) ---------- */
.filter-chips, .tabs-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn, .chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--r-pill); padding: 6px 12px; font-size: .8rem; font-weight: 600;
}
.tab-btn.active, .chip.active, .chip[aria-pressed="true"], .tab-btn[aria-pressed="true"] {
  background: var(--brand); color: var(--brand-contrast); border-color: var(--brand);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* abas do painel admin (hook: .admin-tab-btn / .admin-tab-content) */
.admin-tab-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--r-sm); padding: 8px 12px; font-weight: 600; }
.admin-tab-btn.active { background: var(--brand); color: var(--brand-contrast); }
.admin-tab-content { display: none; }
.admin-tab-content.active { display: block; }

/* ---------- TIRA DE STATS ---------- */
.stats-strip { display: grid; grid-template-columns: repeat(2,1fr); gap: 1px; background: var(--border); border-radius: var(--r-md); overflow: hidden; }
.stat { background: var(--surface); padding: 10px 14px; }
.stat .num { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat .lbl { font-size: .7rem; color: var(--text-muted); }
.stat.is-products .num { color: var(--brand); }
.stat.is-updated  .num { color: var(--success); }
.stat.is-low      .num { color: var(--danger); }
.stat.is-value    .num { color: var(--accent-dark); }

/* ---------- CARD DE PRODUTO (mobile) ---------- */
.product-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 12px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px;
}
.product-card .pc-name { font-weight: 600; font-size: .95rem; }
.product-card .pc-sub { font-size: .72rem; color: var(--text-muted); }
.product-card .pc-row { display: flex; align-items: center; justify-content: space-between; }
.qty-control { display: inline-flex; align-items: center; gap: 12px; }
.qty-control button { width: var(--tap); height: var(--tap); border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); font-size: 1.25rem; color: var(--text); }
.qty-control button.plus { background: var(--brand); color: var(--brand-contrast); border: none; }
.qty-control .qty { font-weight: 700; font-size: 1.1rem; min-width: 28px; text-align: center; }

/* ---------- BADGES ---------- */
.badge { font-size: .7rem; padding: 3px 8px; border-radius: var(--r-pill); font-weight: 600; }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-neutral { background: var(--surface-2);  color: var(--text-muted); }

/* ---------- TABELA (desktop) ---------- */
table { border-collapse: collapse; }
.product-table, table.data-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .85rem; color: var(--text); }
.product-table th, table.data-table th { text-align: left; padding: 8px 14px; font-size: .68rem; text-transform: uppercase; color: var(--text-muted); }
.product-table td, table.data-table td { padding: 10px 14px; border-top: 1px solid var(--border); }
.product-table .qty-control button { width: 28px; height: 28px; font-size: 1rem; }
.sort-icon { color: var(--text-muted); font-size: .7rem; }

/* hook: linha de estoque baixo */
tr.low-stock, .low-stock { background: var(--danger-bg); }
tr.low-stock td { color: var(--danger-fg); }

/* hook: linha/elemento editavel + modo edicao */
.editable-row { cursor: pointer; }
.editable-row:hover { background: var(--surface-2); }
.edit-mode-active .editable-row { outline: 1px dashed var(--accent); }

/* ---------- MODAL (hook: .show abre) ----------
   O app.js abre alguns modais via style.display='block' (inline vence o CSS).
   margin:auto no card garante centralizacao tanto em display:block quanto flex. */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; overflow: auto; }
.modal.show { display: flex; }
.modal-card, .modal-content { background: var(--surface); color: var(--text); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; margin: 5vh auto; }
.large-modal .modal-card, .large-modal .modal-content { max-width: 760px; }
.modal-head, .modal-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 16px; }
.modal-foot, .modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- FORM ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .78rem; color: var(--text-muted); font-weight: 600; }
.field input, .field select, .field textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 12px;
  background: var(--surface); color: var(--text); font-size: .95rem; min-height: var(--tap);
}
.form-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.suggestion-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--r-sm); padding: 4px 10px; font-size: .8rem; }

/* ---------- TOAST (hook: .show + variantes) ---------- */
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 60; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: var(--r-md); padding: 12px 16px; box-shadow: var(--shadow-lg); max-width: 90vw; display: none; }
.toast.show { display: block; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }

/* ---------- BARRA DE ACAO FIXA (mobile) ---------- */
.action-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 12px; display: flex; gap: 8px; z-index: 10; }
.action-bar .btn { flex: 1; }

/* ---------- SCANNER (hook: .scanning, video) ---------- */
.scanner-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; z-index: 70; }
.scanner-overlay.show { display: flex; }
.scanner-container { position: relative; width: 90%; max-width: 500px; height: 70vh; background: #000; border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.scanner-close-btn { position: absolute; top: 12px; right: 12px; z-index: 10; background: rgba(255,255,255,.2) !important; border: 2px solid rgba(255,255,255,.3) !important; color: #fff !important; border-radius: 50%; }
.scanner-close-btn:hover { background: rgba(255,255,255,.35) !important; }
.scanner-frame { width: 80vw; max-width: 320px; aspect-ratio: 1; border: 3px solid var(--accent); border-radius: var(--r-lg); pointer-events: none; }
.scanner-video-wrap { width: 100%; height: 100%; background: #000; position: absolute; inset: 0; }
.scanning video, video { max-width: 100%; border-radius: var(--r-md); }

/* ---------- LOGIN MODAL BRANDING ---------- */
.login-modal-head { background: var(--brand); color: var(--brand-contrast); border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: none; padding: 20px 24px; justify-content: center; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand-icon { font-size: 2rem; }
.login-brand-name { font-size: 1.1rem; font-weight: 800; color: var(--brand-contrast); }
.login-brand-sub { font-size: .75rem; opacity: .8; color: var(--brand-contrast); }
.login-submit-btn { width: 100%; justify-content: center; font-size: 1rem; min-height: 48px; }

/* hook: drag & drop de arquivo */
.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--surface-2); }

/* ---------- CLASSES-HOOK GLOBAIS ---------- */
.hidden { display: none !important; }
.active { /* estado generico; efeito definido por componente acima */ }
body.body-scroll-locked { overflow: hidden; }

/* ---------- UTILITARIOS ---------- */
.row { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--text-muted); }
.mobile-only { display: revert; }
.desktop-only { display: none; }

/* ---------- CLASSES GERADAS PELO JS (app.js / updateInventoryDisplay) ---------- */
/* item wrapper */
.inventory-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 12px; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  cursor: pointer; transition: box-shadow .15s;
}
.inventory-item:hover { box-shadow: var(--shadow-md); }
.inventory-item.updated { border-left: 3px solid var(--success); }
.inventory-item.low-stock { background: var(--danger-bg); border-color: var(--danger); }
.inventory-item.no-barcode { opacity: .8; }
/* item content */
.item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item-name { font-weight: 600; font-size: .92rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-category { font-size: .7rem; color: var(--text-muted); }
.item-updated-info { font-size: .7rem; color: var(--success); display: flex; align-items: center; gap: 4px; }
.item-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.item-meta-tag { font-size: .65rem; background: var(--surface-2); color: var(--text-muted); padding: 2px 6px; border-radius: var(--r-pill); }
/* quantity */
.item-quantity { font-size: 1.3rem; font-weight: 800; color: var(--brand); min-width: 36px; text-align: center; flex-shrink: 0; }
.item-quantity.low { color: var(--danger); }
.item-quantity.updated { color: var(--success); }
/* pagination */
.pagination-btn {
  min-width: 36px; height: 36px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.pagination-btn.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.pagination-btn:disabled { opacity: .4; cursor: default; }
.pagination-info { font-size: .75rem; color: var(--text-muted); }
/* sync indicator */
.sync-indicator { font-size: .75rem; display: inline-flex; align-items: center; gap: 4px; }
.sync-indicator.syncing { color: var(--accent-light, #fbbf24); }
.sync-indicator.online  { color: var(--success); }
.sync-indicator.offline { color: var(--danger); }

/* ---------- RESPONSIVO: desktop >=1024px ---------- */
@media (min-width: 1024px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: revert; }
  .stats-strip { grid-template-columns: repeat(4,1fr); }
  .toolbar { flex-direction: row; align-items: center; }
  .action-bar { display: none; }
  .form-row { grid-template-columns: 1fr 1fr; }
  /* desktop: inventory items as flat rows */
  .inventory-item { border-radius: 0; border-left: none; border-right: none; border-top: none; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .inventory-item:first-child { border-top: 1px solid var(--border); }
  .inventory-item.updated { border-left: 3px solid var(--success); }
  .item-quantity { font-size: 1rem; min-width: 48px; }
}

/* ---------- CLASSES GERADAS PELO JS (script.js / estoqueminimo.html) ---------- */
/* status badge — aplicado como <span class="status-badge critico|suficiente|vazio"> */
.status-badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  border-radius: var(--r-pill); padding: 3px 10px;
}
.status-badge.suficiente { background: var(--success-bg); color: var(--success-fg); }
.status-badge.critico    { background: var(--danger-bg);  color: var(--danger-fg); }
.status-badge.vazio      { background: var(--warning-bg); color: var(--warning-fg); }

/* category-tag — aplicado em <span class="category-tag"> para categoria/subcategoria */
.category-tag {
  display: inline-block; font-size: .7rem;
  background: var(--surface-2); color: var(--text-muted);
  border-radius: var(--r-pill); padding: 2px 8px; border: 1px solid var(--border);
}

/* edit-icon — ícone inline aplicado em modo edição */
.edit-icon { color: var(--text-muted); font-size: .75rem; margin-left: 4px; opacity: .7; }
.editable-row:hover .edit-icon { opacity: 1; color: var(--brand); }

/* footer-row / footer-info — linha de rodapé das tabelas */
tr.footer-row td { background: var(--surface-2); color: var(--text-muted); font-size: .78rem; }
.footer-info     { font-size: .78rem; color: var(--text-muted); }

/* sort-asc / sort-desc — classes aplicadas pelo JS no <th> ativo */
th.sort-asc  .sort-icon { color: var(--brand); }
th.sort-desc .sort-icon { color: var(--brand); }

/* toast-* — classes aplicadas pelo script.js nos toasts dinâmicos */
.toast-info    { border-left-color: var(--info); }
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
