html {
    font-size: 15px;
}

html, body {
    overflow-x: hidden;
}

body {
    background: linear-gradient(180deg, #f3f7fb 0%, #e9eff7 55%, #ffffff 100%);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    color: #212529;
}

.main-content {
    margin-left: 250px;
    transition: margin-left 0.3s ease;
}

/* Sidebar Styles */
#sidebar {
    transition: transform 0.3s ease, width 0.3s ease;
    overflow-y: auto;
    width: 250px;
    z-index: 1100;
    transform: translateX(0);
    position: fixed;
    inset: 0 auto 0 0;
    background: linear-gradient(180deg, #0f4a7f 0%, #1f72b1 100%);
}

#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 41, 78, 0.55);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.sidebar-open #sidebarOverlay {
    display: block;
    opacity: 1;
}

body.sidebar-open {
    overflow: hidden;
}

body.sidebar-open #sidebar {
    transform: translateX(0);
}

#sidebar .nav-link,
#sidebar .module-toggle {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.35rem;
    transition: all 0.3s ease;
    color: rgba(255,255,255,0.95);
}

#sidebar .nav-link:hover,
#sidebar .module-toggle:hover {
    background-color: rgba(255, 255, 255, 0.12);
    transform: translateX(4px);
}

#sidebar .nav-link.active {
    background-color: rgba(255, 255, 255, 0.18);
    font-weight: 600;
}

#sidebar .collapse ul .nav-link {
    padding: 0.65rem 1rem 0.65rem 2rem;
    font-size: 0.92rem;
}

/* Main Content */
.flex-grow-1 {
    padding: 1.5rem;
}

/* Cards */
.card {
    background: rgba(255,255,255,0.95);
    border: none;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(37, 83, 133, 0.1);
    backdrop-filter: blur(15px);
    animation: fadeIn 0.5s ease-out;
}

.card-header {
    background: linear-gradient(135deg, #4a90e2, #66b3d1);
    color: white;
    border-radius: 18px 18px 0 0 !important;
    border-bottom: none;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    padding: 1rem 1.25rem;
}

.card-body {
    padding: 1.6rem;
}

.card-body p,
.card-body .text-muted {
    color: #5d6d7a;
}

.alert {
    margin-top: 1rem;
    border-radius: 14px;
    border: none;
    box-shadow: 0 10px 30px rgba(34, 63, 102, 0.06);
}

.btn-primary,
.btn-success,
.btn-warning,
.btn-info {
    border: none;
    border-radius: 999px;
    padding: 0.75rem 1.4rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #4a90e2, #3178c6);
    box-shadow: 0 10px 22px rgba(71, 126, 189, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #3178c6, #205ea7);
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #3cb371, #2f8f63);
}

.btn-success:hover {
    transform: translateY(-2px);
}

.btn-outline-primary {
    border-color: #4a90e2;
    color: #4a90e2;
    border-radius: 999px;
    padding: 0.55rem 1.25rem;
    font-weight: 600;
}

.btn-outline-primary:hover {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
    transform: translateY(-1px);
}

.btn-outline-light {
    border-color: rgba(255, 255, 255, 0.55);
    color: white;
}

.btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.18);
}

.form-control,
.form-select {
    border-radius: 14px;
    border: 1px solid #dae5ee;
    padding: 0.85rem;
    background: rgba(255, 255, 255, 0.95);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 0 0.18rem rgba(74,144,226,0.18);
    background: white;
}

.form-label {
    font-weight: 700;
    color: #495057;
}

.nav-pills .nav-link {
    border-radius: 999px;
    padding: 0.75rem 1.35rem;
    margin: 0 0.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(255, 255, 255, 0.92);
    color: #3178c6;
    border: 1px solid #c3d8ef;
}

