:root {
    --primary: #4361ee;
    --primary-hover: #3a56d4;
    --secondary: #1a1a2e;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #777777;
    --border: #e2e8f0;
    --success: #10b981;
    --error: #ef4444;
    --radius: 16px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    height: 100%;
    width: 100%;
    overflow: hidden; /* Prevent scrolling outside bottom sheet */
}

header {
    background-color: var(--secondary);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000; /* Above Leaflet map */
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-import-shp {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.btn-import-shp:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

#status-indicator {
    font-size: 0.85rem;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
}

#status-indicator.online {
    background-color: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

#status-indicator.offline {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* User Profile Menu */
.user-profile {
    position: relative;
    display: inline-block;
}
.avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    margin-left: 10px;
}
.profile-menu {
    position: absolute;
    top: 50px;
    right: 0;
    background: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border-radius: 12px;
    width: 220px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 2000;
    color: var(--text-main);
}
.profile-menu.active {
    display: flex;
}
.profile-menu .menu-header {
    padding: 15px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
}
.profile-menu hr {
    margin: 0;
    border: none;
    border-top: 1px solid var(--border);
}
.profile-menu button {
    background: none;
    border: none;
    padding: 12px 15px;
    text-align: left;
    width: 100%;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
    color: var(--text-main);
}
.profile-menu button:hover {
    background: #f1f5f9;
}

/* Map specific styles */
#map {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1; /* Lowest level */
    padding-top: 60px; /* Space for header */
}

/* Coordinate Bar (Proj4) */
#coord-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(26, 26, 46, 0.85); /* var(--secondary) with opacity */
    color: var(--text-muted);
    text-align: center;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-family: monospace;
    z-index: 400; /* Above map, below FAB & bottom-sheet */
    pointer-events: none; /* Let clicks pass through to map */
    backdrop-filter: blur(4px);
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* Floating Action Button for GPS */
.fab-btn {
    position: absolute;
    bottom: 30px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: white;
    color: var(--primary);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 500;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s;
}

.fab-btn:active {
    transform: scale(0.95);
    background-color: #f8fafc;
}

/* Bottom Sheet Mechanism */
.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 2000; /* Above everything */
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.bottom-sheet.active {
    bottom: 0;
}

.sheet-scroller {
    width: 40px;
    height: 6px;
    background-color: #cbd5e1;
    border-radius: 3px;
    margin: 12px auto;
}

.sheet-content {
    padding: 0 1.5rem 2rem 1.5rem;
    overflow-y: auto;
}

.bottom-sheet h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--secondary);
    font-weight: 700;
    text-align: center;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.type-btn {
    background-color: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Modifying old inputs for the bottom sheet */
.input-group {
    margin-bottom: 1.25rem;
}

.input-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

select {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background-color: #f8fafc;
    color: var(--text-main);
    appearance: none;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23777' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.25rem;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.upload-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    background-color: rgba(67, 97, 238, 0.05);
    border: 2px dashed var(--primary);
    border-radius: 12px;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn:active {
    background-color: rgba(67, 97, 238, 0.1);
}

input[type="file"] {
    display: none;
}

#photo-preview {
    width: 100%;
    margin-top: 1rem;
    border-radius: 12px;
    object-fit: cover;
    max-height: 200px;
    border: 1px solid var(--border);
}

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

.btn-primary {
    flex: 2;
    background-color: var(--primary);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(67, 97, 238, 0.3);
    transition: transform 0.1s, box-shadow 0.2s;
}

.btn-secondary {
    flex: 1;
    background-color: #f1f5f9;
    color: var(--text-main);
    font-size: 1.05rem;
    font-weight: 600;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    width: 100%; /* For full width layout outside flex */
}

.btn-primary:active, .btn-secondary:active {
    transform: translateY(2px);
}

.btn-primary:disabled {
    background-color: #94a3b8;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-main);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 3000;
    white-space: nowrap;
}

.toast.show {
    bottom: 24px;
}

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

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
    backdrop-filter: blur(2px);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--secondary);
    font-size: 1.2rem;
}

.modal-content p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Splash Screen */
#splash-screen {
    position: fixed;
    inset: 0;
    background-color: #ffffff;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s ease-out, visibility 0.6s;
    opacity: 1;
    visibility: visible;
}

#splash-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-logo {
    width: 250px;
    max-width: 80%;
    height: auto;
    object-fit: contain;
    animation: splash-pulse 2s infinite ease-in-out;
}

@keyframes splash-pulse {
    0% { transform: scale(0.95); }
    50% { transform: scale(1.05); }
    100% { transform: scale(0.95); }
}

/* --- CIVIL ENGINEERING UI --- */
.alveoles-container {
    display: grid;
    grid-template-areas: 
        ". top ."
        "left . right"
        ". bottom .";
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
}
#grid-Haut { grid-area: top; text-align: center; }
#grid-Bas { grid-area: bottom; text-align: center; }
#grid-Gauche { grid-area: left; text-align: center; }
#grid-Droite { grid-area: right; text-align: center; }
#grid-Haut h4, #grid-Bas h4, #grid-Gauche h4, #grid-Droite h4 { margin: 0 0 5px 0; font-size: 0.8rem; color: #555; }

.alveole-grid {
    display: grid;
    grid-template-columns: repeat(6, 20px);
    grid-template-rows: repeat(6, 20px);
    gap: 2px;
    background: #ccc;
    padding: 4px;
    border-radius: 4px;
    margin: 0 auto;
}

.alveole-cell {
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: bold;
    color: #fff;
    box-shadow: inset 0 0 2px rgba(0,0,0,0.1);
}

.alveole-cell:hover { opacity: 0.8; }
.alveole-cell.occupy-45 { background: #3498db; }
.alveole-cell.occupy-60 { background: #2ecc71; color: #000; }
.alveole-cell.occupy-80 { background: #f1c40f; color: #000; }
.alveole-cell.occupy-100 { background: #e67e22; }
.alveole-cell.occupy-150 { background: #e74c3c; }

.btn-dia {
    padding: 8px 12px;
    border: none;
    border-radius: 20px;
    background: #e9ecef;
    font-weight: bold;
    cursor: pointer;
    color: #495057;
}
.btn-dia:hover { background: #ced4da; }

/* Style de base d'un conduit dessiné dans la grille */
.status-conduit { z-index: 10; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; width: 90%; height: 90%; margin: 5%; }
.status-empty { background-color: #ffffff; border: 1px solid #ccc; }
.status-25 { background-color: #3498db; color: white; }    /* Bleu */
.status-75 { background-color: #e67e22; color: white; }    /* Orange */
.status-100 { background-color: #e74c3c !important; color: white; }   /* Rouge */
.status-100 { background-color: #e74c3c !important; color: white; }   /* Rouge */

.main-controls-stack {
    position: fixed !important;
    bottom: 30px !important;
    right: 20px !important;
    display: flex !important;
    flex-direction: column !important; /* L'un au-dessus de l'autre */
    align-items: flex-end !important;
    gap: 6px !important; /* Espace entre les boutons */
    z-index: 9999 !important;
}

.main-controls-stack button, .main-controls-stack .floating-btn {
    position: relative !important; /* Libère la position fixe individuelle */
    bottom: auto !important;
    right: auto !important;
    margin: 0 !important;
    padding: 5px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
}
