/* ============================================================================
   Avatar PH Documentos — Estilos v1.1.0
   ============================================================================ */

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
    --aph-brand:       #5a9f3e;
    --aph-brand-dark:  #4a8530;
    --aph-brand-light: #f0f8ed;
    --aph-sidebar-w:   290px;
    --aph-toc-w:       210px;
    --aph-radius:      5px;
    --aph-gray-50:     #f9fafb;
    --aph-gray-100:    #f3f4f6;
    --aph-gray-200:    #e5e7eb;
    --aph-gray-400:    #9ca3af;
    --aph-gray-600:    #6b7280;
    --aph-gray-800:    #1f2937;
    --aph-font:        16px;
    --aph-transition:  .22s ease;
}

/* ── Barra de progreso de lectura ─────────────────────────────────────────── */
.aph-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: var(--aph-brand);
    z-index: 9999;
    transition: width .1s linear;
}

/* ── Wrapper general ──────────────────────────────────────────────────────── */
.aph-docs-wrap {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 20px 60px;
    box-sizing: border-box;
}

/* ── Breadcrumbs ──────────────────────────────────────────────────────────── */
.aph-breadcrumbs {
    padding: 10px 0 14px;
    font-size: .82rem;
    color: var(--aph-gray-600);
    border-bottom: 1px solid var(--aph-gray-200);
    margin-bottom: 0;
}
.aph-breadcrumbs a {
    color: var(--aph-gray-600);
    text-decoration: none;
}
.aph-breadcrumbs a:hover { color: var(--aph-brand); }

/* ── Layout: 3 columnas ───────────────────────────────────────────────────── */
.aph-docs-layout {
    display: grid;
    grid-template-columns: var(--aph-sidebar-w) 1fr var(--aph-toc-w);
    grid-template-rows: auto;
    gap: 0;
    align-items: start;
    position: relative;
    transition: grid-template-columns var(--aph-transition);
}

/* Sidebar compacto */
.aph-docs-layout.sidebar-compact {
    grid-template-columns: 42px 1fr var(--aph-toc-w);
}
.aph-docs-layout.sidebar-compact .aph-sidebar-wrap {
    overflow: hidden;
}
.aph-docs-layout.sidebar-compact .aph-docs-nav-tree,
.aph-docs-layout.sidebar-compact .aph-sidebar-search {
    opacity: 0;
    pointer-events: none;
}

/* ── Sidebar izquierdo ────────────────────────────────────────────────────── */
.aph-sidebar-wrap {
    grid-column: 1;
    position: sticky;
    top: 70px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--aph-gray-200);
    padding-bottom: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--aph-gray-200) transparent;
    transition: width var(--aph-transition), opacity var(--aph-transition);
}
.aph-sidebar-wrap::-webkit-scrollbar { width: 4px; }
.aph-sidebar-wrap::-webkit-scrollbar-thumb { background: var(--aph-gray-200); border-radius: 2px; }

/* Botón cerrar (solo mobile) */
.aph-sidebar-close {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--aph-gray-600);
    line-height: 1;
    padding: 4px;
}

/* ── Botón compactar sidebar (desktop) ────────────────────────────────────── */
.aph-sidebar-compact-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: calc(var(--aph-sidebar-w) - 13px);
    top: 8px;
    z-index: 10;
    width: 22px;
    height: 22px;
    border: 1px solid var(--aph-gray-200);
    border-radius: 50%;
    background: #fff;
    color: var(--aph-gray-600);
    font-size: .8rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: left var(--aph-transition), transform var(--aph-transition), color var(--aph-transition);
}
.aph-sidebar-compact-btn:hover { color: var(--aph-brand); border-color: var(--aph-brand); }
.aph-docs-layout.sidebar-compact .aph-sidebar-compact-btn {
    left: 30px;
    transform: rotate(180deg);
}

