/* Variables & Theming */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --gray-light: #e2e8f0;
    --white: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--light);
    color: var(--dark);
    overflow: hidden; /* Prevent body scroll for dashboard */
}

/* Dashboard Layout */
.dashboard-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--white);
    border-right: 1px solid var(--gray-light);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 1000;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    position: absolute;
    height: 100%;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

.sidebar-menu {
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--gray);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
}

a.menu-item {
    color: var(--gray);
}

.menu-item:hover {
    background-color: var(--light);
    color: var(--primary);
}

.menu-item.active {
    background-color: var(--primary);
    color: var(--white);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

/* Topbar */
.topbar {
    height: 70px;
    background-color: var(--white);
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    z-index: 900;
    min-width: 0;
    overflow: hidden;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--gray);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
}

.btn-icon:hover {
    background-color: var(--light);
    color: var(--primary);
}

.search-bar {
    display: none;
    align-items: center;
    flex: 0 1 320px;
    background-color: #f8fafc;
    border: 1px solid var(--gray-light);
    border-radius: 999px;
    height: 42px;
    padding: 0 12px 0 16px;
    width: min(30vw, 320px);
    min-width: 190px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.main-content.map-mode .search-bar {
    display: flex;
}

.search-bar:focus-within {
    background-color: var(--white);
    border-color: rgba(79, 70, 229, 0.38);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.08);
}

.search-bar input {
    border: none;
    background: none;
    outline: none;
    padding: 0;
    width: 100%;
    font-size: 0.9rem;
    color: var(--dark);
    min-width: 0;
}

.search-bar input::placeholder {
    color: #94a3b8;
}

.search-bar button {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--white);
    border: none;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.search-bar button:hover {
    background-color: #eef2ff;
}

.search-bar.hidden,
.map-header-controls.hidden {
    display: none;
}

.map-header-controls {
    display: none;
    align-items: center;
    flex: 1 1 auto;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 1px;
    scrollbar-width: thin;
    scrollbar-color: rgba(79, 70, 229, 0.28) transparent;
}

.map-header-controls::-webkit-scrollbar {
    height: 4px;
}

.map-header-controls::-webkit-scrollbar-track {
    background: transparent;
}

.map-header-controls::-webkit-scrollbar-thumb {
    background-color: rgba(79, 70, 229, 0.28);
    border-radius: 999px;
}

.main-content.map-mode .map-header-controls {
    display: flex;
}

.header-filter {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 7px;
    min-height: 42px;
    background-color: #f8fafc;
    border: 1px solid var(--gray-light);
    border-radius: 999px;
    padding: 4px 8px 4px 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.header-filter:focus-within {
    background-color: var(--white);
    border-color: rgba(79, 70, 229, 0.38);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.08);
}

.header-filter i {
    color: var(--primary);
    font-size: 0.82rem;
}

.header-filter label {
    color: var(--gray);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
}

.header-filter select {
    min-width: 142px;
    border: none;
    border-left: 1px solid var(--gray-light);
    border-radius: 0;
    background-color: transparent;
    color: var(--dark);
    font-size: 0.88rem;
    font-weight: 600;
    outline: none;
    padding: 6px 4px 6px 10px;
    cursor: pointer;
}

.user-profile {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 12px;
    font-weight: 500;
    margin-left: auto;
    min-width: 0;
}

.main-content.map-mode .user-profile {
    display: none;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-link {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--gray);
    background-color: var(--light);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: var(--transition);
}

.logout-link:hover {
    color: var(--danger);
    background-color: #fee2e2;
}

@media (max-width: 1280px) {
    .main-content.map-mode .search-bar {
        flex-basis: 260px;
        width: 260px;
        min-width: 170px;
    }

    .main-content.map-mode .header-filter {
        gap: 6px;
        padding: 4px 7px 4px 10px;
    }

    .main-content.map-mode .header-filter label {
        display: none;
    }

    .main-content.map-mode .header-filter select {
        min-width: 132px;
        border-left: none;
        padding-left: 4px;
    }

}

@media (max-width: 1040px) {
    .main-content.map-mode .search-bar {
        flex-basis: 220px;
        width: 220px;
    }

    .main-content.map-mode .topbar {
        gap: 10px;
        padding: 0 16px;
    }
}

