/* VíveresPRO — Design System v3 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; display: block; }

/* ── TEMA CLARO (defecto) ── */
:root, [data-theme="light"] {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #6366f1;
  --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,.1);
  --success: #22c55e;
  --success-bg: #f0fdf4; --success-text: #166534; --success-border: #bbf7d0;
  --warning: #f59e0b;
  --warning-bg: #fffbeb; --warning-text: #92400e; --warning-border: #fde68a;
  --danger: #ef4444;
  --danger-bg: #fef2f2; --danger-text: #991b1b; --danger-border: #fecaca;
  --info: #3b82f6;
  --info-bg: #eff6ff; --info-text: #1e40af; --info-border: #bfdbfe;
  --radius: .5rem;
  --radius-lg: .75rem;
}

/* ── TEMA OSCURO ── */
[data-theme="dark"] {
  --bg-primary: #0f172a; --bg-secondary: #1e293b; --bg-tertiary: #334155;
  --text-primary: #f1f5f9; --text-secondary: #94a3b8; --text-muted: #64748b;
  --border: #334155; --border-focus: #818cf8;
  --success-bg: #14532d; --success-text: #86efac; --success-border: #166534;
  --warning-bg: #451a03; --warning-text: #fcd34d; --warning-border: #92400e;
  --danger-bg: #450a0a; --danger-text: #fca5a5; --danger-border: #991b1b;
  --info-bg: #1e3a5f; --info-text: #93c5fd; --info-border: #1e40af;
}

/* ── BODY ── */
body {
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL
   ═══════════════════════════════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
}

/* ── SIDEBAR: cabecera ── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  min-height: 64px;
  flex-shrink: 0;
}
.sidebar-logo {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: .375rem;
  flex-shrink: 0;
}
.sidebar-brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── SIDEBAR: navegación ── */
.sidebar-nav {
  padding: .5rem 0;
  flex: 1;
}
.sidebar-section {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: .625rem 1.25rem .25rem;
}

/* ── SIDEBAR: items ── */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .55rem 1.25rem;
  color: var(--text-secondary);
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none !important;
  transition: background .12s, color .12s;
  border-left: 3px solid transparent;
  white-space: nowrap;
  cursor: pointer;
}
/* ⬇ CRÍTICO: limitar tamaño de SVG dentro del menú */
.sidebar-item svg,
.sidebar-nav svg {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  min-height: 16px;
  flex-shrink: 0;
}
.sidebar-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-item.active {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidebar-footer {
  padding: .75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ── TOPBAR ── */
.topbar {
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: .5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: .65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  pointer-events: none;
}

/* ── PAGE CONTENT ── */
.page-content {
  padding: 1.5rem;
  flex: 1;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title   { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.page-subtitle { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }

/* ═══════════════════════════════════════════════════════════════
   COMPONENTES UI
   ═══════════════════════════════════════════════════════════════ */

/* ── CARD ── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── BOTONES ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none !important;
  line-height: 1.4;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary   { background: var(--primary);    color: #fff;                   border-color: var(--primary);       }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline   { background: transparent;        color: var(--text-primary);    border-color: var(--border);        }
.btn-outline:hover { background: var(--bg-tertiary); }
.btn-ghost     { background: transparent;        color: var(--text-secondary);  border-color: transparent;          }
.btn-ghost:hover { background: var(--bg-tertiary); }
.btn-success   { background: var(--success);     color: #fff;                   border-color: var(--success);       }
.btn-danger    { background: var(--danger-bg);   color: var(--danger-text);     border-color: var(--danger-border); }

.btn-sm  { padding: .25rem .625rem; font-size: .8rem; }
.btn-lg  { padding: .75rem 1.5rem;  font-size: 1rem;  }
.btn-xl  { padding: 1rem 2rem;      font-size: 1.1rem; }
.btn-block  { width: 100%; }
.btn-icon   { padding: .5rem; aspect-ratio: 1; position: relative; }

/* ── FORMULARIOS ── */
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: .375rem;
}
.form-control,
.form-select {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: .875rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
textarea.form-control { resize: vertical; min-height: 80px; }
input[type="color"].form-control { padding: .2rem .4rem; cursor: pointer; }

/* ── TABLA ── */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th {
  background: var(--bg-tertiary);
  padding: .625rem .75rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  white-space: nowrap;
}
.table td {
  padding: .625rem .75rem;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-tertiary); }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 9999px;
  font-size: .72rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border);  }
.badge-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border);    }

/* ── ALERTS ── */
.alert {
  padding: .875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: .875rem;
  margin-bottom: 1rem;
}
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border);  }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border);    }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; margin: 0; }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  font-weight: 500;
  min-width: 240px;
  max-width: 360px;
  border-left: 4px solid;
  animation: toastIn .2s ease;
  pointer-events: all;
}
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success); }
.toast-error   { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger);  }
.toast-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning); }
.toast-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info);    }

