/* ==========================================================================
   TomaPedidos TAT - Design System & Responsive Styles (Tablet & Mobile First)
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-dark: #1e3a8a;
  
  --secondary: #0f172a;
  --secondary-surface: #1e293b;
  
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-light: #ecfdf5;

  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #06b6d4;

  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 10px -1px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.12);
  --shadow-float: 0 14px 34px -4px rgba(37,99,235,0.25);

  --sidebar-width: 250px;
  --touch-target: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
  font-size: 15px;
}

/* Scrollbar estilizada */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* ================= Layout Structure ================= */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  background: var(--bg);
}

/* Sidebar para Escritorio y Tablet Horizontal */
.sidebar {
  width: var(--sidebar-width);
  background: var(--secondary);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  font-weight: bold;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 16px 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-link i {
  font-size: 18px;
  color: #94a3b8;
  transition: color 0.2s;
}

.nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.nav-link:hover i {
  color: #fff;
}

.nav-link.active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.nav-link.active i {
  color: #ffffff;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.2);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #334155;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-info-text {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: #94a3b8;
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: calc(100vw - var(--sidebar-width));
}

/* Top App Header */
.app-header {
  height: 64px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-toggle-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--secondary);
  cursor: pointer;
  padding: 6px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--secondary);
}

.company-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.online-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 10px;
  background: var(--accent-light);
  border-radius: 12px;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

/* Page Container */
.page-content {
  padding: 24px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ================= UI Components ================= */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Botones con estilo táctil */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  min-height: 42px;
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}
.btn-accent:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(16,185,129,0.3);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  min-height: 32px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 24px;
  min-height: var(--touch-target);
  font-size: 16px;
  border-radius: var(--radius-lg);
}

.btn-block {
  width: 100%;
}

/* Form Controls */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #334155;
}

.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  font-size: 14.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text-main);
  outline: none;
  min-height: 44px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 12px;
}

.badge-success { background: var(--accent-light); color: var(--accent-hover); }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-danger { background: var(--danger-light); color: #b91c1c; }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* Grid de Métricas / KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--secondary);
  margin-top: 4px;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

/* ================= Vendedor / Tablet Module Styles ================= */
.tablet-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  height: calc(100vh - 110px);
}

/* Panel Izquierdo: Rutero / Clientes */
.client-sidebar {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.client-sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.client-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.client-item {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: #ffffff;
}

.client-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.client-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px var(--primary);
}

.client-name {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--secondary);
}

.client-address {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.client-debt {
  font-size: 11px;
  color: #dc2626;
  font-weight: 700;
}

/* Panel Derecho: Catálogo de Productos para Tablet */
.catalog-panel {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.catalog-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cat-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  width: 100%;
}

.cat-pill {
  padding: 6px 14px;
  border-radius: 20px;
  background: #ffffff;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  color: #475569;
  transition: all 0.2s;
}

.cat-pill:hover, .cat-pill.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.product-grid {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.product-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

/* Recuadro de Foto del Producto en Toma de Pedidos */
.product-card .product-thumb {
  width: 100%;
  height: 110px;
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  overflow: hidden;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e2e8f0;
}

.product-card .product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.product-card:hover .product-thumb img {
  transform: scale(1.05);
}

/* Modo Compacto sin Fotos (cuando el vendedor las oculta para rapidez/ahorro de datos) */
.product-grid.no-images .product-thumb {
  display: none !important;
}

.product-grid.no-images {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.product-grid.no-images .product-card {
  padding: 8px 10px;
}

.product-grid.no-images .product-name {
  margin: 2px 0 4px 0;
  font-size: 12.5px;
}

.product-grid.no-images .stepper-btn {
  height: 32px;
  width: 32px;
}

.product-grid.no-images .stepper-input {
  height: 32px;
  width: 36px;
}


.product-sku {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
}

.product-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--secondary);
  line-height: 1.3;
  margin: 4px 0 8px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
}

.product-stock {
  font-size: 11.5px;
  margin-bottom: 10px;
}

.stock-in { color: #059669; font-weight: 600; }
.stock-low { color: #d97706; font-weight: 600; }
.stock-out { color: #dc2626; font-weight: 700; }

/* Stepper táctil para agregar cantidades */
.qty-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f8fafc;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: #ffffff;
  font-size: 18px;
  font-weight: bold;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper-btn:active {
  background: #e2e8f0;
}

.stepper-input {
  width: 44px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  border: none;
  background: transparent;
  outline: none;
}

/* Barra flotante inferior de Carrito en Tablet / Celular */
.floating-cart-bar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  background: var(--secondary);
  color: #ffffff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 85;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
  transition: all 0.3s;
}

.cart-summary {
  display: flex;
  align-items: center;
  gap: 16px;
}

.cart-icon-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.cart-counter {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #ffffff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
}

.cart-total-text {
  font-size: 13px;
  color: #cbd5e1;
}

.cart-total-amount {
  font-size: 20px;
  font-weight: 800;
  color: #ffffff;
}

/* Modales */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--secondary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

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

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease;
  min-width: 280px;
}

.toast.toast-success { border-left: 4px solid var(--accent); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-warning { border-left: 4px solid var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(50px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Tablas Responsivas */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.custom-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.custom-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}

.custom-table tr:hover td {
  background: #f8fafc;
}

/* ================= Responsividad para Celular y Tablet Vertical ================= */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 95;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .main-wrapper {
    margin-left: 0;
    width: 100vw;
  }

  .header-toggle-btn {
    display: block;
  }

  .floating-cart-bar {
    left: 0;
  }

  .tablet-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .client-sidebar {
    height: 380px;
  }

  .catalog-panel {
    min-height: 500px;
  }
}

@media (max-width: 576px) {
  .page-content {
    padding: 14px;
    padding-bottom: 90px; /* Espacio para barra de carrito */
  }

  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .cart-total-amount {
    font-size: 16px;
  }
}
