*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== THEMES ===== */
:root {
  --bg:      #111111;
  --surface: #1a1a1a;
  --surface2:#222222;
  --border:  rgba(255,255,255,0.08);
  --text:    #e5e5e5;
  --muted:   rgba(255,255,255,0.4);
  --accent:  #7c3aed;
  --radius:  12px;
  --sidebar-bg: #0a0a0a;
  --header-bg:  #161616;
}
html[data-theme="light"] {
  --bg:      #f0f2f5;
  --surface: #ffffff;
  --surface2:#f8f9fa;
  --border:  rgba(0,0,0,0.1);
  --text:    #111111;
  --muted:   rgba(0,0,0,0.45);
  --accent:  #7c3aed;
  --sidebar-bg: #1a1a2e;
  --header-bg:  #ffffff;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.3); border-radius: 4px; }

/* ===== LAYOUT ===== */
#app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* Critical: fix flex scroll chain */
#app, main, .flex-scroll {
  min-height: 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--bg);
}

.main-inner {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  color: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 20px 10px;
  gap: 3px;
}
#sidebar.collapsed { width: 66px; }
#sidebar.collapsed .nav-label,
#sidebar.collapsed .brand-name { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  color: rgba(255,255,255,0.55);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.15); color: #fff; }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ===== HEADER ===== */
header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
}

/* ===== VIEWS ===== */
.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  min-height: 0;
}

/* POS special */
#view-pos {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
#view-pos.hidden-view, .view.hidden-view { display: none !important; }

/* ===== BOTTOM NAV (mobile only) ===== */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 62px;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  z-index: 200;
  align-items: center;
  justify-content: space-around;
}
html[data-theme="light"] #bottom-nav { background: #fff; }
.bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  border-radius: 8px;
  min-width: 52px;
  transition: color 0.15s;
}
.bnav-item.active { color: var(--accent); }
.bnav-item svg { width: 22px; height: 22px; }

/* ===== CART FAB (mobile only) ===== */
#cart-fab {
  display: none;
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 99px;
  padding: 12px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  z-index: 100;
  gap: 8px;
  align-items: center;
  box-shadow: 0 6px 24px rgba(124,58,237,0.55);
  white-space: nowrap;
}

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

/* ===== PRODUCT GRID ===== */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.product-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.product-card:active { transform: scale(0.97); }

/* ===== CART ===== */
.cart-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== BADGE ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
  white-space: nowrap;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: 0.88; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #6d28d9; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: rgba(128,128,128,0.1); }
.btn-danger { background: rgba(239,68,68,0.12); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.flex-1 { flex: 1; }

/* ===== INPUT ===== */
.input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }
.input::placeholder { color: var(--muted); }
select.input { cursor: pointer; }
select.input option { background: var(--surface); color: var(--text); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  animation: scaleIn 0.2s;
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 76px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.25s ease;
  max-width: 300px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  pointer-events: all;
}
.toast-success { background: #166534; color: #bbf7d0; }
.toast-error   { background: #991b1b; color: #fecaca; }
.toast-info    { background: #1e3a5f; color: #bfdbfe; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; min-width: 560px; }
.data-table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--surface2);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tbody tr:hover { background: rgba(128,128,128,0.05); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ===== PRINT ===== */
@media print {
  * { margin: 0 !important; padding: 0 !important; background: transparent !important; box-shadow: none !important; }
  body { background: #fff !important; color: #000 !important; }
  body * { display: none !important; }
  #receipt-print { display: block !important; position: absolute !important; top: 0 !important; left: 0 !important; width: 80mm !important; }
  #receipt-print * { display: block !important; color: #000 !important; background: transparent !important; text-align: left !important; }
  #receipt-print div { margin: 0 !important; padding: 0 !important; }
  @page { size: 80mm auto; margin: 0; padding: 0; }
}

/* ===== MISC ===== */
.tab-btn {
  padding: 7px 15px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
}
.tab-btn.active { background: rgba(128,128,128,0.15); color: var(--text); }
.qty-btn {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 17px;
  font-weight: 500;
  transition: background 0.15s;
  flex-shrink: 0;
}
.qty-btn:hover { background: rgba(128,128,128,0.2); }
#login-screen {
  position: fixed; inset: 0;
  background: var(--sidebar-bg);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }
.chart-container { position: relative; height: 200px; }
label { color: var(--muted); font-size: 13px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  /* Hide desktop sidebar */
  #sidebar { display: none !important; }

  /* Show bottom nav */
  #bottom-nav { display: flex !important; }

  /* Add padding for bottom nav */
  #app { padding-bottom: 62px; }

  /* POS: products fill screen, cart is overlay */
  #view-pos { flex-direction: column; position: relative; }
  #pos-products-area { width: 100% !important; }
  #pos-products { grid-template-columns: repeat(2, 1fr) !important; }

  /* Cart panel: slide from bottom */
  #pos-cart-panel {
    position: fixed !important;
    bottom: 62px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 75vh !important;
    border-radius: 18px 18px 0 0 !important;
    border-left: none !important;
    border-top: 1px solid var(--border) !important;
    transform: translateY(105%) !important;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1) !important;
    z-index: 150 !important;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.4);
  }
  #pos-cart-panel.cart-open { transform: translateY(0) !important; }

  /* Cart drag handle */
  #cart-fab { display: flex !important; }

  /* Stats 2 col */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Reports charts stack */
  .reports-charts { grid-template-columns: 1fr !important; }

  /* Barcodes stack */
  .bc-grid { grid-template-columns: 1fr !important; }

  /* View padding smaller */
  .view { padding: 14px; }

  /* Modal from bottom */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-width: 100%; max-height: 92vh; }

  /* Header compact */
  header { height: 52px; padding: 0 14px; }

  /* Toast */
  #toast-container { bottom: 80px; right: 12px; }
}

@media (max-width: 480px) {
  #pos-products { grid-template-columns: repeat(2, 1fr) !important; }
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .view { padding: 12px; }
}

/* ===== MOBILE MENU DRAWER ===== */
.mob-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 8px;
  border-radius: 12px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  background: rgba(255,255,255,0.05);
  transition: background 0.15s, color 0.15s;
}
.mob-menu-item:hover,
.mob-menu-item:active { background: rgba(255,255,255,0.12); color: #fff; }
.mob-menu-item svg { width: 24px; height: 24px; flex-shrink: 0; }
html[data-theme="light"] .mob-menu-item { color: rgba(0,0,0,0.65); background: rgba(0,0,0,0.05); }
html[data-theme="light"] #mobile-menu-drawer { background: #fff; }

/* Responsive fixes adicionales */
@media (max-width: 900px) {
  /* Login centrado en móvil */
  #login-screen > div { width: 90% !important; max-width: 360px; }

  /* Tablas scrollables en móvil */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Inputs más grandes para touch */
  input[type="text"], input[type="number"], input[type="email"],
  input[type="password"], input[type="tel"], select, textarea {
    font-size: 16px !important; /* evita zoom en iOS */
  }

  /* POS: grid de productos */
  #pos-products { grid-template-columns: repeat(2, 1fr) !important; }

  /* Cards de stats 2 columnas */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 380px) {
  #mobile-menu-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .mob-menu-item { font-size: 10px; padding: 10px 4px; }
}

/* ===== LOGIN LOGO ===== */
.logo-login {
  display: block;
  max-width: 210px;
  width: 100%;
  height: auto;
  object-fit: contain;
  margin: 0 auto 1.5rem;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,.45));
}
@media (max-width: 768px) {
  .logo-login { max-width: 180px; }
}
