/**
 * HABITAT-360 V9 - Styles principaux
 *
 * Interface simplifiée avec:
 * - Sidebar gauche (commune, couches, heatmaps)
 * - Carte centrale
 * - Panneau détail droit
 * - Barre de statut en bas
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #4a5568;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-orange: #f97316;
    --accent-red: #ef4444;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.3);

    --sidebar-width: 280px;
    --detail-panel-width: 350px;
    --header-height: 56px;
    --statusbar-height: 36px;
}

/* ============================================
   BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ============================================
   LAYOUT
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

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

.header-logo svg {
    width: 32px;
    height: 32px;
    fill: var(--accent-blue);
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.header-title .st-trigger {
    cursor: pointer;
}

.header-search {
    flex: 1;
    max-width: 400px;
    margin: 0 40px;
}

.header-search input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 14px;
}

.header-search input::placeholder {
    color: var(--text-muted);
}

.header-search input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

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

.header-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.2s;
}

.header-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.version-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-blue);
    color: var(--accent-blue);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.version-toggle:hover {
    background: var(--accent-blue);
    color: white;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Commune selector */
.commune-selector {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.commune-selector:hover {
    border-color: var(--accent-blue);
}

.commune-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.commune-code {
    font-size: 12px;
    color: var(--text-secondary);
}

.commune-dropdown-arrow {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: auto;
}

/* Commune dropdown */
.commune-dropdown {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.commune-dropdown-item {
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s;
}

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

.commune-dropdown-item:hover {
    background: var(--bg-secondary);
}

.commune-dropdown-item.active {
    background: rgba(59, 130, 246, 0.2);
    border-left: 3px solid var(--accent-blue);
}

.commune-dropdown-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.commune-dropdown-info {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted);
}

.btn-add-commune {
    width: 100%;
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 8px;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-add-commune:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* Layer items */
.layer-group {
    margin-bottom: 16px;
}

.layer-group:last-child {
    margin-bottom: 0;
}

.layer-group-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.layer-item:hover {
    background: var(--bg-tertiary);
}

.layer-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-blue);
}

.layer-item label {
    flex: 1;
    font-size: 13px;
    cursor: pointer;
}

.layer-item .layer-icon {
    width: 20px;
    text-align: center;
}

/* Score type selector */
.score-selector {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.score-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.score-radio:hover {
    background: var(--bg-tertiary);
}

.score-radio input {
    accent-color: var(--accent-blue);
}

/* Heatmap options */
.heatmap-options {
    margin-left: 26px;
    margin-top: 8px;
    display: flex;
    gap: 6px;
}

.heatmap-mode-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.heatmap-mode-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

/* Phase 2 panel */
.phase2-panel {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
}

.phase2-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.phase2-header h4 {
    font-size: 13px;
    font-weight: 600;
}

.phase2-status {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-muted);
}

.phase2-status.ready {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-green);
}

.phase2-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.phase2-stats .stat {
    text-align: center;
}

.phase2-stats .stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-blue);
}

.phase2-stats .stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.btn-phase2 {
    width: 100%;
    background: var(--accent-blue);
    border: none;
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-phase2:hover {
    background: #2563eb;
}

.btn-phase2:disabled {
    background: var(--bg-primary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* ============================================
   MAP CONTAINER
   ============================================ */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* ============================================
   DETAIL PANEL
   ============================================ */
.detail-panel {
    width: var(--detail-panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.detail-panel.hidden {
    transform: translateX(100%);
    position: absolute;
    right: 0;
    top: var(--header-height);
    bottom: var(--statusbar-height);
}

.detail-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.btn-close-detail {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
}

.detail-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.detail-address {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Score display */
.score-display {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.score-main {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.score-value {
    font-size: 36px;
    font-weight: 700;
}

.score-value.low { color: var(--accent-green); }
.score-value.medium { color: var(--accent-orange); }
.score-value.high { color: var(--accent-red); }

.score-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.score-bar {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.score-bar-fill.low { background: var(--accent-green); }
.score-bar-fill.medium { background: var(--accent-orange); }
.score-bar-fill.high { background: var(--accent-red); }

/* Score breakdown */
.score-breakdown {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.score-item {
    background: var(--bg-primary);
    padding: 10px;
    border-radius: 6px;
}

.score-item-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.score-item-value {
    font-size: 18px;
    font-weight: 600;
}

/* Detail actions */
.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.detail-actions button {
    flex: 1;
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-blue);
    border: none;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* ============================================
   STATUS BAR
   ============================================ */
.status-bar {
    height: var(--statusbar-height);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-stats {
    display: flex;
    gap: 24px;
}

.status-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
}

.status-dot.warning { background: var(--accent-orange); }
.status-dot.error { background: var(--accent-red); }

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1200px) {
    .detail-panel {
        width: 300px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        width: 240px;
    }

    .detail-panel {
        position: absolute;
        right: 0;
        top: var(--header-height);
        bottom: var(--statusbar-height);
        z-index: 50;
    }
}

@media (max-width: 600px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: var(--header-height);
        bottom: var(--statusbar-height);
        z-index: 50;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .header-search {
        display: none;
    }
}
