/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 250px;
  background: var(--gray-900);
  color: #fff;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 0.5rem 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-700);
  margin-bottom: 0.5rem;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.sidebar-header small {
  color: var(--gray-500);
  font-size: 0.75rem;
}

.sidebar nav { flex: 1; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  color: var(--gray-300);
  font-size: 0.9rem;
  transition: background 0.15s;
  text-decoration: none;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: var(--primary-dark);
  color: #fff;
  text-decoration: none;
}

.sidebar nav a .icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--gray-700);
  font-size: 0.85rem;
}

.sidebar-footer .user-name { font-weight: 600; }
.sidebar-footer .user-role { color: var(--gray-500); font-size: 0.75rem; }
.sidebar-footer button {
  margin-top: 0.5rem;
  background: none;
  border: 1px solid var(--gray-500);
  color: var(--gray-300);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}

.main-content {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow-y: auto;
}

/* === Login === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark), #1e40af);
}

.login-card {
  background: #fff;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
}

.login-card h1 { text-align: center; margin-bottom: 0.25rem; }
.login-card p { text-align: center; color: var(--gray-500); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* === Componentes === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header h2 { font-size: 1.5rem; font-weight: 700; }

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

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

.card-header h3 { font-size: 1rem; font-weight: 600; }

/* Stats grid para dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .stat-label {
  color: var(--gray-500);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.info .stat-value { color: var(--primary); }

/* Grid de dos columnas */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* === Tabla === */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

th {
  font-weight: 600;
  color: var(--gray-500);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover { background: var(--gray-50); }

/* === Formularios === */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--gray-700);
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea { resize: vertical; min-height: 80px; }

/* === Botones === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-100); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-info { background: #dbeafe; color: #1e40af; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-gray { background: var(--gray-200); color: var(--gray-700); }

/* === Pestañas de naves === */
.nave-tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.nave-tab {
  padding: 0.5rem 1rem;
  border: 2px solid var(--gray-200);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--gray-100);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.nave-tab:hover { background: var(--gray-200); }
