/* ============================================================
   QC Grin Group – Professional Design System
   ============================================================ */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --brand-primary: #2D6A4F;
  --brand-secondary: #52B788;
  --brand-accent: #F77F00;
  --brand-light: #D8F3DC;
  --brand-dark: #1B4332;
  --bg-body: #F0F2F5;
  --bg-card: #FFFFFF;
  --bg-sidebar: #1B4332;
  --bg-sidebar-hover: #2D6A4F;
  --bg-topbar: #FFFFFF;
  --text-primary: #212529;
  --text-secondary: #6C757D;
  --text-muted: #ADB5BD;
  --text-sidebar: #B7E4C7;
  --text-sidebar-active: #FFFFFF;
  --border-color: #E9ECEF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --sidebar-width: 260px;
  --sidebar-collapsed: 70px;
  --topbar-height: 60px;
  --success: #2D6A4F;
  --warning: #F77F00;
  --danger: #E63946;
  --info: #457B9D;
  --transition: all .25s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--brand-dark); }

h1, h2, h3, h4, h5, h6 { font-weight: 600; color: var(--text-primary); margin-bottom: .5rem; }

/* ---------- Layout: Sidebar + Main ---------- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--bg-sidebar) 0%, #143D28 100%);
  color: var(--text-sidebar);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

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

.sidebar-brand img { height: 38px; flex-shrink: 0; }
.sidebar-brand span {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,.35);
  padding: 16px 20px 6px;
  font-weight: 600;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-sidebar);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  border-left: 3px solid transparent;
  white-space: nowrap;
}

.sidebar-link:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
  border-left-color: var(--brand-secondary);
}

.sidebar-link.active {
  background: rgba(82,183,136,.15);
  color: #fff;
  border-left-color: var(--brand-secondary);
  font-weight: 600;
}

.sidebar-link i { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-dropdown .sidebar-submenu {
  display: none;
  padding-left: 34px;
}
.sidebar-dropdown.open .sidebar-submenu { display: block; }
.sidebar-dropdown .sidebar-toggle { cursor: pointer; }
.sidebar-dropdown .sidebar-toggle::after {
  content: '\F282';
  font-family: 'bootstrap-icons';
  margin-left: auto;
  font-size: 12px;
  transition: transform .2s;
}
.sidebar-dropdown.open .sidebar-toggle::after { transform: rotate(180deg); }

.sidebar-submenu .sidebar-link {
  padding: 7px 20px 7px 0;
  font-size: 13px;
  border-left: none;
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info .name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info .role { font-size: 11px; color: var(--brand-secondary); }

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: var(--shadow-sm);
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 8px;
  margin-right: 12px;
}

.breadcrumb-area { flex: 1; }
.breadcrumb-area .breadcrumb {
  margin: 0;
  background: none;
  padding: 0;
  font-size: 13px;
}
.breadcrumb-area .breadcrumb-item a { color: var(--text-secondary); }
.breadcrumb-area .breadcrumb-item.active { color: var(--text-primary); font-weight: 600; }
.breadcrumb-area .page-title { font-size: 18px; font-weight: 700; margin: 0; line-height: 1.2; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-search {
  position: relative;
}
.topbar-search input {
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 16px 6px 36px;
  font-size: 13px;
  width: 220px;
  background: var(--bg-body);
  transition: var(--transition);
}
.topbar-search input:focus { width: 280px; border-color: var(--brand-secondary); box-shadow: 0 0 0 3px rgba(82,183,136,.15); outline: none; }
.topbar-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; }

/* ---------- Page Content ---------- */
.page-content { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-md); }

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

.card-body { padding: 20px; }

/* ---------- KPI Cards ---------- */
.kpi-card {
  background: var(--bg-card);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px;
  height: 100%;
}
.kpi-card.kpi-total::before { background: var(--brand-primary); }
.kpi-card.kpi-approved::before { background: var(--success); }
.kpi-card.kpi-observed::before { background: var(--warning); }
.kpi-card.kpi-rejected::before { background: var(--danger); }

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-total .kpi-icon { background: rgba(45,106,79,.1); color: var(--brand-primary); }
.kpi-approved .kpi-icon { background: rgba(45,106,79,.1); color: var(--success); }
.kpi-observed .kpi-icon { background: rgba(247,127,0,.1); color: var(--warning); }
.kpi-rejected .kpi-icon { background: rgba(230,57,70,.1); color: var(--danger); }

