:root {
    --sidebar-width: 260px;
    --bg-body: #f3f4f6;
    --bg-sidebar: #020617;
    --radius-card: 1rem;
    --shadow-card: 0 18px 40px rgba(15, 23, 42, 0.04);
    --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    width: 100%;
    max-width: 100vw;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    margin: 0;
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow-y: auto;
    /* Don't use overflow-x: hidden - it prevents table-responsive from scrolling */
}

.layout {
    min-height: 100vh;
    display: flex;
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow-x: hidden; /* Prevent layout from scrolling horizontally */
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset-block: 0;
    z-index: 1030;
    transition: transform 0.25s ease, width 0.25s ease;
}
.sidebar-brand {
    height: 64px;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}
.sidebar-brand span {
    font-weight: 600;
    font-size: 1.1rem;
}
.sidebar-brand .logo {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.75rem;
}
.sidebar-brand small {
    color: #9ca3af;
}
.sidebar-brand .logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.sidebar-nav {
    padding: 1rem 0.75rem 1rem;
    flex: 1;
    overflow-y: auto;
    /* Hide scrollbar for Chrome, Safari and Opera */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}
.sidebar-nav::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}
.sidebar-title {
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    padding: 0.75rem 0.75rem 0.25rem;
}
.sidebar .nav-link {
    color: #e5e7eb;
    font-size: 0.9rem;
    border-radius: 0.75rem;
    padding: 0.55rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.15rem;
}
.sidebar .nav-link i {
    font-size: 1rem;
}
.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
}

.sidebar-footer {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    font-size: 0.8rem;
    color: #9ca3af;
}

/* MAIN */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    width: calc(100vw - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden; /* Prevent main from scrolling horizontally */
    transition: margin-left 0.25s ease, width 0.25s ease, max-width 0.25s ease;
}

/* Sidebar collapsed (hide) - dipakai di desktop & mobile */
.layout.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    width: 0;
    min-width: 0;
    overflow: hidden;
}
.layout.sidebar-collapsed .main {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
}

/* TOPBAR */
.topbar {
    height: 64px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffffcc;
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-inner {
    height: 100%;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}
.breadcrumb {
    margin-bottom: 0;
    font-size: 0.8rem;
}

/* CONTENT */
.content {
    padding: 1.5rem;
    width: 100%;
    max-width: 100%;
    overflow-x: visible; /* Allow table-responsive to scroll */
    position: relative;
}

.card {
    border-radius: var(--radius-card);
    border: none;
    box-shadow: var(--shadow-card);
}

.card-kpi h6 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
}
.kpi-value {
    font-size: 1.4rem;
    font-weight: 600;
}
.kpi-badge {
    font-size: 0.75rem;
}

/* CHART WRAPPER */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 260px;
    border-radius: 0.9rem;
    background: radial-gradient(circle at top left, #eef2ff, #e5e7eb);
    padding: 0.75rem;
}
.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* SMALL CHARTS */
.chart-wrapper-sm {
    position: relative;
    width: 100%;
    height: 180px;
    border-radius: 0.9rem;
    background: radial-gradient(circle at top left, #f5f3ff, #e5e7eb);
    padding: 0.5rem;
}
.chart-wrapper-sm canvas {
    width: 100% !important;
    height: 100% !important;
}

.table-sm td,
.table-sm th {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}

/* TABLE RESPONSIVE - Bootstrap's table-responsive with enhanced scroll */
/* This creates a new scroll context that works even with parent overflow-x: hidden */
.table-responsive {
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block !important;
    width: 100%;
    position: relative;
    /* Break out of parent overflow-x: hidden by creating new stacking context */
    isolation: isolate;
    /* Force hardware acceleration */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    will-change: scroll-position;
}

/* Ensure tables inside table-responsive can be wider than container */
.table-responsive table {
    width: max-content !important;
    min-width: 100%;
    margin-bottom: 0;
    display: table !important;
}

/* Ensure card-body doesn't interfere */
.card-body {
    overflow-x: visible !important;
    position: relative;
}

/* Custom scrollbar for table-responsive */
.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* AVATAR */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: #e5e7eb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

/* AUTH (LOGIN) */
body.auth {
    min-height: 100vh;
    background: radial-gradient(circle at top left, #4f46e5, #0f172a 55%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-card {
    max-width: 420px;
    width: 100%;
    border-radius: 1.25rem;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.65);
    overflow: hidden;
}
.auth-header {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    padding: 1.5rem 1.75rem;
}
.auth-header h1 {
    font-size: 1.25rem;
    margin: 0;
}
.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}
.brand-logo {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.auth-body {
    padding: 1.75rem;
    background: #f9fafb;
}

/* BADGES & SMALL UI */
.badge-soft {
    border-radius: 999px;
    padding-inline: 0.65rem;
}

/* MAP STYLES */
#map {
    z-index: 1;
}
.custom-marker {
    background: transparent !important;
    border: none !important;
}
.legend {
    font-family: var(--font-main);
}

