:root{
  --brand:#2b4c7e; --brand-700:#1f365b; --ink:#222; --muted:#666; --bg:#f4f6f9; --line:#ddd; --chip:#e7f0ff; --ok:#10b981; --warn:#f59e0b; --danger:#ef4444;
}
*{box-sizing:border-box}
html,body{height:100%}
body{font-family:'Poppins',sans-serif;background:var(--bg);margin:0;padding:20px;color:var(--ink)}

/* ============================================================ */
/* LAYOUT E LOGIN                                               */
/* ============================================================ */
.container{
  max-width:1024px; margin:auto; background:#fff;
  border-radius:14px; padding:18px 20px; box-shadow:0 8px 28px rgba(0,0,0,.06);
}

#login-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  z-index: 10000; padding: 20px;
}
.login-box {
  width: 100%; max-width: 400px; background: #fff; padding: 25px 30px;
  border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.08);
  display: flex; flex-direction: column; align-items: center;
}
.login-box h2 {
  font-size: 20px; color: var(--brand); margin: 0 0 20px 0; 
  padding-bottom: 5px; border-bottom: 2px solid #e0e0e0;
}
.login-box .field { width: 100%; margin-bottom: 15px; }
.login-box.loading { opacity: 0.7; pointer-events: none; }
.login-box.loading button[type="submit"] { cursor: wait; }