.kpi-info { flex: 1; }
.kpi-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi-total .kpi-value { color: var(--brand-primary); }
.kpi-approved .kpi-value { color: var(--success); }
.kpi-observed .kpi-value { color: var(--warning); }
.kpi-rejected .kpi-value { color: var(--danger); }

/* ---------- Status Badges ---------- */
.badge-result {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .3px;
}
.badge-result.result-A { background: rgba(45,106,79,.12); color: var(--success); }
.badge-result.result-OA { background: rgba(247,127,0,.12); color: var(--warning); }
.badge-result.result-R { background: rgba(230,57,70,.12); color: var(--danger); }

.badge-status { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-status.status-active { background: rgba(45,106,79,.12); color: var(--success); }
.badge-status.status-inactive { background: rgba(108,117,125,.12); color: var(--text-secondary); }

/* ---------- Tables ---------- */
.table {
  font-size: 13px;
  margin-bottom: 0;
}
.table thead th {
  background: var(--bg-body);
  border-bottom: 2px solid var(--border-color);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-secondary);
  padding: 10px 12px;
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
}
.table tbody tr:hover { background: rgba(45,106,79,.03); }
.table tbody tr:last-child td { border-bottom: none; }

/* ---------- 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;
}
.btn:focus { box-shadow: 0 0 0 3px rgba(45,106,79,.2); }

.btn-brand {
  background: var(--brand-primary);
  color: #fff;
  border: none;
}
.btn-brand:hover { background: var(--brand-dark); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }

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

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

.btn-action {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-secondary);
  font-size: 14px;
  transition: var(--transition);
}
.btn-action:hover { background: var(--bg-body); color: var(--text-primary); }
.btn-action.action-edit:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-action.action-delete:hover { border-color: var(--danger); color: var(--danger); }
.btn-action.action-view:hover { border-color: var(--info); color: var(--info); }
.btn-action.action-photo:hover { border-color: var(--brand-secondary); color: var(--brand-secondary); }

/* ---------- Forms ---------- */
.form-control, .form-select {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  padding: 8px 12px;
  transition: var(--transition);
  background: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-secondary);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-section-title {
  font-size: 14px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 12px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-title.quality-section {
  background: rgba(230,57,70,.08);
  color: var(--danger);
  border-left: 3px solid var(--danger);
}
.form-section-title.condition-section {
  background: rgba(247,127,0,.08);
  color: var(--warning);
  border-left: 3px solid var(--warning);
}

/* ---------- Modals ---------- */
.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 16px 20px;
}
.modal-header .modal-title { font-weight: 700; font-size: 16px; }
.modal-header .btn-close { filter: brightness(0) invert(1); }
.modal-body { padding: 20px; }
.modal-footer { border-top: 1px solid var(--border-color); padding: 12px 20px; }

/* ---------- Nav Tabs (in modals) ---------- */
.nav-tabs { border-bottom: 2px solid var(--border-color); }
.nav-tabs .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
  padding: 8px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}
.nav-tabs .nav-link:hover { color: var(--brand-primary); }
.nav-tabs .nav-link.active {
  color: var(--brand-primary);
  font-weight: 700;
  border-bottom-color: var(--brand-primary);
  background: transparent;
}

/* ---------- Toast Notifications ---------- */
.toast-modern {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastSlideIn .4s ease;
  min-width: 300px;
  max-width: 450px;
}
.toast-item.toast-success { background: var(--success); }
.toast-item.toast-error { background: var(--danger); }
.toast-item.toast-warning { background: var(--warning); }
.toast-item .toast-icon { font-size: 18px; }
.toast-item .toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}
.toast-item .toast-close:hover { color: #fff; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(100px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastFadeOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100px); }
}

/* ---------- Photo Gallery ---------- */
.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo-card {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-body);
  transition: var(--transition);
  cursor: pointer;
}
.photo-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.photo-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}
.photo-card .photo-label {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.photo-card .photo-delete {
  color: var(--danger);
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transition: var(--transition);
}
.photo-card:hover .photo-delete { opacity: 1; }

/* ---------- Lightbox ---------- */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.85);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .3s;
}
.lightbox-overlay img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: #fff;
  font-size: 32px;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 14px; margin: 0; }

