/**
 * Thai Education Foundation (TEF) — Knowledge & Resources Library Stylesheet
 * Distinct, hierarchy-first presentation for documents, videos, guides, and portals.
 */

:root {
    --res-forest: #243e36;
    --res-forest-dark: #172823;
    --res-sage: #7ca982;
    --res-sage-light: #e0eee3;
    --res-sage-tint: rgba(124, 169, 130, 0.12);
    --res-border: #e2e8f0;
    --res-text-dark: #1e293b;
    --res-text-muted: #64748b;
    --res-card-bg: #ffffff;
    --res-radius: 12px;
    --res-transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Live Search & Filter Bar ────────────────────────────────────────────── */
.tef-resources-toolbar-wrapper {
    margin-bottom: 28px;
}

.tef-resources-toolbar {
    background: var(--res-card-bg);
    border: 1px solid var(--res-border);
    border-radius: var(--res-radius);
    padding: 16px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.tef-res-search-box {
    position: relative;
    flex: 1;
    min-width: 260px;
    max-width: 420px;
}

.tef-res-search-box i.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--res-text-muted);
    font-size: 14px;
    pointer-events: none;
}

.tef-res-search-input {
    width: 100%;
    height: 42px;
    padding: 8px 14px 8px 40px;
    border-radius: 8px;
    border: 1px solid var(--res-border);
    font-size: 13.5px;
    font-family: inherit;
    background: #f8fafc;
    color: var(--res-text-dark);
    transition: var(--res-transition);
}

.tef-res-search-input:focus {
    outline: none;
    border-color: var(--res-forest);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(36, 62, 54, 0.12);
}

.tef-res-filter-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.tef-res-chip {
    padding: 7px 14px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 20px;
    border: 1px solid var(--res-border);
    background: #ffffff;
    color: var(--res-text-dark);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--res-transition);
}

.tef-res-chip:hover {
    border-color: var(--res-forest);
    background: #f8fafc;
    color: var(--res-forest);
}

.tef-res-chip.active {
    background: var(--res-forest);
    border-color: var(--res-forest);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(36, 62, 54, 0.25);
}

.tef-res-chip .chip-count {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.08);
}

.tef-res-chip.active .chip-count {
    background: rgba(255, 255, 255, 0.22);
}

/* ── 1. HIERARCHY TREE LAYOUT (PRIMARY) ──────────────────────────────────── */
.tef-res-hierarchy-container {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.tef-branch-card {
    background: var(--res-card-bg);
    border: 1px solid var(--res-border);
    border-radius: var(--res-radius);
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    transition: var(--res-transition);
}

.tef-branch-card:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    border-color: #cbd5e1;
}

.tef-branch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 2px solid #f1f5f9;
}

.tef-branch-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.tef-branch-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.tef-branch-icon.icon-file {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.tef-branch-icon.icon-video {
    background: #fff1f2;
    color: #e11d48;
    border: 1px solid #fecdd3;
}

.tef-branch-icon.icon-text {
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.tef-branch-icon.icon-link {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

.tef-branch-title-group h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--res-text-dark);
}

.tef-branch-title-group p {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: var(--res-text-muted);
}

.tef-branch-count-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    background: #f1f5f9;
    color: #475569;
}

/* Tree Structure Rail & Nodes */
.tef-tree-rail {
    position: relative;
    padding-left: 28px;
    margin-left: 20px;
    border-left: 2px dashed #cbd5e1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tef-tree-node {
    position: relative;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    transition: var(--res-transition);
}

/* Horizontal elbow connector line */
.tef-tree-node::before {
    content: '';
    position: absolute;
    left: -29px;
    top: 50%;
    width: 28px;
    height: 2px;
    border-top: 2px dashed #cbd5e1;
}

/* Bullet circle connector point */
.tef-tree-node::after {
    content: '';
    position: absolute;
    left: -32px;
    top: calc(50% - 4px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--res-forest);
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px #cbd5e1;
}

