/**
 * AlumbradoPro - Estilos principales
 * Gestión de Alumbrado Público
 * 
 * @author Rubén Pantxo
 * @version 1.0.0
 */

/* ============================================
   VARIABLES CSS
   ============================================ */
:root {
    --bg-dark: #0a0f14;
    --bg-panel: #12181f;
    --bg-card: #1a222c;
    --border: #2a3544;
    --text-primary: #e8ecf1;
    --text-secondary: #8896a7;
    --accent-yellow: #fbbf24;
    --accent-yellow-glow: rgba(251, 191, 36, 0.4);
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --accent-orange: #f97316;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

body {
    font-family: 'Space Grotesk', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 60px;
}

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

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

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-yellow), var(--accent-orange));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.logo-icon img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.logo-text {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
}

.location-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.location-badge::before {
    content: "📍";
}

/* Stats */
.header-stats {
    display: flex;
    gap: 20px;
}

.stat {
    text-align: center;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 20px;
    font-weight: 700;
}

.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-on .stat-value { color: var(--accent-yellow); }
.stat-off .stat-value { color: var(--text-secondary); }
.stat-ok .stat-value { color: var(--accent-green); }
.stat-notok .stat-value { color: var(--accent-red); }

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.main-container {
    display: flex;
    height: calc(100vh - 60px);
    margin-top: 60px;
}

.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 320px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

/* Tool Selector */
.tool-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.tool-btn {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 10px 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tool-btn:hover {
    border-color: var(--accent-yellow);
    transform: translateY(-2px);
}

.tool-btn.active {
    border-color: var(--accent-yellow);
    background: rgba(251, 191, 36, 0.1);
    box-shadow: 0 0 20px var(--accent-yellow-glow);
}

.tool-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-icon img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.tool-name {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}

/* Filter Section */
.filter-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.filter-title {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-chip {
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-family: 'Space Grotesk', sans-serif;
}

.filter-chip:hover {
    border-color: var(--accent-blue);
}

.filter-chip.active {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
}

/* Elements List */
.elements-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.element-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.element-card:hover {
    border-color: var(--accent-blue);
    transform: translateX(4px);
}

.element-card.selected {
    border-color: var(--accent-yellow);
    box-shadow: 0 0 15px var(--accent-yellow-glow);
}

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

.element-type {
    display: flex;
    align-items: center;
    gap: 8px;
}

.element-type-icon {
    width: 24px;
    height: 24px;
}

.element-type-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.element-type-name {
    font-size: 13px;
    font-weight: 600;
}

.element-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-dark);
    padding: 2px 8px;
    border-radius: 4px;
}

.element-status {
    display: flex;
    gap: 8px;
}

/* Status Badges */
.status-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-on {
    background: rgba(251, 191, 36, 0.2);
    color: var(--accent-yellow);
}

.status-off {
    background: rgba(136, 150, 167, 0.2);
    color: var(--text-secondary);
}

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

.status-notok {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
}

.status-pending {
    background: rgba(249, 115, 22, 0.2);
    color: var(--accent-orange);
}

.status-vehicle {
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.5;
}

.empty-state-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.empty-state-text {
    font-size: 13px;
}

/* Sidebar Actions */
.sidebar-actions {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn-primary {
    background: var(--accent-yellow);
    color: var(--bg-dark);
}

.action-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px var(--accent-yellow-glow);
}

.action-btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

/* ============================================
   CONTROLES DEL MAPA
   ============================================ */
.map-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-control-btn {
    width: 44px;
    height: 44px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s ease;
}

.map-control-btn:hover {
    border-color: var(--accent-yellow);
    transform: scale(1.05);
}

.map-control-btn.active {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.2);
}

/* ============================================
   PANELES FLOTANTES
   ============================================ */
.legend-panel,
.layer-panel {
    position: absolute;
    bottom: 20px;
    left: 70px;
    z-index: 500;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    box-shadow: var(--shadow);
    display: none;
    min-width: 180px;
}

.legend-panel.show,
.layer-panel.show {
    display: block;
}