/* ---------- Login Page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--brand-primary) 50%, var(--brand-secondary) 100%);
  position: relative;
}
.login-page::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='https://static.vecteezy.com/system/resources/thumbnails/067/755/353/small_2x/plus-seamless-pattern-simple-cross-texture-graphic-cross-symbol-grid-plus-sign-repeat-pattern-graphic-texture-illustration-isolated-on-white-background-vector.jpg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.login-card {
  width: 420px;
  max-width: 95vw;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  position: relative;
  z-index: 1;
}
.login-card .login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-card .login-logo img { height: 60px; }
.login-card .login-logo h4 { margin-top: 12px; font-weight: 800; color: var(--brand-primary); font-size: 20px; }
.login-card .login-logo small { color: var(--text-secondary); font-size: 13px; }

.login-input-group {
  position: relative;
  margin-bottom: 16px;
}
.login-input-group i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
}
.login-input-group input {
  padding-left: 42px;
  height: 44px;
  border-radius: var(--radius-sm);
}

/* ---------- Rejection Alert ---------- */
.rejection-alert {
  background: rgba(230,57,70,.08);
  border: 1px solid rgba(230,57,70,.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--danger);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.rejection-alert i { font-size: 16px; margin-top: 1px; flex-shrink: 0; }

/* ---------- Stepper ---------- */
.form-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 20px;
  padding: 0 4px;
}
.stepper-step {
  flex: 1;
  text-align: center;
  position: relative;
}
.stepper-step .step-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border-color);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 4px;
  transition: var(--transition);
}
.stepper-step .step-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.stepper-step.active .step-circle { background: var(--brand-primary); color: #fff; }
.stepper-step.active .step-label { color: var(--brand-primary); font-weight: 600; }
.stepper-step.completed .step-circle { background: var(--brand-secondary); color: #fff; }
.stepper-step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 16px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border-color);
  z-index: -1;
}
.stepper-step.completed:not(:last-child)::after { background: var(--brand-secondary); }

/* ---------- Drag & Drop Area ---------- */
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  transition: var(--transition);
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--brand-secondary);
  background: rgba(82,183,136,.05);
  color: var(--brand-primary);
}
.drop-zone i { font-size: 36px; margin-bottom: 8px; display: block; }

/* ---------- Pagination ---------- */
.pagination-modern {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  padding: 16px 0;
}
.pagination-modern .page-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.pagination-modern .page-btn:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.pagination-modern .page-btn.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }

/* ---------- Container Status ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.status-PROGRAMADO { background: rgba(69,123,157,.12); color: var(--info); }
.status-EN_TRANSITO { background: rgba(247,127,0,.12); color: var(--warning); }
.status-ARRIBADO { background: rgba(45,106,79,.12); color: var(--success); }

/* ============================================================
   RESPONSIVE DESIGN SYSTEM – Complete
   ============================================================ */

/* ---------- Sidebar Overlay (all sizes) ---------- */
.sidebar-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 1035;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* ---------- Body scroll lock when sidebar open on mobile ---------- */
body.sidebar-open { overflow: hidden; }

/* ---------- Table responsive helpers ---------- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.table-responsive::-webkit-scrollbar { height: 4px; }
.table-responsive::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* Scroll indicator for horizontal tables */
.table-scroll-hint {
  display: none;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--text-muted);
  background: linear-gradient(90deg, transparent, rgba(45,106,79,.06), transparent);
}
.table-scroll-hint i { animation: scrollHint 1.5s ease infinite; }
@keyframes scrollHint { 0%,100% { transform: translateX(0); } 50% { transform: translateX(6px); } }

/* ============================
   Desktop grande: 1200px+
   ============================ */
@media (min-width: 1200px) {
  .kpi-card .kpi-value { font-size: 28px; }
}

/* ============================
   Desktop pequeño: 992px - 1199px
   ============================ */
@media (max-width: 1199.98px) {
  .kpi-card .kpi-value { font-size: 24px; }
  .topbar-search input { width: 180px; }
  .topbar-search input:focus { width: 220px; }
}