/* ── Buscador en sidebar ──────────────────────────────────────────────────── */
.aph-sidebar-search {
    padding: 12px 12px 8px;
    position: relative;
    transition: opacity var(--aph-transition);
}
.aph-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    font-size: .8rem;
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    outline: none;
    background: var(--aph-gray-50);
    color: var(--aph-gray-800);
}
.aph-search-input:focus { border-color: var(--aph-brand); background: #fff; }
.aph-search-results {
    position: absolute;
    top: calc(100% - 8px);
    left: 12px;
    right: 12px;
    background: #fff;
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
    z-index: 200;
    max-height: 340px;
    overflow-y: auto;
}
.aph-search-results[hidden] { display: none; }
.aph-search-result-item {
    display: block;
    padding: 9px 12px;
    text-decoration: none;
    color: var(--aph-gray-800);
    border-bottom: 1px solid var(--aph-gray-100);
    font-size: .8rem;
    line-height: 1.4;
}
.aph-search-result-item:last-child { border-bottom: none; }
.aph-search-result-item:hover { background: var(--aph-brand-light); }
.aph-search-result-title { font-weight: 600; display: block; margin-bottom: 2px; }
.aph-search-result-excerpt { color: var(--aph-gray-600); font-size: .75rem; display: block; }
.aph-search-highlight { background: #fef08a; border-radius: 2px; }
.aph-search-no-results { padding: 12px; color: var(--aph-gray-600); font-size: .82rem; text-align: center; }

/* Título raíz */
.aph-tree-root-title {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--aph-gray-600);
    padding: 16px 16px 10px;
}
.aph-tree-root-title a { color: inherit; text-decoration: none; }
.aph-tree-root-title a:hover { color: var(--aph-brand); }

/* Árbol */
.aph-tree-list,
.aph-tree-sub {
    list-style: none;
    margin: 0;
    padding: 0;
}
.aph-tree-item { margin: 0; }

.aph-tree-row {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    padding: 5px 14px 5px 16px;
    cursor: default;
}
.aph-tree-row:hover { background: var(--aph-gray-50); }

/* Toggle button */
.aph-tree-toggle {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    width: 16px;
    height: 18px;
    padding: 0;
    color: var(--aph-gray-400);
    font-size: .6rem;
    line-height: 18px;
    transition: transform var(--aph-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.aph-tree-toggle::before { content: '▶'; display: block; }
.aph-tree-item.is-open > .aph-tree-row > .aph-tree-toggle {
    transform: rotate(90deg);
}
.aph-tree-leaf-icon {
    flex-shrink: 0;
    width: 16px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    color: var(--aph-gray-400);
}
.aph-tree-leaf-icon::before { content: '—'; }

.aph-tree-link {
    font-size: .82rem;
    color: var(--aph-gray-800);
    text-decoration: none;
    line-height: 1.4;
    flex: 1;
}
.aph-tree-link:hover,
.aph-tree-link.is-active { color: var(--aph-brand); }
.aph-tree-link.is-active { font-weight: 600; }

/* Subniveles */
.aph-tree-sub { padding-left: 20px; }
.aph-tree-sub[hidden] { display: none; }

/* ── Botón toggle (acceso rápido al sidebar) ──────────────────────────────── */
.aph-sidebar-toggle {
    display: none; /* visible en tablet/mobile */
    position: fixed;
    bottom: 24px;
    left: 20px;
    z-index: 900;
    background: var(--aph-brand);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    line-height: 1;
}

/* ── Banner continuar leyendo ─────────────────────────────────────────────── */
.aph-resume-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--aph-brand-light);
    border: 1px solid var(--aph-brand);
    border-radius: var(--aph-radius);
    padding: 10px 14px;
    font-size: .85rem;
    color: var(--aph-gray-800);
    margin-bottom: 14px;
}
.aph-resume-banner[hidden] { display: none; }
.aph-resume-link { color: var(--aph-brand-dark); font-weight: 600; text-decoration: underline; }
.aph-resume-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--aph-gray-600);
    font-size: .85rem;
    padding: 0 2px;
    line-height: 1;
}

/* ── Contenido principal ──────────────────────────────────────────────────── */
.aph-docs-main {
    grid-column: 2;
    padding: 24px 36px 24px 32px;
    min-width: 0;
    font-size: var(--aph-font);
    line-height: 1.7;
}

.aph-meta-bar {
    display: flex;
    justify-content: flex-end;
    gap: 14px;
    font-size: .78rem;
    color: var(--aph-gray-600);
    margin-bottom: 14px;
}

.aph-doc-version {
    background: var(--aph-gray-100);
    border-radius: var(--aph-radius);
    padding: 1px 7px;
    font-weight: 600;
    color: var(--aph-gray-800);
}

.aph-article-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 10px;
    color: var(--aph-gray-800);
    line-height: 1.2;
}

.aph-article-stats {
    display: flex;
    gap: 18px;
    font-size: .8rem;
    color: var(--aph-gray-600);
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--aph-gray-200);
}

.aph-root-actions {
    margin-bottom: 24px;
}

