:root {
    --primary: #10B981;
    /* Emerald green - tech/secure feel */
    --primary-hover: #059669;
    --bg-dark: #0f172a;
    /* Slate 900 */
    --bg-panel: #1e293b;
    /* Slate 800 */
    --text-main: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */
    --border-color: #334155;
    /* Slate 700 */

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    /* Prevent scrolling, app-like feel */
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

/* =========================================
   Sidebar
   ========================================= */
.sidebar {
    width: 380px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 2rem;
    overflow-y: auto;
    z-index: 10;
    /* Above the map */
    box-shadow: var(--shadow-lg);
}

.sidebar-header {
    margin-bottom: 0.5rem;
}

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

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: white;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-group h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.help-text {
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.mt-auto {
    margin-top: auto;
}

/* --- Search Box --- */
.search-box {
    display: flex;
    gap: 0.5rem;
}

.search-box input {
    flex: 1;
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.search-box button {
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.search-box button:hover {
    background-color: var(--primary-hover);
}

/* --- Autocomplete --- */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    list-style: none;
    box-shadow: var(--shadow-md);
    margin-top: -2px;
    /* Slight overlap for seamless look */
}

.autocomplete-list.hidden {
    display: none;
}

.autocomplete-item {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: var(--text-main);
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background-color: rgba(16, 185, 129, 0.15);
    /* Primary with opacity */
    color: white;
}

/* --- Tools Grid --- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.tool-btn {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.tool-btn:hover {
    border-color: var(--primary);
    background-color: rgba(16, 185, 129, 0.05);
    transform: translateY(-2px);
}

.tool-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-panel);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.tool-btn span {
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
}

/* --- Form --- */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.input-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.input-group input,
.input-group textarea {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all 0.2s;
}

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

.submit-btn {
    width: 100%;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    margin-top: 0.5rem;
}

.submit-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.submit-btn:disabled {
    background-color: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.notification {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--primary);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
    font-weight: 500;
    font-size: 0.875rem;
    transition: opacity 0.3s;
}

.notification.hidden {
    display: none;
    opacity: 0;
}

.notification.error {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    /* red-500 */
    border-color: rgba(239, 68, 68, 0.2);
}

/* =========================================
   Map Area
   ========================================= */
.map-container {
    flex: 1;
    position: relative;
    background-color: #e2e8f0;
    /* Map loading background */
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Custom Marker Styles */
.custom-div-icon {
    background: transparent;
    border: none;
}

.marker-pin {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    cursor: grab;
    transition: transform 0.1s;
}

.marker-pin:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.marker-pin::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 14px;
    /* Center (36/2) - (border/2) */
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 8px solid var(--primary);
}

/* Specific colors for marker types */
.marker-PTZ {
    border-color: #3b82f6;
}

/* Blue */
.marker-PTZ::after {
    border-top-color: #3b82f6;
}

.marker-Fixe {
    border-color: #f59e0b;
}

/* Amber */
.marker-Fixe::after {
    border-top-color: #f59e0b;
}

.marker-Internet {
    border-color: #8b5cf6;
}

/* Purple */
.marker-Internet::after {
    border-top-color: #8b5cf6;
}

/* 4G Cameras */
.marker-PTZ4G {
    border-color: #ef4444;
    /* Red */
}

.marker-PTZ4G::after {
    border-top-color: #ef4444;
}

.marker-Fixe4G {
    border-color: #f43f5e;
    /* Rose */
}

.marker-Fixe4G::after {
    border-top-color: #f43f5e;
}

/* Panoramique */
.marker-Panoramique {
    border-color: #10b981;
    /* Emerald */
}

.marker-Panoramique::after {
    border-top-color: #10b981;
}

/* FOV Rotation Slider in Popup */
.fov-slider-container {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.fov-slider-container label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.fov-slider {
    width: 100%;
    cursor: ew-resize;
}

/* Map Loader Overlay */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Leaflet Dark Theme Overrides (Optional for better integration) */
.leaflet-container {
    font-family: 'Outfit', sans-serif;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--bg-panel);
    color: var(--text-main);
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-content {
    margin: 12px 14px;
    font-size: 0.875rem;
}

.leaflet-container a.leaflet-popup-close-button {
    color: var(--text-muted);
}

/* =========================================
   Responsive Design (Mobile)
   ========================================= */
@media screen and (max-width: 768px) {
    .app-container {
        flex-direction: column-reverse;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .map-container {
        height: 50vh;
        height: 50dvh;
        width: 100%;
        position: relative;
        z-index: 1;
    }

    .sidebar {
        width: 100%;
        height: 50vh;
        height: 50dvh;
        overflow-y: auto;
        padding: 1rem;
        padding-bottom: calc(5rem + env(safe-area-inset-bottom));
        /* Espace très large pour la barre de navigation Android et clavier */
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
        z-index: 10;
        border-right: none;
        border-top: 2px solid var(--border-color);
        border-radius: 12px 12px 0 0;
    }

    .tools-grid {
        gap: 0.5rem;
    }

    .tool-btn {
        padding: 0.75rem 0.25rem;
    }

    .tool-icon {
        width: 32px;
        height: 32px;
        font-size: 1.25rem;
    }
}

/* =========================================
   Help Modal & Button Styles
========================================= */

.help-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.help-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    transform: scale(1.05);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    /* important for mobile */
    background: rgba(15, 23, 42, 0.85);
    /* Dark blur background */
    backdrop-filter: blur(5px);
    z-index: 9999;
    /* Increased to ensure it's above everything, even on mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: flex;
    /* Keep flex to maintain structure, just hide visually */
    opacity: 0;
    pointer-events: none;
    z-index: -1;
    /* Prevent invisible clicks */
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
    transform: translateY(20px);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 10;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-light);
}

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

.close-modal-btn:hover {
    color: var(--text-light);
}

.modal-body {
    padding: 1.5rem;
}

.help-steps {
    padding-left: 1.5rem;
    margin-bottom: 2rem;
}

.help-steps li {
    margin-bottom: 1.25rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.help-steps li strong {
    display: block;
    color: var(--text-light);
    margin-bottom: 0.25rem;
    font-size: 1.05rem;
}

.help-steps ul {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
    list-style-type: disc;
}

.help-steps ul li {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.modal-footer {
    display: flex;
    justify-content: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Utility Hidden Class */
.hidden {
    display: none !important;
}