:root {
  --bg: #f8fafc; --card: #fff; --text: #0f172a; --text-muted: #64748b;
  --primary: #3b82f6; --primary-dark: #2563eb; --danger: #ef4444; --success: #10b981;
  --border: #e2e8f0; --shadow: 0 4px 12px rgba(0,0,0,0.08); --radius: 12px;
  --sidebar-w: 260px; --sidebar-c: 100px;
}

[data-theme="dark"] {
  --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; --text-muted: #94a3b8;
  --border: #334155; --shadow: 0 4px 12px rgba(0,0,0,0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', system-ui, sans-serif; }
body { background: var(--bg); color: var(--text); min-height: 100vh; }
.glass { background: var(--card); backdrop-filter: blur(10px); border: 1px solid var(--border); }

.app-layout { display: flex; min-height: 100vh; }

/* ================= SIDEBAR DEFAULT ================= */
.sidebar { width: var(--sidebar-w); height: 100vh; position: fixed; left: 0; top: 0; padding: 1.5rem; display: flex; flex-direction: column; transition: width 0.3s; z-index: 100; border-right: 1px solid var(--border); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; }
.brand { font-size: 1.25rem; font-weight: 800; display: flex; align-items: center; gap: 0.5rem; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.nav-link { display: flex; align-items: center; justify-content: flex-start; gap: 0.75rem; padding: 0.875rem 1rem; border-radius: 10px; color: var(--text-muted); text-decoration: none; transition: 0.2s; cursor: pointer; }
.nav-link:hover { background: var(--bg); color: var(--primary); }
.nav-link.active { background: var(--primary); color: #fff; box-shadow: var(--shadow); }

.sidebar-footer { padding-top: 1rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.75rem; }
.icon-btn { background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: 0.5rem; border-radius: 8px; color: var(--text-muted); display: flex; justify-content: flex-start; align-items: center; }
.icon-btn:hover { background: var(--bg); }
.btn-logout { display: flex; align-items: center; justify-content: flex-start; gap: 0.75rem; padding: 0.875rem; background: var(--danger); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; }

/* ================= SIDEBAR COLLAPSED ================= */
.sidebar.collapsed { width: var(--sidebar-c); }
.sidebar.collapsed .brand span, .sidebar.collapsed .nav-link span:last-child, .sidebar.collapsed .btn-logout span:last-child { display: none; }
.sidebar.collapsed .brand, .sidebar.collapsed .nav-link { justify-content: center; padding: 0.875rem 2rem; width: 100%; margin: 0 0 0.5rem 0; border-radius: 10px; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 0; }
.sidebar.collapsed .icon-btn, .sidebar.collapsed .btn-logout { justify-content: center !important; padding: 0.875rem 2rem; width: 100%; margin: 0; }

/* ================= MAIN AREA & TOPBAR ================= */
.main-area { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; transition: margin-left 0.3s; }
.sidebar.collapsed ~ .main-area { margin-left: var(--sidebar-c); }
.topbar { height: 70px; margin: 1rem 1rem 0; border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; gap: 1rem; }
.content-area { padding: 1.5rem; flex: 1; overflow-y: auto; }
.user-badge { background: var(--bg); padding: 0.5rem 1rem; border-radius: 20px; font-weight: 600; font-size: 0.875rem; white-space: nowrap; }

/* ================= COMPONENTS ================= */
.btn { padding: 0.625rem 1.25rem; border-radius: 8px; border: none; cursor: pointer; font-weight: 500; transition: 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
.badge { padding: 0.25rem 0.625rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; background: var(--bg); }
.card { background: var(--card); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 200; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--card); padding: 2rem; border-radius: var(--radius); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }
#toastContainer { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--card); padding: 1rem 1.5rem; border-radius: 10px; box-shadow: var(--shadow); border-left: 4px solid var(--success); animation: slideIn 0.3s; }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.loader { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 40vh; color: var(--text-muted); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.website-btn { display: block; width: 100%; padding: 0.75rem 1rem; text-decoration: none; border-radius: 8px; text-align: center; font-weight: 600; font-size: 0.875rem; margin: 0.75rem 0 0 0; transition: all 0.2s; border: none; }
.website-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }

/* ================= LOGIN PAGE (DARK MODE / AI SLOP) ================= */
.login-body { display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at center, #1a1a1a 0%, #000000 80%); min-height: 100vh; padding: 20px; }
.login-card { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 20px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5); }
.login-card .logo { width: 70px; height: 70px; border-radius: 50%; background: #ffffff; color: #000000; display: flex; justify-content: center; align-items: center; font-size: 2rem; margin: 0 auto 25px auto; }
.login-card h1 { text-align: center; color: #ffffff; font-size: 1.6rem; font-weight: 600; margin-bottom: 5px; }
.login-card p { text-align: center; color: #888888; font-size: 0.9rem; margin-bottom: 30px; }

/* Efek Floating Label */
.form-group { margin-bottom: 25px; position: relative; }
.form-group label { display: block; color: #888888; font-size: 0.85rem; margin-bottom: 5px; transition: all 0.3s ease; }
.form-group input { width: 100%; background: transparent; border: none; border-bottom: 1px solid #555555; color: #ffffff; font-size: 1rem; outline: none; transition: border-color 0.3s; }
.form-group input:focus { border-bottom-color: #ffffff; }
.form-group:focus-within label { color: #ffffff; transform: translateY(-10px); font-size: 0.75rem; }

#loginBtn { width: 100%; padding: 15px; border-radius: 50px; background: #ffffff; color: #000000; border: none; cursor: pointer; font-size: 1rem; font-weight: 700; margin-top: 10px; transition: background 0.3s, transform 0.2s; box-shadow: 0 4px 15px rgba(255, 255, 255, 0.2); }
#loginBtn:hover { background: #e6e6e6; transform: translateY(-2px); }
.error-msg { display: none;  background: rgba(255, 0, 0, 0.1); color: #ff4444; padding: 10px; border-radius: 8px; margin-top: 15px; font-size: 0.85rem; text-align: center; }

@media (max-width: 600px) {
  .login-card { padding: 25px; max-width: 320px; }
  .login-card .logo { width: 60px; height: 60px; font-size: 1.6rem; margin-bottom: 20px; }
  .login-card h1 { font-size: 1.4rem; }
  #loginBtn { padding: 12px; }
}

/* ================= RESPONSIVE & MOBILE MENU ================= */
.mobile-menu-btn { display: none; }
.sidebar-overlay { display: none; }

@media(max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; width: 260px !important; background: var(--card) !important; color: var(--text) !important; transform: translateX(-100%); transition: transform 0.3s ease; z-index: 1000; box-shadow: 4px 0 20px rgba(0,0,0,0.3); border-right: 1px solid var(--border); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 260px !important; }
  .sidebar.collapsed .brand span, .sidebar.collapsed .nav-link span:last-child, .sidebar.collapsed .btn-logout span:last-child { display: inline !important; }
  .nav-link { justify-content: flex-start !important; padding: 0.875rem 1rem !important; width: 100% !important; margin: 0 !important; }
  .icon-btn, .btn-logout { justify-content: center !important; padding: 0.875rem !important; width: 100% !important; margin: 0 !important; }
  .brand { justify-content: flex-start !important; }
  .main-area { margin-left: 0 !important; width: 100%; }
  .mobile-menu-btn { display: block !important; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); padding: 0.5rem; margin-right: 0.5rem; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
  .sidebar-overlay.active { display: block; }
  .stats-grid, .charts-row { grid-template-columns: 1fr !important; }
  .filter-controls > div:first-child { grid-template-columns: 1fr !important; }
  .lamaran-table { font-size: 0.8rem; }
  .lamaran-table th, .lamaran-table td { padding: 0.5rem 0.25rem; }
  .grid-cards, [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .modal-box { margin: 1rem; padding: 1.5rem; }
  #toastContainer { left: 1rem; right: 1rem; }
  .toast { width: 100%; }
}

/* ================= FINAL FIX: TOGGLE SIDEBAR & THEME ================= */
.sidebar.collapsed #toggleSidebar { padding-left: 0 !important; padding-right: 0 !important; width: auto !important; justify-content: center !important; margin: 0 auto !important; }
.sidebar.collapsed .sidebar-footer .icon-btn { padding-left: 2rem !important; padding-right: 2rem !important; width: 100% !important; }

#themeToggle { display: flex !important; justify-content: center !important; align-items: center !important; width: 100% !important; padding: 0.875rem 2rem !important; margin: 0 auto !important; }
.sidebar.collapsed #themeToggle { display: flex !important; justify-content: center !important; align-items: center !important; width: 100% !important; padding: 0.875rem 2rem !important; margin: 0 auto !important; }

/* ==========================================================
   PERBAIKAN TOPBAR MOBILE (JUDUL & USER BADGE)
   ========================================================== */
@media(max-width: 768px) {
  /* Kurangi padding agar lebih lega */
  .topbar {
    padding: 0 1rem;
    gap: 0.5rem;
  }

  /* Judul: Kecilkan ukurannya dan potong dengan "..." jika kepanjangan */
  #pageTitle {
    font-size: 1.1rem !important; 
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1; /* Mengisi sisa ruang, tapi bisa menyusut */
  }

  /* User Badge: Batasi lebarnya agar tidak keluar layar */
  .user-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    max-width: 40vw; /* Maksimal 40% dari lebar layar */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1; /* Boleh menyusut jika sempit */
  }
}