/* Views */
.view-panel {
    display: none;
    flex: 1;
    min-height: 0;
    position: relative;
}

.view-panel.active {
    display: flex;
}

.dashboard-view {
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    padding: 28px;
    background:
        linear-gradient(180deg, rgba(79, 70, 229, 0.06), rgba(248, 250, 252, 0) 260px),
        var(--light);
}

.dashboard-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.dashboard-page-header h1 {
    font-size: 2rem;
    line-height: 1.2;
    margin-bottom: 8px;
}

.dashboard-page-header p {
    color: var(--gray);
    max-width: 720px;
}

.dashboard-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.eyebrow {
    color: var(--primary) !important;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    text-transform: uppercase;
}

/* Dashboard Stats */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
}

.stat-card {
    background-color: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

.stat-card.success { border-left-color: var(--secondary); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.warning { border-left-color: var(--warning); }

.stat-card h3 {
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--dark);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1.15fr) repeat(2, minmax(240px, 1fr));
    gap: 18px;
}

.dashboard-card {
    background-color: var(--white);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.card-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.card-title h2 {
    font-size: 1.1rem;
}

.card-title span {
    color: var(--gray);
    font-size: 0.85rem;
    text-align: right;
}

.status-list {
    display: grid;
    gap: 14px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    padding: 14px;
}

.status-item strong {
    display: block;
    font-size: 1.35rem;
    line-height: 1;
}

.status-item p {
    color: var(--gray);
    font-size: 0.9rem;
    margin-top: 4px;
}

.status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.status-dot.success { background-color: var(--secondary); }
.status-dot.warning { background-color: var(--warning); }
.status-dot.danger { background-color: var(--danger); }

.quick-actions {
    display: grid;
    gap: 12px;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    background-color: var(--light);
    color: var(--dark);
    cursor: pointer;
    font-weight: 600;
    padding: 12px 14px;
    transition: var(--transition);
    text-decoration: none;
}

.quick-action i {
    color: var(--primary);
    font-size: 1.2rem;
}

.quick-action:hover {
    border-color: var(--primary);
    background-color: #eef2ff;
}

.legend-list {
    display: grid;
    gap: 14px;
    color: var(--dark);
    font-size: 0.95rem;
}

.legend-list div {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
}

.legend-marker.ri {
    background-color: var(--primary);
    box-shadow: 0 0 0 5px rgba(79, 70, 229, 0.12);
}

.legend-marker.reached { background-color: var(--secondary); }
.legend-marker.blank { background-color: var(--danger); }

.priority-list,
.need-list {
    display: grid;
    gap: 10px;
}

.priority-item,
.need-item {
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    padding: 12px;
    background: var(--light);
}

.priority-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
}

.priority-score {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: white;
    font-weight: 800;
}

.priority-item strong,
.need-item strong {
    display: block;
    margin-bottom: 4px;
}

.priority-item p,
.need-item p {
    color: var(--gray);
    font-size: 0.85rem;
}

.map-view {
    height: calc(100vh - 70px);
    min-height: 0;
}

/* Map Container */
.map-fullscreen {
    flex: 1;
    width: 100%;
    height: 100%;
}

/* Floating Action Button */
.fab-location {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--white);
    color: var(--primary);
    border: none;
    box-shadow: var(--shadow-lg);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-location:hover {
    background-color: var(--light);
    transform: translateY(-2px);
}

.fab-container {
    position: absolute;
    bottom: 30px;
    right: 100px;
    z-index: 500;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 12px;
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-main:hover {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.fab-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: var(--transition);
}

.fab-container:hover .fab-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.fab-item {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--white);
    color: var(--primary);
    border: none;
    box-shadow: var(--shadow);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-item:hover {
    background-color: var(--light);
    transform: scale(1.1);
}

/* Leaflet Overrides */
.ri-div-icon {
    background: transparent;
    border: none;
}

.ri-marker {
    width: 36px;
    height: 36px;
    border: 3px solid var(--white);
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--white);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    position: relative;
}

.ri-marker::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -7px;
    width: 12px;
    height: 12px;
    background-color: inherit;
    border-right: 3px solid var(--white);
    border-bottom: 3px solid var(--white);
    transform: translateX(-50%) rotate(45deg);
    box-shadow: 4px 4px 8px rgba(15, 23, 42, 0.12);
}

