/* ════════════════════════════════════════════════════════════════
   PURO SABOR — ADMIN DASHBOARD (MEJORADO)
   Interfaz profesional, robusta e intuitiva
   ════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap');

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

:root {
  --brand: #C0392B;
  --brand-d: #a93226;
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --surface2: #252525;
  --border: rgba(255,255,255,0.08);
  --text: #f0f0f0;
  --text-secondary: #a0a0a0;
  --muted: #666;
  --success: #27ae60;
  --warning: #f39c12;
  --error: #e74c3c;
  --info: #3498db;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── LOGIN ──────────────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, #1a0a09 0%, #0a0a0a 70%);
  z-index: 100;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 50px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 40px 80px rgba(0,0,0,0.6);
  text-align: center;
}

.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-card h1 { font-size: 32px; font-weight: 800; margin-bottom: 4px; }
.login-subtitle { font-size: 14px; color: var(--muted); margin-bottom: 36px; }

.input-group {
  text-align: left;
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}

.input-group input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: all 0.2s;
}

.input-group input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.login-error {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid rgba(231, 76, 60, 0.4);
  border-radius: 8px;
  color: #ff6b6b;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 14px;
  margin-bottom: 16px;
  text-align: left;
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
}

.login-card button[type="submit"]:hover {
  background: var(--brand-d);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(192, 57, 43, 0.3);
}

.login-card button[type="submit"]:active {
  transform: scale(0.98);
}

/* ─── ADMIN LAYOUT ───────────────────────────────────────────── */
.admin-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.admin-sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 16px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.sidebar-brand span { font-size: 32px; }
.sidebar-brand h2 { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.nav-item.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.2);
}

.nav-item span:first-child { font-size: 18px; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.btn-logout-sidebar {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout-sidebar:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(231, 76, 60, 0.1);
}

/* ─── ADMIN MAIN ─────────────────────────────────────────────── */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 10;
}

.header-title h1 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.header-title p {
  font-size: 13px;
  color: var(--muted);
}

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

