/**
 * SIPEKANA Custom Dashboard Styles
 * Theme: BPBD Kabupaten Tasikmalaya
 * Colors: Primary Orange (#F97316), Primary Blue (#2563EB), Dark Blue (#1E3A8A)
 */

:root {
    --sipekana-orange: #F97316;
    --sipekana-orange-hover: #EA580C;
    --sipekana-blue: #2563EB;
    --sipekana-blue-hover: #1D4ED8;
    --sipekana-dark: #1E3A8A;
    --sipekana-darker: #0F172A;
    --sipekana-bg: #F8FAFC;
    --sipekana-card-bg: #FFFFFF;
    --sipekana-border: #E2E8F0;
    --sipekana-text: #1E293B;
    --sipekana-muted: #64748B;
    --sidebar-width: 260px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--sipekana-bg);
    color: var(--sipekana-text);
    overflow-x: hidden;
}

/* ----------------------------------------------------
 * Layout Container
 * ---------------------------------------------------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ----------------------------------------------------
 * Sidebar
 * ---------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: linear-gradient(180deg, #1E3A8A 0%, #0F172A 100%);
    color: #F8FAFC;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease-in-out;
    z-index: 1040;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
}

.app-sidebar .sidebar-brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-decoration: none;
    color: #FFFFFF;
}

.app-sidebar .sidebar-brand .brand-logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--sipekana-orange) 0%, #F59E0B 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-weight: 700;
    font-size: 1.25rem;
    box-shadow: 0 4px 10px rgba(249, 115, 22, 0.35);
}

.app-sidebar .sidebar-brand .brand-text {
    display: flex;
    flex-direction: column;
}

.app-sidebar .sidebar-brand .brand-title {
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: 0.5px;
    color: #FFFFFF;
    line-height: 1.2;
}

.app-sidebar .sidebar-brand .brand-subtitle {
    font-size: 0.7rem;
    color: #94A3B8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.menu-header {
    font-size: 0.68rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #94A3B8;
    padding: 1rem 0.75rem 0.4rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    color: #CBD5E1;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    margin-bottom: 2px;
}

.menu-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    color: #94A3B8;
    transition: color 0.2s;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
}

.menu-item:hover i {
    color: var(--sipekana-orange);
}

.menu-item.active {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.2) 0%, rgba(37, 99, 235, 0.2) 100%);
    color: #FFFFFF;
    border-left: 3px solid var(--sipekana-orange);
    font-weight: 600;
}

.menu-item.active i {
    color: var(--sipekana-orange);
}

.menu-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.badge-coming-soon {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
    background: rgba(255, 255, 255, 0.12);
    color: #CBD5E1;
    border-radius: 4px;
}

/* ----------------------------------------------------
 * Sidebar Submenu Styles
 * ---------------------------------------------------- */
.sidebar-submenu {
    padding: 0.2rem 0 0.2rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-submenu .menu-item.sub-item {
    font-size: 0.825rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: transparent;
    color: #94A3B8;
}

.sidebar-submenu .menu-item.sub-item i {
    font-size: 0.95rem;
    width: 18px;
    color: #64748B;
}

.sidebar-submenu .menu-item.sub-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #FFFFFF;
}

.sidebar-submenu .menu-item.sub-item:hover i {
    color: var(--sipekana-orange);
}

.sidebar-submenu .menu-item.sub-item.active {
    background: rgba(249, 115, 22, 0.15);
    color: #FFFFFF;
    border-left: 2px solid var(--sipekana-orange);
    font-weight: 600;
}

.sidebar-submenu .menu-item.sub-item.active i {
    color: var(--sipekana-orange);
}

/* Parent menu collapse toggle */
.menu-item[data-bs-toggle="collapse"] .submenu-arrow {
    transition: transform 0.2s ease;
}

.menu-item[data-bs-toggle="collapse"][aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

.menu-item[data-bs-toggle="collapse"].collapsed .submenu-arrow {
    transform: rotate(0deg);
}

.menu-item[data-bs-toggle="collapse"].active {
    background: rgba(255, 255, 255, 0.05);
    color: #FFFFFF;
    border-left: none;
}

.menu-item[data-bs-toggle="collapse"].active > div > i {
    color: var(--sipekana-orange);
}

/* ----------------------------------------------------
 * Main Content Area
 * ---------------------------------------------------- */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.3s ease-in-out;
}