.ri-marker i {
    position: relative;
    z-index: 1;
}

.ri-marker.ri-mosque {
    background-color: #2563eb;
}

.ri-marker.ri-church {
    background-color: #7c3aed;
}

.ri-marker.ri-temple {
    background-color: #d97706;
}

.ri-marker.ri-vihara {
    background-color: #0891b2;
}

.ri-marker.ri-klenteng {
    background-color: #dc2626;
}

.ri-marker.ri-other {
    background-color: #475569;
}

.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 280px !important;
}

.popup-header {
    background-color: var(--primary);
    color: var(--white);
    padding: 16px;
}

.popup-header.success { background-color: var(--secondary); }
.popup-header.danger { background-color: var(--danger); }
.popup-header.warning { background-color: var(--warning); }

.popup-header h3 {
    margin: 0 0 4px 0;
    font-size: 1.1rem;
}

.popup-header p {
    margin: 0;
    font-size: 0.85rem;
    opacity: 0.9;
}

.popup-body {
    padding: 16px;
}

.popup-row {
    display: flex;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.popup-row .label {
    width: 100px;
    color: var(--gray);
    font-weight: 500;
}

.popup-row .value {
    flex: 1;
    font-weight: 600;
}

.popup-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-light);
}

.popup-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
}

.btn-edit { background-color: var(--warning); color: var(--dark); }
.btn-delete { background-color: var(--danger); color: var(--white); }

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: var(--transition);
}

.modal-content-sm {
    max-width: 520px;
}

.modal-backdrop.show .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-kicker {
    margin: 0 0 4px;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray);
    cursor: pointer;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 16px;
}

.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid.two-cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-hint {
    margin-top: 6px;
    color: var(--gray);
    font-size: 0.8rem;
}

.form-alert {
    border: 1px solid #fecaca;
    border-radius: 8px;
    background-color: #fef2f2;
    color: #991b1b;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 10px 12px;
}

.form-alert.success {
    border-color: #bbf7d0;
    background-color: #f0fdf4;
    color: #166534;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-light);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
}

.btn-secondary {
    background-color: var(--gray-light);
    color: var(--dark);
}

.btn-secondary:hover {
    background-color: #cbd5e1;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

/* Dynamic Forms */
.dynamic-list {
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.dynamic-item {
    border-bottom: 1px dashed var(--gray-light);
    padding-bottom: 12px;
    margin-bottom: 12px;
    position: relative;
}

.dynamic-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.btn-remove {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background-color: #dcfce7; color: #166534; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-warning { background-color: #fef3c7; color: #92400e; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }

    .topbar {
        padding: 0 16px;
        gap: 10px;
    }

    .main-content.map-mode .topbar {
        height: auto;
        min-height: 70px;
        flex-wrap: wrap;
        align-content: center;
        padding: 10px 16px;
    }

    .main-content.map-mode #toggle-sidebar {
        order: 1;
        flex: 0 0 auto;
    }

    .search-bar {
        flex: 1 0 150px;
        width: auto;
        min-width: 0;
        padding: 0 10px 0 12px;
    }

    .main-content.map-mode .search-bar {
        order: 2;
        flex: 1 1 140px;
        width: auto;
        min-width: 0;
    }

    .map-header-controls {
        flex: 1 1 100%;
        gap: 8px;
        overflow-x: auto;
    }

    .main-content.map-mode .map-header-controls {
        order: 4;
        flex: 0 0 100%;
        width: 100%;
        padding: 2px 1px 0;
    }

    .header-filter {
        flex: 0 0 auto;
        min-height: 38px;
        padding: 4px 8px;
    }

    .header-filter label {
        display: none;
    }

    .header-filter select {
        min-width: 128px;
        border-left: none;
        padding: 6px 2px;
    }

    .form-grid.two-cols {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .dashboard-view {
        padding: 20px 16px;
    }

    .dashboard-page-header {
        flex-direction: column;
        gap: 16px;
    }

    .dashboard-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .dashboard-header-actions .btn {
        flex: 1 1 150px;
    }

    .dashboard-page-header h1 {
        font-size: 1.55rem;
    }
    
    .stats-container {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .fab-location {
        right: 20px;
        bottom: 24px;
    }

    .fab-container {
        right: 88px;
        bottom: 24px;
    }
}
