/* ============================================================
   MiEnvio - Custom Stylesheet
   ============================================================ */

:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light:#dbeafe;
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;
  --info:         #0891b2;
  --purple:       #7c3aed;
  --orange:       #ea580c;
  --sidebar-bg:   #0f172a;
  --sidebar-w:    260px;
  --sidebar-w-c:  72px;
  --topbar-h:     64px;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 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;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: #f1f5f9;
  color: #1e293b;
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

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

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left .3s ease;
  display: flex;
  flex-direction: column;
}

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

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .3s ease;
  z-index: 1000;
}

.sidebar.collapsed { width: var(--sidebar-w-c); }
.sidebar.collapsed + .main-content { margin-left: var(--sidebar-w-c); }

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  min-height: 68px;
  gap: 0;
}

.sidebar-brand-logo { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; text-decoration: none; }
.sidebar-logo-img {
  height: 38px; width: auto; border-radius: 6px;
  object-fit: contain; flex-shrink: 0;
  transition: height .3s ease;
}
.sidebar.collapsed .sidebar-logo-img { height: 30px; }
.sidebar-brand-text { display: flex; flex-direction: column; overflow: hidden; }
.sidebar.collapsed .sidebar-brand-text { display: none; }
.brand-name { display: block; color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap; line-height: 1.2; }
.brand-sub  { display: block; color: #64748b; font-size: 10px; white-space: nowrap; text-transform: uppercase; letter-spacing: .4px; }

.sidebar-toggle {
  background: transparent;
  border: none;
  color: #64748b;
  padding: 4px 8px;
  cursor: pointer;
  transition: var(--transition);
}
.sidebar-toggle:hover { color: #fff; }

.sidebar-user {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  gap: 12px;
  overflow: hidden;
}

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name { display: block; color: #e2e8f0; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; color: #64748b; font-size: 11px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.nav-section-title {
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 10px 18px 4px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #94a3b8;
  padding: 9px 18px;
  border-radius: 0;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
  margin: 1px 8px;
  border-radius: 8px;
}

.sidebar .nav-link:hover {
  background: rgba(255,255,255,.06);
  color: #e2e8f0;
}

.sidebar .nav-link.active {
  background: linear-gradient(135deg, rgba(37,99,235,.8), rgba(124,58,237,.5));
  color: #fff;
}

.sidebar .nav-link i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar .nav-link span { overflow: hidden; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #64748b;
  text-decoration: none;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: var(--transition);
}
.btn-logout:hover { background: rgba(220,38,38,.15); color: #ef4444; }
.btn-logout i { font-size: 16px; }

/* Collapsed sidebar */
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .btn-logout span { display: none; }

.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }
.sidebar.collapsed .sidebar-toggle { margin: 0; }
.sidebar.collapsed .sidebar-user   { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .sidebar .nav-link { justify-content: center; padding: 10px 0; margin: 1px 8px; }
.sidebar.collapsed .btn-logout { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .sidebar-footer { padding: 14px 0; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-breadcrumb {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.sucursal-switcher-btn {
  font-size: 12px;
  font-weight: 600;
  min-width: 0;
}
.sucursal-switcher-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
  display: inline-block;
}

.topbar-toggle {
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px 8px;
}
.topbar-toggle:hover { color: var(--primary); }

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
}

.topbar-search {
  position: relative;
  width: 220px;
  flex-shrink: 1;
  min-width: 120px;
}
.topbar-search .form-control {
  background: #f8fafc;
  border-color: #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  padding-left: 12px;
}
.topbar-search .form-control:focus { background: #fff; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-height: 300px;
  overflow-y: auto;
}
.search-result-item { display: block; padding: 10px 14px; color: #1e293b; text-decoration: none; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.search-result-item:hover { background: #f8fafc; }
.search-empty { padding: 14px; text-align: center; color: #94a3b8; font-size: 13px; }

.btn-icon {
  background: transparent;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  transition: var(--transition);
  position: relative;
  overflow: visible;
  flex-shrink: 0;
}
.btn-icon:hover { background: #f1f5f9; color: var(--primary); }
.btn-icon i { font-size: 18px; }

.badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  font-size: 10px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-btn {
  display: flex;
  align-items: center;
  background: transparent;
  border: none;
  color: #1e293b;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.user-btn:hover { background: #f1f5f9; }

/* Notifications dropdown */
.notif-dropdown { min-width: 320px; padding: 0; }
.notif-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid #e2e8f0; }
.notif-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #f1f5f9; text-decoration: none; color: #1e293b; transition: var(--transition); }
.notif-item:hover { background: #f8fafc; }
.notif-icon { width: 36px; height: 36px; border-radius: 50%; background: #dbeafe; color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.notif-title { font-size: 13px; font-weight: 500; }
.notif-time { font-size: 11px; color: #94a3b8; }
.notif-empty { padding: 20px 16px; text-align: center; color: #94a3b8; font-size: 13px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid #f1f5f9;
  padding: 16px 20px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body { padding: 20px; }

/* Stats cards */
.stat-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; color: var(--primary); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #ede9fe; color: var(--purple); }
.stat-icon.cyan   { background: #cffafe; color: var(--info); }
.stat-icon.orange { background: #ffedd5; color: var(--orange); }

.stat-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  color: #0f172a;
}
.stat-label {
  font-size: 12px;
  color: #64748b;
  font-weight: 500;
  margin-top: 4px;
}
.stat-trend {
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============================================================
   TABLES
   ============================================================ */
.table-responsive { border-radius: var(--radius-sm); }

.table {
  font-size: 13.5px;
  margin-bottom: 0;
}
.table th {
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 16px;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  vertical-align: middle;
  color: #1e293b;
  border-color: #f1f5f9;
}
.table tbody tr { transition: var(--transition); }
.table tbody tr:hover { background: #f8fafc; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label { font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 6px; }
.form-control, .form-select {
  border-color: #d1d5db;
  border-radius: var(--radius-sm);
  font-size: 14px;
  padding: 8px 12px;
  transition: var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.input-group-text { background: #f8fafc; border-color: #d1d5db; font-size: 13px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  font-weight: 500;
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  padding: 8px 16px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; border-radius: 6px; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  font-weight: 600;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
}
.bg-purple { background-color: #7c3aed !important; }
.bg-orange { background-color: #ea580c !important; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  color: #0f172a;
}
.page-header-left .breadcrumb {
  font-size: 12px;
  margin: 4px 0 0;
  color: #94a3b8;
}
.page-header-left .breadcrumb a { color: var(--primary); text-decoration: none; }

/* ============================================================
   FILTERS BAR
   ============================================================ */
.filters-bar {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.filters-bar .form-control,
.filters-bar .form-select {
  font-size: 13px;
  padding: 6px 10px;
}

/* ============================================================
   TIMELINE (Tracking)
   ============================================================ */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 11px; top: 0; bottom: 0; width: 2px; background: #e2e8f0; }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot {
  position: absolute;
  left: -22px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}
.timeline-dot.completed { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.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-time { font-size: 11px; color: #94a3b8; }
.timeline-title { font-weight: 600; font-size: 13px; }
.timeline-desc  { font-size: 12.5px; color: #64748b; }

/* ============================================================
   MODAL OVERRIDES
   ============================================================ */
.modal-content { border: none; border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid #f1f5f9; padding: 18px 24px; }
.modal-footer { border-top: 1px solid #f1f5f9; padding: 16px 24px; }
.modal-body   { padding: 24px; }
.modal-title  { font-weight: 700; font-size: 16px; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border: none; border-radius: var(--radius-sm); font-size: 13.5px; }
.alert-success { background: #f0fdf4; color: #166534; border-left: 4px solid var(--success); }
.alert-danger  { background: #fef2f2; color: #991b1b; border-left: 4px solid var(--danger); }
.alert-warning { background: #fffbeb; color: #92400e; border-left: 4px solid var(--warning); }
.alert-info    { background: #f0f9ff; color: #075985; border-left: 4px solid var(--info); }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: #94a3b8;
}
.empty-state i { font-size: 56px; margin-bottom: 16px; opacity: .4; }
.empty-state h5 { color: #64748b; margin-bottom: 8px; }

/* ============================================================
   STATUS STEPS
   ============================================================ */
.status-steps { display: flex; gap: 4px; margin-bottom: 24px; }
.status-step {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  background: #f1f5f9;
  color: #94a3b8;
  transition: var(--transition);
  cursor: default;
}
.status-step.active   { background: var(--primary); color: #fff; }
.status-step.done     { background: #dcfce7; color: var(--success); }
.status-step i        { display: block; font-size: 16px; margin-bottom: 4px; }

/* ============================================================
   PACKAGE CARD
   ============================================================ */
.pkg-card {
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.pkg-card:hover { box-shadow: var(--shadow-md); border-color: #bfdbfe; }
.pkg-number { font-family: 'Courier New', monospace; font-weight: 700; font-size: 13px; color: var(--primary); }
.pkg-weight { font-size: 12px; background: #f8fafc; padding: 2px 8px; border-radius: 6px; color: #64748b; }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .sidebar, .topbar, .filters-bar, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 16px; }
}

@media (max-width: 576px) {
  .stat-card { padding: 14px; }
  .stat-value { font-size: 20px; }
  .topbar { padding: 0 16px; }
  .topbar-search { display: none !important; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-muted-sm { color: #94a3b8; font-size: 12px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.cursor-pointer { cursor: pointer; }
.border-dashed { border-style: dashed !important; }
.rounded-lg { border-radius: var(--radius) !important; }
.overlay-loading {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.spinner-ring {
  width: 50px; height: 50px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login page */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px;
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
}
.login-logo {
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 24px;
  width: auto; height: auto;
  background: none; border-radius: 0;
}
.login-logo-img {
  height: 64px; width: auto; border-radius: 10px;
}
.login-title { text-align: center; font-size: 22px; font-weight: 800; color: #0f172a; margin-bottom: 6px; }
.login-sub   { text-align: center; font-size: 13px; color: #64748b; margin-bottom: 32px; }