/* ----------------------------------------------------
 * Topbar
 * ---------------------------------------------------- */
.app-topbar {
    height: 70px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--sipekana-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.35rem;
    color: var(--sipekana-muted);
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-sidebar-toggle:hover {
    background: var(--sipekana-bg);
    color: var(--sipekana-dark);
}

.topbar-breadcrumb {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--sipekana-text);
}

.avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sipekana-blue) 0%, var(--sipekana-dark) 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

/* ----------------------------------------------------
 * Page Body & Footer
 * ---------------------------------------------------- */
.app-content {
    flex: 1;
    padding: 2rem 1.75rem;
}

.app-footer {
    padding: 1.25rem 1.75rem;
    border-top: 1px solid var(--sipekana-border);
    background: #FFFFFF;
    color: var(--sipekana-muted);
    font-size: 0.8125rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ----------------------------------------------------
 * Components & Cards (Tailwind-like Modern Look)
 * ---------------------------------------------------- */
.card-modern {
    background: #FFFFFF;
    border: 1px solid var(--sipekana-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-modern:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.stat-card {
    padding: 1.5rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.stat-card.stat-card-centered {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.stat-card.stat-card-centered .stat-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.stat-card.stat-card-centered .stat-label {
    text-align: center;
    margin-bottom: 0.35rem;
}

.stat-card.stat-card-centered .stat-value {
    text-align: center;
    margin-bottom: 0.35rem;
}

.stat-card.stat-card-centered .stat-icon {
    margin-left: auto;
    margin-right: auto;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-card:hover .stat-icon {
    transform: scale(1.08);
}

/* Stat Icon Color Variants aligned with Design System */
.stat-icon.orange,
.stat-icon.warning-alt {
    background: rgba(249, 115, 22, 0.12);
    color: var(--sipekana-orange);
}

.stat-icon.blue,
.stat-icon.primary {
    background: rgba(37, 99, 235, 0.12);
    color: var(--sipekana-blue);
}

.stat-icon.navy {
    background: rgba(30, 58, 138, 0.12);
    color: var(--sipekana-dark);
}

.stat-icon.emerald,
.stat-icon.success {
    background: rgba(16, 185, 129, 0.12);
    color: #10B981;
}

.stat-icon.red,
.stat-icon.danger {
    background: rgba(239, 68, 68, 0.12);
    color: #EF4444;
}

.stat-icon.gray,
.stat-icon.secondary {
    background: rgba(100, 116, 139, 0.12);
    color: #64748B;
}

.stat-icon.teal,
.stat-icon.info {
    background: rgba(14, 165, 233, 0.12);
    color: #0EA5E9;
}

.stat-icon.yellow,
.stat-icon.warning {
    background: rgba(245, 158, 11, 0.12);
    color: #F59E0B;
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.12);
    color: #8B5CF6;
}

.stat-icon.indigo {
    background: rgba(99, 102, 241, 0.12);
    color: #6366F1;
}

.stat-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--sipekana-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--sipekana-text);
    line-height: 1.2;
}

/* ----------------------------------------------------
 * Desktop Sidebar Collapse / Expand
 * ---------------------------------------------------- */
@media (min-width: 992px) {
    html.sidebar-collapsed .app-sidebar,
    body.sidebar-collapsed .app-sidebar,
    .app-sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width)) !important;
        box-shadow: none !important;
    }

    html.sidebar-collapsed .app-main,
    body.sidebar-collapsed .app-main,
    .app-main.expanded {
        margin-left: 0 !important;
    }
}

/* ----------------------------------------------------
 * Responsive Sidebar Offcanvas (Mobile)
 * ---------------------------------------------------- */
@media (max-width: 991.98px) {
    .app-sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
        box-shadow: none;
    }
    .app-sidebar.show {
        margin-left: 0 !important;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.35) !important;
    }
    .app-main {
        margin-left: 0 !important;
    }
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.55);
        backdrop-filter: blur(2px);
        z-index: 1035;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
}