.nav-pills .nav-link.active {
    background: linear-gradient(135deg, #4a90e2, #3178c6);
    color: white;
    border-color: transparent;
}

.nav-pills .nav-link:not(.active):hover {
    background: #4a90e2;
    color: white;
    transform: translateY(-1px);
}

.table {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 14px;
    overflow: hidden;
}

.table thead th {
    background: linear-gradient(135deg, #4a90e2, #3178c6);
    color: white;
    border: none;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.dashboard-card {
    padding: 1rem;
}

.dashboard-header {
    padding: 1rem 1.25rem 1.25rem;
    background: rgba(255,255,255,0.95);
    border-radius: 18px;
    box-shadow: 0 16px 40px rgba(37, 83, 133, 0.08);
    margin-bottom: 1rem;
}

.metric-card {
    min-height: 190px;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(74,144,226,0.18), transparent 30%);
    pointer-events: none;
}

.metric-card .card-body {
    position: relative;
    z-index: 1;
    padding: 1.8rem 1.4rem;
}

.metric-card .card-title {
    font-size: 0.82rem;
    letter-spacing: 0.16em;
    color: #5d6d7a;
}

.metric-value {
    font-size: 2.5rem;
    letter-spacing: -0.03em;
}

.metric-title,
.metric-note,
.metric-pill {
    white-space: nowrap;
    word-break: keep-all;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metric-note {
    font-size: 0.92rem;
    color: #6c757d;
    margin-top: 0.55rem;
}

.chart-widget {
    min-height: 430px;
}

.map-widget {
    min-height: auto;
}

.map-panel {
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    min-height: auto;
    overflow: hidden;
}

.map-panel .chart-card-heading {
    padding: 1.25rem 1.5rem 0.75rem;
}

.map-panel .plotly-graph-div,
.map-panel .plotly {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0;
    margin: 0 !important;
    padding: 5px;
}

    /* Leader info professional styling */
    #leader-info,
    #leader-info-1x12 {
        border-left: 4px solid #3178c6;
        background: linear-gradient(180deg, #ffffff 0%, #f6fbff 100%);
        padding: 1rem;
        border-radius: 12px;
        box-shadow: 0 10px 30px rgba(23,63,101,0.06);
    }

    #leader-info h5,
    #leader-info-1x12 h5 {
        margin-top: 0;
        margin-bottom: 0.5rem;
        color: #123a52;
        font-weight: 800;
    }

    #leader-info dl,
    #leader-info-1x12 dl {
        margin: 0;
    }

    #leader-info dt,
    #leader-info-1x12 dt {
        color: #274b57;
        font-weight: 700;
        margin-bottom: 0.15rem;
    }

    #leader-info dd,
    #leader-info-1x12 dd {
        color: #4b6a72;
        margin-bottom: 0.6rem;
    }

    /* Compact responsive layout for leader details */
    @media (min-width: 576px) {
        #leader-info dl.row dt.col-sm-4,
        #leader-info-1x12 dl.row dt.col-sm-4 {
            flex: 0 0 30%;
            max-width: 30%;
        }
        #leader-info dl.row dd.col-sm-8,
        #leader-info-1x12 dl.row dd.col-sm-8 {
            flex: 0 0 70%;
            max-width: 70%;
        }
    }

    /* Small visual badge for ids (if later added) */
    .leader-badge {
        display: inline-block;
        background: rgba(49,120,198,0.12);
        color: #175a93;
        padding: 0.18rem 0.5rem;
        border-radius: 999px;
        font-weight: 700;
        font-size: 0.82rem;
    }

    /* Active filters container: compact, horizontally scrollable */
    #activeFilters {
        padding: 0.35rem 0.25rem;
    }
    #activeFilters .badge-container {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 0.25rem 0;
        -webkit-overflow-scrolling: touch;
    }
    #activeFilters .badge {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        max-width: 220px;
    }
    #activeFilters .badge-more {
        background: rgba(0,0,0,0.08);
        color: #234;
        cursor: default;
    }

.chart-card-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.chart-card-heading div,
.metric-title,
.metric-note,
.chart-title,
.text-muted {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chart-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1f3d5a;
}

.summary-card {
    background: linear-gradient(135deg, rgba(255,255,255,0.96), rgba(243,247,251,0.9));
    border: 1px solid rgba(208, 221, 235, 0.9);
    box-shadow: 0 18px 35px rgba(40, 77, 126, 0.08);
}