.current-time {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.btn-export {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-export:hover {
  border-color: var(--brand);
  background: rgba(192, 57, 43, 0.1);
  color: var(--brand);
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.admin-content::-webkit-scrollbar { width: 8px; }
.admin-content::-webkit-scrollbar-track { background: transparent; }
.admin-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.page-content { display: none; }
.page-content.active { display: block; }

/* ═══ KPI CARDS (DASHBOARD) ═══════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.kpi-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--muted);
}

.kpi-card.kpi-total::before { background: var(--info); }
.kpi-card.kpi-pending::before { background: var(--warning); }
.kpi-card.kpi-revenue::before { background: var(--success); }
.kpi-card.kpi-changes::before { background: var(--brand); }

.kpi-card:hover {
  transform: translateY(-4px);
  border-color: rgba(192, 57, 43, 0.4);
  box-shadow: 0 12px 24px rgba(192, 57, 43, 0.1);
}

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

.kpi-icon {
  font-size: 32px;
}

.kpi-trend {
  font-size: 20px;
  font-weight: 700;
  color: var(--success);
}

.kpi-content { flex: 1; }

.kpi-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.kpi-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -1px;
}

.kpi-subtitle {
  font-size: 12px;
  color: var(--muted);
}

/* ─── CHARTS ─────────────────────────────────────────────────── */
.dashboard-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.chart-container h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.chart-container canvas {
  max-height: 300px;
}

/* ─── ACTIVITY CARDS ─────────────────────────────────────────── */
.dashboard-activity {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
}

.activity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

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

.activity-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.view-all {
  font-size: 12px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.view-all:hover {
  color: var(--brand-d);
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.activity-item {
  padding: 14px;
  background: var(--surface2);
  border-radius: 10px;
  border-left: 3px solid var(--brand);
  transition: all 0.2s;
}

.activity-item:hover {
  background: rgba(192, 57, 43, 0.1);
  border-left-color: var(--brand-d);
}

.activity-item-id {
  font-weight: 700;
  color: var(--brand);
  font-size: 13px;
}

.activity-item-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ═══ PEDIDOS PAGE ══════════════════════════════════════════════ */
.pedidos-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.toolbar-filters {
  display: flex;
  gap: 12px;
  flex: 1;
  min-width: 300px;
}

.search-wrapper {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 200px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  transition: all 0.2s;
}

.search-wrapper:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.search-wrapper svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  margin-right: 8px;
  flex-shrink: 0;
}

.search-wrapper input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  outline: none;
  padding: 10px 0;
}

.search-wrapper input::placeholder {
  color: var(--muted);
}

.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-select:focus {
  border-color: var(--brand);
}

.orders-stat {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* ─── ORDERS TABLE (MODERN) ────────────────────────────────────── */
.orders-table-modern {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.orders-table-modern-header {
  display: grid;
  grid-template-columns: 70px 1fr 150px 100px 120px 80px 80px;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(90deg, var(--surface2) 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.orders-table-modern-row {
  display: grid;
  grid-template-columns: 70px 1fr 150px 100px 120px 80px 80px;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  transition: all 0.2s;
}

.orders-table-modern-row:hover {
  background: var(--surface2);
}

.order-id { font-weight: 700; color: var(--brand); font-size: 13px; }
.order-client { color: var(--text); font-size: 13px; }
.order-info { font-size: 12px; color: var(--muted); }

.status-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.status-pendiente { background: rgba(243, 156, 18, 0.2); color: #f39c12; }
.status-preparando { background: rgba(52, 152, 219, 0.2); color: #3498db; }
.status-listo { background: rgba(39, 174, 96, 0.2); color: #27ae60; }
.status-entregado { background: rgba(155, 89, 182, 0.2); color: #9b59b6; }
.status-pagado { background: rgba(46, 204, 113, 0.2); color: #2ecc71; }

.order-total { font-weight: 700; color: var(--brand); font-size: 13px; }

.btn-view-order {
  background: rgba(52, 152, 219, 0.15);
  border: 1px solid rgba(52, 152, 219, 0.4);
  color: #3498db;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-view-order:hover {
  background: rgba(52, 152, 219, 0.3);
  border-color: #3498db;
  transform: scale(1.1);
}

.btn-delete-order {
  background: rgba(231, 76, 60, 0.2);
  border: 1px solid rgba(231, 76, 60, 0.4);
  color: #e74c3c;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-delete-order:hover {
  background: rgba(231, 76, 60, 0.3);
  border-color: #e74c3c;
  transform: scale(1.1);
}

/* ─── ORDER DETAIL MODAL ──────────────────────────────────────── */
.order-detail-wrap { display: flex; flex-direction: column; gap: 20px; }

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

.detail-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.detail-highlight {
  color: var(--brand);
  font-size: 15px;
}

.detail-items-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-item-row:last-child { border-bottom: none; }

.detail-item-qty {
  background: var(--brand);
  color: #fff;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 700;
  min-width: 30px;
  text-align: center;
}

.detail-item-name { flex: 1; font-weight: 600; }

.detail-item-price {
  font-weight: 700;
  color: var(--brand);
}

.detail-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.detail-total-amount {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.detail-audit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-audit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
}

.detail-audit-who {
  font-weight: 700;
  color: var(--brand);
  flex: 1;
}

.detail-audit-type {
  background: rgba(255,255,255,0.07);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-secondary);
}

.detail-audit-when { color: var(--muted); }

/* ─── AUDIT TIMELINE (MODERN) ──────────────────────────────────── */
.audit-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.audit-timeline-modern {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.audit-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 10px;
  padding: 18px;
  transition: all 0.2s;
}

.audit-item:hover {
  border-left-color: var(--brand-d);
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.1);
}

.audit-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.audit-item-id {
  font-weight: 700;
  color: var(--brand);
  font-size: 14px;
}

.audit-item-time {
  font-size: 12px;
  color: var(--muted);
}

.audit-item-type {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.audit-changes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audit-change {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 12px;
}

.audit-change-field { font-weight: 700; color: var(--muted); min-width: 100px; }
.audit-change-before { color: var(--error); text-decoration: line-through; }
.audit-change-arrow { color: var(--muted); margin: 0 4px; }
.audit-change-after { color: var(--success); font-weight: 600; }

/* ─── REPORTES ─────────────────────────────────────────────────── */
.reportes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
}

.reporte-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

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

.reporte-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.reporte-badge {
  font-size: 11px;
  background: rgba(192, 57, 43, 0.2);
  color: var(--brand);
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: 600;
}

.reporte-ranking {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reporte-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 13px;
  transition: all 0.2s;
}

.reporte-item:hover {
  background: rgba(192, 57, 43, 0.1);
}

.reporte-item-name { flex: 1; font-weight: 600; }
.reporte-item-value { font-weight: 700; color: var(--brand); }

.reporte-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(192, 57, 43, 0.2);
  color: var(--brand);
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  margin-right: 12px;
  flex-shrink: 0;
}

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

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-large { max-width: 700px; }

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

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.modal-close:hover {
  color: var(--text);
}

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

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

.btn-secondary {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--brand);
  background: rgba(192, 57, 43, 0.1);
}

/* ─── TOAST ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--brand);
  color: white;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1001;
  box-shadow: 0 8px 24px rgba(192, 57, 43, 0.3);
  animation: slideIn 0.3s ease;
}

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

/* ─── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-charts { grid-template-columns: 1fr; }
  .dashboard-activity { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .admin-sidebar { width: 200px; padding: 16px 12px; }
  .sidebar-brand h2 { font-size: 14px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .pedidos-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-filters { flex-direction: column; }
  .search-wrapper { width: 100%; }
}
