:root {
  --sidebar-width: 240px;
  --sidebar-collapsed: 60px;
  --primary: #0d6efd;
  --dark: #1a1d23;
  --card-shadow: 0 2px 10px rgba(0,0,0,.08);
  --navbar-height: 56px;
}

body { font-family: 'Inter', sans-serif; font-size: 14px; background: #f5f6fa; min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden; }

/* ===================== WRAPPER ===================== */
.wrapper {
  align-items: flex-start;
  flex: 1 0 auto;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--navbar-height));
  background: #1a1d23 !important;
  transition: width .25s ease;
  overflow-x: hidden;
  overflow-y: auto;
  flex-shrink: 0;
  position: sticky;
  top: var(--navbar-height);
  z-index: 100;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-heading,
.sidebar.collapsed .badge { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: .5rem; }
.sidebar .nav-link {
  color: #adb5bd;
  padding: .45rem 1rem;
  border-radius: 6px;
  margin: 1px 6px;
  font-size: .875rem;
  display: flex;
  align-items: center;
  transition: all .2s;
  white-space: nowrap;
}
.sidebar .nav-link:hover,
.sidebar .nav-link.active { color: #fff; background: rgba(255,255,255,.1); }
.sidebar .nav-link.active { background: var(--primary) !important; color: #fff !important; }
.sidebar .sidebar-heading { font-size: .7rem; letter-spacing: .08em; padding: 0 1rem; }
.sidebar .nav-link i { width: 20px; font-size: 1rem; flex-shrink: 0; }

/* ===================== MOBILE SIDEBAR ===================== */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-width));
    top: 0;
    height: 100vh;
    z-index: 1045;
    overflow-y: auto;
    transition: left .25s ease;
  }
  .sidebar.mobile-open {
    left: 0;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.show { display: block; }
  .main-content { width: 100%; }
}

.main-content { min-width: 0; overflow-x: hidden; }

/* ===================== NAVBAR ===================== */
.navbar { position: sticky; top: 0; z-index: 1030; height: var(--navbar-height); }
#mobileMenuBtn { display: none; }
@media (max-width: 991.98px) {
  #mobileMenuBtn { display: inline-flex; }
  #sidebarToggle { display: none !important; }
}

/* Search bar */
@media (max-width: 575px) {
  .navbar-search { display: none; }
  .navbar-search.show { display: flex; width: 100%; }
}