/* ============================
   Tablet: 768px - 991px
   ============================ */
@media (max-width: 991.98px) {
  /* Sidebar: overlay drawer */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.show {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.3);
  }
  .main-content { margin-left: 0; }
  .topbar-toggle { display: flex; }

  /* Page content */
  .page-content { padding: 20px; }

  /* KPIs: 2 columns */
  .kpi-card .kpi-value { font-size: 22px; }
  .kpi-card .kpi-icon { width: 42px; height: 42px; font-size: 20px; }

  /* Forms: 2 columns where appropriate */
  .form-row-responsive > .col-md-1,
  .form-row-responsive > .col-md-2 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* Cards */
  .card-body { padding: 16px; }
  .card-header { padding: 12px 16px; }

  /* Photo gallery: 3 columns */
  .photo-gallery { grid-template-columns: repeat(3, 1fr); }

  /* Topbar search */
  .topbar-search input { width: 160px; }
  .topbar-search input:focus { width: 200px; }

  /* Nav tabs: scrollable */
  .nav-tabs { 
    flex-wrap: nowrap; 
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-link { white-space: nowrap; }
}

/* ============================
   Móvil: 576px - 767px
   ============================ */
@media (max-width: 767.98px) {
  /* Page content */
  .page-content { padding: 14px; }

  /* Topbar */
  .topbar { padding: 0 12px; height: 52px; }
  .topbar-search { display: none; }
  .topbar-toggle { margin-right: 8px; font-size: 24px; }
  .breadcrumb-area .page-title { font-size: 15px; }

  /* Typography */
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  h3 { font-size: 18px; }
  h4 { font-size: 16px; }
  h5 { font-size: 15px; }
  h6 { font-size: 14px; }
  body { font-size: 14px; }

  /* KPI Cards: stack nicely */
  .kpi-card { padding: 12px; gap: 12px; }
  .kpi-card .kpi-value { font-size: 20px; }
  .kpi-card .kpi-icon { width: 40px; height: 40px; font-size: 18px; }
  .kpi-card .kpi-label { font-size: 11px; }

  /* Cards */
  .card-body { padding: 14px; }
  .card-header { padding: 10px 14px; font-size: 13px; }

  /* Tables: show scroll hint */
  .table-scroll-hint { display: block; }
  .table thead th { font-size: 11px; padding: 8px 10px; }
  .table tbody td { padding: 8px 10px; font-size: 12px; }

  /* Forms: full width */
  .form-control, .form-select { font-size: 14px; padding: 10px 12px; }
  .form-label { font-size: 12px; }
  [class*="col-md-"], [class*="col-lg-"], [class*="col-xl-"] {
    /* Allow Bootstrap grid to stack on mobile */
  }

  /* Buttons: touch-friendly */
  .btn { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  .btn-action { width: 38px; height: 38px; font-size: 16px; }

  /* Modals: full screen on mobile */
  .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    min-height: 100vh;
  }
  .modal-content {
    border-radius: 0 !important;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  .modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
  }
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 1;
    padding: 12px 16px;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  }
  .modal-header {
    border-radius: 0 !important;
    padding: 14px 16px;
  }
  .modal-header .modal-title { font-size: 15px; }

  /* Nav tabs: scrollable horizontal */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-link { white-space: nowrap; padding: 8px 14px; font-size: 12px; }

  /* Photo gallery: 2 columns */
  .photo-gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .photo-card img { height: 120px; }

  /* Lightbox */
  .lightbox-overlay img { max-width: 96vw; max-height: 85vh; border-radius: var(--radius-sm); }
  .lightbox-close { top: 10px; right: 10px; font-size: 28px; }

  /* Dropzone */
  .drop-zone { padding: 20px; }
  .drop-zone i { font-size: 28px; }

  /* Pagination */
  .pagination-modern .page-btn { width: 36px; height: 36px; font-size: 14px; }

  /* Toasts */
  .toast-modern { top: 10px; right: 10px; left: 10px; }
  .toast-item { min-width: auto; max-width: 100%; font-size: 12px; }

  /* Stepper */
  .form-stepper { gap: 0; }
  .stepper-step .step-circle { width: 28px; height: 28px; font-size: 12px; }
  .stepper-step .step-label { font-size: 10px; }

  /* Empty state */
  .empty-state { padding: 32px 16px; }
  .empty-state i { font-size: 36px; }

  /* Login card */
  .login-card { padding: 28px 20px; }
  .login-card .login-logo img { height: 48px; }
  .login-card .login-logo h4 { font-size: 18px; }

  /* Accordion */
  .accordion-button { font-size: 13px; padding: 10px 14px; }

  /* Rejection alert */
  .rejection-alert { font-size: 11px; padding: 8px 10px; }

  /* Flex utilities for mobile page headers */
  .d-flex.flex-wrap.justify-content-between { gap: 8px !important; }

  /* Row gutters smaller on mobile */
  .row.g-3 { --bs-gutter-x: 0.75rem; --bs-gutter-y: 0.75rem; }
  .row.g-2 { --bs-gutter-x: 0.5rem; --bs-gutter-y: 0.5rem; }

  /* Charts: ensure minimum usable height */
  .card-body canvas { min-height: 200px; }
}

