/* --- VARIABLES & RESET --- */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-app: #f1f5f9;
    --bg-panel: #ffffff;
    --text-main: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 10px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05);
}

body { font-family: 'Inter', sans-serif; margin: 0; height: 100vh; display: flex; overflow: hidden; background: var(--bg-app); color: var(--text-main); }
* { box-sizing: border-box; }

/* --- SIDEBAR IZQUIERDA --- */
#sidebar-left {
    width: 360px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    box-shadow: 4px 0 24px rgba(0,0,0,0.02);
    flex-shrink: 0;
}

.sidebar-header { 
    padding: 24px; 
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; justify-content: space-between;
}
.brand-icon { 
    width: 36px; height: 36px; background: var(--primary); color: white; 
    border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.app-title { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text-main); line-height: 1.2;}
.app-subtitle { font-size: 0.75rem; color: var(--text-secondary); font-weight: 400; }

.sidebar-scroll-area { flex-grow: 1; overflow-y: auto; padding: 24px; }

/* Upload Zone */
.upload-container { margin-bottom: 24px; }
.file-input { display: none; }
.upload-label {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 20px; cursor: pointer; transition: all 0.2s;
    background: #f8fafc; text-align: center; gap: 8px;
}
.upload-label:hover { border-color: var(--primary); background: #eff6ff; }
.upload-label i { font-size: 24px; color: var(--primary); }
.upload-text { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }
.upload-subtext { font-size: 0.7rem; color: #94a3b8; }

/* Action Buttons */
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 30px; }
.btn-secondary {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: white; border: 1px solid var(--border); padding: 8px;
    border-radius: 6px; color: var(--text-secondary); font-size: 0.8rem; font-weight: 500;
    cursor: pointer; transition: 0.2s;
}
.btn-secondary:hover { border-color: var(--text-secondary); color: var(--text-main); }

/* KPIs */
.section-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: #94a3b8; font-weight: 700; margin-bottom: 12px; display: block; }

.kpi-container { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 30px; }
.kpi-card { background: white; border: 1px solid var(--border); padding: 12px; border-radius: 8px; box-shadow: var(--shadow); }
.kpi-card h3 { margin: 0 0 4px 0; font-size: 0.7rem; color: var(--text-secondary); font-weight: 500; }
.kpi-card .value { font-size: 1.25rem; font-weight: 700; color: var(--text-main); }

/* Charts */
.chart-wrapper { position: relative; height: 140px; width: 100%; margin-bottom: 24px; }

/* Inputs & Filters */
.input-group { margin-bottom: 16px; }
.input-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-main); margin-bottom: 6px; }
.custom-select {
    width: 100%; padding: 10px; border-radius: 6px; border: 1px solid var(--border);
    background: white; font-size: 0.85rem; color: var(--text-main); outline: none;
    appearance: none; background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2364748b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat; background-position: right 12px top 50%; background-size: 8px auto;
}

.checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; cursor: pointer; }
.checkbox-row input { accent-color: var(--primary); width: 16px; height: 16px; }
.checkbox-row span { font-size: 0.85rem; color: var(--text-secondary); }
.checkbox-row i { color: var(--text-secondary); font-size: 1.1rem; }

/* --- MAPA --- */
#main-content { flex-grow: 1; position: relative; }
#map { width: 100%; height: 100%; z-index: 1; }

/* --- SIDEBAR DERECHA --- */
#sidebar-right {
    position: absolute; right: 0; top: 0; height: 100%;
    width: 420px; background: white; border-left: 1px solid var(--border);
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 3000; display: flex; flex-direction: column;
    box-shadow: -8px 0 24px rgba(0,0,0,0.05);
}
#sidebar-right.active { transform: translateX(0); }

