/* ─────────────────────────────────────────────────────────
   style.css — "Lupa Pública" Aesthetics
   Premium Fintech, Dark Mode, Glassmorphism
───────────────────────────────────────────────────────── */
:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --neon-green: #10b981;
    --neon-cyan: #06b6d4;
    --glass-bg: rgba(30, 41, 59, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-highlight: rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-main);
    overflow: hidden;
    /* App-like feel */
    height: 100vh;
}

/* ── Layout ───────────────────────────────────────────── */
.dashboard {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 320px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    border-right: 1px solid var(--glass-border);
    z-index: 10;
    overflow-y: auto;
    /* Fix overlap */
}

.chart-container {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at center, var(--bg-dark) 0%, var(--bg-darker) 100%);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Typography & Logo ────────────────────────────────── */
.logo-area {
    margin-bottom: 2.5rem;
    position: relative;
}

.logo-area h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, var(--text-main), var(--neon-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-area .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.glow-dot {
    position: absolute;
    top: -10px;
    left: -15px;
    width: 40px;
    height: 40px;
    background: var(--neon-cyan);
    filter: blur(25px);
    opacity: 0.3;
    border-radius: 50%;
}

/* ── Glassmorphism Controls ───────────────────────────── */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
    flex-shrink: 0;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

.glass-select {
    appearance: none;
    background: var(--glass-highlight);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
    cursor: pointer;
}

.glass-select:focus,
.glass-select:hover {
    border-color: var(--neon-cyan);
    background: rgba(255, 255, 255, 0.1);
}

.glass-select option {
    background: var(--bg-dark);
    color: var(--text-main);
}

/* ── Buttons ──────────────────────────────────────────── */
.neon-btn {
    background: transparent;
    color: var(--neon-cyan);
    border: 1px solid var(--neon-cyan);
    padding: 1rem;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.neon-btn:hover {
    background: var(--neon-cyan);
    color: var(--bg-darker);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.5);
}

.neon-btn:active {
    transform: scale(0.98);
}

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

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    box-shadow: none;
    border-color: var(--text-main);
}

.neon-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--glass-border);
    border-radius: 5px;
    outline: none;
    transition: background 0.3s ease;
}

.neon-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--neon-cyan);
    cursor: pointer;
    box-shadow: 0 0 10px var(--neon-cyan);
}

.loader-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ── Legend ──────────────────────────────────────────── */
.legend-area {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--glass-highlight);
    border: 1px dashed var(--glass-border);
    border-radius: 8px;
    flex-shrink: 0;
}

.legend-area h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-main);
}

.legend-circle {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--neon-cyan);
    opacity: 0.8;
}

.legend-circle.normal {
    border: 1px solid var(--bg-darker);
}

.legend-circle.monopoly {
    border: 2px solid #fcd34d;
    border-style: dashed;
    box-shadow: 0 0 5px rgba(245, 158, 11, 0.4);
}

.legend-circle.delay {
    border: 2px solid #ef4444;
    animation: pulseBorderRed 2s infinite;
}

/* ── Metrics ──────────────────────────────────────────── */
.metrics {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
    /* changed from auto */
    flex-shrink: 0;
}

.metric-card {
    background: var(--glass-highlight);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 8px;
}

.metric-card h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 0.5rem;
}

.odometer {
    font-size: 2rem;
    font-weight: 600;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.text-neon {
    color: var(--neon-green);
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.sidebar-footer {
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
    margin-top: 2rem;
}

.sidebar-footer small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ── Main Chart Area ──────────────────────────────────── */
.state-message {
    position: absolute;
    text-align: center;
    max-width: 400px;
    color: var(--text-muted);
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#viz-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* D3 nodes */
.node {
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease;
}

.node circle {
    fill: var(--neon-cyan);
    opacity: 0.7;
    stroke: var(--bg-darker);
    stroke-width: 2px;
}

.node:hover circle {
    opacity: 1;
    fill: var(--neon-green);
    stroke: var(--neon-green);
}

.node:hover {
    filter: drop-shadow(0 0 8px var(--neon-green));
}

/* ── Alert Styles for Nodes ── */
.alert-monopoly {
    stroke: #fcd34d !important;
    /* Amarillo / Naranja suave */
    stroke-width: 3px !important;
    stroke-dasharray: 4 2 !important;
    filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.4));
}

.alert-delay {
    stroke: #ef4444 !important;
    /* Rojo */
    stroke-width: 3px !important;
    animation: pulseBorderRed 2s infinite !important;
}

@keyframes pulseBorderRed {
    0% {
        stroke-opacity: 1;
    }

    50% {
        stroke-opacity: 0.3;
        stroke-width: 5px;
    }

    100% {
        stroke-opacity: 1;
    }
}

.alert-delay.alert-monopoly {
    /* If it has both, red takes precedence for the animation/border */
    stroke: #ef4444 !important;
    stroke-width: 4px !important;
    stroke-dasharray: 4 2 !important;
}

.node text {
    font-family: 'Outfit', sans-serif;
    fill: var(--text-main);
    text-anchor: middle;
    pointer-events: none;
}

.node .label-name {
    font-weight: 600;
    font-size: 14px;
}

.node .label-value {
    font-size: 11px;
    opacity: 0.8;
}

/* ── Tooltip ──────────────────────────────────────────── */
.glass-tooltip {
    position: absolute;
    pointer-events: auto;
    cursor: pointer;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    padding: 1.25rem;
    border-radius: 8px;
    width: 320px;
    z-index: 100;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease;
    /* initial hide handled by JS styles */
}

.glass-tooltip h4 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    line-height: 1.3;
    color: var(--text-main);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.tt-hint {
    margin-top: 10px;
    font-size: 0.75rem;
    color: var(--neon-cyan);
    text-align: center;
    font-style: italic;
    border-top: 1px dashed var(--glass-border);
    padding-top: 5px;
}

.tt-row {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.tt-label {
    color: var(--text-muted);
    font-weight: 600;
    margin-right: 0.5rem;
}

.tt-bold {
    font-weight: 800;
    font-size: 1rem;
}

.tt-desc {
    margin-top: 0.25rem;
    color: var(--text-main);
    opacity: 0.9;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tt-action-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
    font-size: 0.85rem;
    background: rgba(16, 185, 129, 0.1);
}

/* ── Details Panel (V3) ───────────────────────────────── */
.details-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: rgba(15, 23, 42, 0.95);
    border-left: 1px solid var(--glass-border);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.6);
    z-index: 500;
    transform: translateX(0);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.details-panel.closed {
    transform: translateX(110%);
}

.close-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text-main);
}

.panel-content {
    padding: 3rem 2rem 2rem 2rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel-content h2 {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 400;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.panel-content h3 {
    font-size: 1.5rem;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.dp-section h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.long-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.85);
}

.dp-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: var(--glass-highlight);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.dp-metric {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dp-metric span {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.dp-metric strong {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Alerts */
.alert-box {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.alert-box.warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.5);
    color: #fcd34d;
}

.alert-box.danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #fca5a5;
    animation: pulseRed 2s infinite;
}

@keyframes pulseRed {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.link-btn {
    text-decoration: none;
    margin-top: auto;
}