/* ==========================================================================
   TIENDA PALPAN — PANEL DE ADMINISTRACIÓN
   Estilos CSS del Panel Administrativo de Supermercado
   ========================================================================== */

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

:root {
  --primary: #059669;
  --primary-dark: #047857;
  --primary-light: #10b981;
  --primary-subtle: #ecfdf5;

  --accent: #f59e0b;
  --accent-dark: #d97706;

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --white: #ffffff;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.1), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-md: 14px;
  --radius-full: 9999px;

  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.2s ease;
}

body {
  font-family: var(--font-main);
  background: var(--gray-50);
  color: var(--gray-800);
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 250px;
  background: var(--gray-900);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

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

.sidebar-logo {
  height: 32px;
  width: auto;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--white);
}

.sidebar-subtitle {
  font-size: 0.72rem;
  color: var(--primary-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  padding: 1rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: block;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--white);
}

.nav-btn.active {
  background: var(--primary);
  color: var(--white);
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.35);
}

.sidebar-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 0.75rem 0;
}

.store-link {
  color: var(--accent);
}

/* MAIN CONTENT */
.admin-main {
  margin-left: 250px;
  flex: 1;
  padding: 1.75rem 2.25rem;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.topbar h1 {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--gray-900);
}

.topbar-date {
  font-size: 0.82rem;
  color: var(--gray-500);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
  box-shadow: var(--shadow-xs);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.status-dot.error { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }
.status-dot.loading { background: #f59e0b; }

/* SECCIONES ADMIN */
.admin-section {
  display: none;
}

.admin-section.active {
  display: block;
}

.order-count { background:#ef4444;color:#fff;border-radius:999px;padding:.1rem .4rem;font-size:.7rem; }
.orders-inbox { display:grid; gap:1rem; }
.loading-row { position:relative;overflow:hidden;background:#f1f5f9;border-radius:10px;padding:1rem; }
.order-card { background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:1rem; }
.route-map-canvas { min-height:360px;background:linear-gradient(135deg,#ecfdf5,#eff6ff);border:1px solid #cbd5e1;border-radius:14px;overflow:hidden;display:grid;place-items:center; }
.route-map-canvas svg { width:100%;height:360px;display:block; }
.route-map-note { margin:.55rem .8rem .8rem;color:#52625a;font-size:.8rem; }
.route-map-loading { min-height:320px;display:flex;align-items:center;justify-content:center;gap:.65rem;color:#52625a; }
[hidden] { display:none !important; }
.order-card-head { display:flex;justify-content:space-between;gap:1rem;flex-wrap:wrap; }
.order-actions { display:flex;gap:.5rem;flex-wrap:wrap;margin-top:.8rem; }

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--white);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary-subtle);
  color: var(--primary-dark);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card.warning .stat-icon-wrap {
  background: #fffbeb;
  color: #b45309;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  font-weight: 600;
  margin-top: 0.2rem;
}

/* PANELES */
.panel-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel {
  background: var(--white);
  padding: 1.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-xs);
  margin-bottom: 1.5rem;
}

.panel h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.panel-desc {
  font-size: 0.88rem;
  color: var(--gray-600);
  margin-bottom: 1.25rem;
}

/* TABLAS */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--white);
}

.admin-table th {
  background: var(--gray-100);
  color: var(--gray-700);
  font-weight: 700;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

.admin-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-800);
}

.admin-table tr:hover td {
  background: var(--gray-50);
}

.loading-row {
  text-align: center;
  color: var(--gray-500);
  padding: 2rem !important;
}

/* TOOLBAR */
.panel-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.admin-search {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.88rem;
  outline: none;
}

.admin-search:focus {
  border-color: var(--primary);
}

.admin-select {
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.88rem;
  background: var(--white);
  color: var(--gray-700);
  outline: none;
  cursor: pointer;
}

/* BOTONES */
.btn-primary {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

.btn-edit { background: var(--primary-subtle); color: var(--primary-dark); }
.btn-edit:hover { background: var(--primary); color: var(--white); }
.btn-delete { background: #fef2f2; color: #b91c1c; }
.btn-delete:hover { background: var(--danger); color: var(--white); }

/* STATS ROW & MINI STATS */
.stats-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.mini-stat {
  background: var(--white);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  flex: 1;
  min-width: 150px;
}

/* MODAL */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] { display: none !important; }

.modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(3px);
}

.modal-content {
  background: var(--white);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  padding: 1.75rem;
  position: relative;
  z-index: 2;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: var(--gray-100);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gray-700);
}

.form-group input, .form-group textarea, .form-group select {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--primary);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--gray-900);
  color: var(--white);
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 3000;
}

.toast.success { background: #065f46; border: 1px solid #10b981; }
.toast.error { background: #991b1b; border: 1px solid #ef4444; }

/* RESPONSIVE */
@media (max-width: 900px) {
  .sidebar { width: 70px; }
  .sidebar-header div, .sidebar-subtitle, .nav-btn span, .sidebar-title { display: none; }
  .nav-btn { text-align: center; padding: 0.75rem; }
  .admin-main { margin-left: 70px; padding: 1.25rem; }
}