.login-container {
    min-height: 100vh;
    display: flex;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

.login-left {
    flex: 1;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.login-left::before {
    content: "";
    position: absolute;
    top: -50%;
    right: -20%;
    width: 500px;
    height: 500px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 50%;
}

.login-left::after {
    content: "";
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 400px;
    height: 400px;
    background: rgba(255, 152, 0, 0.1);
    border-radius: 50%;
}

.illustration-wrapper {
    position: relative;
    z-index: 1;
    text-align: center;
}

.illustration-text {
    color: #1976d2;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 2rem;
    line-height: 1.4;
}

.illustration-text .highlight {
    color: #ff9800;
}

.illustration-placeholder {
    width: 100%;
    max-width: 500px;
    height: 400px;
    background: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    position: relative;
}

.login-right {
    flex: 1;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    position: relative;
}

.login-form-wrapper {
    width: 100%;
    max-width: 420px;
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.login-logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
}

.login-logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1976d2;
}

.login-greeting {
    font-size: 1.1rem;
    color: #424242;
    margin-bottom: 0.5rem;
}

.login-register-link {
    font-size: 0.9rem;
    color: #757575;
    margin-bottom: 2rem;
}

.login-register-link a {
    color: #2196f3;
    text-decoration: none;
    font-weight: 600;
}

.form-label {
    font-weight: 500;
    color: #424242;
    margin-bottom: 0.5rem;
}

.form-control {
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    padding: 0.75rem 1rem;
}

.form-control:focus {
    border-color: #2196f3;
    box-shadow: 0 0 0 0.2rem rgba(33, 150, 243, 0.1);
}

.password-toggle {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #757575;
    cursor: pointer;
}

.password-wrapper {
    position: relative;
}

.btn-login {
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    border: none;
    border-radius: 8px;
    padding: 0.75rem;
    font-weight: 600;
    width: 100%;
    margin-top: 1rem;
}

.btn-login:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
}

.forgot-password {
    text-align: center;
    margin-top: 1rem;
}

.forgot-password a {
    color: #2196f3;
    text-decoration: none;
    font-size: 0.9rem;
}

.social-login {
    margin-top: 2rem;
    text-align: center;
}

.social-login-title {
    font-size: 0.9rem;
    color: #757575;
    margin-bottom: 1rem;
}

.social-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.btn-social {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    color: #424242;
    font-size: 1.2rem;
    transition: all 0.3s;
}

.btn-social:hover {
    background: #f5f5f5;
    border-color: #bdbdbd;
}

.btn-social.facebook {
    background: #1877f2;
    color: white;
    border-color: #1877f2;
}

.btn-social.facebook:hover {
    background: #166fe5;
}

.remember-device {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.remember-device input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.remember-device label {
    font-size: 0.9rem;
    color: #424242;
    cursor: pointer;
    margin: 0;
}

.terms-text {
    margin-top: 2rem;
    font-size: 0.85rem;
    color: #757575;
    text-align: center;
    line-height: 1.5;
}

.terms-text a {
    color: #2196f3;
    text-decoration: none;
}

@media (max-width: 992px) {
    .login-container {
        flex-direction: column;
    }

    .login-left {
        min-height: 300px;
    }
}

/* RESPONSIVE */
@media (max-width: 992px) {
    :root {
        --sidebar-width: 260px;
    }
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    .layout:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }
    .layout.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        min-width: unset;
    }
    .main {
        margin-left: 0;
    }
    #map {
        height: 400px !important;
    }
}
