/* ===== VARIABLES Y RESET ===== */
:root {
  --primary: #019ee3;
  --primary-dark: #0180b8;
  --primary-light: #4db8e8;
  --accent: #00cec9;
  --bg: #f0f2f5;
  --sidebar-bg: #01567a;
  --sidebar-hover: #017aab;
  --card: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --border: #dfe6e9;
  --success: #00b894;
  --danger: #e74c3c;
  --warning: #fdcb6e;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --transition: all 0.2s ease;

  /* Fluid spacing & sizing — scale with viewport */
  --sidebar-width: clamp(200px, 15vw, 280px);
  --cart-width: clamp(300px, 25vw, 420px);
  --content-padding: clamp(12px, 2vw, 32px);
  --card-padding: clamp(14px, 1.8vw, 28px);

  /* Fluid typography */
  --fs-xs: clamp(0.65rem, 0.6rem + 0.25vw, 0.78rem);
  --fs-sm: clamp(0.72rem, 0.65rem + 0.35vw, 0.88rem);
  --fs-base: clamp(0.8rem, 0.72rem + 0.4vw, 1rem);
  --fs-md: clamp(0.88rem, 0.78rem + 0.5vw, 1.1rem);
  --fs-lg: clamp(1rem, 0.85rem + 0.7vw, 1.35rem);
  --fs-xl: clamp(1.2rem, 1rem + 1vw, 1.8rem);
  --fs-stat: clamp(1.2rem, 1rem + 1.2vw, 2rem);
}

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

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  font-size: var(--fs-base);
}

/* ===== LOGIN ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #01567a 0%, #019ee3 50%, #4db8e8 100%);
}

.login-card {
  background: var(--card);
  padding: clamp(28px, 4vw, 48px) clamp(24px, 3.5vw, 40px);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: clamp(300px, 85vw, 400px);
  text-align: center;
}

.login-card h1 {
  font-size: var(--fs-xl);
  color: var(--primary);
  margin-bottom: 8px;
}

.login-card p { color: var(--text-light); margin-bottom: clamp(16px, 3vw, 32px); font-size: var(--fs-sm); }

.form-group {
  margin-bottom: clamp(12px, 1.5vw, 20px);
  text-align: left;
}

.form-group label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: clamp(8px, 1vw, 12px) clamp(10px, 1.2vw, 16px);
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: var(--fs-base);
  transition: var(--transition);
  outline: none;
  font-family: inherit;
  background: white;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1,158,227,0.15);
}

/* ===== BOTONES ===== */
.btn {
  padding: clamp(8px, 1vw, 12px) clamp(14px, 1.8vw, 24px);
  border: none;
  border-radius: 10px;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #00a381; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-sm { padding: clamp(4px, 0.5vw, 8px) clamp(8px, 1vw, 16px); font-size: var(--fs-xs); }
.btn-lg { padding: clamp(10px, 1.2vw, 14px) clamp(20px, 2.5vw, 32px); font-size: var(--fs-base); }
.btn-block { width: 100%; justify-content: center; }

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

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
}

.sidebar-header {
  padding: clamp(14px, 1.8vw, 24px) clamp(12px, 1.5vw, 20px);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  color: white;
  font-size: var(--fs-md);
  font-weight: 700;
}

.sidebar-header span {
  color: var(--primary-light);
  font-size: var(--fs-xs);
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: clamp(8px, 0.8vw, 12px);
  padding: clamp(8px, 1vw, 12px) clamp(12px, 1.5vw, 20px);
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--sidebar-hover); color: white; }

.nav-item.active {
  background: var(--sidebar-hover);
  color: white;
  border-left-color: var(--accent);
}

.nav-item .icon { font-size: var(--fs-md); width: 24px; text-align: center; }

