*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-2: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #06b6d4;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.06);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  background: white;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
label { display: block; font-size: .8125rem; font-weight: 500; color: var(--text-2); margin-bottom: .25rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .65rem .75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .875rem; }
th { font-weight: 600; color: var(--text-2); background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
.hidden { display: none !important; }

/* LOGIN */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  padding: 1rem;
}
.login-card {
  background: white;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo svg { color: var(--primary); }
.login-logo h1 { margin: .5rem 0 .25rem; font-size: 1.75rem; }
.login-logo p { color: var(--text-2); margin: 0; }
.login-hint { text-align: center; font-size: .8125rem; color: var(--text-2); margin: 1rem 0 0; }

/* ALERTA MODERNO DE LOGIN */
.login-alert {
  display: flex; align-items: flex-start; gap: .85rem;
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  border: 1px solid #fca5a5;
  border-left: 4px solid #dc2626;
  color: #7f1d1d;
  padding: .85rem 1rem;
  border-radius: 10px;
  margin: 0 0 1rem;
  box-shadow: 0 4px 12px rgba(220, 38, 38, .15);
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transform: translateY(-8px);
  transition: opacity .25s ease, max-height .3s ease, transform .25s ease, margin .25s ease;
  pointer-events: none;
}
.login-alert.show {
  opacity: 1;
  max-height: 200px;
  transform: translateY(0);
  pointer-events: auto;
  animation: shakeAlert .5s ease-in-out;
}
.login-alert-icon {
  flex-shrink: 0;
  color: #dc2626;
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
}
.login-alert-content { flex: 1; min-width: 0; }
.login-alert-title { font-weight: 700; font-size: .9rem; margin-bottom: .15rem; }
.login-alert-message { font-size: .8125rem; line-height: 1.35; color: #991b1b; }
.login-alert-close {
  background: transparent; border: none;
  color: #991b1b; font-size: 1.4rem; line-height: 1;
  cursor: pointer; padding: 0 .25rem;
  opacity: .65; transition: opacity .15s;
}
.login-alert-close:hover { opacity: 1; }

@keyframes shakeAlert {
  0%, 100% { transform: translateX(0); }
  15%, 75% { transform: translateX(-4px); }
  30%, 60% { transform: translateX(4px); }
  45% { transform: translateX(-3px); }
}

/* Variante de sucesso (caso queira reutilizar) */
.login-alert.success {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border-color: #6ee7b7;
  border-left-color: #059669;
  color: #064e3b;
  box-shadow: 0 4px 12px rgba(5, 150, 105, .15);
}
.login-alert.success .login-alert-icon { color: #059669; }
.login-alert.success .login-alert-message { color: #065f46; }
.login-alert.success .login-alert-close { color: #065f46; }
.form-group { margin-bottom: 1rem; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: .875rem;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .35rem .65rem; font-size: .8125rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; display: flex; }
.btn-icon { padding: .35rem; width: 30px; height: 30px; }

/* APP LAYOUT */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 240px;
  background: #1e293b;
  color: #cbd5e1;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 1.25rem 1.25rem;
  display: flex; align-items: center; gap: .75rem;
  font-weight: 700; font-size: 1.05rem;
  color: white;
  border-bottom: 1px solid #334155;
}
.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .65rem .85rem;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: .9rem;
  transition: all .15s;
  margin-bottom: .15rem;
}
.sidebar-nav a:hover { background: #334155; color: white; }
.sidebar-nav a.active { background: var(--primary); color: white; }
.sidebar-nav .ico { font-size: 1.1rem; }
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #334155;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.user-info { display: flex; align-items: center; gap: .65rem; }
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.user-name { color: white; font-weight: 500; font-size: .875rem; }
.user-role { color: #94a3b8; font-size: .75rem; text-transform: uppercase; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  background: white;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.clock { color: var(--text-2); font-variant-numeric: tabular-nums; font-size: .875rem; }
.cash-status {
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.cash-status.open { background: var(--success-light); color: #065f46; }
.cash-status.closed { background: var(--surface-2); color: var(--text-2); }

.content { flex: 1; padding: 1.5rem; overflow-y: auto; }

/* CARDS */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.card-subtitle { color: var(--text-2); font-size: .8125rem; margin: .15rem 0 0; }

/* DASHBOARD */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.info { border-left-color: var(--info); }
.stat-label { color: var(--text-2); font-size: .8125rem; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: .25rem; line-height: 1.2; }
.stat-meta { color: var(--text-2); font-size: .8125rem; margin-top: .35rem; }
.stat-meta.up { color: var(--success); }
.stat-meta.down { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* PDV */
.pdv-layout { display: grid; grid-template-columns: 1fr 380px; gap: 1.25rem; height: calc(100vh - 130px); }
.pdv-products { background: white; border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.pdv-search { display: flex; gap: .5rem; margin-bottom: .75rem; }
.pdv-categories { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .75rem; }
.pdv-cat-chip {
  padding: .35rem .75rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: .8125rem;
  color: var(--text-2);
  cursor: pointer;
  font-weight: 500;
}
.pdv-cat-chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.pdv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .65rem;
  overflow-y: auto;
  padding-right: .25rem;
  flex: 1;
}
.pdv-prod-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem;
  cursor: pointer;
  transition: all .15s;
  position: relative;
}
.pdv-prod-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.pdv-prod-card.disabled { opacity: .5; cursor: not-allowed; }
.pdv-prod-card .pname { font-weight: 600; font-size: .85rem; margin-bottom: .35rem; line-height: 1.3; min-height: 2.2em; }
.pdv-prod-card .pprice { color: var(--primary); font-weight: 700; font-size: 1.05rem; }
.pdv-prod-card .pstock { color: var(--text-2); font-size: .7rem; margin-top: .25rem; }
.pdv-cat-tag {
  position: absolute; top: .35rem; right: .35rem;
  width: 8px; height: 8px; border-radius: 50%;
}

.pdv-cart { background: white; border-radius: var(--radius); display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; }
.pdv-cart-header { padding: .85rem 1rem; background: var(--primary); color: white; display: flex; justify-content: space-between; align-items: center; }
.pdv-customer { padding: .65rem 1rem; border-bottom: 1px solid var(--border); display: flex; gap: .5rem; align-items: center; font-size: .85rem; }
.pdv-cart-items { flex: 1; overflow-y: auto; padding: .5rem 0; }
.pdv-cart-item { padding: .65rem 1rem; border-bottom: 1px solid var(--border); }
.pdv-cart-item .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.pdv-cart-item .name { font-weight: 600; font-size: .875rem; flex: 1; }
.pdv-cart-item .qty-control { display: flex; align-items: center; gap: .35rem; }
.pdv-cart-item .qty-btn { width: 24px; height: 24px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.pdv-cart-item .qty-input { width: 50px; text-align: center; padding: .25rem; }
.pdv-cart-item .price { color: var(--text-2); font-size: .8rem; margin-top: .25rem; }
.pdv-cart-item .total { font-weight: 600; }
.pdv-cart-empty { text-align: center; color: var(--text-2); padding: 2rem 1rem; }

.pdv-totals { padding: 1rem; background: var(--surface-2); border-top: 1px solid var(--border); }
.pdv-total-row { display: flex; justify-content: space-between; padding: .25rem 0; font-size: .9rem; }
.pdv-total-row.grand { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-top: .35rem; padding-top: .65rem; border-top: 1px solid var(--border); }
.pdv-actions { padding: .85rem; display: flex; gap: .5rem; }

/* TABLES */
.table-wrap { background: white; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-toolbar { padding: 1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar .filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.table-toolbar input, .table-toolbar select { width: auto; min-width: 200px; }

/* BADGES */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info { background: var(--primary-light); color: #1e40af; }
.badge-gray { background: var(--surface-2); color: var(--text-2); }

/* MODAL */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { transform: translateY(20px); opacity: 0; } }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }
.modal-header { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close { color: var(--text-2); font-size: 1.5rem; line-height: 1; padding: 0 .35rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* TOAST */
#toast-root { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 2000; }
.toast {
  padding: .85rem 1.1rem;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  min-width: 280px;
  animation: toastIn .25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } }

/* MISC */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-2); }
.empty-state .icon { font-size: 3rem; margin-bottom: .5rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-2); }
.flex { display: flex; }
.gap-sm { gap: .5rem; }
.gap-md { gap: 1rem; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.flex-1 { flex: 1; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.fw-bold { font-weight: 600; }
.text-lg { font-size: 1.1rem; }
.text-sm { font-size: .8125rem; }
.text-xs { font-size: .75rem; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 380px; }
.section-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 .85rem; }

/* RECEIPT */
.receipt {
  font-family: 'Courier New', monospace;
  background: white;
  padding: 1.25rem;
  max-width: 320px;
  margin: 0 auto;
  font-size: .8rem;
}
.receipt .center { text-align: center; }
.receipt .line { border-top: 1px dashed #999; margin: .5rem 0; }
.receipt table { font-size: .75rem; }
.receipt th, .receipt td { padding: .15rem .25rem; border: none; }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; top: 0; left: 0; width: 100%; }
}

/* ============================================================
   RESPONSIVIDADE MOBILE (TABLET + PHONE)
   - <= 1024px: tablet, reduz colunas
   - <= 768px: phone, sidebar vira drawer com hamburger
   ============================================================ */

/* Toggle button (escondido em desktop) */
.mobile-menu-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 200;
  background: #1e293b; color: white; border: none;
  width: 44px; height: 44px; border-radius: 10px;
  align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.mobile-menu-toggle svg { width: 22px; height: 22px; }

/* Overlay quando sidebar aberta em mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 1024px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; gap: 1rem; }
  .pdv-layout { grid-template-columns: 1fr; height: auto; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  /* Mostrar botão hamburger */
  .mobile-menu-toggle { display: flex; }

  /* Sidebar vira drawer off-canvas */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s ease;
    z-index: 160; box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-header { padding-left: 4rem; } /* dá espaço pro botão hamburger por baixo */

  /* Main content ocupa tudo */
  .app { flex-direction: column; }
  .main { width: 100%; }
  .topbar { padding-left: 4rem; padding-right: 1rem; flex-wrap: wrap; gap: .5rem; }
  .topbar h1 { font-size: 1.1rem; }
  .content { padding: 1rem; }

  /* Cards e grids empilham */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; gap: .5rem; }

  /* Tabelas com scroll horizontal — wrap precisa wrapper class .table-wrap */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 600px; }

  /* Cards menos padding em mobile */
  .card { padding: 1rem; }

  /* Modal full-screen em phone */
  .modal-overlay .modal { width: 95vw !important; max-width: 95vw; margin: 1rem; }

  /* Sidebar nav touch-friendly */
  .sidebar-nav a { padding: .9rem 1rem; font-size: .95rem; }
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 1rem; }
  .topbar .clock { font-size: .75rem; }
  .stat-value { font-size: 1.4rem !important; }
  .btn-lg { padding: .65rem 1.2rem; font-size: .9rem; }
  .login-card { padding: 1.5rem !important; max-width: 100% !important; margin: 1rem; }
}