.summary-card .card-body {
    padding: 1.5rem;
}

.metric-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.25rem 0.9rem;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.metric-pill-primary {
    background: rgba(74, 144, 226, 0.14);
    color: #3178c6;
}

.metric-pill-success {
    background: rgba(61, 176, 102, 0.14);
    color: #2f8f63;
}

.metric-pill-warning {
    background: rgba(243, 179, 59, 0.14);
    color: #b37b1f;
}

.metric-pill-info {
    background: rgba(23, 162, 184, 0.14);
    color: #117a8b;
}

.chart-panel {
    padding: 1.25rem;
}

.chart-panel .card-body {
    padding: 0;
}

.plotly-graph-div,
.plotly {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 400px;
    border-radius: 20px;
    background: rgba(255,255,255,0.98);
    box-shadow: 0 25px 55px rgba(23, 56, 97, 0.08);
}

.modal {
    z-index: 1200 !important;
}

.modal-backdrop {
    z-index: 1190 !important;
}

.modal-dialog {
    z-index: 1205;
}

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 24px;
    background: rgba(255,255,255,0.98);
    border: 1px solid rgba(227, 236, 246, 0.95);
    box-shadow: 0 28px 80px rgba(37, 83, 133, 0.18);
}

.login-card .card-title {
    font-weight: 800;
    font-size: 1.5rem;
    color: #1f3d5a;
}

.login-card .form-control,
.login-card .form-select {
    border-radius: 14px;
}

.login-card p {
    color: #667085;
}

.modal-content {
    border-radius: 18px;
    overflow: hidden;
    border: none;
    box-shadow: 0 22px 60px rgba(18, 47, 84, 0.12);
}

.modal-header {
    border-bottom: none;
    padding: 1.2rem 1.4rem;
    background: linear-gradient(135deg, #f8fbff, #e9f2fb);
}

.modal-title {
    font-weight: 700;
    color: #1f3d5a;
    letter-spacing: 0.03em;
}

.modal-body {
    padding: 1.4rem;
    background: rgba(248, 250, 253, 0.95);
}

.modal-footer {
    border-top: none;
    padding: 1rem 1.4rem 1.4rem;
    background: rgba(248, 250, 253, 0.95);
}

.btn-secondary {
    background: #6c757d;
    border-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a646f;
    border-color: #5a646f;
}

.btn-outline-success {
    border-color: #3cb371;
    color: #3cb371;
}

.btn-outline-success:hover {
    background: #3cb371;
    color: white;
    border-color: #3cb371;
}

.btn-outline-warning {
    border-color: #f0ad4e;
    color: #f0ad4e;
}

.btn-outline-warning:hover {
    background: #f0ad4e;
    color: white;
    border-color: #f0ad4e;
}

.btn-outline-info {
    border-color: #17a2b8;
    color: #17a2b8;
}

.btn-outline-info:hover {
    background: #17a2b8;
    color: white;
    border-color: #17a2b8;
}

.btn-close {
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.15));
}

.plotly-graph-div,
.plotly {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 16px;
}

.mobile-topbar {
    padding: 0.85rem 1rem;
    background: rgba(255,255,255,0.96);
    border-radius: 16px;
    box-shadow: 0 12px 30px rgba(21, 34, 60, 0.08);
}

