/* ── Reset & Tokens ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg: #f4f5f7;
  --c-surface: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #1a202c;
  --c-muted: #718096;
  --c-primary: #2563eb;
  --c-primary-dark: #1d4ed8;
  --c-primary-light: #eff6ff;
  --c-success: #059669;
  --c-danger: #dc2626;
  --c-warning: #d97706;
  --c-orange: #ea580c;
  --c-blue-light: #dbeafe;
  --c-green-light: #d1fae5;
  --c-red-light: #fee2e2;
  --c-orange-light: #ffedd5;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--c-bg); color: var(--c-text); font-size: 14px; line-height: 1.5; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'SF Mono', 'Fira Code', monospace; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ── Login ───────────────────────────────────────────────────── */
#login-screen {
  display: flex; position: fixed; inset: 0; background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  align-items: center; justify-content: center; z-index: 100;
}
.login-card {
  background: white; border-radius: 16px; padding: 40px 36px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 28px; font-weight: 800; color: var(--c-primary); }
.login-logo p { color: var(--c-muted); font-size: 13px; }
#login-erro { color: var(--c-danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ── App Shell ───────────────────────────────────────────────── */
#app-shell { display: none; height: 100vh; overflow: hidden; }

/* Top Bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--c-primary); color: white; display: flex; align-items: center;
  padding: 0 16px; gap: 12px; z-index: 50; box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-menu-btn { background: none; border: none; color: white; cursor: pointer; padding: 8px; border-radius: 8px; display: flex; align-items: center; }
.topbar-menu-btn:hover { background: rgba(255,255,255,.1); }
#app-title { font-weight: 700; font-size: 16px; flex: 1; }
.topbar-subtitle { font-size: 12px; opacity: .7; }

/* Sidebar */
#nav-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; }
#nav-overlay.active { display: block; }

#sidebar {
  position: fixed; top: 0; left: calc(-1 * var(--sidebar-w) - 10px); bottom: 0; width: var(--sidebar-w);
  background: var(--c-surface); z-index: 70; transition: left .25s ease;
  box-shadow: 2px 0 16px rgba(0,0,0,.1); display: flex; flex-direction: column; padding-top: var(--topbar-h);
}
#sidebar.open { left: 0; }

.nav-brand { padding: 20px 20px 12px; border-bottom: 1px solid var(--c-border); }
.nav-brand h3 { font-size: 14px; font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .05em; }

.nav-items { padding: 12px 0; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 20px; cursor: pointer;
  color: var(--c-muted); font-weight: 500; transition: all .15s; border: none; background: none;
  width: 100%; text-align: left; font-size: 14px;
}
.nav-item:hover { background: var(--c-primary-light); color: var(--c-primary); }
.nav-item.active { background: var(--c-primary-light); color: var(--c-primary); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }

.nav-bottom { padding: 16px 20px; border-top: 1px solid var(--c-border); }
.btn-logout { background: none; border: none; color: var(--c-danger); cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; }

/* Main Content */
#main-content {
  padding-top: var(--topbar-h); height: 100vh; overflow-y: auto;
  background: var(--c-bg);
}
#view { padding: 20px 16px; max-width: 1100px; margin: 0 auto; }

/* ── Cards & Layout ──────────────────────────────────────────── */
.card {
  background: var(--c-surface); border-radius: var(--radius); border: 1px solid var(--c-border);
  padding: 16px; box-shadow: var(--shadow);
}
.card h4 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--c-text); }
.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-list-item { cursor: pointer; transition: border-color .15s; }
.card-list-item:hover { border-color: var(--c-primary); }
.card-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.card-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.card-obs { margin-top: 8px; font-size: 12px; color: var(--c-muted); padding-top: 8px; border-top: 1px solid var(--c-border); }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }

/* ── KPI Grid ────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media(min-width: 640px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-card { border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; opacity: .8; }
.kpi-value { font-size: 20px; font-weight: 700; line-height: 1.2; }
.kpi-sub { font-size: 11px; margin-top: 3px; opacity: .7; }

.kpi-blue { background: var(--c-blue-light); color: #1d4ed8; }
.kpi-green { background: var(--c-green-light); color: #065f46; }
.kpi-red { background: var(--c-red-light); color: #991b1b; }
.kpi-orange { background: var(--c-orange-light); color: #9a3412; }
.kpi-gray { background: #f1f5f9; color: #475569; }

/* ── Dashboard ───────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media(min-width: 640px) { .dash-grid { grid-template-columns: 1fr 1fr; } }

.list-item-mini { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--c-border); gap: 8px; }
.list-item-mini:last-child { border-bottom: none; }
.list-item-mini.clickable { cursor: pointer; border-radius: 6px; padding: 8px; margin: 0 -8px; }
.list-item-mini.clickable:hover { background: var(--c-primary-light); }
.item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.item-nome { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-cat { font-size: 12px; color: var(--c-muted); }
.item-valor { font-weight: 600; color: var(--c-primary); flex-shrink: 0; }
.item-badge { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.badge-min { font-size: 11px; color: var(--c-muted); }

/* ── View Header ─────────────────────────────────────────────── */
.view-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.view-header h2 { font-size: 20px; font-weight: 700; }
.subtitle { font-size: 13px; color: var(--c-muted); font-weight: 400; }

