/* ══════════════════════════════════════════════════════════ */
/* Fecha: 2026-02-14                                        */
/* Ruta: /var/www/html/averias/css/styles.css                */
/* Servicio: GestAverías — Estilos principales               */
/* Descripción: Layout, componentes y animaciones            */
/*              Los colores vienen de theme-dark/loxone.css   */
/* ══════════════════════════════════════════════════════════ */

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

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

/* ══════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════ */

.app {
    display: grid;
    grid-template-columns: 320px 1fr 380px;
    grid-template-rows: 60px 1fr;
    height: 100vh;
}

/* ══════════════════════════════════════════════
   TOP BAR
   ══════════════════════════════════════════════ */

.topbar {
    grid-column: 1 / -1;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-brand .logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #437B33);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.topbar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.topbar-brand h1 span {
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
    font-size: 13px;
}

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

.stat-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    transition: background 0.3s;
}

.stat-pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.stat-pill.critical { background: var(--red-bg); color: var(--red); }
.stat-pill.critical .dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.stat-pill.pending { background: var(--orange-bg); color: var(--orange); }
.stat-pill.pending .dot { background: var(--orange); }
.stat-pill.progress { background: var(--blue-bg); color: var(--blue); }
.stat-pill.progress .dot { background: var(--blue); }
.stat-pill.resolved { background: var(--green-bg); color: var(--green); }
.stat-pill.resolved .dot { background: var(--green); }

.topbar-actions {
    display: flex;
    gap: 10px;
}

/* ══════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════ */

.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn:hover { background: var(--bg-card-hover); box-shadow: var(--shadow-sm); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px var(--accent-glow);
}

/* Theme toggle */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-toggle:hover { background: var(--bg-card-hover); }

/* ══════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════ */

.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s, border-color 0.3s;
}

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

.sidebar-header h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.search-box {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, background 0.3s;
}

.search-box:focus { border-color: var(--accent); }
.search-box::placeholder { color: var(--text-muted); }

.filter-tabs {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}

.filter-tab {
    flex: 1;
    padding: 6px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.filter-tab:hover { color: var(--text-secondary); background: var(--bg-card); }
.filter-tab.active { background: var(--bg-card); color: var(--text-primary); }

/* ══════════════════════════════════════════════
   INCIDENT LIST
   ══════════════════════════════════════════════ */

.incident-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.incident-list::-webkit-scrollbar { width: 4px; }
.incident-list::-webkit-scrollbar-track { background: transparent; }
.incident-list::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.incident-card {
    padding: 14px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid transparent;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.incident-card:hover { background: var(--bg-card-hover); border-color: var(--border); }

.incident-card.active {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 16px var(--accent-glow);
}

.incident-card .priority-bar {
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 0 3px 3px 0;
}

.incident-card .priority-bar.critical { background: var(--red); }
.incident-card .priority-bar.high { background: var(--orange); }
.incident-card .priority-bar.medium { background: var(--yellow); }
.incident-card .priority-bar.low { background: var(--green); }

.incident-card .ic-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
    padding-left: 8px;
}

.incident-card .ic-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

.incident-card .ic-status {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ic-status.abierta { background: var(--red-bg); color: var(--red); }
.ic-status.pendiente { background: var(--orange-bg); color: var(--orange); }
.ic-status.en-curso { background: var(--blue-bg); color: var(--blue); }
.ic-status.resuelta { background: var(--green-bg); color: var(--green); }

.incident-card .ic-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    padding-left: 8px;
    line-height: 1.3;
}

.incident-card .ic-villa {
    font-size: 12px;
    color: var(--text-secondary);
    padding-left: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.incident-card .ic-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    padding-left: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════
   MAP
   ══════════════════════════════════════════════ */

.map-container {
    position: relative;
}

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

.leaflet-container {
    background: var(--bg-primary);
}

/* Custom markers */
.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    font-family: 'JetBrains Mono', monospace;
    color: white;
    border: 3px solid var(--marker-border);
    box-shadow: var(--shadow-md);
    transition: transform 0.2s;
}

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

.marker-ok { background: var(--green); }
.marker-warning { background: var(--orange); }
.marker-critical { background: var(--red); animation: pulse-marker 2s infinite; }
.marker-progress { background: var(--blue); }

@keyframes pulse-marker {
    0%, 100% { box-shadow: 0 2px 12px rgba(0,0,0,0.4); }
    50% { box-shadow: 0 2px 12px rgba(255, 90, 90, 0.6), 0 0 20px rgba(255, 90, 90, 0.3); }
}

/* Leaflet popups */
.leaflet-popup-content-wrapper {
    background: var(--popup-bg) !important;
    border: 1px solid var(--popup-border) !important;
    border-radius: 12px !important;
    box-shadow: var(--shadow-lg) !important;
    color: var(--text-primary) !important;
}

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

.popup-content h3 { font-size: 15px; margin-bottom: 4px; }
.popup-content .popup-addr { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.popup-content .popup-incidents { font-size: 12px; display: flex; gap: 8px; }

.popup-content .popup-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}

.map-overlay-legend {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    z-index: 1000;
    display: flex;
    gap: 16px;
    font-size: 12px;
    box-shadow: var(--shadow-md);
    transition: background 0.3s, border-color 0.3s;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ══════════════════════════════════════════════
   DETAIL PANEL
   ══════════════════════════════════════════════ */

.detail-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s, border-color 0.3s;
}

.detail-panel.empty {
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-empty {
    text-align: center;
    color: var(--text-muted);
}

.detail-empty .icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

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

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

.detail-header .dh-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 6px;
}

.detail-header .dh-villa {
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.detail-body::-webkit-scrollbar { width: 4px; }
.detail-body::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.detail-section {
    margin-bottom: 24px;
}

.detail-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.detail-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.meta-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    transition: background 0.3s;
}

.meta-item .label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.meta-item .value {
    font-size: 13px;
    font-weight: 600;
}

.detail-description {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Photos */
.detail-photos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.photo-thumb {
    aspect-ratio: 4/3;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
    position: relative;
}

.photo-thumb:hover { border-color: var(--accent); }

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-thumb .exif-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 16px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -19px;
    top: 6px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg-secondary);
}

.timeline-item.active::before { background: var(--accent); }

.timeline-item .tl-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 2px;
}

.timeline-item .tl-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.timeline-item .tl-user {
    font-weight: 600;
    color: var(--text-primary);
}

/* Detail actions */
.detail-actions {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.detail-actions .btn { flex: 1; justify-content: center; }

/* ══════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════ */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-backdrop);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s;
}

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

.modal-body { padding: 24px; }

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group select,
.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, background 0.3s;
}

.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-group select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.photo-upload-area {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    font-size: 13px;
}

.photo-upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.photo-upload-area .upload-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.gps-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--green-bg);
    border-radius: 6px;
    font-size: 12px;
    color: var(--green);
    font-weight: 500;
    margin-top: 8px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */

@media (max-width: 1200px) {
    .app {
        grid-template-columns: 280px 1fr 340px;
    }
    .topbar-stats { gap: 12px; }
}

@media (max-width: 1024px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 60px 1fr;
    }
    .sidebar, .detail-panel { display: none; }
    .topbar-stats { display: none; }
}

/* ══════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════ */

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

.incident-card { animation: fadeIn 0.3s ease both; }
.incident-card:nth-child(2) { animation-delay: 0.05s; }
.incident-card:nth-child(3) { animation-delay: 0.1s; }
.incident-card:nth-child(4) { animation-delay: 0.15s; }
.incident-card:nth-child(5) { animation-delay: 0.2s; }