/* Contenido editorial */
.aph-content h2 { font-size: 1.35rem; margin: 2em 0 .6em; position: relative; }
.aph-content h3 { font-size: 1.1rem;  margin: 1.6em 0 .5em; position: relative; }
.aph-content h4 { font-size: 1rem;    margin: 1.4em 0 .4em; }
.aph-content p  { margin-bottom: 1em; }
.aph-content ul,
.aph-content ol { margin: .5em 0 1em 1.5em; }
.aph-content li { margin-bottom: .35em; }
.aph-content blockquote {
    margin: 1.5em 0;
    padding: 12px 20px;
    border-left: 4px solid var(--aph-brand);
    background: var(--aph-brand-light);
    border-radius: 0 var(--aph-radius) var(--aph-radius) 0;
}
.aph-content table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1.5em;
    font-size: .9em;
}
.aph-content th,
.aph-content td {
    border: 1px solid var(--aph-gray-200);
    padding: 8px 12px;
    text-align: left;
}
.aph-content th { background: var(--aph-gray-100); font-weight: 600; }

/* Heading anchors */
.aph-heading-anchor {
    display: inline-block;
    margin-left: 7px;
    opacity: 0;
    font-size: .75em;
    color: var(--aph-gray-400);
    text-decoration: none;
    transition: opacity var(--aph-transition), color var(--aph-transition);
    cursor: pointer;
    vertical-align: middle;
}
.aph-content h2:hover .aph-heading-anchor,
.aph-content h3:hover .aph-heading-anchor {
    opacity: 1;
}
.aph-heading-anchor:hover { color: var(--aph-brand); }
.aph-heading-anchor.copied { color: var(--aph-brand); opacity: 1; }

/* Grid de índice (documento raíz) */
.aph-index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 28px;
}
.aph-index-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    text-decoration: none;
    color: var(--aph-gray-800);
    font-size: .88rem;
    font-weight: 500;
    transition: border-color var(--aph-transition), background var(--aph-transition);
    line-height: 1.35;
}
.aph-index-card:hover {
    border-color: var(--aph-brand);
    background: var(--aph-brand-light);
    color: var(--aph-brand-dark);
}
.aph-index-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

/* Prev / Next */
.aph-article-nav {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: 12px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--aph-gray-200);
}
.aph-nav-prev,
.aph-nav-next {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    text-decoration: none;
    color: var(--aph-gray-800);
    font-size: .85rem;
    max-width: 46%;
    transition: border-color var(--aph-transition), color var(--aph-transition);
    line-height: 1.3;
}
.aph-nav-prev:hover,
.aph-nav-next:hover { border-color: var(--aph-brand); color: var(--aph-brand); }
.aph-nav-next { margin-left: auto; text-align: right; flex-direction: row-reverse; }
.aph-nav-arrow { font-size: 1rem; flex-shrink: 0; }

/* ── Sidebar derecho (controles + TOC) ────────────────────────────────────── */
.aph-toc-wrap {
    grid-column: 3;
    position: sticky;
    top: 70px;
    padding: 20px 0 20px 18px;
    border-left: 1px solid var(--aph-gray-200);
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.aph-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.aph-font-size-controls { display: flex; gap: 3px; }
.aph-ctrl-btn {
    padding: 4px 9px;
    font-size: .78rem;
    font-weight: 600;
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    background: #fff;
    cursor: pointer;
    color: var(--aph-gray-800);
    line-height: 1.6;
    transition: border-color var(--aph-transition), color var(--aph-transition);
}
.aph-ctrl-btn:hover { border-color: var(--aph-brand); color: var(--aph-brand); }
.aph-print-btn { font-size: .9rem; }

/* TOC */
.aph-toc { font-size: .78rem; }
.aph-toc-heading {
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--aph-gray-600);
    margin-bottom: 8px;
}
.aph-toc ul { list-style: none; margin: 0; padding: 0; }
.aph-toc li { margin-bottom: 5px; line-height: 1.3; }
.aph-toc li.toc-h3 a { padding-left: 12px; }
.aph-toc a {
    color: var(--aph-gray-600);
    text-decoration: none;
    display: block;
}
.aph-toc a:hover,
.aph-toc a.is-active { color: var(--aph-brand); }