/* ============================
   Móvil pequeño: 320px - 575px
   ============================ */
@media (max-width: 575.98px) {
  /* Page content tighter */
  .page-content { padding: 10px; }

  /* Typography even smaller */
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }
  .breadcrumb-area .page-title { font-size: 14px; }
  body { font-size: 13px; }

  /* KPIs: 1 column full width */
  .kpi-card { padding: 10px; gap: 10px; }
  .kpi-card .kpi-value { font-size: 18px; }
  .kpi-card .kpi-icon { width: 36px; height: 36px; font-size: 16px; }

  /* Sidebar brand */
  .sidebar-brand { padding: 16px; }
  .sidebar-brand img { height: 32px; }
  .sidebar-brand span { font-size: 14px; }

  /* Cards */
  .card-body { padding: 12px; }
  .card-header { padding: 10px 12px; font-size: 12px; }

  /* Tables */
  .table thead th { font-size: 10px; padding: 6px 8px; }
  .table tbody td { padding: 6px 8px; font-size: 11px; }

  /* Buttons */
  .btn { font-size: 13px; padding: 10px 14px; }
  .btn-action { width: 36px; height: 36px; }

  /* Photo gallery: 2 columns tighter */
  .photo-gallery { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .photo-card img { height: 100px; }

  /* Login */
  .login-card { padding: 24px 16px; width: 100%; max-width: 100vw; border-radius: 0; }

  /* Form section titles */
  .form-section-title { font-size: 13px; padding: 6px 10px; }

  /* Badge adjustments */
  .badge-result { font-size: 11px; padding: 3px 8px; }
  .status-badge { font-size: 10px; padding: 3px 8px; }

  /* Topbar */
  .topbar { padding: 0 10px; height: 48px; }
  .topbar-toggle { font-size: 22px; padding: 2px 6px; }

  /* Stepper: very compact */
  .stepper-step .step-circle { width: 24px; height: 24px; font-size: 10px; }
  .stepper-step .step-label { font-size: 9px; display: none; }
}

/* ============================
   Print styles
   ============================ */