/* ----------------------------------------------------
 * Searchable Select Component (SIPEKANA Custom UI)
 * ---------------------------------------------------- */
.searchable-select-container {
    position: relative;
    width: 100%;
}

.searchable-select-native {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -1 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

.searchable-select-toggle {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    text-align: left;
    background-color: #ffffff;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    padding-right: 0.75rem;
}

.searchable-select-toggle:focus,
.searchable-select-container.is-open .searchable-select-toggle {
    border-color: #93c5fd;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.18);
}

.searchable-select-toggle.is-invalid {
    border-color: #dc3545;
}

.searchable-select-toggle.is-invalid:focus {
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

.searchable-select-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.5rem;
    flex: 1 1 auto;
}

.searchable-select-chevron {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.2s ease;
}

.searchable-select-container.is-open .searchable-select-chevron {
    transform: rotate(180deg);
}

.searchable-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 1060;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.14), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: searchableSelectFadeIn 0.15s ease-out;
}

.searchable-select-container.is-open .searchable-select-menu {
    display: flex;
}

.searchable-select-container.dropup .searchable-select-menu {
    top: auto;
    bottom: calc(100% + 4px);
}

@keyframes searchableSelectFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.searchable-select-search-box {
    position: relative;
    padding: 0.5rem;
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
}

.searchable-select-search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: #94a3b8;
    pointer-events: none;
}

.searchable-select-input {
    padding-left: 2.2rem !important;
    padding-right: 2rem !important;
    font-size: 0.85rem;
    border-radius: 0.375rem;
    border: 1px solid #cbd5e1;
    background: #ffffff;
}

.searchable-select-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.searchable-select-clear {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    text-decoration: none;
    line-height: 1;
}

.searchable-select-list {
    max-height: 220px;
    overflow-y: auto;
    padding: 0.25rem 0;
    margin: 0;
}

.searchable-select-list::-webkit-scrollbar {
    width: 6px;
}

.searchable-select-list::-webkit-scrollbar-track {
    background: #f8fafc;
}

.searchable-select-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.searchable-select-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.searchable-select-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.1s ease, color 0.1s ease;
}

.searchable-select-item:hover,
.searchable-select-item.is-focused {
    background-color: #eff6ff;
    color: #1e40af;
}

.searchable-select-item.is-selected {
    background-color: #e0e7ff;
    color: #1e3a8a;
    font-weight: 600;
}

.searchable-select-item.is-selected .searchable-select-item-check {
    display: inline-block;
}

.searchable-select-item-check {
    display: none;
    color: #2563eb;
    margin-left: 0.5rem;
    font-size: 0.95rem;
}

.searchable-select-empty {
    padding: 1.25rem 0.75rem;
    font-size: 0.85rem;
    color: #64748b;
    text-align: center;
}

.searchable-select-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    font-size: 0.72rem;
    color: #94a3b8;
}

/* ----------------------------------------------------
 * Leaflet Custom Map Marker & Popup
 * ---------------------------------------------------- */
.custom-leaflet-marker {
    background: transparent !important;
    border: none !important;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
    border: 1px solid #E2E8F0;
}

.leaflet-popup-content {
    margin: 12px 14px;
}

/* ----------------------------------------------------
 * Custom Tooltip Styling
 * ---------------------------------------------------- */
.tooltip-inner {
    max-width: 320px;
    padding: 0.6rem 0.85rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    text-align: left;
    background-color: #1e293b;
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
}

/* ----------------------------------------------------
 * Extra Small Button Utility
 * ---------------------------------------------------- */
.btn-xs {
    padding: 0.2rem 0.55rem;
    font-size: 0.775rem;
    line-height: 1.35;
    border-radius: 0.25rem;
}

/* ----------------------------------------------------
 * Modal Text Wrapping & Overflow Protection
 * ---------------------------------------------------- */
.modal,
.modal-dialog,
.modal-content,
.modal-body,
.modal-header,
.modal-footer {
    white-space: normal !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

