/* ============================================================
   FatextilPro — Tema Visual Moderno
   Bootstrap 5.3.3 + Custom Design System
   ============================================================ */

/* --- Custom Properties --- */
:root {
  --font-ui: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

  /* Brand palette */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* Neutrals */
  --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;

  /* Semantic */
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;

  /* Surfaces */
  --surface-body: #f1f5f9;
  --surface-card: #ffffff;
  --surface-sidebar: #1e293b;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);

  /* Radius */
  --radius-sm: .375rem;
  --radius-md: .625rem;
  --radius-lg: .875rem;
  --radius-xl: 1rem;
}

/* --- Global Reset --- */
body {
  font-family: var(--font-ui);
  background-color: var(--surface-body);
  color: var(--gray-800);
  font-size: .9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- Fixed Sidebar Layout --- */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 210px;
  background: var(--surface-sidebar);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
}

.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .brand-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.025em;
}

.sidebar-nav {
  padding: .5rem 0;
  flex: 1;
}

/* Module toggle (collapsible header) */
.sidebar-module {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  color: var(--gray-300);
  font-size: .8125rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: .01em;
  text-decoration: none;
  cursor: pointer;
  transition: all .15s ease;
  border-top: 1px solid rgba(255,255,255,.04);
  margin-top: .25rem;
}

.sidebar-module:first-child {
  border-top: none;
  margin-top: 0;
}

.sidebar-module:hover {
  color: #fff;
  background: rgba(255,255,255,.04);
}

.sidebar-module .module-left {
  display: flex;
  align-items: center;
  gap: .625rem;
}

.sidebar-module .module-left i {
  font-size: 1rem;
  opacity: .7;
  width: 1.25rem;
  text-align: center;
}

.sidebar-module .module-arrow {
  font-size: .625rem;
  transition: transform .25s ease;
  opacity: .5;
}

.sidebar-module[aria-expanded="true"] .module-arrow {
  transform: rotate(180deg);
}

/* Sub-menu links */
.sidebar-submenu {
  padding: .125rem 0 .375rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .4rem 1rem .4rem 2.5rem;
  color: var(--gray-400);
  font-size: .8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: all .15s ease;
}

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

.sidebar-link.active {
  background: rgba(99,102,241,.15);
  color: var(--brand-200);
}

.sidebar-link i {
  font-size: .9375rem;
  width: 1.25rem;
  text-align: center;
  opacity: .6;
}

.sidebar-link:hover i {
  opacity: 1;
}

/* Main area pushed right */
.app-main {
  margin-left: 210px;
  min-height: 100vh;
}

.app-content {
  padding: .75rem 0;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1035;
}

/* Mobile: sidebar off-screen by default */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-sidebar.open ~ .sidebar-overlay {
    display: block;
  }
  .app-main {
    margin-left: 0;
  }
}

::selection {
  background: var(--brand-200);
  color: var(--brand-700);
}

/* --- Navbar --- */
.app-navbar {
  background: var(--surface-card);
  border-bottom: 1px solid var(--gray-200);
  backdrop-filter: blur(12px);
  z-index: 1030;
}

.navbar-page-title {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--brand-600);
  letter-spacing: -.025em;
}

.app-navbar .user-badge {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .375rem .75rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 2rem;
  font-size: .8125rem;
  color: var(--gray-600);
}

.app-navbar .user-badge .user-avatar {
  width: 26px;
  height: 26px;
  background: var(--brand-100);
  color: var(--brand-600);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
}


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

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  background: var(--surface-card);
  border-bottom: 1px solid var(--gray-100);
  padding: 1rem 1.25rem;
  font-weight: 600;
}

.card-body {
  padding: 1.25rem;
}

