/* ============================================================
   MENSAJERÍA PLATFORM - Main Stylesheet
   Design: Modern Fintech/Logistics
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --secondary:     #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #3b82f6;
  --dark:          #1e293b;
  --gray-50:       #f9fafb;
  --gray-100:      #f3f4f6;
  --gray-200:      #e5e7eb;
  --gray-300:      #d1d5db;
  --gray-400:      #9ca3af;
  --gray-500:      #6b7280;
  --gray-600:      #4b5563;
  --gray-700:      #374151;
  --gray-800:      #1f2937;
  --sidebar-width: 260px;
  --sidebar-collapsed: 70px;
  --topbar-height: 64px;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:     0 10px 15px rgba(0,0,0,.07), 0 4px 6px rgba(0,0,0,.05);
  --transition:    all .2s ease;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  margin: 0;
  line-height: 1.6;
}

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

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--dark);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: var(--transition);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .sidebar-footer .nav-link span {
  display: none;
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .sidebar-user {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 16px 8px;
}

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left .2s ease;
  min-width: 0;
}

.main-wrapper.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}

/* ── Sidebar Brand ─────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-logo {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: white;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 14px;
  color: white;
  line-height: 1.2;
  display: block;
}

.brand-sub {
  font-size: 11px;
  color: var(--gray-400);
}

/* ── Sidebar User ──────────────────────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 8px;
}

.user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: white;
  flex-shrink: 0;
}

.user-avatar-sm {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: white;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-role {
  font-size: 10px;
  background: rgba(37,99,235,.3);
  color: #93c5fd;
  border-radius: 4px;
  padding: 2px 6px;
}

/* ── Sidebar Nav ───────────────────────────────────────────── */
.sidebar-nav {
  list-style: none;
  padding: 0 8px;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-500);
  padding: 14px 8px 6px;
}

.nav-item .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  margin-bottom: 2px;
}

.nav-item .nav-link:hover {
  background: rgba(255,255,255,.07);
  color: white;
}

.nav-item .nav-link.active {
  background: var(--primary);
  color: white;
}

.nav-item .nav-link i {
  width: 18px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ── Sidebar Footer ────────────────────────────────────────── */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-footer .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  transition: var(--transition);
}

.sidebar-footer .nav-link:hover { background: rgba(255,255,255,.07); color: white; }
.sidebar-footer .nav-link.text-danger { color: #f87171 !important; }
.sidebar-footer .nav-link.text-danger:hover { background: rgba(239,68,68,.1); }

/* ── Overlay móvil ─────────────────────────────────────────── */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1039;
  display: none;
}

.sidebar-overlay.show { display: block; }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  background: white;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-600);
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
}

.btn-icon:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

.notification-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid white;
}

.breadcrumb { font-size: 13px; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--gray-400); }
.breadcrumb-item a { color: var(--primary); text-decoration: none; }
.breadcrumb-item.active { color: var(--gray-600); }

/* ── Page Content ──────────────────────────────────────────── */
.page-content {
  padding: 24px;
  min-height: calc(100vh - var(--topbar-height));
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  background: white;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
}

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