/* ===================== CARDS ===================== */
.card { border: none; box-shadow: var(--card-shadow); border-radius: 12px; }
.card-header { border-bottom: 1px solid rgba(0,0,0,.06); background: #fff; font-weight: 600; border-radius: 12px 12px 0 0 !important; }
.stat-card { border-radius: 12px; overflow: hidden; transition: transform .2s, box-shadow .2s; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.stat-card .icon-box { width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.icon-box { display: flex; align-items: center; justify-content: center; }

/* ===================== TABLES ===================== */
.table-responsive { border-radius: 12px; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; color: #6c757d; border-top: none; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(13,110,253,.04); }

/* ===================== FORMS ===================== */
.form-control, .form-select { border-radius: 8px; border-color: #dee2e6; font-size: .875rem; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 .2rem rgba(13,110,253,.15); }
.form-label { font-weight: 500; color: #495057; font-size: .875rem; }
.btn { border-radius: 8px; font-size: .875rem; font-weight: 500; }
.btn-primary { background: var(--primary); }

/* ===================== BADGES ===================== */
.badge { font-size: .75rem; padding: .35em .65em; border-radius: 6px; }

/* ===================== AUTH PAGES ===================== */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0d6efd22 0%, #6610f222 100%); }
.auth-card { width: 100%; max-width: 460px; border-radius: 16px !important; }
.auth-logo { font-size: 1.6rem; font-weight: 700; color: var(--primary); }

/* ===================== UPLOAD ZONE ===================== */
.upload-zone { border: 2px dashed #dee2e6; border-radius: 12px; padding: 2.5rem; text-align: center; transition: border-color .2s, background .2s; cursor: pointer; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: rgba(13,110,253,.04); }
.upload-zone i { font-size: 2.5rem; color: #6c757d; }
.upload-progress { display: none; }
.upload-progress.show { display: block; }
.upload-progress .progress { height: 20px; border-radius: 10px; background: #e9ecef; }
.upload-progress .progress-bar { transition: width .2s ease; font-size: .75rem; line-height: 20px; }

/* ===================== STAR RATING ===================== */
.star-rating { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 2px; }
.star-rating input { display: none; }
.star-rating label { font-size: 1.2rem; color: #ddd; cursor: pointer; transition: color .15s; }
.star-rating input:checked ~ label,
.star-rating label:hover,
.star-rating label:hover ~ label { color: #ffc107; }

/* ===================== NOTICE BAR ===================== */
.notice-bar { font-size: .85rem; }

/* ===================== FILE ICONS ===================== */
.file-icon { font-size: 1.8rem; }

/* ===================== PAGINATION ===================== */
.pagination .page-link { border-radius: 6px !important; margin: 0 2px; border: none; color: var(--primary); }
.pagination .page-item.active .page-link { background: var(--primary); }

/* ===================== SEARCH ===================== */
mark { background: #fff3cd; padding: 0 2px; border-radius: 3px; }

/* ===================== DARK MODE ===================== */
body.dark-mode { background: #121212; color: #e0e0e0; }
body.dark-mode .card { background: #1e1e1e; color: #e0e0e0; }
body.dark-mode .table { color: #e0e0e0; }
body.dark-mode .form-control { background: #2a2a2a; color: #e0e0e0; border-color: #444; }

/* ===================== TOOLTIPS / MISC ===================== */
[data-bs-toggle="tooltip"] { cursor: pointer; }
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-state i { font-size: 3rem; color: #dee2e6; }
.activity-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.hover-shadow:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12) !important; }
.word-break-all { word-break: break-all; }

/* ===================== APPROVAL BADGE ===================== */
.pending-count-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: .65rem;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================== TOGGLE SWITCH ===================== */
.form-check-input[type="checkbox"].toggle-switch {
  width: 3em;
  height: 1.5em;
  border-radius: 999px;
}

/* ===================== HIGHLIGHTED HANDOUTS ===================== */
.highlight-badge {
  background: linear-gradient(135deg, #ffc107, #ff9800);
  color: #1a1d23;
  font-weight: 600;
}

/* ===================== FOOTER ALWAYS AT BOTTOM ===================== */
footer.footer { flex-shrink: 0; margin-top: auto; }

/* ===================== NAVBAR BRAND TEXT ===================== */
.navbar-brand-text {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}
@media (max-width: 400px) {
  .navbar-brand-text { max-width: 80px; font-size: .85rem; }
}

/* ===================== MOBILE LAYOUT FIXES ===================== */
@media (max-width: 991.98px) {
  /* Sidebar scrolls independently inside the fixed overlay */
  .sidebar {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Main content gets its own scroll, not tied to sidebar */
  .main-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Prevent body scroll when sidebar overlay is shown */
  body.sidebar-body-lock {
    overflow: hidden;
  }
  /* Wrapper min-height so footer stays down */
  .wrapper {
    min-height: calc(100vh - var(--navbar-height));
  }
}

/* ===================== INDEPENDENT SCROLL LAYOUT ===================== */
/* Wrapper takes full viewport height below navbar */
.wrapper {
  height: calc(100vh - var(--navbar-height));
  overflow: hidden;
  display: flex;
}
/* Sidebar: fixed height, independent scroll */
.sidebar {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}
/* Main content: fills rest, independent scroll */
.main-content {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}
/* Footer stays inside wrapper flow — keep it visible */
.footer-wrapper {
  flex-shrink: 0;
}

/* ===================== CUSTOM HEADER NAV MENU ===================== */
.header-menu-link {
  font-size: .8rem;
  padding: .3rem .65rem;
  font-weight: 500;
  border-color: rgba(255,255,255,.35) !important;
  color: #fff !important;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.header-menu-link:hover {
  background: rgba(255,255,255,.18) !important;
  border-color: rgba(255,255,255,.7) !important;
}

/* ===================== DASHBOARD V2 ENHANCEMENTS ===================== */
.stat-card-v2 {
  border: none !important;
  border-radius: 14px !important;
  transition: transform .2s, box-shadow .2s;
  overflow: hidden;
  position: relative;
}
.stat-card-v2:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(0,0,0,.18) !important;
}
.stat-icon-v2 {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: #fff;
}
.stat-number-v2 { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label-v2  { font-size: .75rem; opacity: .85; font-weight: 500; }
.stat-card-v2 .stretched-link::after { z-index: 2; }

/* Quick link cards */
.quick-link-card {
  border-radius: 10px !important;
  transition: transform .15s, box-shadow .15s;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.06) !important;
}
.quick-link-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,.12) !important;
}

/* ===================== SIDEBAR ACTIVE STATE FIX ===================== */
/* Ensure active nav-link always visible and correctly highlighted */
.sidebar .nav-link.active {
  background: rgba(255,255,255,.15) !important;
  color: #fff !important;
  font-weight: 600;
  border-left: 3px solid rgba(255,255,255,.8);
}
.sidebar .nav-link.active i {
  opacity: 1;
}

/* Notice bar cleanup */
.notice-bar .btn-close { opacity: .5; }
.notice-bar .btn-close:hover { opacity: 1; }