/* ============================================================ */
/* HEADER E NAVEGAÇÃO                                           */
/* ============================================================ */
.header{
  display:flex; gap: 16px; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.header img{max-width:130px; flex-shrink: 0;}

.header-info-wrapper { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.header-user-controls {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  background: #f7faff; padding: 6px 12px; border-radius: 10px;
  border: 1px solid #e2e8f0; min-width: 200px; text-align: right;
}
#info-usuario-logado { font-size: 13px; color: var(--muted); font-weight: 600; }
.info-loja{ font-size:12px; color:#333; text-align: right; line-height: 1.4; }

h1{font-size:22px;color:var(--brand);margin:14px 0 10px;border-bottom:2px solid #e0e0e0;padding-bottom:6px}
h2{font-size:18px;color:var(--brand);margin:18px 0 8px}

/* MENU (ABAS) - CORRIGIDO PARA FLEX */
.tabs{
  display: flex; flex-wrap: wrap; gap: 6px; margin: 20px 0 16px;
}
.tab{
  flex: 1; min-width: 120px; padding: 8px 12px;
  border: 1px solid #cfd8e3; border-radius: 10px; background: #f7faff;
  cursor: pointer; font-weight: 600; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px;
  transition: all 0.2s ease;
}
.tab.active{background:var(--brand);color:#fff;border-color:var(--brand)}

/* ============================================================ */
/* FORMULÁRIOS E GRIDS                                          */
/* ============================================================ */
.grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px 14px}
.col-span-2{grid-column:span 2}
.col-span-3{grid-column:span 3}
.col-span-4{grid-column:1 / -1}

label{font-weight:600;font-size:13px}
.field{display:flex;flex-direction:column;gap:6px}

input,select,textarea{width:100%;padding:9px 11px;border:1px solid #cfcfcf;border-radius:8px;font-size:14px;min-height:40px}
textarea{min-height:80px;resize:vertical}
input[type="date"]{line-height:1.2}
input::placeholder,textarea::placeholder{color:#9aa3ac}
input:focus,select:focus,textarea:focus {outline: 2px solid var(--brand);border-color: var(--brand);}
input[inputmode="decimal"] {font-family: 'Poppins', monospace;}

.hint{font-size:12px;color:#6b7280}
.produtos{display:flex;flex-direction:column;gap:8px;margin-top:6px}

.btn{padding:10px 16px;border:none;border-radius:10px;background:var(--brand);color:#fff;font-weight:600;cursor:pointer;display:inline-flex;align-items:center;gap:8px}
.btn:hover{background:var(--brand-700)}
.btn:focus {outline: 2px solid var(--brand);outline-offset: 2px;}
.btn.alt{background:#eef2ff;color:#1f2937}
.btn.ok{background:var(--ok)}
.btn.warn{background:var(--warn)}
.btn.danger{background:var(--danger)}

.actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
.sticky-bar{position:sticky;bottom:-10px;background:linear-gradient(180deg, rgba(255,255,255,0), #fff 30%);padding-top:12px; z-index: 100;}

/* ============================================================ */
/* TABELAS                                                      */
/* ============================================================ */
table{width:100%;border-collapse:collapse;font-size:13px}
th,td{border:1px solid #ccc;padding:8px;text-align:left; text-transform: capitalize;}
th{background:var(--chip)}
tbody tr:nth-child(odd){background:#f8fbff}

/* Cores das Linhas (Entrada/Saída) */
#financeiro tbody tr[data-tipo="entrada"],
#caixa tbody tr[data-tipo="entrada"],
#relatorios #rel-area tbody tr[data-tipo="Venda Bruta"] { background:#eefbf3; }

#financeiro tbody tr[data-tipo="saida"],
#despesas tbody tr[data-tipo="saida"],
#caixa tbody tr[data-tipo="saida"],
#relatorios #rel-area tbody tr[data-tipo="Saída"] { background:#fff1f1; }

#financeiro tbody tr[data-tipo="entrada"] td:nth-child(4),
#caixa tbody tr[data-tipo="entrada"] td:nth-child(4){ color:var(--ok); font-weight:600; }

#financeiro tbody tr[data-tipo="saida"] td:nth-child(4),
#despesas tbody tr[data-tipo="saida"] td:last-child,
#caixa tbody tr[data-tipo="saida"] td:nth-child(4){ color:var(--danger); font-weight:600; }

.btn-del-d, .btn-del-m, .btn-del-m-caixa {font-size: 12px;padding: 6px 12px;min-height: auto;}

/* ============================================================ */
/* PEDIDOS & IMPRESSÃO VISUAL                                   */
/* ============================================================ */
.cliente-box{background:#f7faff;border-left:4px solid var(--brand);border-radius:10px;padding:12px 14px;margin:14px 0}
.cliente-cols{display: flex;justify-content: space-between;align-items: flex-start;gap: 20px;flex-wrap: wrap;}
.cliente-info {flex: 1;min-width: 300px;}
.cliente-qr {flex-shrink: 0;text-align: center;padding: 10px;background: #f8fafc;border-radius: 8px;border: 1px solid #e2e8f0;min-width: 140px;}
.cliente-qr img {width: 90px;height: 90px;object-fit: contain;}
.cliente-qr div {font-size: 11px;margin: 4px 0;}
.print-divider{height:1px;background:#e9ecef;margin:14px 0 12px}

.total{text-align:right;margin-top:12px}
.chip-total {display:inline-block;background:var(--chip);color:#000;padding:10px 16px;border-radius:8px;font-weight:700;font-size:18px;border:1px solid #d3def6;}
.rodape{text-align:center;font-size:11px;margin-top:28px;color:#999}
#pedido-gerado{display:none}

/* ============================================================ */
/* LINHA DE PRODUTO & AUTOCOMPLETE                              */
/* ============================================================ */
.produto-bloco-novo {
  display: grid;
  grid-template-columns: 2fr 70px 100px 100px 100px 110px 1fr 70px auto;
  gap: 10px; align-items: flex-end; padding: 10px;
  border-radius: 8px; background: #fdfdfd; border: 1px solid #eee;
  margin-bottom: 8px; position: relative;
}
.produto-bloco-novo .field { margin: 0; padding: 0; }
.produto-bloco-novo .field label { font-size: 11px; color: #555; margin-bottom: 2px; }
.produto-bloco-novo .remove {
  height: 38px; width: 38px; background: #fbe9e9; color: var(--danger);
  border: none; border-radius: 6px; font-size: 20px; font-weight: 600;
  cursor: pointer; padding: 0; margin-left: 5px;
}
.produto-bloco-novo .remove:hover { background: #f8d0d0; }
.produto-bloco-novo .parcelas-field { display: none; }
.produto-bloco-novo.com-cartao .parcelas-field { display: block; }
.parcelas-field select {min-height: 40px;width: 100%;padding: 9px 11px;border: 1px solid #cfcfcf;border-radius: 8px;font-size: 14px;}

#autocomplete-container {
  display: none; position: absolute; background: #fff;
  border: 1px solid #ccc; border-radius: 0 0 6px 6px;
  z-index: 1000; max-height: 250px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.autocomplete-item { padding: 10px 12px; cursor: pointer; font-size: 14px; }
.autocomplete-item:hover { background: #f5f5f5; }
.autocomplete-item.sem-estoque { color: #a0a0a0; background: #fcfcfc; font-style: italic; }
.autocomplete-item:not(:last-child) { border-bottom: 1px solid #eee; }

/* ============================================================ */
/* DASHBOARD & CARDS                                            */
/* ============================================================ */
.panel{display:none}
.panel.active{display:block; animation: fadeIn 0.3s ease-in-out;}
@keyframes fadeIn {from { opacity: 0; } to { opacity: 1; }}

.dashboard-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.dashboard-header h1 { margin: 0; }

.dashboard-month-picker { display: inline-flex; align-items: center; gap: 8px; }
.dashboard-month-picker input[type="month"] {
  background: transparent; border: none; min-height: auto; padding: 0; margin: 0;
  font-size: 14px; font-weight: 600; font-family: 'Poppins', sans-serif; width: 155px;
}
.btn.alt input[type="month"] { color: #1f2937; }
.dashboard-month-picker input[type="month"]:focus { outline: none; box-shadow: none; }

.dashboard-cards {display: grid;grid-template-columns: repeat(2, 1fr);gap: 20px;margin: 20px 0;}
.card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;
  padding: 25px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-height: 120px; display: flex; flex-direction: column; justify-content: center;
}
.card:hover {transform: translateY(-2px);box-shadow: 0 6px 20px rgba(0,0,0,0.15);}
.card.small { background: linear-gradient(135deg, #4fd1c7 0%, #319795 100%); padding: 15px; min-height: 80px; }
.card.warning { background: linear-gradient(135deg, #f87171 0%, var(--danger) 100%); }
.card-title { font-size: 14px; opacity: 0.9; margin-bottom: 8px; overflow-wrap: break-word; }
.card-value {font-size: 28px;font-weight: 700;}
.card.small .card-value {font-size: 20px;margin-bottom: 4px;}
.card-subvalue {font-size: 12px;opacity: 0.9;}

.dashboard-grid {display: grid;grid-template-columns: 1fr 1fr;gap: 30px;margin-top: 20px;}
.dashboard-section {background: #f8fafc;border-radius: 12px;padding: 20px;margin-bottom: 25px;border: 1px solid #e2e8f0; overflow-x: hidden;}
.dashboard-section h2 {margin-top: 0;color: #2d3748;font-size: 18px;border-bottom: 1px solid #e2e8f0;padding-bottom: 10px;}
.formas-pagamento-grid {display: grid;grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));gap: 15px;margin: 15px 0;}

.vendas-canal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 15px; }
.card.canal-online { background: linear-gradient(135deg, #2b7de9 0%, #2b4c7e 100%); }
.card.canal-presencial { background: linear-gradient(135deg, #2ac5b5 0%, #1f8e83 100%); }

#aviso-estoque-dashboard, #aviso-estoque-produtos { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); min-height: 70px; }

/* Gráficos e Relatórios */
#chart-vendas-mensais {max-height: 250px;width: 100%;margin: 20px 0;}
#chart-tipos-venda {max-height: 250px; width: 100%;margin-bottom: 20px;}
#chart-formas-pagamento {max-height: 350px; width: 100%;margin-top: 30px;margin-bottom: 30px;}

.sum{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px; margin-bottom: 16px;}
.pill{background:#f5f7ff;border:1px solid #d9e2ff;border-radius:999px;padding:6px 10px;font-weight:600}
.taxas-config {max-width: 800px;}
.empty-state {text-align: center;padding: 40px 20px;color: #6b7280;}
.empty-state .icon {font-size: 48px;margin-bottom: 16px;opacity: 0.5;}

#relatorios .actions {justify-content: flex-start;gap: 12px;margin: 10px 0 20px 0; }
#relatorios h2:nth-of-type(2) {margin-top: 20px;}
#relatorios .btn {min-width: 150px;justify-content: center;flex-grow: 0;}
#rel-area table {font-size: 12px;}
#rel-area th,#rel-area td {padding: 6px 8px;}

/* ============================================================ */
/* IMPRESSÃO (@media print)                                     */
/* ============================================================ */
@media print {
  @page { margin: 0; size: auto; }
  html, body {
    background: #fff !important; width: 100% !important; height: auto !important;
    margin: 0 !important; padding: 0 !important; overflow: visible !important;
    font-family: 'Poppins', sans-serif; color: #000 !important;
    -webkit-print-color-adjust: exact;
  }
  .container, #pedidos, #pedido-gerado {
    width: 100% !important; max-width: 100% !important; margin: 0 !important;
    padding: 0 !important; box-shadow: none !important; border: none !important;
    display: block !important;
  }
  .no-print, .sticky-bar, .panel:not(#pedidos), 
  #pedidos > *:not(#pedido-gerado), canvas, #login-overlay,
  .print-divider, .via-estab, #pedido-gerado hr, #pedido-gerado h2,
  .header-info-wrapper, #btn-sair, .tabs, .header-user-controls {
    display: none !important;
  }
  #pedido-gerado .header {
    display: flex !important; flex-direction: column !important; align-items: center !important;
    text-align: center !important; margin-bottom: 5px; border-bottom: 1px solid #ddd;
    padding-bottom: 5px; width: 100% !important;
  }
  #pedido-gerado .header img { max-width: 120px !important; margin: 0 !important; }
  #pedido-gerado .header .info-loja {
    font-size: 10px !important; color: #444 !important; margin-top: 2px;
    display: block !important; text-align: center !important;
  }
  h1 {
    font-size: 18px !important; text-align: left; margin: 5px 0 !important;
    font-weight: 600 !important; color: var(--brand) !important; border: none !important;
  }
  .cliente-box {
    border: none !important; border-left: 4px solid var(--brand) !important;
    padding: 0 0 0 5px !important; margin: 0 0 5px 0 !important; background: transparent !important;
    width: 100% !important;
  }
  .cliente-cols { display: block !important; width: 100% !important; }
  .cliente-info { width: 100% !important; font-size: 12px !important; line-height: 1.3; color: #000; }
  .cliente-qr {
    width: 100% !important; display: flex !important; flex-direction: column;
    align-items: center; justify-content: center; margin-top: 5px; padding: 0 !important;
    border: none !important;
  }
  .cliente-qr br { display: none !important; }
  .cliente-qr img { width: 100px !important; height: 100px !important; display: block; }
  
  table { width: 100% !important; margin-top: 5px; font-size: 11px !important; }
  tr { page-break-inside: avoid; }
  th, td { border-bottom: 1px solid #eee !important; padding: 4px 0 !important; text-align: right; color: #000; }
  th { background: #f4f4f4 !important; border-top: 1px solid #ccc !important; font-weight: 600; }
  th:nth-child(1), td:nth-child(1) { text-align: left !important; width: 55%; } 
  th:nth-child(2), td:nth-child(2) { text-align: center !important; width: 15%; }
  th:nth-child(7), td:nth-child(7) { text-align: right !important; width: 30%; font-weight: bold; }
  th:nth-child(3), td:nth-child(3), th:nth-child(4), td:nth-child(4),
  th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display: none !important; }
  
  .total { margin-top: 10px !important; text-align: right !important; width: 100% !important; }
  .chip-total { font-size: 15px !important; background: #f4f6f9 !important; color: #000 !important; border: 1px solid #ddd !important; }
  .rodape { display: block !important; text-align: center; font-size: 9px; margin-top: 15px; width: 100% !important; }
  #pedido-gerado .via-estab, #pedido-gerado h2, #pedido-gerado hr { display: none !important; }
}

/* ============================================================ */
/* RESPONSIVIDADE (MOBILE)                                      */
/* ============================================================ */
@media (max-width: 768px) {
    .dashboard-grid,.relatorios-grid {grid-template-columns: 1fr;}
    .dashboard-cards,.formas-pagamento-grid,.grid {grid-template-columns: 1fr;}
    .dashboard-grid {gap: 12px;}
    .cliente-cols {flex-direction: column;gap: 15px;}
    .cliente-qr {align-self: center;}
    .col-span-2,.col-span-3,.col-span-4 {grid-column: 1;}
    
    .vendas-canal-grid { grid-template-columns: 1fr; gap: 12px; }

    /* Scroll horizontal em tabelas para não quebrar layout */
    #financeiro table, #caixa table, #despesas table,
    #produtos table, #configuracoes table, #rel-area table {
      display: block; overflow-x: auto; white-space: nowrap;
    }
    
    .header { flex-wrap: wrap; justify-content: space-between; }
    .header-info-wrapper { align-items: center; }
    .header-user-controls { flex-direction: row; gap: 10px; }
    
    /* Nova linha de produto responsiva */
    .produto-bloco-novo { grid-template-columns: 1fr; gap: 6px; }
    .produto-bloco-novo .field { max-width: 100% !important; }
    
    #relatorios .actions:nth-of-type(2) {grid-template-columns: 1fr; display:grid;}
    #relatorios .actions:nth-of-type(2) .btn {width: 100%;min-width: auto; grid-column: 1 / -1;}
}

@media (max-width: 480px) {
    .container {padding: 12px 15px;margin: 10px;}
    body {padding: 10px;}
    .header { flex-direction: column; align-items: center; }
    .header-user-controls { flex-direction: column; gap: 6px; align-items: center; }
    .actions {flex-direction: column;}
    .btn {justify-content: center;}
    .sticky-bar .actions {flex-direction: row;flex-wrap: wrap;justify-content: center;}
    .card {padding: 20px;}
    .card-value {font-size: 24px;}
    .login-box { padding: 20px; }
    
    /* Correção Datas Mobile */
    input[type="date"] { min-width: 0; width: 100%; font-size: 16px; max-width: 100%; -webkit-appearance: none; appearance: none; }
    .field input[type="date"] { background: #fff; padding: 9px 11px; }
    
    #form-pedido.grid, #despesas.grid { display: flex; flex-direction: column; gap: 12px; }
    #form-pedido .field { width: 100%; }
    
    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .dashboard-month-picker { width: 100%; justify-content: space-between; }
}

@media (max-width: 360px) {
    .grid, .vendas-canal-grid { grid-template-columns: 1fr; }
    input[type="date"] { font-size: 14px; padding: 8px 10px; }
    .card.small.canal-online, .card.small.canal-presencial { min-height: 75px; padding: 12px 15px; }
    .card.small .card-value { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) { .card,.tab,.barra {transition: none;} }