/* ============================================================
   CarniHub — Custom Styles
   Uses Tailwind CDN as base; this file adds custom overrides
   ============================================================ */

:root {
  --color-primario:       #C8102E;
  --color-primario-hover: #A00D24;
  --color-primario-light: #FEE2E2;
  --sidebar-bg:           #1A1D23;
  --sidebar-text:         #9CA3AF;
  --sidebar-text-active:  #FFFFFF;
  --sidebar-active-bg:    #C8102E;
  --bg-content:           #F3F4F6;
  --card-bg:              #FFFFFF;
  --text-primary:         #111827;
  --text-secondary:       #6B7280;
  --border-color:         #E5E7EB;
  --success:              #10B981;
  --warning:              #F59E0B;
  --danger:               #EF4444;
  --info:                 #3B82F6;
}

/* ── Base ─────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  font-family: 'Inter', 'Roboto', sans-serif;
  background: var(--bg-content);
  color: var(--text-primary);
  margin: 0;
}

/* ── Sidebar Admin ────────────────────────────────── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 20px 24px;
  border-bottom: 1px solid #2D3139;
}

.sidebar-logo img, .sidebar-logo svg {
  height: 36px;
}

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

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--sidebar-text-active);
  background: rgba(200,16,46,0.12);
  border-left-color: var(--color-primario);
}

.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4B5563;
  padding: 16px 20px 4px;
}

/* ── Main Content ─────────────────────────────────── */
.main-content {
  margin-left: 240px;
  min-height: 100vh;
  background: var(--bg-content);
}

.topbar {
  background: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; z-index: 50;
}

.page-content { padding: 24px; }

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  padding: 20px;
}

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

.card-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }

/* ── KPI Cards ────────────────────────────────────── */
.kpi-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); }
.kpi-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 4px; }

.kpi-delta { font-size: 0.75rem; font-weight: 600; }
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger);  }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--color-primario);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primario-hover); }

.btn-secondary {
  background: #F3F4F6;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: #E5E7EB; }

.btn-danger  { background: var(--danger);  color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm      { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg      { padding: 12px 28px; font-size: 1rem; border-radius: 10px; }
.btn-block   { width: 100%; justify-content: center; }
.btn-outline-primary {
  background: transparent;
  border: 1.5px solid var(--color-primario);
  color: var(--color-primario);
}
.btn-outline-primary:hover { background: var(--color-primario); color: #fff; }

/* ── Badges / Status ──────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-success  { background: #D1FAE5; color: #065F46; }
.badge-warning  { background: #FEF3C7; color: #92400E; }
.badge-danger   { background: #FEE2E2; color: #991B1B; }
.badge-info     { background: #DBEAFE; color: #1E40AF; }
.badge-gray     { background: #F3F4F6; color: #374151; }
.badge-blue     { background: #EFF6FF; color: #1D4ED8; }
.badge-orange   { background: #FFF7ED; color: #C2410C; }

/* Estado pedido */
.estado-pendiente      { @apply badge badge-warning; }
.estado-confirmado     { @apply badge badge-blue; }
.estado-en_preparacion { @apply badge badge-orange; }
.estado-en_ruta        { @apply badge badge-info; }
.estado-entregado      { @apply badge badge-success; }
.estado-cancelado      { @apply badge badge-danger; }

/* ── Tables ───────────────────────────────────────── */
.table-container {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

table { width: 100%; border-collapse: collapse; background: #fff; }
thead th {
  background: #F9FAFB;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}
tbody td {
  padding: 12px 14px;
  font-size: 0.875rem;
  border-bottom: 1px solid #F3F4F6;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #FAFAFA; }

/* ── Forms ────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--color-primario); box-shadow: 0 0 0 3px rgba(200,16,46,0.1); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236B7280'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 36px;
}

/* ── Pagination ───────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 0 0;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  background: #fff;
}
.pagination a:hover  { background: var(--color-primario-light); color: var(--color-primario); }
.pagination .active  { background: var(--color-primario); color: #fff; border-color: var(--color-primario); }

/* ── Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-body  { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Toast ────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #fff;
  border-radius: 10px;
  padding: 14px 18px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  border-left: 4px solid var(--info);
  min-width: 280px;
  font-size: 0.875rem;
  animation: slideIn 0.3s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

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

/* ── Checkout Steps ───────────────────────────────── */
.checkout-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 32px;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #9CA3AF;
}
.step-number {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #E5E7EB;
  color: #6B7280;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}
.step.active .step-number { background: var(--color-primario); color: #fff; }
.step.active              { color: var(--color-primario); }
.step.done .step-number   { background: var(--success); color: #fff; }
.step.done                { color: var(--success); }
.step-line { flex: 1; height: 2px; background: #E5E7EB; min-width: 40px; }
.step.done ~ .step-line { background: var(--success); }

/* ── Carrito Multi-sucursal ───────────────────────── */
.carrito-table th.sucursal-col { background: #EFF6FF; color: #1E40AF; text-align: center; }
.carrito-table td.cantidad-input { text-align: center; }
.carrito-table input[type="number"] {
  width: 70px;
  padding: 5px 8px;
  border: 1.5px solid #D1D5DB;
  border-radius: 6px;
  text-align: center;
  font-size: 0.875rem;
}

.subtotal-sucursal {
  background: #F8FAFC;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
}

/* ── Repartidor Dark Theme ────────────────────────── */
body.repartidor-theme {
  background: #111827;
  color: #F9FAFB;
}
.rep-card {
  background: #1F2937;
  border-radius: 14px;
  padding: 18px;
  border: 1px solid #374151;
}
.rep-topbar {
  background: #111827;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1F2937;
}

/* ── Bottom Nav (Mobile) ──────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border-color);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  text-decoration: none;
  color: #9CA3AF;
  font-size: 0.65rem;
  font-weight: 600;
  gap: 3px;
  transition: color 0.2s;
}
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--color-primario); }

body.repartidor-theme .bottom-nav {
  background: #1F2937;
  border-top-color: #374151;
}
body.repartidor-theme .bottom-nav-item { color: #6B7280; }
body.repartidor-theme .bottom-nav-item.active { color: var(--color-primario); }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar       { transform: translateX(-100%); }
  .sidebar.open  { transform: translateX(0); }
  .main-content  { margin-left: 0; padding-bottom: 70px; }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 99;
  }
  .sidebar-overlay.active { display: block; }
  .hide-mobile { display: none !important; }
}

@media (min-width: 769px) {
  .bottom-nav  { display: none; }
  .hide-desktop { display: none !important; }
}

/* ── Precios Escalonados Table ────────────────────── */
.precio-table { width: 100%; }
.precio-table tr.precio-highlight td { background: #FEF2F2; font-weight: 700; color: var(--color-primario); }

/* ── Signature Pad ────────────────────────────────── */
#signature-pad {
  border: 2px dashed #D1D5DB;
  border-radius: 12px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

/* ── Loading ──────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid #E5E7EB;
  border-top-color: var(--color-primario);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Leaflet map container ────────────────────────── */
.map-container {
  height: 420px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}
