:root {
  --primary: #0d6efd;
  --primary-light: #e7f1ff;
  --bg-main: #f4f7f6;
  --bg-card: #ffffff;
  --text-main: #212529;
  --text-muted: #6c757d;
  --border-color: #dee2e6;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --transition-fast: 0.2s ease;
  
  --surface-card: var(--bg-card);
  --surface-bg: var(--bg-main);
  --text-primary: var(--text-main);
  --text-secondary: var(--text-muted);
  --border-subtle: var(--border-color);
  --accent: var(--primary);
  --accent-light: var(--primary-light);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.soft-shadow {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03) !important;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.soft-shadow:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04) !important;
}

.rounded-card {
  border-radius: 12px !important;
  border: none !important;
}

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: loadingSkeleton 1.5s infinite;
  border-radius: 0.5rem;
}
@keyframes loadingSkeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Global Loading Overlay */
#global-loading {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.loading-spinner-wrapper {
  background: #ffffff;
  padding: 24px 48px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

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

/* Desktop Sidebar */
#sidebar-wrapper {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
  overflow-y: auto;
  background: linear-gradient(180deg, #132B78 0%, #0E235F 50%, #081A45 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
}
#wrapper {
  max-width: 100%;
  overflow-x: hidden;
}
#page-content-wrapper {
  min-width: 0;
}
.sidebar-expanded {
  width: 250px !important;
}
.sidebar-collapsed {
  width: 70px !important;
}
.sidebar-collapsed .sidebar-text,
.sidebar-collapsed .sidebar-heading-text {
  display: none;
  opacity: 0;
}

/* --- OVERRIDES UNTUK SIDEBAR COLLAPSED (WIDTH 70px) --- */
.sidebar-collapsed .sidebar-item {
  margin: 4px 10px !important; /* Perkecil margin agar muat 70px */
  padding: 12px 0 !important; /* Buang padding horizontal agar icon center */
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 50px !important;
}
.sidebar-collapsed .sidebar-item i {
  margin-right: 0 !important; /* Hapus me-2 */
}
.sidebar-collapsed .sidebar-item:hover {
  transform: none !important; /* Matikan animasi geser */
}
.sidebar-collapsed hr {
  margin-left: 10px !important;
  margin-right: 10px !important;
}
.sidebar-collapsed .profile-card-wrapper {
  padding: 10px !important;
}
.sidebar-collapsed .profile-card {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  justify-content: center !important;
}
.sidebar-collapsed .profile-info {
  display: none !important;
}
.sidebar-collapsed .profile-avatar {
  margin-right: 0 !important; /* Hapus me-3 */
}
/* ------------------------------------------------------ */
.sidebar-item {
  white-space: nowrap;
  overflow: hidden;
  transition: all 0.25s ease;
  border-radius: 50rem !important; /* rounded penuh (pill) */
  margin: 4px 16px !important;
  padding: 12px 20px !important;
  font-weight: 500;
  background: transparent !important;
  color: #94a3b8 !important;
  width: auto !important; /* Mencegah overflow 100% Bootstrap */
}
.sidebar-item i {
  color: #94a3b8;
  transition: all 0.25s ease;
}
.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #fff !important;
  transform: translateX(4px);
}
.sidebar-item:hover i {
  color: #fff !important;
}
.sidebar-item.active {
  background: linear-gradient(90deg, #3b82f6, #1d4ed8) !important; /* Gradient Biru terang */
  color: #fff !important;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
  border-left: none !important;
}
.sidebar-item.active i {
  color: #fff !important;
}

.logout-btn {
  color: #f87171 !important;
}
.logout-btn i {
  color: #f87171 !important;
}
.logout-btn:hover {
  background: #ef4444 !important;
  color: #fff !important;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}
.logout-btn:hover i {
  color: #fff !important;
}

@media (min-width: 992px) {
  #sidebar-wrapper.sidebar-expanded {
    width: 250px !important;
    min-width: 250px;
  }
  #sidebar-wrapper.sidebar-collapsed {
    width: 70px !important;
    min-width: 70px;
  }
  .sidebar-overlay {
    display: none !important;
  }
}

@media (max-width: 991.98px) {
  #sidebar-wrapper {
    position: fixed;
    top: 0; left: -280px; width: 280px !important; height: 100vh;
    z-index: 1045; box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
  }
  #sidebar-wrapper.sidebar-expanded { left: 0; }
  #sidebar-wrapper.sidebar-collapsed { left: -280px; }
  .sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5); z-index: 1040;
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  .sidebar-overlay.show { opacity: 1; visibility: visible; }
}

