/* =======================================================
 * Account Tree Selector - DJN Habitat v3.0
 * Revisión 2: mayor claridad visual, jerarquía inequívoca
 * ======================================================= */

/* Wrapper del componente */
.acct-tree-wrapper {
    position: relative;
    width: 100%;
}

/* ---- DISPLAY (cerrado) ---- */
.acct-tree-display {
    width: 100%;
    padding: 0.55rem 0.9rem;
    border-radius: 8px;
    border: 1.5px solid rgba(15, 23, 42, 0.12);
    background: white;
    font-size: 0.82rem;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    user-select: none;
    min-height: 36px;
    font-family: inherit;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.acct-tree-display:hover {
    border-color: var(--brand-blue-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.acct-tree-display.open {
    border-color: var(--brand-blue-accent);
    border-bottom-color: transparent;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.acct-tree-display .placeholder {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.78rem;
}

.acct-tree-display .arrow {
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.acct-tree-display.open .arrow { transform: rotate(180deg); }

.acct-tree-display .selected-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
}

/* ---- PANEL DROPDOWN ---- */
.acct-tree-panel {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: white;
    border: 1.5px solid var(--brand-blue-accent);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 14px 30px -6px rgba(15, 23, 42, 0.14);
    z-index: 9000;
    animation: treeSlideDown 0.16s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

@keyframes treeSlideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.acct-tree-panel.open { display: block; }

/* ---- BÚSQUEDA ---- */
.acct-tree-search {
    padding: 0.5rem 0.6rem;
    background: #f8faff;
    border-bottom: 1px solid rgba(15,23,42,0.06);
}

.acct-tree-search input {
    width: 100%;
    padding: 0.42rem 0.65rem;
    border-radius: 6px;
    border: 1px solid rgba(15,23,42,0.1);
    font-size: 0.78rem;
    font-family: inherit;
    outline: none;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
}

.acct-tree-search input:focus {
    border-color: var(--brand-blue-accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* ---- NODOS SCROLLEABLE ---- */
.acct-tree-nodes {
    max-height: 240px;
    overflow-y: auto;
    padding: 0.3rem 0 0.4rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(15,23,42,0.12) transparent;
}

.acct-tree-nodes::-webkit-scrollbar { width: 4px; }
.acct-tree-nodes::-webkit-scrollbar-thumb {
    background: rgba(15,23,42,0.12);
    border-radius: 10px;
}

/* ---- CABECERA DE GRUPO (TIPO CONTABLE) ---- */
.acct-group-header {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.8rem;
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    cursor: pointer;
    border-top: 1px solid rgba(15,23,42,0.04);
    transition: filter 0.15s;
    /* NO sticky — evita superposiciones en el scroll */
}

.acct-group-header:first-child { border-top: none; }
.acct-group-header:hover { filter: brightness(0.96); }

.acct-group-header .toggle-btn {
    font-size: 0.55rem;
    line-height: 1;
    display: inline-block;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 12px;
    text-align: center;
    flex-shrink: 0;
}

.acct-group-header .toggle-btn.open { transform: rotate(90deg); }

/* Paleta de colores por tipo */
.acct-group-activo     { background: rgba(34,197,94,0.08);  color: #155c2a; }
.acct-group-pasivo     { background: rgba(239,68,68,0.08);  color: #8b1a1a; }
.acct-group-patrimonio { background: rgba(59,130,246,0.08); color: #1e3a8a; }
.acct-group-ingreso    { background: rgba(245,158,11,0.09); color: #7c3000; }
.acct-group-gasto      { background: rgba(168,85,247,0.08); color: #4a1973; }
.acct-group-orden      { background: rgba(100,116,139,0.07);color: #2d3a4b; }

/* ---- NODO GENÉRICO ---- */
.acct-node {
    display: flex;
    align-items: flex-start;
    gap: 0.3rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: background 0.12s;
    line-height: 1.35;
}

/* Indentación por nivel — izquierda generada por padding */
.acct-node[data-depth="1"] { padding: 0.3rem 0.8rem 0.3rem 1rem;   }
.acct-node[data-depth="2"] { padding: 0.28rem 0.8rem 0.28rem 1.6rem; }
.acct-node[data-depth="3"] { padding: 0.25rem 0.8rem 0.25rem 2.2rem; }
.acct-node[data-depth="4"] { padding: 0.23rem 0.8rem 0.23rem 2.8rem; }
.acct-node[data-depth="5"] { padding: 0.2rem 0.8rem 0.2rem 3.4rem;  }

.acct-node .toggle-btn {
    font-size: 0.52rem;
    width: 12px;
    flex-shrink: 0;
    text-align: center;
    color: transparent;            /* invisible por defecto */
    display: inline-block;
    line-height: 1.6;
    transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── NODO PADRE (código que tiene hijos) ─────────────── */
.acct-node.is-parent {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.78rem;
    background: rgba(15,23,42,0.018);
    border-left: 2px solid rgba(15,23,42,0.06);
}

.acct-node.is-parent .toggle-btn {
    color: var(--brand-blue-accent);
}

.acct-node.is-parent .toggle-btn.open { transform: rotate(90deg); }

.acct-node.is-parent:hover {
    background: rgba(15,23,42,0.035);
}

/* ── NODO HOJA (seleccionable) ────────────────────────── */
.acct-node.is-leaf {
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-left: 2px solid transparent;
}

.acct-node.is-leaf::before {
    content: '└';
    color: rgba(15,23,42,0.18);
    font-size: 0.72rem;
    margin-right: 3px;
    flex-shrink: 0;
    line-height: 1.6;
}

.acct-node.is-leaf:hover {
    background: rgba(59,130,246,0.07);
    color: var(--brand-blue-accent);
    border-left-color: var(--brand-blue-accent);
    font-weight: 600;
}

.acct-node.is-leaf.selected {
    background: rgba(59,130,246,0.10);
    color: var(--brand-blue-accent);
    border-left-color: var(--brand-blue-accent);
    font-weight: 700;
}

/* Hijos colapsados / expandidos */
.acct-children          { display: none; }
.acct-children.open     { display: block; }

/* ── DETALLE / SUGERENCIA DE USO ─────────────────────────── */
/* Para desactivar globalmente: define('ACCT_TREE_SHOW_DETAIL', false) en accounting_helper.php */
.acct-node-detail {
    display: block;
    font-size: 0.68rem;
    font-weight: 400;
    color: rgba(15, 23, 42, 0.38);
    line-height: 1.3;
    margin-top: 1px;
    white-space: normal;
    font-style: italic;
    pointer-events: none;
}

.acct-node.is-parent .acct-node-detail {
    font-size: 0.65rem;
    color: rgba(15, 23, 42, 0.28);
}

.acct-node.is-leaf:hover .acct-node-detail,
.acct-node.is-leaf.selected .acct-node-detail {
    color: rgba(59, 130, 246, 0.55);
}

/* Estado vacío */
.acct-tree-empty {
    padding: 0.8rem 1rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    display: none;
}
