/* ═══════════════════════════════════════════════
   CARDETEX — Sistema Integral de Operaciones
   Estilos globales
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --brand: #1E3A8A;
  --brand-light: #EEF2FF;
  --brand-dark: #162D6E;
  --accent: #F0A500;
  --danger: #D93025;
  --danger-light: #FDE8E7;
  --warn: #E37400;
  --warn-light: #FEF3E2;
  --info: #1A73E8;
  --info-light: #E8F0FE;
  --surface: #FFFFFF;
  --surface2: #F6F8FA;
  --surface3: #EEF1F5;
  --border: #DDE1E7;
  --border2: #C8CDD5;
  --text1: #1A1F2E;
  --text2: #4A5368;
  --text3: #8891A5;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.1);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text1);
  background: var(--surface2);
  line-height: 1.5;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
}

.sidebar-logo {
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo .logo-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.3px;
  color: #fff;
  line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 10px;
  color: rgba(255,255,255,.5);
  margin-top: 1px;
}

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

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.4);
  padding: 12px 10px 4px;
  font-weight: 500;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: all .15s;
  margin-bottom: 2px;
}

.nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 500; }

.nav-icon {
  width: 18px;
  height: 18px;
  opacity: .7;
  flex-shrink: 0;
}

.nav-link.active .nav-icon,
.nav-link:hover .nav-icon { opacity: 1; }

.sidebar-user {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--brand);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.user-name { font-size: 13px; color: rgba(255,255,255,.85); font-weight: 500; }
.user-rol  { font-size: 11px; color: rgba(255,255,255,.45); }

.btn-logout {
  margin-left: auto;
  background: none; border: none;
  color: rgba(255,255,255,.4);
  cursor: pointer; padding: 4px;
  border-radius: 4px;
  transition: color .15s;
}
.btn-logout:hover { color: rgba(255,255,255,.8); }

/* Main content */
.main { margin-left: 220px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky; top: 0;
  z-index: 50;
}

.topbar-title { font-size: 16px; font-weight: 600; color: var(--text1); }
.topbar-sep { color: var(--border2); }
.topbar-sub { font-size: 13px; color: var(--text3); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.page-body { padding: 24px 28px; flex: 1; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text1); }
.card-body { padding: 20px; }

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-outline {
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text1);
}
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b8271d; }

.btn-ghost { background: none; border: none; color: var(--text2); padding: 6px 10px; }
.btn-ghost:hover { background: var(--surface3); color: var(--text1); }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-icon { padding: 7px; }

/* Formularios */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text1);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11,110,79,.12);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; gap: 14px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Tabla */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text1);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

.td-mono { font-family: var(--font-mono); font-size: 12.5px; }
.td-muted { color: var(--text3); font-size: 12.5px; }