.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.kpi-icon.blue   { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green  { background: #d1fae5; color: var(--secondary); }
.kpi-icon.yellow { background: #fef3c7; color: var(--warning); }
.kpi-icon.red    { background: #fee2e2; color: var(--danger); }
.kpi-icon.purple { background: #ede9fe; color: #7c3aed; }

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
}

.kpi-label {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
  margin-top: 2px;
}

.kpi-change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

.kpi-change.up   { color: var(--secondary); }
.kpi-change.down { color: var(--danger); }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}

.table {
  margin: 0;
  font-size: 13px;
}

.table thead th {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-500);
  padding: 12px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
  color: var(--gray-700);
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--gray-50); }

/* ── Badges / Status ───────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.warning  { background: #fef3c7; color: #92400e; }
.status-badge.info     { background: #dbeafe; color: #1e40af; }
.status-badge.success  { background: #d1fae5; color: #065f46; }
.status-badge.danger   { background: #fee2e2; color: #991b1b; }
.status-badge.secondary{ background: var(--gray-100); color: var(--gray-600); }
.status-badge.primary  { background: var(--primary-light); color: var(--primary-dark); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-control, .form-select {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 13px;
  padding: 9px 12px;
  color: var(--gray-800);
  transition: var(--transition);
  background: white;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  outline: none;
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-valid   { border-color: var(--secondary); }

.input-group-text {
  background: var(--gray-50);
  border-color: var(--gray-300);
  color: var(--gray-500);
  font-size: 13px;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
}
.btn-primary:hover { background: var(--primary-dark); color: white; }

.btn-success { background: var(--secondary); color: white; }
.btn-success:hover { background: #059669; color: white; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; color: white; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }

.btn-outline-primary {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: white; }

.btn-light {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-light:hover { background: var(--gray-200); }

.btn-sm {
  font-size: 12px;
  padding: 6px 12px;
}

.btn-xs {
  font-size: 11px;
  padding: 4px 8px;
}

/* ── Timeline ──────────────────────────────────────────────── */
.timeline {
  position: relative;
  padding: 0;
  list-style: none;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 20px; top: 0; bottom: 0;
  width: 2px;
  background: var(--gray-200);
}

.timeline-item {
  position: relative;
  padding: 0 0 24px 52px;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: 12px;
  top: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 0 2px var(--gray-300);
  background: var(--gray-400);
  z-index: 1;
}

.timeline-dot.active  { background: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.timeline-dot.success { background: var(--secondary); box-shadow: 0 0 0 2px var(--secondary); }
.timeline-dot.warning { background: var(--warning); box-shadow: 0 0 0 2px var(--warning); }
.timeline-dot.danger  { background: var(--danger); box-shadow: 0 0 0 2px var(--danger); }
.timeline-dot.hidden-item { background: var(--gray-300); opacity: .5; }

.timeline-content { background: var(--gray-50); border-radius: var(--radius-sm); padding: 12px 16px; border: 1px solid var(--gray-200); }
.timeline-title { font-weight: 600; font-size: 13px; color: var(--gray-800); }
.timeline-time  { font-size: 11px; color: var(--gray-500); margin-top: 2px; }
.timeline-body  { font-size: 12px; color: var(--gray-600); margin-top: 6px; }
.timeline-internal { border-left: 3px solid var(--warning); background: #fffbeb; }

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title i {
  color: var(--primary);
  font-size: 20px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ── Search & Filters ──────────────────────────────────────── */
.filter-bar {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.search-box {
  position: relative;
}

.search-box .form-control {
  padding-left: 38px;
}

.search-box .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 13px;
}

/* ── Tracking Stepper (público) ────────────────────────────── */
.tracking-steps {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  position: relative;
  padding: 20px 0;
}

.tracking-steps::before {
  content: '';
  position: absolute;
  top: 36px; left: 40px; right: 40px;
  height: 3px;
  background: var(--gray-200);
}

.tracking-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  position: relative;
}

.tracking-step-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-400);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  z-index: 1;
  border: 3px solid white;
  box-shadow: var(--shadow);
}

.tracking-step.done .tracking-step-icon   { background: var(--secondary); color: white; }
.tracking-step.active .tracking-step-icon { background: var(--primary); color: white; }

.tracking-step-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-align: center;
  line-height: 1.3;
}

.tracking-step.done .tracking-step-label,
.tracking-step.active .tracking-step-label { color: var(--gray-700); }

/* ── Toast alerts ──────────────────────────────────────────── */
.toast-alert {
  position: fixed;
  top: 80px; right: 20px;
  z-index: 9999;
  min-width: 300px;
  max-width: 450px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius);
  animation: slideIn .3s ease;
}

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

/* ── Modals ────────────────────────────────────────────────── */
.modal-content {
  border-radius: var(--radius);
  border: none;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--gray-100);
  padding: 16px 20px;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-footer {
  border-top: 1px solid var(--gray-100);
  padding: 14px 20px;
}

/* ── Avatar ────────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}

.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state h5 { color: var(--gray-600); font-size: 16px; }
.empty-state p  { font-size: 13px; }

/* ── Sidebar Toggle button ─────────────────────────────────── */
.sidebar-toggle { background: none; border: none; color: var(--gray-400); cursor: pointer; padding: 4px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .sidebar.mobile-open { transform: translateX(0); }

  .main-wrapper { margin-left: 0 !important; }

  .page-content { padding: 16px; }

  .topbar { padding: 0 16px; }

  .kpi-card { padding: 16px; }

  .kpi-value { font-size: 20px; }

  .tracking-steps { flex-direction: column; align-items: flex-start; gap: 16px; }
  .tracking-steps::before { display: none; }

  .table-wrapper { border-radius: 0; border-left: none; border-right: none; }
}

/* ── Utility ───────────────────────────────────────────────── */
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--gray-500) !important; }
.text-success { color: var(--secondary) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-primary { color: var(--primary) !important; }
.bg-primary-light { background: var(--primary-light) !important; }
.rounded-lg { border-radius: var(--radius) !important; }

/* ── Loading spinner ───────────────────────────────────────── */
.spinner-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

/* ── Print styles ──────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, .filter-bar { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .page-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ── Photo preview ─────────────────────────────────────────── */
.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.photo-preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--gray-200);
}

.photo-preview-item img { width: 100%; height: 100%; object-fit: cover; }

.photo-preview-item .remove-photo {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  cursor: pointer;
  border: none;
}

/* ── Charts ────────────────────────────────────────────────── */
.chart-container { position: relative; height: 250px; }

/* ── Nav tabs ──────────────────────────────────────────────── */
.nav-tabs .nav-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  border-radius: 0;
}

.nav-tabs .nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: none;
}

.nav-tabs .nav-link:hover { color: var(--gray-700); border-color: transparent; }

/* ── Progress ──────────────────────────────────────────────── */
.progress { height: 6px; border-radius: 3px; background: var(--gray-100); }
.progress-bar { border-radius: 3px; background: var(--primary); }

/* ── QR Code ───────────────────────────────────────────────── */
.qr-container {
  text-align: center;
  padding: 20px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

.qr-container img { max-width: 200px; }