button#sidebarToggle {
    min-width: 52px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 991.98px) {
    .dashboard-body {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
    }

    .mobile-chart-controls {
        display: block;
        width: 100%;
    }

    .mobile-chart-controls .nav-link {
        flex: 1 1 auto;
        margin: 0 0.15rem;
        font-size: 0.85rem;
        padding: 0.85rem 0.75rem;
    }

    .mobile-chart-display {
        width: 100%;
    }

    .mobile-chart-panel {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
        box-sizing: border-box;
    }

    .mobile-chart-display,
    .mobile-chart-display .col-12 {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .mobile-chart-display .card-body,
    .mobile-chart-panel .card-body {
        padding: 0;
    }

    .mobile-chart-panel .plotly-graph-div,
    .mobile-chart-panel .plotly,
    .mobile-chart-panel .plotly > div,
    .mobile-chart-panel .plotly svg {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box;
    }

    .mobile-chart-panel .plotly {
        height: auto !important;
        min-height: 360px !important;
    }

    .dashboard-summary-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
        width: 100%;
        grid-auto-rows: 1fr;
    }

    .dashboard-summary-row .col-12.col-sm-6.col-lg-3 {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        flex: none;
        display: block;
    }

    .dashboard-summary-row .card {
        min-height: 220px;
    }

    .mobile-chart-controls {
        overflow-x: auto;
        padding-bottom: 0.5rem;
    }

    .mobile-chart-controls .nav {
        min-width: 100%;
    }

    .mobile-chart-controls .nav-link {
        white-space: nowrap;
        min-width: 33%;
        text-align: center;
    }

    .dashboard-summary-row .col-12.col-sm-6.col-lg-3 {
        flex: 0 0 50%;
        max-width: 50%;
        width: 50%;
    }

    .dashboard-summary-row .card {
        min-height: 220px;
    }
}

/* Responsive */
@media (max-width: 1200px) {
    .card-body {
        padding: 1.5rem;
    }
    .table-responsive {
        overflow-x: auto;
    }
}

@media (max-width: 992px) {
    .main-content {
        margin-left: 0;
    }
    #sidebar {
        position: fixed;
        transform: translateX(-100%);
        width: 100%;
        max-width: 320px;
    }
    body.sidebar-open #sidebar {
        transform: translateX(0);
    }
    .flex-grow-1 {
        padding: 1rem;
    }
    .dashboard-header {
        margin-bottom: 1rem;
        padding: 0.9rem 1rem 1rem;
    }
    .metric-card {
        min-height: 170px;
    }
}

@media (max-width: 576px) {
    .card {
        border-radius: 16px;
    }
    .card-body {
        padding: 1.2rem;
    }
    .metric-card .card-body {
        padding: 1.2rem 1rem;
    }
    .metric-title {
        font-size: 0.78rem;
    }
    .metric-value {
        font-size: 2rem;
    }
    .metric-note {
        font-size: 0.85rem;
    }
    .chart-widget {
        min-height: 320px;
    }
    .plotly-graph-div,
    .plotly {
        min-height: 340px;
    }
    .chart-card-heading {
        gap: 0.5rem;
    }
    .chart-title {
        font-size: 1rem;
    }
    .mobile-topbar {
        padding: 0.75rem 0.9rem;
    }
    .dashboard-body {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
    }
    .dashboard-summary-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
    .dashboard-summary-row .col-12.col-sm-6.col-lg-3 {
        width: 100%;
        max-width: 100%;
        flex: none;
        display: block;
    }
    .dashboard-pie-col,
    .dashboard-timeline-col,
    .dashboard-top-col,
    .dashboard-map-col {
        width: 100%;
        max-width: 100%;
    }
}

@media (min-width: 992px) {
    .dashboard-body {
        display: grid;
        grid-template-columns: 2fr 1fr;
        grid-template-areas:
            "summary summary"
            "map top"
            "timeline pie";
        gap: 1.5rem;
    }
    .dashboard-summary-row {
        grid-area: summary;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 1.5rem;
        align-items: stretch;
    }
    .dashboard-map-row {
        grid-area: map;
    }
    .dashboard-top-row {
        grid-area: top;
    }
    .dashboard-timeline-row {
        grid-area: timeline;
    }
    .dashboard-pie-row {
        grid-area: pie;
    }
    .dashboard-pie-col,
    .dashboard-timeline-col,
    .dashboard-top-col,
    .dashboard-map-col {
        width: 100%;
        max-width: 100%;
    }
    .dashboard-summary-row .col-12.col-sm-6.col-lg-3 {
        flex: 0 0 auto;
        max-width: 100%;
        width: 100%;
    }
}