.detail-header { padding: 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: start; background: #f8fafc; }
.detail-title h2 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--text-main); }
.detail-title p { margin: 4px 0 0 0; font-size: 0.85rem; color: var(--text-secondary); display: flex; align-items: center; gap: 4px;}
.close-btn { background: none; border: none; font-size: 1.2rem; color: #94a3b8; cursor: pointer; padding: 4px; transition: 0.2s; }
.close-btn:hover { color: var(--text-main); }

/* Botones de Acción en Detalle */
.detail-actions { display: flex; gap: 10px; margin-top: 15px; }
.action-icon-btn { 
    background: white; border: 1px solid var(--border); color: var(--text-secondary);
    padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 500;
    display: flex; align-items: center; gap: 6px; transition: 0.2s;
}
.action-icon-btn:hover { background: #f1f5f9; color: var(--text-main); }
.action-icon-btn.danger:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }

.detail-body { padding: 24px; overflow-y: auto; flex-grow: 1; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.stat-box { background: white; border: 1px solid var(--border); padding: 12px; border-radius: 8px; text-align: center; }
.stat-box label { font-size: 0.7rem; font-weight: 600; color: #94a3b8; text-transform: uppercase; }
.stat-box div { font-size: 1.1rem; font-weight: 700; margin-top: 4px; color: var(--text-main); }

.table-container { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 24px; }
.rr-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.rr-table th { background: #f8fafc; padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.rr-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-main); }
.rr-table tr:last-child td { border-bottom: none; }

.status-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: 600; }
.status-badge.mora { background: #fee2e2; color: #991b1b; }

/* AI Button */
.ai-btn {
    width: 100%; border: none; padding: 14px; border-radius: 8px;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white; font-weight: 600; font-size: 0.9rem;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    cursor: pointer; transition: transform 0.1s;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}
.ai-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3); }

/* AI CONTENT MARKDOWN STYLES */
.ai-content { margin-top: 16px; background: #eff6ff; border: 1px solid #dbeafe; padding: 16px; border-radius: 8px; font-size: 0.9rem; line-height: 1.6; color: #1e3a8a; }
.ai-content h1, .ai-content h2, .ai-content h3 { font-size: 0.9rem; color: #1e40af; margin-top: 15px; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.ai-content p { margin-bottom: 10px; }
.ai-content ul { margin: 10px 0; padding-left: 20px; list-style-type: disc; }
.ai-content li { margin-bottom: 5px; }
.ai-content strong { color: #172554; font-weight: 700; }

/* Custom SVG Markers Styles */
.marker-icon-svg { filter: drop-shadow(0 3px 3px rgba(0,0,0,0.2)); }

/* Toast Message */
#toast { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1e293b; color: white; padding: 10px 20px; border-radius: 30px; font-size: 0.9rem; font-weight: 500; display: none; z-index: 5000; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 8px; }

/* LOGIN SCREEN & AUTH */
#login-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #f8fafc; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
}
.login-card {
    background: white; width: 360px; padding: 40px;
    border-radius: 16px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); border: 1px solid #e2e8f0;
}
.login-header { text-align: center; margin-bottom: 30px; }
.login-header h2 { margin: 0; color: #0f172a; font-size: 1.5rem; font-weight: 700; }
.login-header p { margin: 5px 0 0 0; color: #64748b; font-size: 0.9rem; }

.auth-switch { margin-top: 15px; font-size: 0.8rem; color: #64748b; text-align: center; }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

/* MODAL & TENANT STYLES */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
    z-index: 4000; display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: white; padding: 25px; border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease-out;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.modal-header h3 { margin: 0; font-size: 1.1rem; color: var(--text-main); display: flex; align-items: center; gap: 8px; }

/* Tenant Row Style in Modal */
.tenant-row { 
    display: grid; 
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 30px; 
    gap: 8px; 
    margin-bottom: 8px; 
    align-items: center;
}
.tenant-row input { 
    padding: 8px; 
    border: 1px solid var(--border); 
    border-radius: 4px; 
    font-size: 0.8rem; 
    width: 100%;
    background: #f8fafc;
}
.tenant-row input:focus {
    border-color: var(--primary);
    background: white;
    outline: none;
}
.tenant-btn-remove { 
    color: #ef4444; 
    background: none; 
    border: none; 
    cursor: pointer; 
    font-size: 1.1rem; 
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.tenant-btn-remove:hover {
    transform: scale(1.1);
}