.nave-tab.active { background: #fff; border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* === Mapa de depósito (grid de racks) === */
.rack-grid {
  display: grid;
  gap: 4px;
}

.rack-cell {
  border: 2px solid var(--gray-200);
  border-radius: 4px;
  padding: 0.35rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  overflow: hidden;
}

.rack-cell:hover { box-shadow: var(--shadow); transform: scale(1.03); }
.rack-cell .rack-name { font-weight: 700; font-size: 0.85rem; }
.rack-cell .rack-info { font-size: 0.6rem; color: var(--gray-500); }
.rack-cell .rack-product { font-size: 0.6rem; font-weight: 600; color: var(--gray-700); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.rack-cell .rack-stock { font-size: 0.7rem; font-weight: 700; }
.rack-cell .rack-venc { font-size: 0.55rem; }

/* Semáforo */
.rack-cell.s-libre   { background: #E5E7EB; border-color: #D1D5DB; }
.rack-cell.s-verde   { background: #dcfce7; border-color: #22C55E; }
.rack-cell.s-verde .rack-stock { color: #16a34a; }
.rack-cell.s-amarillo { background: #fef9c3; border-color: #EAB308; }
.rack-cell.s-amarillo .rack-venc { color: #92400e; font-weight: 600; }
.rack-cell.s-rojo    { background: #fee2e2; border-color: #EF4444; }
.rack-cell.s-rojo .rack-stock { color: #dc2626; }
.rack-cell.s-busqueda { border-color: #3B82F6 !important; box-shadow: 0 0 0 2px rgba(59,130,246,0.4); }

/* Tipos especiales */
.rack-cell.t-pasillo {
  background: #9CA3AF;
  border-color: #9CA3AF;
  cursor: default;
  min-height: 48px;
}
.rack-cell.t-bloqueado {
  background-color: #4B5563;
  background-image: repeating-linear-gradient(45deg,transparent,transparent 4px,rgba(0,0,0,0.2) 4px,rgba(0,0,0,0.2) 8px);
  border-color: #4B5563;
  cursor: default;
  color: #9CA3AF;
}
.rack-cell.t-vacia {
  background: transparent;
  border: 2px dashed var(--gray-200);
  cursor: default;
  min-height: 48px;
}

/* === Editor layout === */
.mapa-editor-layout { display: flex; gap: 1rem; }
.mapa-editor-panel {
  width: 220px;
  flex-shrink: 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  max-height: 75vh;
  overflow-y: auto;
}
.mapa-editor-panel h4 { margin-bottom: 0.75rem; font-size: 0.9rem; }
.mapa-editor-grid { flex: 1; }

/* Racks arrastrables en panel */
.drag-rack {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  margin-bottom: 0.35rem;
  cursor: grab;
  font-size: 0.85rem;
  background: #fff;
  transition: background 0.1s;
}
.drag-rack:active { cursor: grabbing; }
.drag-rack:hover { background: var(--gray-50); }

/* Drop target highlighting */
.rack-cell.drag-over { border-color: var(--primary) !important; background: #dbeafe !important; }
.rack-cell.dragging { opacity: 0.4; }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* === Toast/Alert === */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
}

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

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

/* === Buscador === */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-bar input { max-width: 350px; }

/* === Responsive tablet === */
@media (max-width: 1024px) {
  .sidebar { width: 200px; }
  .main-content { padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 0;
  }
  .sidebar-header { display: none; }
  .sidebar nav { display: flex; }
  .sidebar nav a { white-space: nowrap; padding: 0.75rem 1rem; }
  .sidebar-footer { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* === Loading === */
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 0.75rem;
  color: var(--gray-500);
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-500);
}

.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* === Campana de notificaciones (esquina superior derecha) === */
.notif-bell-fixed {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1500;
  cursor: pointer;
  font-size: 1.4rem;
  background: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: box-shadow 0.15s;
}
.notif-bell-fixed:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.25); }

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* === Panel de notificaciones === */
.notif-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 12px rgba(0,0,0,0.15);
  z-index: 2000;
  overflow-y: auto;
  padding: 1rem;
}

.notif-panel h3 { margin-bottom: 1rem; }

.notif-item {
  padding: 0.6rem;
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.notif-item.unread { background: #eff6ff; }
.notif-item .notif-msg { flex: 1; }
.notif-item .notif-time { font-size: 0.7rem; color: var(--gray-500); white-space: nowrap; }
.notif-item .notif-actions { display: flex; gap: 0.25rem; margin-top: 0.25rem; }

/* === Buscador global dropdown === */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 3000;
  max-height: 300px;
  overflow-y: auto;
  color: var(--gray-900);
}

.search-dropdown .search-group { padding: 0.25rem 0; }
.search-dropdown .search-group-title {
  padding: 0.35rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
}
.search-dropdown .search-result {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.search-dropdown .search-result:hover { background: var(--gray-50); }

/* === FEFO steps === */
.fefo-step {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.fefo-step.active { border-color: var(--primary); background: #eff6ff; }
.fefo-step.done { border-color: var(--success); background: #f0fdf4; opacity: 0.7; }
.fefo-step h4 { margin-bottom: 0.5rem; }

/* Rack pulsante para FEFO */
.rack-cell.pulse-highlight {
  animation: pulse 1.5s ease-in-out infinite;
  border-color: #3B82F6 !important;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.3);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(59,130,246,0.1); }
}

/* === Barras simples para métricas === */
.metric-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}
.metric-bar .bar-label { width: 120px; text-align: right; }
.metric-bar .bar-fill {
  height: 20px;
  background: var(--primary);
  border-radius: 3px;
  min-width: 2px;
}
.metric-bar .bar-value { font-weight: 600; font-size: 0.8rem; }