.sidebar-footer {
  padding: clamp(10px, 1.2vw, 16px) clamp(12px, 1.5vw, 20px);
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.user-avatar {
  width: clamp(28px, 2.5vw, 40px);
  height: clamp(28px, 2.5vw, 40px);
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: var(--fs-xs);
}

.user-name { color: white; font-size: var(--fs-xs); font-weight: 600; }
.user-role { color: var(--primary-light); font-size: var(--fs-xs); text-transform: capitalize; }

/* ===== CONTENIDO PRINCIPAL ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.top-bar {
  background: var(--card);
  padding: clamp(10px, 1.2vw, 16px) var(--content-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  z-index: 10;
}

.top-bar h1 { font-size: var(--fs-lg); color: var(--text); }

.content-area {
  flex: 1;
  padding: var(--content-padding);
  overflow-y: auto;
}

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--card-padding);
  margin-bottom: clamp(12px, 1.5vw, 20px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(12px, 1.5vw, 20px);
  flex-wrap: wrap;
  gap: 8px;
}

.card-header h3 { font-size: var(--fs-base); color: var(--text); }

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(130px, 12vw, 220px), 1fr));
  gap: clamp(8px, 1vw, 16px);
  margin-bottom: clamp(12px, 1.8vw, 24px);
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: clamp(12px, 1.5vw, 20px);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}

.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }

.stat-value { font-size: var(--fs-stat); font-weight: 700; color: var(--text); }
.stat-label { font-size: var(--fs-xs); color: var(--text-light); margin-top: 4px; }

/* ===== TABLAS ===== */
.table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

thead th {
  background: var(--bg);
  padding: clamp(8px, 1vw, 12px) clamp(8px, 1.2vw, 16px);
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
}

tbody td {
  padding: clamp(8px, 1vw, 12px) clamp(8px, 1.2vw, 16px);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: rgba(1,158,227,0.04); }

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  gap: clamp(8px, 1vw, 12px);
  margin-bottom: clamp(12px, 1.5vw, 20px);
  flex-wrap: wrap;
}

.search-bar input {
  flex: 1;
  min-width: 150px;
  padding: clamp(8px, 0.8vw, 10px) clamp(10px, 1.2vw, 16px);
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: var(--fs-sm);
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}

.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1,158,227,0.15);
}

/* ===== VENTAS - LAYOUT DOS COLUMNAS ===== */
.sales-layout {
  display: grid;
  grid-template-columns: 1fr var(--cart-width);
  gap: clamp(12px, 1.5vw, 20px);
  height: calc(100vh - clamp(100px, 10vw, 140px));
}

.products-panel { overflow-y: auto; }

.cart-panel {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cart-header {
  padding: clamp(10px, 1.2vw, 16px) clamp(12px, 1.5vw, 20px);
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: var(--fs-base);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: clamp(8px, 1vw, 12px);
}

.cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(6px, 0.8vw, 10px) clamp(8px, 1vw, 12px);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg);
  font-size: var(--fs-xs);
}

.cart-item-name { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-item-qty { color: var(--text-light); margin: 0 clamp(6px, 0.8vw, 12px); }
.cart-item-price { font-weight: 600; color: var(--primary); white-space: nowrap; }

.cart-item-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: var(--fs-base);
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: var(--transition);
}
.cart-item-remove:hover { background: rgba(231,76,60,0.1); }

.cart-footer {
  padding: clamp(10px, 1.2vw, 16px) clamp(12px, 1.5vw, 20px);
  border-top: 2px solid var(--border);
}

.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-lg);
  font-weight: 700;
  margin-bottom: clamp(10px, 1.2vw, 16px);
  color: var(--text);
}

/* ===== PRODUCTOS GRID ===== */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(130px, 12vw, 200px), 1fr));
  gap: clamp(8px, 0.8vw, 12px);
}

.product-card {
  background: var(--card);
  border-radius: 10px;
  padding: clamp(10px, 1.2vw, 16px);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
  text-align: center;
}