/* ═══════════════════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 1rem;
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

/* ═══════════════════════════════════════════════════════════════
   POS
   ═══════════════════════════════════════════════════════════════ */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: calc(100vh - 52px);
  overflow: hidden;
}
.pos-products {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}
.pos-cats {
  display: flex;
  gap: .375rem;
  padding: .5rem .75rem;
  overflow-x: auto;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pos-cats::-webkit-scrollbar { height: 3px; }
.cat-btn {
  padding: .3rem .7rem;
  border-radius: 2rem;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all .12s;
}
.cat-btn.active,
.cat-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .625rem;
  padding: .75rem;
  overflow-y: auto;
  align-content: start;
  flex: 1;
}
.pcard {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: .625rem;
  padding: .625rem;
  cursor: pointer;
  transition: all .12s;
  user-select: none;
}
.pcard:hover  { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.pcard:active { transform: scale(.96); }
.pcard-img    { width: 100%; height: 72px; object-fit: cover; border-radius: .375rem; margin-bottom: .375rem; background: var(--bg-tertiary); }
.pcard-name   { font-size: .8rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: .25rem; }
.pcard-price  { font-size: .95rem; font-weight: 800; color: var(--primary); }
.pcard-stock  { font-size: .7rem; color: var(--text-muted); }
.pcard-nostock { opacity: .4; cursor: not-allowed; }

.pos-cart {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow: hidden;
}
.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .625rem .75rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
}
.cart-items { flex: 1; overflow-y: auto; padding: .5rem .75rem; }
.cart-footer {
  padding: .75rem;
  border-top: 2px solid var(--border);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}
.cart-total { display: flex; justify-content: space-between; align-items: center; margin-bottom: .625rem; }
.cart-total-label { font-size: .9rem; color: var(--text-muted); }
.cart-total-val   { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.cart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); gap: .5rem; font-size: .875rem; text-align: center; }
.citem { display: flex; align-items: center; gap: .375rem; padding: .375rem 0; border-bottom: 1px solid var(--border); font-size: .8rem; }
.citem-name  { flex: 1; font-weight: 500; line-height: 1.3; }
.citem-price { color: var(--primary); font-weight: 700; font-size: .85rem; white-space: nowrap; }
.qty-ctrl { display: flex; align-items: center; gap: 2px; }
.qb {
  width: 22px; height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-tertiary);
  cursor: pointer;
  font-weight: 700;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}
.qb:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.qnum { width: 28px; text-align: center; font-weight: 700; font-size: .85rem; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-content {
    margin-left: 0;
  }
  .pos-layout {
    grid-template-columns: 1fr;
  }
  .pos-cart {
    position: fixed;
    bottom: 0; right: 0; left: 0;
    height: 55vh;
    transform: translateY(100%);
    transition: transform .2s;
    z-index: 50;
  }
  .pos-cart.open { transform: translateY(0); }
}
@media (max-width: 768px) {
  .page-header { flex-direction: column; }
  .page-content { padding: 1rem; }
  .table { font-size: .8rem; }
  .table th, .table td { padding: .5rem; }
}

/* ══════════════════════════════════════════════════════════
   ADMIN RESPONSIVE — Small screens
   ══════════════════════════════════════════════════════════ */

/* Topbar hamburger always visible */
#btn-menu { display: flex !important; }

/* Page header wraps on small screens */
@media (max-width: 640px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .625rem;
  }
  .page-header > div:last-child,
  .page-header > a,
  .page-header > button {
    width: 100%;
  }
  .page-header .btn { width: 100%; justify-content: center; }
  .page-content { padding: .75rem; }

  /* Cards: full width stacked */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  /* Exception: 2-col form grids get 1fr 1fr on 400+ */
}

@media (min-width: 401px) and (max-width: 640px) {
  .grid-2col { grid-template-columns: 1fr 1fr !important; }
}

/* Tables: horizontal scroll + smaller text */
@media (max-width: 640px) {
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: .75rem; min-width: 480px; }
  .table th, .table td { padding: .375rem .5rem; white-space: nowrap; }
  .badge { font-size: .65rem; padding: .1rem .35rem; }
  /* Hide less important columns on mobile */
  .table .hide-mobile { display: none !important; }
}

/* Form controls full width */
@media (max-width: 640px) {
  .form-control, .form-select { font-size: 16px; } /* Prevents iOS zoom */
  .btn-sm { padding: .3rem .6rem; font-size: .78rem; }
}

/* Sidebar overlay on mobile */
@media (max-width: 1024px) {
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 199;
  }
  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.active { display: block; }
}

/* Stats grid responsive */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Modal full screen on very small devices */
@media (max-width: 480px) {
  .modal {
    max-width: 100% !important;
    margin: 0;
    border-radius: 1rem 1rem 0 0;
  }
  .modal-overlay {
    align-items: flex-end;
  }
}

/* Topbar actions: icon-only on small screens */
@media (max-width: 480px) {
  .topbar .btn span.hide-mobile { display: none; }
  .topbar { padding: 0 .5rem; gap: .25rem; }
}

/* ── Admin page-specific responsive ── */
@media (max-width: 640px) {
  /* Topbar title hidden on large, visible on mobile */
  .topbar-title { display: block; }
  /* Stack action buttons */
  .page-header .btn + .btn { margin-top: .25rem; }
  /* Tighter card padding */
  .card > [style*="padding:1.25rem"] { padding: .875rem !important; }
  .card > [style*="padding:1.5rem"]  { padding: .875rem !important; }
  /* Form grids: single column */
  [style*="grid-template-columns:repeat(auto-fit,minmax(280px,1fr))"] {
    grid-template-columns: 1fr !important;
  }
  [style*="grid-template-columns:min("] {
    grid-template-columns: 1fr !important;
  }
  /* Table action buttons */
  .table .btn-sm { padding: .2rem .4rem; font-size: .72rem; }
  /* Overflow table wrapper */
  [style*="overflow-x:auto"] { border-radius: 0; }
}

@media (max-width: 640px) {
  .topbar-title { display: block !important; }
}
@media (min-width: 641px) {
  .topbar-title { display: none; }
}
