/* ==========================================================================
   VISTA DETALLE: LIENZO DEL ÁRBOL DE VALOR MINERO (TREE CANVAS)
   ========================================================================== */

/* Header de la Vista de Árbol */
.app-header {
    height: 56px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 50;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    position: relative;
}

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

.brand-logo-img {
    height: 28px !important;
    max-height: 28px !important;
    width: auto !important;
    max-width: 160px !important;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.brand-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    flex-shrink: 0;
}

.brand-info h1 {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    line-height: 1;
}

.brand-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--copper-light);
    color: var(--copper-primary);
    border: 1px solid #fde68a;
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

/* KPIs de Resumen en Header */
.header-kpi-summary {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    padding: 4px 14px;
    border-radius: var(--radius-md);
}

.kpi-chip {
    display: flex;
    align-items: center;
    gap: 6px;
}

.kpi-chip .chip-label {
    font-size: 0.68rem;
    color: var(--text-dim);
    text-transform: uppercase;
    font-weight: 600;
}

.kpi-chip .chip-val {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-main);
}

.kpi-chip-divider {
    width: 1px;
    height: 16px;
    background: var(--border-color);
}

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

/* Toolbar de Filtros y Zoom */
.app-toolbar {
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 40;
    flex-shrink: 0;
    position: relative;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 600;
}

.filter-select {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 5px 10px;
    font-family: var(--font-main);
    font-size: 0.74rem;
    color: var(--text-main);
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: var(--transition-fast);
}

.filter-select:hover {
    background: #ffffff;
    border-color: #cbd5e1;
}

.filter-select:focus {
    border-color: var(--cyan-accent);
    box-shadow: 0 0 0 2px var(--cyan-light);
}

/* Controles de Zoom */
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.view-controls {
    display: flex;
    align-items: center;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 2px;
}

.control-btn {
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.control-btn:hover {
    background: #ffffff;
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.control-btn.btn-fit {
    width: auto;
    padding: 0 10px;
    gap: 5px;
    font-size: 0.74rem;
    color: var(--text-main);
}

.zoom-level-text {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    min-width: 38px;
    text-align: center;
}

/* Barra de Simulación What-If */
.simulation-bar {
    background: #0f172a;
    color: #ffffff;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 30;
    border-bottom: 2px solid var(--cyan-accent);
    animation: slideDown 0.2s ease-out;
}

.simulation-bar.hidden {
    display: none;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.sim-info {
    font-size: 0.78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--cyan-accent);
}

.sim-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.sim-slider-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
}

.sim-slider {
    accent-color: var(--cyan-accent);
    cursor: pointer;
}

/* ==========================================================================
   LIENZO INTERACTIVO (VIEWPORT & CANVAS)
   ========================================================================== */

.canvas-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-canvas);
    cursor: grab;
    width: 100%;
    height: 100%;
}

.canvas-viewport:active {
    cursor: grabbing;
}

.tree-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 5000px;
    height: 4000px;
    transform-origin: 0 0;
    will-change: transform;
}

/* Capa SVG de Conectores */
.tree-svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.tree-connector {
    fill: none !important;
    stroke: #cbd5e1;
    stroke-width: 2px;
    stroke-linecap: round;
    transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.tree-connector.pulse-green {
    stroke: #86efac;
    stroke-width: 2px;
}

.tree-connector.pulse-yellow {
    stroke: #fde68a;
    stroke-width: 2px;
}

.tree-connector.pulse-red {
    stroke: #fca5a5;
    stroke-width: 2px;
}

.tree-connector.connector-active {
    stroke: var(--cyan-accent);
    stroke-width: 3.5px;
}

/* Capa de Nodos HTML */
.tree-nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* ==========================================================================
   TARJETAS DE NODOS (MINIMALIST & SLIM DESIGN)
   ========================================================================== */

.tree-node-card {
    position: absolute;
    width: 235px;
    height: 78px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 8px 12px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    user-select: none;
    box-sizing: border-box;
}

.tree-node-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
    background: #ffffff;
}

.tree-node-card.selected {
    border-color: var(--cyan-accent) !important;
    box-shadow: 0 0 0 2px var(--cyan-light), var(--shadow-md) !important;
}

.tree-node-card.status-green { border-left: 4px solid var(--status-green) !important; }
.tree-node-card.status-yellow { border-left: 4px solid var(--status-yellow) !important; }
.tree-node-card.status-red { border-left: 4px solid var(--status-red) !important; }

/* Fila Superior del Nodo: Título y Píldora Semafórica */
.node-compact-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
}

.node-compact-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    flex: 1;
}

.node-semaphore-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    font-size: 0.68rem;
    font-weight: 700;
    font-family: var(--font-mono);
    flex-shrink: 0;
}

.node-semaphore-pill.green {
    background: var(--status-green-bg);
    color: var(--status-green-text);
}

.node-semaphore-pill.yellow {
    background: var(--status-yellow-bg);
    color: var(--status-yellow-text);
}

.node-semaphore-pill.red {
    background: var(--status-red-bg);
    color: var(--status-red-text);
}

.semaphore-beacon {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.node-semaphore-pill.green .semaphore-beacon { background: var(--status-green); }
.node-semaphore-pill.yellow .semaphore-beacon { background: var(--status-yellow); }
.node-semaphore-pill.red .semaphore-beacon { background: var(--status-red); }

.variance-text {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
}

/* Fila Inferior del Nodo: Valor Actual y Meta */
.node-compact-values {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
}

.node-compact-actual {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

.node-compact-actual small {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: 2px;
}

.node-compact-target-badge {
    display: inline-flex;
    align-items: center;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.target-number {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-dim);
}

/* Botón de Colapso (+ / −) */
.node-collapse-toggle {
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--text-muted);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    z-index: 10;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
    padding: 0;
    outline: none;
}

.node-collapse-toggle:hover {
    background: var(--cyan-accent);
    color: #ffffff;
    border-color: var(--cyan-accent);
    transform: translateY(-50%) scale(1.15);
}

.node-collapse-toggle.collapsed {
    background: #f0fdf4;
    color: var(--status-green);
    border-color: #86efac;
    width: auto;
    min-width: 22px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
}

/* ==========================================================================
   LEYENDA EJECUTIVA INFERIOR
   ========================================================================== */

.tree-executive-legend {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 6px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    z-index: 30;
    white-space: nowrap;
}

.legend-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-group-title {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
}

.legend-pill-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
}

.legend-val-real {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-main);
    background: #ffffff;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid #cbd5e1;
}

.legend-val-target {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-dim);
    background: #f8fafc;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid #e2e8f0;
}

.legend-desc {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.green { background: var(--status-green); }
.legend-dot.yellow { background: var(--status-yellow); }
.legend-dot.red { background: var(--status-red); }

.legend-vdivider {
    width: 1px;
    height: 16px;
    background: var(--border-color);
}

.legend-shortcuts {
    color: var(--text-dim);
    font-size: 0.7rem;
}

.legend-shortcut-pill {
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
}

/* Botón Flotante de Ayuda */
.floating-help-btn {
    position: absolute;
    top: 16px;
    right: 20px;
    z-index: 35;
    background: #ffffff;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 7px 14px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.floating-help-btn:hover {
    background: #f8fafc;
    border-color: var(--cyan-accent);
    color: var(--cyan-accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