/* ── Shortcode: catálogo ──────────────────────────────────────────────────── */
.aph-docs-catalog {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin: 24px 0;
}
.aph-doc-card {
    border: 1px solid var(--aph-gray-200);
    border-radius: var(--aph-radius);
    overflow: hidden;
    transition: box-shadow var(--aph-transition);
    background: #fff;
}
.aph-doc-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.09); }
.aph-doc-card-thumb img { width: 100%; height: 160px; object-fit: cover; display: block; }
.aph-doc-card-body { padding: 18px; }
.aph-doc-card-title { font-size: 1rem; font-weight: 700; margin: 0 0 8px; color: var(--aph-gray-800); }
.aph-doc-card-excerpt { font-size: .85rem; color: var(--aph-gray-600); line-height: 1.5; margin-bottom: 14px; }
.aph-doc-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Shortcode: header/CTA ────────────────────────────────────────────────── */
.aph-doc-header-block { margin: 16px 0 24px; }
.aph-doc-header-title { font-size: 1.6rem; font-weight: 700; margin: 0 0 8px; }
.aph-doc-header-desc  { font-size: 1rem; color: var(--aph-gray-600); margin-bottom: 16px; }
.aph-doc-header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Shortcode: TOC ───────────────────────────────────────────────────────── */
.aph-doc-toc-shortcode { margin: 16px 0 24px; }
.aph-toc-sc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.aph-toc-sc-item { margin-bottom: 6px; }
.aph-toc-sc-item a {
    color: var(--aph-gray-800);
    text-decoration: none;
    font-size: .9rem;
}
.aph-toc-sc-item a:hover { color: var(--aph-brand); }
.aph-toc-sc-item .aph-toc-sc-list { padding-left: 18px; margin-top: 4px; }
.aph-toc-sc-item.depth-1 > a { font-weight: 600; font-size: .95rem; }
.aph-toc-sc-item.depth-2 > a { color: var(--aph-gray-600); }
.aph-toc-sc-item.depth-3 > a { color: var(--aph-gray-400); font-size: .82rem; }

/* ── Botones ──────────────────────────────────────────────────────────────── */
.aph-btn {
    display: inline-block;
    padding: 10px 22px;
    border-radius: var(--aph-radius);
    font-size: .85rem;
    font-weight: 700;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: .06em;
    cursor: pointer;
    border: 2px solid transparent;
    transition: background var(--aph-transition), border-color var(--aph-transition), color var(--aph-transition);
}
.aph-btn-primary {
    background: var(--aph-brand);
    border-color: var(--aph-brand);
    color: #fff;
}
.aph-btn-primary:hover {
    background: var(--aph-brand-dark);
    border-color: var(--aph-brand-dark);
    color: #fff;
}
.aph-btn-outline {
    background: transparent;
    border-color: var(--aph-brand);
    color: var(--aph-brand);
}
.aph-btn-outline:hover {
    background: var(--aph-brand);
    color: #fff;
}

/* ── Responsive: tablet ───────────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .aph-toc-wrap { display: none; }
    .aph-docs-layout { grid-template-columns: var(--aph-sidebar-w) 1fr; }
    .aph-docs-layout.sidebar-compact { grid-template-columns: 42px 1fr; }
    .aph-sidebar-compact-btn { display: none; }
}

/* ── Responsive: mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .aph-docs-layout { grid-template-columns: 1fr; }

    .aph-sidebar-wrap {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        width: min(var(--aph-sidebar-w), 85vw);
        background: #fff;
        z-index: 1000;
        border-right: 1px solid var(--aph-gray-200);
        box-shadow: 4px 0 16px rgba(0,0,0,.12);
        transform: translateX(-110%);
        transition: transform var(--aph-transition);
        overflow-y: auto;
        padding-top: 48px;
    }
    .aph-sidebar-wrap.is-open { transform: translateX(0); }
    .aph-sidebar-close { display: block; }

    .aph-sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .aph-sidebar-compact-btn { display: none; }

    /* Overlay */
    .aph-sidebar-wrap.is-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.3);
        z-index: -1;
    }

    .aph-docs-main { padding: 16px; }
    .aph-article-title { font-size: 1.5rem; }
    .aph-index-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .aph-nav-label { display: none; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
    .aph-progress-bar,
    .aph-sidebar-wrap,
    .aph-toc-wrap,
    .aph-article-nav,
    .aph-sidebar-toggle,
    .aph-sidebar-compact-btn,
    .aph-resume-banner,
    .aph-root-actions,
    .aph-breadcrumbs,
    .aph-controls { display: none !important; }

    .aph-docs-layout   { grid-template-columns: 1fr !important; display: block !important; }
    .aph-docs-main     { padding: 0 !important; }
    .aph-docs-wrap     { padding: 0 !important; max-width: none !important; }

    .aph-article-title {
        font-size: 18pt !important;
        page-break-after: avoid;
    }
    .aph-content h2 {
        font-size: 14pt !important;
        page-break-after: avoid;
        margin-top: 24pt !important;
        border-top: 1pt solid #ccc;
        padding-top: 6pt;
    }
    .aph-content h3 {
        font-size: 12pt !important;
        page-break-after: avoid;
    }
    .aph-content p, .aph-content li {
        font-size: 10pt !important;
        line-height: 1.5 !important;
        orphans: 3;
        widows: 3;
    }
    .aph-content table { page-break-inside: avoid; font-size: 9pt !important; }
    .aph-meta-bar { display: flex !important; font-size: 9pt !important; margin-bottom: 12pt !important; }
    .aph-article-stats { font-size: 9pt !important; }
    .aph-heading-anchor { display: none !important; }

    @page {
        margin: 2cm 2.5cm;
    }
}