/* ── Filter / Search ─────────────────────────────────────────── */
.search-bar, .filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar input, .filter-bar input { flex: 1; min-width: 160px; }
.filter-bar select { min-width: 140px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-secondary { background: var(--c-border); color: var(--c-text); }
.btn-secondary:hover { background: #cbd5e0; }
.btn-danger { background: var(--c-danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: none; border: 1px solid var(--c-border); color: var(--c-text); padding: 4px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px; color: var(--c-muted); display: inline-flex; align-items: center; }
.btn-icon:hover { background: var(--c-border); color: var(--c-text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .03em; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="text"], input[type="number"], input[type="email"], input[type="date"], input[type="tel"], input[type="password"], select, textarea {
  padding: 9px 12px; border: 1.5px solid var(--c-border); border-radius: 8px; font-size: 14px; background: white;
  color: var(--c-text); transition: border-color .15s; width: 100%; outline: none; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea { resize: vertical; }
.input-mini { padding: 4px 8px; border-radius: 6px; border: 1.5px solid var(--c-border); font-size: 13px; width: 80px; background: white; }
.section-divider { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); margin: 16px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--c-border); }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabela-main { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela-main th { padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); background: #f8fafc; border-bottom: 2px solid var(--c-border); }
.tabela-main td { padding: 10px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.tabela-main tr:hover td { background: #fafbff; }
.row-critico td { background: #fff5f5; }
.row-critico:hover td { background: #fee2e2; }
.tabela-itens { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela-itens th { padding: 6px 8px; text-align: left; font-size: 11px; font-weight: 700; color: var(--c-muted); background: #f8fafc; border-bottom: 1px solid var(--c-border); }
.tabela-itens td { padding: 8px; border-bottom: 1px solid var(--c-border); }
.td-actions { display: flex; gap: 4px; align-items: center; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge { display: inline-flex; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-blue { background: var(--c-blue-light); color: #1d4ed8; }
.badge-green { background: var(--c-green-light); color: #065f46; }
.badge-red { background: var(--c-red-light); color: #991b1b; }
.badge-orange { background: var(--c-orange-light); color: #9a3412; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ── Cards de Produto ────────────────────────────────────────── */
.prod-list { display: flex; flex-direction: column; gap: 10px; }
.prod-card { padding: 14px; }
.prod-card-critico { border-color: #fca5a5; background: #fff5f5; }
.prod-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.prod-info { flex: 1; min-width: 0; }
.prod-nome { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.prod-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.prod-acoes-top { display: flex; gap: 2px; flex-shrink: 0; }

.prod-estoques { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.estoque-bloco { flex: 1; background: #f8fafc; border-radius: 8px; padding: 10px 12px; text-align: center; border: 1px solid var(--c-border); }
.estoque-loja { border-color: #bfdbfe; background: #eff6ff; }
.estoque-reserva { border-color: #fed7aa; background: #fff7ed; }
.estoque-critico { border-color: #fca5a5 !important; background: #fff1f2 !important; }
.estoque-label { font-size: 11px; font-weight: 700; color: var(--c-muted); text-transform: uppercase; margin-bottom: 4px; }
.estoque-valor { font-size: 20px; font-weight: 700; color: var(--c-text); line-height: 1; }
.estoque-un { font-size: 12px; font-weight: 400; color: var(--c-muted); }
.estoque-min { font-size: 11px; color: var(--c-muted); margin-top: 3px; }
.estoque-alerta { font-size: 11px; color: var(--c-danger); font-weight: 700; margin-top: 2px; }
.estoque-seta { color: var(--c-muted); font-size: 18px; flex-shrink: 0; }

.btn-repor {
  display: block; width: 100%; padding: 10px; border: 2px dashed #2563eb; border-radius: 8px;
  background: var(--c-primary-light); color: var(--c-primary); font-size: 13px; font-weight: 700;
  cursor: pointer; margin-bottom: 10px; transition: background .15s;
}
.btn-repor:hover { background: #dbeafe; }

.prod-precos { display: flex; gap: 16px; font-size: 12px; color: var(--c-muted); padding-top: 8px; border-top: 1px solid var(--c-border); }
.prod-precos strong { color: var(--c-text); }

/* ── Modal ───────────────────────────────────────────────────── */
#modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200;
  align-items: flex-start; justify-content: center; padding: 20px 16px; overflow-y: auto;
}
#modal-overlay.active { display: flex; }
.modal {
  background: white; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 24px 80px rgba(0,0,0,.2);
  margin: auto; display: flex; flex-direction: column;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--c-border); }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; max-height: 65vh; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Notas ───────────────────────────────────────────────────── */
.item-add-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.item-add-bar input { flex: 1; }
.busca-lista { border: 1px solid var(--c-border); border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.busca-item { padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--c-border); }
.busca-item:last-child { border-bottom: none; }
.busca-item:hover { background: var(--c-primary-light); }
.busca-resultado { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; margin-bottom: 8px; }
.total-nota { text-align: right; font-size: 16px; padding-top: 10px; border-top: 2px solid var(--c-border); margin-top: 4px; }
.valor-destaque { font-size: 16px; font-weight: 700; color: var(--c-primary); }
.detalhe-nota { display: flex; flex-direction: column; gap: 4px; }
.detalhe-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--c-border); font-size: 13px; }
.detalhe-row:last-child { border-bottom: none; }
.detalhe-row span:first-child { color: var(--c-muted); }

/* ── QR / Barcode ────────────────────────────────────────────── */
.qr-box { background: #f8fafc; border: 1px solid var(--c-border); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.qr-box p { font-size: 13px; color: var(--c-muted); text-align: center; }
#qr-reader, #barcode-reader { width: 100%; max-width: 280px; border-radius: 8px; overflow: hidden; }
.scan-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.scan-box { background: white; border-radius: 14px; padding: 20px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.scan-box h4 { font-size: 16px; font-weight: 700; }

/* ── Relatórios ──────────────────────────────────────────────── */
.periodo-selector { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.periodo-selector select { min-width: 90px; }
.rel-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 16px; }
@media(min-width: 640px) { .rel-grid { grid-template-columns: 1fr 1fr; } }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.bar-label { width: 120px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--c-primary); border-radius: 4px; transition: width .3s; }
.bar-fill-orange { background: var(--c-orange); }
.bar-value { width: 80px; text-align: right; font-weight: 600; flex-shrink: 0; }

/* ── Loading & States ────────────────────────────────────────── */
#loading {
  display: none; position: fixed; inset: 0; background: rgba(255,255,255,.7); z-index: 400;
  align-items: center; justify-content: center;
}
.spinner { width: 36px; height: 36px; border: 3px solid var(--c-border); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 40px 20px; color: var(--c-muted); font-size: 14px; line-height: 2; }
.empty-state.small { padding: 20px; font-size: 13px; }
.loading-text { text-align: center; padding: 20px; color: var(--c-muted); font-size: 13px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #1e293b; color: white; padding: 10px 20px; border-radius: 24px; font-size: 14px;
  font-weight: 500; z-index: 500; transition: transform .3s ease; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--c-danger); }
.toast.toast-success { background: var(--c-success); }

/* ── Utilities ───────────────────────────────────────────────── */
.text-muted { color: var(--c-muted); font-size: 12px; }
.text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); }
.fw-bold { font-weight: 700; }
.link { color: var(--c-primary); cursor: pointer; }

/* ── Desktop ─────────────────────────────────────────────────── */
@media(min-width: 768px) {
  #sidebar { left: 0; }
  .topbar-menu-btn { display: none; }
  #main-content { margin-left: var(--sidebar-w); }
  #nav-overlay { display: none !important; }
  #view { padding: 28px 32px; }
}
