* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0ea5e9;
    --primary-dark: #0369a1;
    --secondary-color: #64748b;
    --danger-color: #dc2626;
    --success-color: #16a34a;
    --warning-color: #ea580c;
    --bg-color: #f0f9ff;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #bae6fd;
    --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);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    color: var(--text-primary);
    overflow-x: hidden;
}

.container {
    max-width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, #0ea5e9 0%, #0369a1 50%, #075985 100%);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: 0 8px 16px rgba(14, 165, 233, 0.3);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border-bottom: 3px solid #7dd3fc;
}

.header-content h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

.stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.stat-item i {
    font-size: 1.2rem;
}

.stat-item span:first-of-type {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Map */
#map {
    flex: 1;
    width: 100%;
    position: relative;
    z-index: 1; /* Normal z-index, below modal */
    background: #87ceeb;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.1);
}

/* Ensure Leaflet map fills container */
#map .leaflet-container {
    width: 100%;
    height: 100%;
}

/* Controls */
.controls {
    position: absolute;
    top: 180px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-btn {
    background: var(--card-bg);
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

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

.control-btn i {
    font-size: 16px;
}

/* Modal Backdrop - semi-transparent overlay that allows map clicks */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 5000; /* High z-index */
    pointer-events: none; /* ALLOW CLICKS TO PASS THROUGH TO MAP */
}

.modal-backdrop.active {
    display: block;
}

/* Modal - CENTERED on screen, ABOVE map */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 6000; /* ABOVE backdrop and map */
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
    pointer-events: none; /* ALLOW CLICKS TO PASS THROUGH TO MAP */
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
    position: relative;
    z-index: 6001; /* ABOVE everything */
    pointer-events: all; /* Form captures clicks */
}

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

@keyframes pulse {
    0% {
        box-shadow: 0 0 20px rgba(22, 163, 74, 0.6);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 30px rgba(22, 163, 74, 0.9);
        transform: scale(1.1);
    }
    100% {
        box-shadow: 0 0 20px rgba(22, 163, 74, 0.6);
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.close-btn:hover {
    color: var(--danger-color);
}

/* Form */
form {
    padding: 1.5rem;
}

/* Instruction Banner */
.instruction-banner {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #f59e0b;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #92400e;
    font-size: 14px;
    animation: slideIn 0.5s ease;
}

.instruction-banner i {
    font-size: 20px;
    color: #f59e0b;
    animation: bounce 2s ease-in-out infinite;
}

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

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group small {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 12px;
    text-align: right;
}

.location-info {
    background: var(--bg-color);
    padding: 12px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.location-info p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

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

.btn-secondary:hover {
    background: #475569;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideInRight 0.3s ease;
    border-left: 4px solid var(--primary-color);
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.warning {
    border-left-color: var(--warning-color);
}

.toast i {
    font-size: 1.25rem;
}

.toast.success i {
    color: var(--success-color);
}

.toast.error i {
    color: var(--danger-color);
}

.toast.warning i {
    color: var(--warning-color);
}

/* Custom Leaflet Popup */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

.incident-popup {
    min-width: 250px;
}

.incident-popup h3 {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.incident-popup p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.incident-popup .description {
    color: var(--text-primary);
    margin: 1rem 0;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 8px;
}

.incident-popup .meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 8px;
    font-size: 0.85rem;
}

.incident-popup .meta i {
    width: 20px;
    margin-right: 0.5rem;
}

.confirmations {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    color: var(--success-color);
    font-weight: 600;
}

/* Popup Actions Container */
.popup-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.confirm-btn,
.resolve-btn {
    flex: 1;
    padding: 10px;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.confirm-btn {
    background: var(--success-color);
}

.confirm-btn:hover {
    background: #15803d;
    transform: translateY(-2px);
}

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

.resolve-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

/* Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        padding: 1rem;
    }

    .header-content h1 {
        font-size: 1.3rem;
    }

    .stats {
        gap: 1rem;
    }

    .controls {
        top: auto;
        bottom: 20px;
        right: 50%;
        transform: translateX(50%);
        flex-direction: row;
    }

    .control-btn span {
        display: none;
    }

    .modal-content {
        width: 95%;
        max-width: 95vw;
    }
}

/* Temporary Location Marker */
.temp-location-marker {
    z-index: 3000 !important; /* Above everything */
}

/* Location Info Highlight */
.location-info.selected {
    background: #dcfce7 !important;
    border-color: var(--success-color) !important;
}