/* MOBILE SPECIFIC */
@media (max-width: 767.98px) {
  #page-content-wrapper .container-fluid {
    padding-bottom: calc(74px + var(--safe-bottom)) !important;
  }
  #top-navbar, #sidebar-wrapper, #sidebar-overlay {
    display: none !important;
  }
  
  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(60px + var(--safe-bottom));
    background: var(--surface-card);
    border-top: 1px solid var(--border-subtle);
    display: flex; align-items: flex-start; justify-content: space-around;
    z-index: 1030; box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.08);
    padding-top: 8px; padding-bottom: var(--safe-bottom);
    transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.25s ease;
  }
  .bottom-nav.nav-hidden {
    transform: translateY(100%) !important; opacity: 0 !important;
  }
  .bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    flex: 1; cursor: pointer; border: none; background: transparent;
    color: var(--text-secondary); font-size: 10px; font-weight: 600;
    transition: color 0.2s ease; text-decoration: none; min-height: 48px;
    padding: 2px 4px; position: relative;
    -webkit-tap-highlight-color: transparent; letter-spacing: 0.3px;
  }
  .bottom-nav-item i { font-size: 18px; transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); position: relative; z-index: 1; }
  .bottom-nav-item span { position: relative; z-index: 1; }
  .bottom-nav-item.active { color: var(--accent); }
  .bottom-nav-item.active i { transform: scale(1.1); }
  .bottom-nav-item.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 40px; height: 28px; background: var(--accent-light); border-radius: 10px; z-index: 0;
  }

  /* FAB */
  .fab-container {
    position: fixed; bottom: calc(72px + var(--safe-bottom)); right: 16px;
    z-index: 1035; display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 10px;
  }
  .fab-main {
    width: 52px; height: 52px; border-radius: 14px; background: var(--accent);
    color: white; border: none; display: flex; align-items: center; justify-content: center;
    font-size: 20px; box-shadow: 0 4px 18px rgba(13, 110, 253, 0.45); cursor: pointer;
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-radius 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .fab-main.open {
    transform: rotate(45deg); border-radius: 50%; background: #e53e3e; box-shadow: 0 4px 18px rgba(229, 62, 62, 0.4);
  }
  .fab-menu {
    display: flex; flex-direction: column-reverse; gap: 10px; align-items: flex-end; pointer-events: none;
  }
  .fab-item {
    display: flex; align-items: center; gap: 10px; opacity: 0; transform: scale(0.7) translateY(20px);
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); pointer-events: none;
  }
  .fab-menu.open, .fab-menu.open .fab-item { pointer-events: auto; }
  .fab-menu.open .fab-item { opacity: 1; transform: scale(1) translateY(0); }
  .fab-item-label { background: var(--surface-card); color: var(--text-primary); font-size: 13px; font-weight: 700; padding: 6px 14px; border-radius: 20px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14); }
  .fab-item-btn { width: 42px; height: 42px; border-radius: 12px; border: none; display: flex; align-items: center; justify-content: center; font-size: 16px; color: white; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22); }
  .fab-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 1034; opacity: 0; visibility: hidden; transition: opacity 0.25s ease, visibility 0.25s ease; }
  .fab-backdrop.show { opacity: 1; visibility: visible; }

  /* Mobile Top Bar */
  .mobile-top-bar {
    position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; justify-content: space-between;
    padding: 0 14px; height: 54px; background: var(--surface-card); border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  }
  .mobile-top-bar-title { font-size: 16px; font-weight: 800; color: var(--text-primary); }

  /* Bottom Sheet */
  .bottom-sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 1060; opacity: 0; visibility: hidden; transition: opacity 0.28s ease, visibility 0.28s ease; }
  .bottom-sheet-backdrop.show { opacity: 1; visibility: visible; }
  .bottom-sheet { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface-card); border-radius: 24px 24px 0 0; z-index: 1061; transform: translateY(100%); transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1); box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12); display: flex; flex-direction: column; max-height: 90vh; }
  .bottom-sheet.show { transform: translateY(0); }
  .bottom-sheet-handle { width: 36px; height: 4px; background: #e2e8f0; border-radius: 4px; margin: 12px auto; }
  .bottom-sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 16px; border-bottom: 1px solid var(--border-subtle); }
  .bottom-sheet-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
  .bottom-sheet-close { background: #f1f5f9; border: none; width: 28px; height: 28px; border-radius: 50%; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; }
  .bottom-sheet-body { padding: 20px; overflow-y: auto; overscroll-behavior: contain; }
}

.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000; padding: 9px 16px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px; justify-content: center; transform: translateY(-100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1); pointer-events: none;
}
.offline-banner.show { transform: translateY(0); pointer-events: auto; }
.offline-banner.offline { background: #dc2626; color: white; }
.offline-banner.online-back { background: #16a34a; color: white; }

/* Desktop overrides for mobile-only elements */
@media (min-width: 768px) {
  .bottom-nav,
  .fab-container,
  .fab-backdrop,
  .bottom-sheet-backdrop,
  .bottom-sheet,
  .mobile-top-bar {
    display: none !important;
  }
}

/* Login Page overrides */
body.login-page #sidebar-wrapper,
body.login-page #sidebar-overlay,
body.login-page #top-navbar,
body.login-page .mobile-top-bar,
body.login-page .bottom-nav,
body.login-page .fab-container,
body.login-page .bottom-sheet-backdrop,
body.login-page .bottom-sheet {
  display: none !important;
}

body.login-page #page-content-wrapper {
  width: 100% !important;
}

/* Shift Focus Mode overrides */
body.shift-mode #sidebar-wrapper,
body.shift-mode #sidebar-overlay,
body.shift-mode #top-navbar,
body.shift-mode .mobile-top-bar,
body.shift-mode .bottom-nav,
body.shift-mode .fab-container,
body.shift-mode .bottom-sheet-backdrop,
body.shift-mode .bottom-sheet {
  display: none !important;
}

body.shift-mode #page-content-wrapper {
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}