/* Badges / Status */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-green  { background: #DCFCE7; color: #166534; }
.badge-blue   { background: #EEF2FF; color: #1E3A8A; }
.badge-blue   { background: #E8F0FE; color: #1A73E8; }
.badge-amber  { background: #FEF3E2; color: #B45300; }
.badge-gray   { background: var(--surface3); color: var(--text2); }
.badge-red    { background: var(--danger-light); color: var(--danger); }
.badge-purple { background: #F0EBFF; color: #5B2FC9; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-lg { max-width: 860px; }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  margin-left: auto;
  background: none; border: none;
  cursor: pointer; color: var(--text3);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-size: 20px; line-height: 1;
}
.modal-close:hover { background: var(--surface3); color: var(--text1); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Stats / KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label { font-size: 12px; color: var(--text3); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 26px; font-weight: 600; color: var(--text1); letter-spacing: -.5px; }
.kpi-sub { font-size: 12px; color: var(--text3); }
.kpi-accent { border-left: 3px solid var(--brand); }

/* Search bar */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

.search-bar:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11,110,79,.12);
}

.search-bar input {
  border: none; outline: none;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text1);
  background: transparent;
  flex: 1;
  min-width: 0;
}

.search-bar-icon {
  padding: 0 10px;
  color: var(--text3);
  display: flex; align-items: center;
}

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error   { background: var(--danger-light); color: var(--danger); border: 1px solid #f5c6c4; }
.alert-success { background: #EEF2FF; color: var(--brand-dark); border: 1px solid #C7D2FE; }
.alert-info    { background: var(--info-light); color: var(--info); border: 1px solid #c5d9f8; }

/* Pill tabs */
.pill-tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface3); border-radius: 10px; }

.pill-tab {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: none;
  color: var(--text2);
  transition: all .15s;
}

.pill-tab.active { background: var(--surface); color: var(--brand); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.pill-tab:hover:not(.active) { color: var(--text1); }

/* Partidas table (pedido) */
.partidas-table { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: visible; }
.partidas-table th { background: var(--surface2); }
.partidas-footer {
  padding: 12px 16px;
  background: var(--surface2);
  display: flex;
  justify-content: flex-end;
  gap: 32px;
  border-top: 1px solid var(--border);
}

.partidas-footer .total-row { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.total-label { font-size: 11.5px; color: var(--text3); }
.total-value { font-size: 15px; font-weight: 600; color: var(--text1); }
.total-value.grand { font-size: 18px; color: var(--brand); }

/* Toast notification */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--text1);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  transition: all .25s;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateY(0); }
#toast.toast-error { background: var(--danger); }
#toast.toast-success { background: var(--brand); }

/* Loading */
.loading-dots::after { content: ''; animation: dots 1.2s infinite; }
@keyframes dots { 0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.empty-sub { font-size: 13px; }

/* ═══════════════════════════════════════════════
   RESPONSIVE — Tablet y Celular
   ═══════════════════════════════════════════════ */

/* ── Botón hamburguesa (oculto en desktop) ── */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 500;
  background: var(--brand-dark);
  border: none;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.menu-toggle svg { stroke: #fff; }

/* Overlay oscuro cuando sidebar está abierto en móvil */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 98;
}
.sidebar-overlay.visible { display: block; }

/* ── TABLET (768px - 1024px) ── */
@media (max-width: 1024px) {
  .sidebar { width: 200px; }
  .main { margin-left: 200px; }
  .page-body { padding: 16px 18px; }
  .topbar { padding: 0 18px; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
  .kpi-value { font-size: 22px; }

  .form-row-4 { grid-template-columns: 1fr 1fr; }
  .modal-lg { max-width: 95vw; }
}

/* ── CELULAR (< 768px) ── */
@media (max-width: 768px) {

  /* Sidebar como drawer lateral */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 260px;
    z-index: 99;
  }
  .sidebar.open { transform: translateX(0); }

  /* Botón hamburguesa visible */
  .menu-toggle { display: flex; }

  /* Contenido principal sin margen */
  .main { margin-left: 0; }

  /* Topbar adaptado */
  .topbar {
    padding: 0 12px 0 60px; /* espacio para el botón hamburguesa */
    height: 52px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .topbar-sep, .topbar-sub { display: none; }
  .topbar-title { font-size: 14px; }
  .topbar-actions {
    margin-left: auto;
    gap: 4px;
  }
  /* Ocultar textos en botones del topbar, dejar solo iconos */
  .topbar-actions .btn span:not(.badge) { display: none; }
  .topbar-actions .btn { padding: 7px 10px; }

  /* Page body */
  .page-body { padding: 12px; }

  /* KPIs en 2 columnas */
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; margin-bottom: 12px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 11px; }

  /* Formularios en una columna */
  .form-row-2,
  .form-row-3,
  .form-row-4 { grid-template-columns: 1fr !important; gap: 10px; }

  /* Tablas con scroll horizontal */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  td, th { padding: 8px 10px; font-size: 12px; }
  .td-mono { font-size: 11px; }

  /* Modales a pantalla completa */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal, .modal-lg {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
    overflow-y: auto;
  }
  .modal-body { padding: 16px; max-height: 60vh; overflow-y: auto; }
  .modal-header { padding: 14px 16px 12px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Cards */
  .card { border-radius: var(--radius); }
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }

  /* Botones de acción más grandes para touch */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; padding: 5px 10px; }
  .btn-icon { min-height: 36px; min-width: 36px; }

  /* Toast en la parte superior en móvil */
  #toast { bottom: auto; top: 16px; right: 12px; left: 12px; font-size: 13px; }

  /* Search bar full width */
  .search-bar { width: 100% !important; }

  /* Panel de avance de producción */
  .panel-avance-grid { grid-template-columns: 1fr 1fr !important; }

  /* Ocultar columnas menos importantes en tablas */
  .td-hide-mobile { display: none; }
  .th-hide-mobile { display: none; }

  /* Autocomplete lista más grande para touch */
  .autocomplete-list { max-height: 200px; }
  .autocomplete-item { padding: 12px 14px; min-height: 48px; }

  /* Partidas footer en columna */
  .partidas-footer { flex-direction: column; gap: 6px; align-items: flex-end; }

  /* Grids inline forzados a colapsar en móvil */
  /* KPI con muchas columnas → 2 col */
  div[style*="grid-template-columns:repeat(4"],
  div[style*="grid-template-columns:repeat(5"],
  div[style*="grid-template-columns:repeat(6"] {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Grids de 3+ columnas dentro de modales y page-body → 1 col */
  .modal-body div[style*="grid-template-columns:1fr 1fr 1fr"],
  .modal-body div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  .page-body div[style*="grid-template-columns:1fr 1fr 1fr"],
  .page-body div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  .page-body div[style*="grid-template-columns:repeat(3"],
  .page-body div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: 1fr !important;
  }
  /* Grids de 2 columnas en modales → 1 col */
  .modal-body div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Paneles laterales (sidebar de detalle) → apilados */
  div[style*="grid-template-columns:320px"],
  div[style*="grid-template-columns:340px"],
  div[style*="grid-template-columns:280px"] {
    grid-template-columns: 1fr !important;
  }
  /* page-body overflow oculto para evitar scroll horizontal */
  .page-body { overflow-x: hidden; }

  /* Panel rastreo logística */
  .rastreo-panel { left: 12px; right: 12px; bottom: 12px; }
  .rastreo-btns { flex-direction: column; }
  .rastreo-btn { flex: none; padding: 12px; font-size: 14px; }
}

/* ── Mejoras táctiles generales ── */
@media (hover: none) {
  /* En touch: quitar hover states que no aplican */
  tbody tr:hover td { background: transparent; }

  /* Aumentar área de toque en botones icono */
  .btn-ghost.btn-icon { padding: 10px; }

  /* Inputs más altos para facilitar toque */
  .form-control { padding: 10px 12px; font-size: 16px; } /* 16px evita zoom en iOS */
  select.form-control { padding: 10px 12px; }
}

/* ══ OVERLAY para sidebar móvil ══ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 149;
}
.overlay.open {
  display: block;
}