.legend-panel-title,
.layer-panel-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

/* Legend Items */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.legend-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.legend-icon img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Layer Panel */
.layer-panel {
    min-width: 220px;
}

.layer-section {
    margin-bottom: 12px;
}

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

.layer-section-title {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.layer-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
}

.layer-option:hover {
    color: var(--accent-yellow);
}

.layer-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.layer-checkbox.checked {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.layer-checkbox.checked::after {
    content: '✓';
    color: white;
    font-size: 12px;
}

.layer-name {
    font-size: 13px;
}

.layer-desc {
    font-size: 10px;
    color: var(--text-secondary);
    margin-left: 28px;
    margin-top: -4px;
}

/* ============================================
   MARCADORES PERSONALIZADOS
   ============================================ */
.custom-marker {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.custom-marker:hover {
    transform: scale(1.15);
}

.marker-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.marker-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.marker-container.on img {
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.8)) drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.marker-container.ok img {
    filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.8)) drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* ============================================
   POPUPS DE LEAFLET
   ============================================ */
.leaflet-popup-content-wrapper {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.leaflet-popup-content {
    margin: 12px 16px;
    color: var(--text-primary);
    font-family: 'Space Grotesk', sans-serif;
}

.leaflet-popup-tip {
    background: var(--bg-panel);
    border: 1px solid var(--border);
}

.popup-content {
    min-width: 200px;
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.popup-icon {
    width: 32px;
    height: 32px;
}

.popup-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.popup-title {
    font-weight: 600;
    font-size: 14px;
}

.popup-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-secondary);
}

.popup-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.popup-control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.toggle-switch.on {
    background: var(--accent-yellow);
    border-color: var(--accent-yellow);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-switch.on::after {
    transform: translateX(24px);
    background: var(--bg-dark);
}

/* Status Toggle Buttons */
.status-toggle {
    display: flex;
    gap: 6px;
}

.status-toggle-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Space Grotesk', sans-serif;
}

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

.status-toggle-btn.active-ok {
    background: rgba(34, 197, 94, 0.2);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.status-toggle-btn.active-notok {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* Delete Button */
.popup-delete {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.delete-btn {
    width: 100%;
    padding: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--accent-red);
    border-radius: 6px;
    color: var(--accent-red);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Space Grotesk', sans-serif;
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ============================================
   UTILIDADES
   ============================================ */

/* Loading Indicator */
.loading-indicator {
    position: absolute;
    top: 80px;
    right: 340px;
    z-index: 600;
    background: var(--bg-panel);
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12px;
    display: none;
    align-items: center;
    gap: 8px;
}

.loading-indicator.show {
    display: flex;
}

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

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-icon {
    font-size: 18px;
}

.toast-text {
    font-size: 13px;
}

/* WMS Attribution */
.wms-attribution {
    position: absolute;
    bottom: 5px;
    right: 340px;
    z-index: 400;
    background: rgba(18, 24, 31, 0.9);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    color: var(--text-secondary);
}

/* Mobile Toggle */
.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 950;
    width: 56px;
    height: 56px;
    background: var(--accent-yellow);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--accent-yellow-glow);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .header {
        padding: 10px 12px;
        height: 56px;
    }

    .location-badge {
        display: none;
    }

    .header-stats {
        gap: 12px;
    }

    .stat-value {
        font-size: 16px;
    }

    .sidebar {
        position: fixed;
        right: -320px;
        top: 56px;
        bottom: 0;
        transition: right 0.3s ease;
        z-index: 900;
    }

    .sidebar.open {
        right: 0;
    }

    .main-container {
        height: calc(100vh - 56px);
        margin-top: 56px;
    }

    .mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .loading-indicator {
        right: 20px;
    }

    .wms-attribution {
        right: 10px;
        bottom: 120px;
    }
}

@media (max-width: 480px) {
    .header-stats {
        gap: 8px;
    }

    .stat-value {
        font-size: 14px;
    }

    .stat-label {
        font-size: 8px;
    }
}