.tef-tree-node:hover {
    border-color: var(--res-forest);
    background: #fafcfb;
    transform: translateX(4px);
    box-shadow: 0 6px 20px rgba(36, 62, 54, 0.08);
}

.tef-tree-node:hover::after {
    background: #e11d48;
    transform: scale(1.2);
}

.tef-node-main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.tef-node-type-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.tef-node-details {
    flex: 1;
    min-width: 0;
}

.tef-node-title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--res-text-dark);
}

.tef-node-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

.tef-node-title a:hover {
    color: var(--res-forest);
}

.tef-node-desc {
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--res-text-muted);
}

.tef-node-meta-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 11.5px;
}

.tef-meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 500;
}

.tef-meta-pill.pill-format {
    background: #e0f2fe;
    color: #0369a1;
    font-weight: 600;
}

.tef-node-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tef-action-btn {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    transition: var(--res-transition);
}

.tef-action-btn.btn-view {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: var(--res-forest);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.tef-action-btn.btn-view:hover {
    border-color: var(--res-forest);
    background: #f8fafc;
    color: var(--res-forest-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(36, 62, 54, 0.12);
}

.tef-action-btn.btn-view i {
    color: #ef4444;
}

.tef-action-btn.btn-download {
    background: var(--res-forest);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(36, 62, 54, 0.2);
}

.tef-action-btn.btn-download:hover {
    background: var(--res-forest-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(36, 62, 54, 0.3);
}

.tef-action-btn.btn-video {
    background: #e11d48;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(225, 29, 72, 0.25);
}

.tef-action-btn.btn-video:hover {
    background: #be123c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(225, 29, 72, 0.35);
}

.tef-action-btn.btn-link {
    background: #ffffff;
    border: 1px solid var(--res-border);
    color: var(--res-text-dark);
}

.tef-action-btn.btn-link:hover {
    border-color: var(--res-forest);
    background: #f8fafc;
    color: var(--res-forest);
    transform: translateY(-2px);
}

.tef-action-btn.btn-guide {
    background: var(--res-sage-light);
    color: var(--res-forest);
    font-weight: 600;
}

.tef-action-btn.btn-guide:hover {
    background: var(--res-sage);
    color: #ffffff;
    transform: translateY(-2px);
}

/* ── 2. DIRECTORY TABLE LAYOUT ───────────────────────────────────────────── */
.tef-res-table-card {
    background: var(--res-card-bg);
    border: 1px solid var(--res-border);
    border-radius: var(--res-radius);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.tef-res-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.tef-res-table thead th {
    background: #f8fafc;
    padding: 14px 18px;
    text-align: left;
    font-weight: 700;
    color: var(--res-text-dark);
    border-bottom: 2px solid var(--res-border);
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tef-res-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.tef-res-table tbody tr:hover {
    background: #fafcfb;
}

.tef-res-table td {
    padding: 16px 18px;
    vertical-align: middle;
}

/* ── 3. ACCORDION LAYOUT ─────────────────────────────────────────────────── */
.tef-res-accordion-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tef-accordion-item {
    background: var(--res-card-bg);
    border: 1px solid var(--res-border);
    border-radius: var(--res-radius);
    overflow: hidden;
    transition: var(--res-transition);
}

.tef-accordion-trigger {
    width: 100%;
    padding: 18px 24px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.tef-accordion-trigger:hover {
    background: #fafcfb;
}

.tef-accordion-chevron {
    transition: transform 0.3s ease;
    color: var(--res-text-muted);
}

.tef-accordion-item.open .tef-accordion-chevron {
    transform: rotate(180deg);
}

.tef-accordion-body {
    display: none;
    padding: 0 24px 24px;
    border-top: 1px solid #f1f5f9;
}

.tef-accordion-item.open .tef-accordion-body {
    display: block;
    padding-top: 18px;
}

/* ── 4. CARD GRID LAYOUT (REFINED) ───────────────────────────────────────── */
.tef-res-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.tef-res-card {
    background: var(--res-card-bg);
    border: 1px solid var(--res-border);
    border-radius: var(--res-radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    transition: var(--res-transition);
    position: relative;
}

.tef-res-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    border-color: var(--res-forest);
}

/* Sub-Topic Block inside Tree Rail */
.tef-subtopic-block {
    position: relative;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 18px 20px;
    transition: var(--res-transition);
}

.tef-subtopic-block:hover {
    border-color: #cbd5e1;
    background: #f1f5f9;
}

.tef-subtopic-block::before {
    content: '';
    position: absolute;
    left: -29px;
    top: 28px;
    width: 28px;
    height: 2px;
    border-top: 2px dashed #cbd5e1;
}

.tef-subtopic-block::after {
    content: '';
    position: absolute;
    left: -33px;
    top: 24px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--res-sage);
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px #cbd5e1;
}

.tef-subtopic-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.tef-subtopic-title-group {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tef-subtopic-bullet {
    font-size: 1.3rem;
    line-height: 1.1;
    color: var(--res-forest);
    font-weight: 900;
}

.tef-subtopic-title {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--res-forest);
}

.tef-subtopic-rail {
    position: relative;
    margin-top: 14px;
    padding-left: 24px;
    margin-left: 6px;
    border-left: 2px dashed #cbd5e1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tef-subtopic-rail .tef-tree-node {
    background: #ffffff;
    border-radius: 8px;
    padding: 12px 18px;
}

.tef-subtopic-rail .tef-tree-node::before {
    left: -25px;
    width: 24px;
}

.tef-subtopic-rail .tef-tree-node::after {
    left: -28px;
    width: 7px;
    height: 7px;
    top: calc(50% - 3.5px);
    background: var(--res-sage);
}

.tef-subtopic-count-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--res-forest);
    background: rgba(36, 62, 54, 0.08);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Level 3 & Deeper Nested Sub-Topic Blocks */
.tef-subtopic-block.tef-level-nested {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 18px;
    margin-top: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.tef-subtopic-block.tef-level-nested:hover {
    border-color: #cbd5e1;
    background: #fafcfb;
    box-shadow: 0 4px 12px rgba(36, 62, 54, 0.06);
}

.tef-subtopic-block.tef-level-nested .tef-subtopic-title {
    font-size: 0.98rem;
    color: var(--res-forest);
}

.tef-subtopic-block.tef-level-nested .tef-subtopic-bullet {
    font-size: 1.15rem;
    color: var(--res-sage);
}

.tef-subtopic-rail > .tef-subtopic-block::before {
    left: -25px;
    width: 24px;
    top: 24px;
}

.tef-subtopic-rail > .tef-subtopic-block::after {
    left: -28px;
    top: 20px;
    width: 8px;
    height: 8px;
    background: var(--res-sage);
}

.tef-meta-pill.pill-size {
    background: #f1f5f9;
    color: #334155;
    font-weight: 600;
}

.tef-meta-pill.pill-pdf {
    background: #fee2e2;
    color: #b91c1c;
    font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .tef-tree-rail {
        padding-left: 14px;
        margin-left: 10px;
    }
    .tef-tree-node {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        padding: 14px;
    }
    .tef-tree-node::before {
        width: 14px;
        left: -15px;
    }
    .tef-tree-node::after {
        left: -18px;
    }
    .tef-subtopic-rail {
        padding-left: 12px;
        margin-left: 4px;
    }
    .tef-subtopic-rail .tef-tree-node::before {
        width: 12px;
        left: -13px;
    }
    .tef-subtopic-rail .tef-tree-node::after {
        left: -16px;
    }
    .tef-subtopic-rail > .tef-subtopic-block::before {
        width: 12px;
        left: -13px;
    }
    .tef-subtopic-rail > .tef-subtopic-block::after {
        left: -16px;
    }
    .tef-node-actions {
        width: 100%;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }
    .tef-node-actions .tef-action-btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 110px;
        justify-content: center;
        padding: 8px 12px;
        font-size: 12px;
    }
    .tef-resources-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .tef-res-search-box {
        max-width: 100%;
    }
}