.product-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.product-name { font-weight: 600; font-size: var(--fs-xs); margin-bottom: 6px; }
.product-code { font-size: var(--fs-xs); color: var(--text-light); margin-bottom: 8px; }
.product-price { font-size: var(--fs-md); font-weight: 700; color: var(--primary); }
.product-stock { font-size: var(--fs-xs); color: var(--success); margin-top: 4px; }
.product-stock.low { color: var(--danger); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 16px;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: var(--card-padding);
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base);
}

.modal h2 { margin-bottom: clamp(14px, 1.8vw, 24px); font-size: var(--fs-lg); }
.modal-actions { display: flex; gap: clamp(8px, 1vw, 12px); justify-content: flex-end; margin-top: clamp(14px, 1.8vw, 24px); flex-wrap: wrap; }

/* ===== BADGES ===== */
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(0,184,148,0.15); color: var(--success); }
.badge-warning { background: rgba(253,203,110,0.3); color: #e17055; }
.badge-danger { background: rgba(231,76,60,0.15); color: var(--danger); }
.badge-primary { background: rgba(1,158,227,0.15); color: var(--primary); }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: clamp(10px, 1.2vw, 14px) clamp(14px, 1.5vw, 20px);
  border-radius: 10px;
  color: white;
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  min-width: 240px;
  max-width: 90vw;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== PAYMENT METHOD SELECTOR ===== */
.payment-methods {
  display: flex;
  gap: clamp(4px, 0.6vw, 8px);
  margin-bottom: clamp(10px, 1.2vw, 16px);
  flex-wrap: wrap;
}

.payment-method-btn {
  flex: 1;
  min-width: 80px;
  padding: clamp(6px, 0.8vw, 10px);
  border: 2px solid var(--border);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  transition: var(--transition);
  font-family: inherit;
}

.payment-method-btn.active {
  border-color: var(--primary);
  background: rgba(1,158,227,0.08);
  color: var(--primary);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: clamp(24px, 3vw, 48px) 20px;
  color: var(--text-light);
}

.empty-state .icon { font-size: clamp(2rem, 3vw, 3rem); margin-bottom: 12px; }
.empty-state p { font-size: var(--fs-sm); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== RESPONSIVE ===== */

/* Pantallas grandes (1600px+) — más espacio, tipografía más cómoda */
@media (min-width: 1600px) {
  :root {
    --sidebar-width: 260px;
    --cart-width: 400px;
  }
}

/* Pantallas medianas-grandes (1200-1024) */
@media (max-width: 1200px) {
  .sales-layout { grid-template-columns: 1fr var(--cart-width); }
}

/* Tablets / pantallas pequeñas (1024px) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
    --cart-width: 300px;
  }
  .sales-layout { grid-template-columns: 1fr; height: auto; }
  .cart-panel { max-height: 400px; }
}

/* Tablets portrait / móviles landscape (768px) */
@media (max-width: 768px) {
  body { overflow: auto; height: auto; }
  .app-layout { flex-direction: column; height: auto; overflow: auto; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
  }
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .nav-item {
    padding: 10px 14px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .sidebar-header { padding: 10px 14px; }
  .sidebar-header h2 { font-size: var(--fs-base); }
  .sidebar-footer { display: none; }

  .main-content { height: auto; overflow: visible; }
  .top-bar h1 { font-size: var(--fs-md); }

  .sales-layout { grid-template-columns: 1fr; height: auto; }
  .cart-panel { max-height: 350px; }

  .modal { max-width: 95vw !important; width: 95vw !important; }
}

/* Móviles (480px) */
@media (max-width: 480px) {
  .sidebar-header { display: none; }
  .nav-item { padding: 8px 10px; font-size: 0; gap: 0; }
  .nav-item .icon { font-size: 1.3rem; }

  .products-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  .cart-total { font-size: var(--fs-md); }
  .login-card { width: 92vw; }

  .payment-methods { flex-wrap: wrap; }
  .payment-method-btn { min-width: calc(50% - 4px); flex: unset; }
}