/* --- Stat Cards (Dashboard badges replacement) --- */
.stat-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--surface-card);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all .15s ease;
}

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

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.stat-card .stat-icon.total   { background: var(--gray-100);   color: var(--gray-600); }
.stat-card .stat-icon.pending { background: #fef3c7;           color: #d97706; }
.stat-card .stat-icon.done    { background: #d1fae5;           color: #059669; }
.stat-card .stat-icon.voided  { background: #fee2e2;           color: #dc2626; }
.stat-card .stat-icon.showing { background: var(--brand-50);    color: var(--brand-600); }

.stat-card .stat-info {
  min-width: 0;
}

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

.stat-card .stat-label {
  font-size: .75rem;
  color: var(--gray-500);
  font-weight: 500;
}

/* --- Tables --- */
.table {
  font-size: .875rem;
  margin-bottom: 0;
}

.table > :not(caption) > * > * {
  padding: .625rem .75rem;
}

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

.table tbody tr {
  transition: background .1s ease;
}

.table tbody tr:hover {
  background: var(--brand-50) !important;
}

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

.table-link {
  color: var(--brand-600);
  text-decoration: none;
  font-weight: 600;
}

.table-link:hover {
  color: var(--brand-700);
  text-decoration: underline;
}

/* Sortable column headers */
.sortable-th {
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}

.sortable-th:hover {
  color: var(--brand-600) !important;
  background: var(--brand-50) !important;
}

.sortable-th .sort-icon {
  margin-left: .25rem;
  font-size: .7rem;
  opacity: .5;
}

.sortable-th.active .sort-icon {
  opacity: 1;
  color: var(--brand-600);
}

/* --- Badges --- */
.badge {
  font-weight: 600;
  font-size: .75rem;
  padding: .3em .6em;
  border-radius: var(--radius-sm);
  letter-spacing: .01em;
}

.badge-estado-cumplido  { background: #d1fae5; color: #065f46; }
.badge-estado-parcial   { background: #fef3c7; color: #92400e; }
.badge-estado-pendiente { background: var(--gray-100); color: var(--gray-600); }
.badge-estado-anulado   { background: #fee2e2; color: #991b1b; }

.badge-dias-vencido   { background: #fee2e2; color: #991b1b; }
.badge-dias-hoy       { background: #fef3c7; color: #92400e; }
.badge-dias-pronto    { background: #fef3c7; color: #92400e; }
.badge-dias-ok        { background: var(--brand-50); color: var(--brand-700); }

.badge-activo   { background: #d1fae5; color: #065f46; }
.badge-inactivo { background: var(--gray-100); color: var(--gray-500); }

/* --- Buttons --- */
.btn {
  font-weight: 600;
  font-size: .875rem;
  border-radius: var(--radius-sm);
  padding: .5rem 1rem;
  transition: all .15s ease;
}

.btn-primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
}

.btn-primary:hover {
  background: var(--brand-700);
  border-color: var(--brand-700);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79,70,229,.25);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
}

.btn-outline-primary {
  color: var(--brand-600);
  border-color: var(--brand-200);
}

.btn-outline-primary:hover {
  background: var(--brand-50);
  border-color: var(--brand-600);
  color: var(--brand-700);
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--gray-500);
  padding: .375rem .5rem;
}

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

.btn-action {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: .875rem;
}

/* --- Forms --- */
.form-control, .form-select {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  padding: .5rem .75rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: .375rem;
}

.form-check-input:checked {
  background-color: var(--brand-600);
  border-color: var(--brand-600);
}

/* --- Alerts --- */
.alert {
  border-radius: var(--radius-md);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  padding: .75rem 1rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info    { background: var(--brand-50); color: var(--brand-700); }

/* --- Filter Panel --- */
.filter-panel {
  background: var(--surface-card);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.filter-panel .filter-chip {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .75rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 2rem;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: all .15s;
}

.filter-chip:has(input:checked) {
  background: var(--brand-50);
  border-color: var(--brand-200);
  color: var(--brand-700);
}

.filter-chip input[type="checkbox"] {
  display: none;
}

/* --- Page Header --- */
.page-header {
  margin-bottom: .75rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -.025em;
  margin: 0;
}

.page-header .page-subtitle {
  font-size: .875rem;
  color: var(--gray-500);
  margin-top: .25rem;
}

/* --- Detail View --- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.detail-item {
  padding: .5rem 0;
}

.detail-item .detail-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-400);
  margin-bottom: .125rem;
}

.detail-item .detail-value {
  font-size: .9375rem;
  color: var(--gray-900);
  font-weight: 500;
}

/* --- Progress indicator for dispatch --- */
.dispatch-progress {
  position: relative;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  margin-top: .5rem;
}

.dispatch-progress .progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .3s ease;
}

.dispatch-progress .progress-fill.ok      { background: var(--success); }
.dispatch-progress .progress-fill.partial { background: var(--warning); }
.dispatch-progress .progress-fill.over    { background: var(--danger); }

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

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

.modal-footer {
  border-top: 1px solid var(--gray-100);
  padding: .75rem 1.25rem;
}

/* --- Pagination --- */
.pagination .page-link {
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  font-size: .875rem;
  font-weight: 500;
  border-radius: var(--radius-sm) !important;
  margin: 0 .125rem;
  padding: .375rem .75rem;
}

.pagination .page-item.active .page-link {
  background: var(--brand-600);
  border-color: var(--brand-600);
}

/* --- Anulado row overlay --- */
tr.row-anulado {
  opacity: .55;
}

tr.row-anulado:hover {
  opacity: .75;
}

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

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: .75rem;
}

/* --- Mobile sidebar toggle --- */
.btn-sidebar {
  width: 38px;
  height: 38px;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  background: var(--surface-card);
  color: var(--gray-600);
  transition: all .15s ease;
}

.btn-sidebar:hover {
  background: var(--gray-50);
  color: var(--gray-800);
  border-color: var(--gray-300);
}

@media (max-width: 991.98px) {
  .btn-sidebar { display: flex; }
}

/* --- Login Page --- */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--gray-900) 0%, var(--gray-800) 50%, var(--brand-700) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-card .login-logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

.login-card h1 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: .25rem;
}

.login-card .login-subtitle {
  color: var(--gray-500);
  font-size: .875rem;
  margin-bottom: 1.5rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .stat-cards-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .table {
    font-size: .8125rem;
  }
}

@media (max-width: 480px) {
  .stat-cards-grid {
    grid-template-columns: 1fr !important;
  }
}