@media print {
  .sidebar, .topbar, .sidebar-overlay, .topbar-toggle { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  .btn, .btn-action { display: none !important; }
  .modal { display: none !important; }
}

/* ============================
   Touch-friendly helpers
   ============================ */
@media (hover: none) and (pointer: coarse) {
  /* Ensure minimum tap targets */
  .btn, .btn-action, a.sidebar-link, .nav-tabs .nav-link,
  .pagination-modern .page-btn, .form-select, .form-control {
    min-height: 44px;
  }
  .sidebar-link { padding: 12px 20px; }
  .sidebar-submenu .sidebar-link { padding: 10px 20px 10px 0; }
  
  /* Show photo delete always on touch */
  .photo-card .photo-delete { opacity: 1; }
  
  /* Larger dropdown/select targets */
  .form-select { padding: 10px 12px; }
  
  /* More spacing between clickable rows */
  .table tbody td { padding: 12px; }
}

/* ============================
   Landscape mobile
   ============================ */
@media (max-height: 500px) and (orientation: landscape) {
  .modal-dialog { min-height: auto; }
  .modal-content { min-height: auto; }
  .sidebar { overflow-y: auto; }
  .kpi-card { padding: 8px 12px; }
}

/* ============================
   Responsive utility classes
   ============================ */
.d-mobile-only { display: none !important; }
.d-desktop-only { display: block !important; }
.d-desktop-only-flex { display: flex !important; }
.d-desktop-only-inline { display: inline-flex !important; }

@media (max-width: 767.98px) {
  .d-mobile-only { display: block !important; }
  .d-mobile-only-flex { display: flex !important; }
  .d-desktop-only { display: none !important; }
  .d-desktop-only-flex { display: none !important; }
  .d-desktop-only-inline { display: none !important; }
}

/* ============================
   Responsive images
   ============================ */
img { max-width: 100%; height: auto; }

/* ============================
   Topbar mobile user avatar
   ============================ */
.topbar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

/* ============================
   Mobile card view for tables
   ============================ */
@media (max-width: 767.98px) {
  .table-card-mobile thead { display: none; }
  .table-card-mobile tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  .table-card-mobile tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0,0,0,.05);
    font-size: 13px;
  }
  .table-card-mobile tbody td:last-child { border-bottom: none; }
  .table-card-mobile tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .3px;
    flex-shrink: 0;
    margin-right: 12px;
  }
}

/* ============================
   Form responsive overrides
   ============================ */
@media (max-width: 767.98px) {
  /* Stack all form columns */
  .row.g-2.align-items-end > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
  /* Exception: half-width for small fields */
  .row.g-2.align-items-end > .col-md-1 {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  /* Tablet: form fields in 2 columns */
  .row.g-2.align-items-end > [class*="col-md-1"],
  .row.g-2.align-items-end > [class*="col-md-2"] {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* ---------- Utilities ---------- */
.text-brand { color: var(--brand-primary) !important; }
.bg-brand { background: var(--brand-primary) !important; }
.bg-brand-light { background: var(--brand-light) !important; }
.border-brand { border-color: var(--brand-primary) !important; }

.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Tooltip custom */
.tooltip-rejection {
  position: relative;
  cursor: help;
}
.tooltip-rejection:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
}



/* ---------- Global Search Dropdown ---------- */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 1050;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
}
.search-item {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid #f0f0f0;
  transition: background .15s;
}
.search-item:hover {
  background: var(--brand-light);
  color: var(--text-primary);
}
.search-item:last-child { border-bottom: none; }

/* ---------- Confirm Dialog (SweetAlert2-style) ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s ease;
}
.confirm-overlay.show { opacity: 1; }
.confirm-dialog {
  background: white;
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  transform: scale(0.9);
  transition: transform .3s ease;
}
.confirm-overlay.show .confirm-dialog { transform: scale(1); }
.confirm-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #FFF3CD;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px;
  color: var(--accent);
}
.confirm-dialog h5 { margin-bottom: 8px; font-weight: 700; }
.confirm-dialog p { margin-bottom: 20px; }

/* ---------- Form Validation States ---------- */
.form-control.is-invalid, .form-select.is-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.15);
}
.form-control.is-valid, .form-select.is-valid {
  border-color: var(--brand-primary) !important;
}
.invalid-feedback {
  display: block;
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 4px;
}

/* ---------- Loading Spinner ---------- */
.spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.15em;
}

/* ---------- Accessibility Improvements ---------- */
*:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}
.btn:focus-visible, .form-control:focus-visible, .form-select:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.2);
}
.sidebar-link:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: -2px;
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--brand-primary);
  color: white;
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  transition: top .2s;
}
.skip-link:focus { top: 0; }

/* High contrast for text */
.text-muted { color: #555 !important; }

/* ---------- Pagination Modern (improvements) ---------- */
.pagination-modern {
  display: flex;
  justify-content: center;
  padding: 12px;
  gap: 4px;
  flex-wrap: wrap;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid #e0e0e0;
  transition: all .2s;
}
.page-btn:hover { background: var(--brand-light); color: var(--brand-primary); }
.page-btn.active {
  background: var(--brand-primary);
  color: white;
  border-color: var(--brand-primary);
}
