.topics-page,
.topic-detail-page {
    display: grid;
    gap: 22px;
}

.topics-hero,
.topic-search-panel,
.topic-filters,
.topic-detail-hero,
.resource-group,
.ungrouped-panel {
    border: 1px solid var(--tp-border);
    border-radius: 16px;
    background: var(--tp-card);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .07);
}

.topics-hero,
.topic-detail-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 26px;
}

.topics-hero h1,
.topic-detail-hero h1,
.resource-group h2 {
    margin: 4px 0 8px;
    color: var(--tp-bronze);
}

.eyebrow {
    margin: 0;
    color: var(--tp-blue);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.hero-actions,
.modal-actions,
.compact-resource-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.secondary-button {
    border: 1px solid var(--tp-border);
    background: #fff;
    color: var(--tp-bronze);
}

.topic-search-panel {
    display: grid;
    gap: 8px;
    padding: 18px 22px;
}

.topic-search-panel label {
    color: #5f584e;
    font-size: .82rem;
    font-weight: 700;
}

.topic-search-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topic-search-row input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cfc6b6;
    border-radius: 9px;
    padding: 11px 13px;
    background: #fff;
    font: inherit;
}

.result-count {
    min-width: max-content;
    color: #6d665d;
    font-size: .88rem;
}

.topic-filters {
    overflow: hidden;
}

.topic-filters > summary {
    display: flex;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    font-weight: 700;
}

.filter-summary-text {
    color: var(--tp-blue);
    font-size: .84rem;
}

.format-filter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 18px;
}

.format-filter-list a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--tp-border);
    border-radius: 999px;
    background: #fff;
    color: var(--tp-text);
    font-size: .82rem;
    text-decoration: none;
}

.format-filter-list a.active,
.format-filter-list a:hover {
    border-color: var(--tp-blue);
    background: #eef5fc;
}

.format-filter-list small {
    color: #777;
}

.topic-list {
    display: grid;
    gap: 14px;
}

.topic-row {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    min-height: 175px;
    overflow: hidden;
    border: 1px solid var(--tp-border);
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .06);
}

.topic-row[hidden] {
    display: none;
}

.topic-cover {
    display: grid;
    min-height: 175px;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, #f4ead7, #fffaf0);
    text-decoration: none;
}

.topic-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.topic-row-content {
    display: grid;
    gap: 14px;
    padding: 20px;
}

.topic-row-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.topic-row h2 {
    margin: 0 0 6px;
    color: var(--tp-bronze);
}

.topic-row h2 a {
    color: inherit;
    text-decoration: none;
}

.topic-row p {
    margin: 0;
    color: #5f584e;
    line-height: 1.5;
}

.muted {
    color: #777;
}

.format-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.format-badges span {
    padding: 5px 8px;
    border-radius: 999px;
    background: #f4f0e7;
    color: #514b43;
    font-size: .76rem;
    font-weight: 700;
}

.topic-row-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--tp-border);
    color: #777;
    font-size: .82rem;
}

.topic-open-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 8px 15px;
    border: 1px solid #8c5913;
    border-radius: 999px;
    background: linear-gradient(180deg, #b87921, #956013);
    box-shadow: 0 2px 7px rgba(117, 72, 12, .2);
    color: #fff;
    font-size: .8rem;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition:
        transform .16s ease,
        box-shadow .16s ease,
        background .16s ease;
}

.topic-open-link::before {
    content: "📂";
    font-size: 1rem;
    line-height: 1;
}

.topic-open-link:hover,
.topic-open-link:focus-visible {
    background: linear-gradient(180deg, #c58427, #a56814);
    box-shadow: 0 5px 13px rgba(117, 72, 12, .28);
    color: #fff;
    outline: none;
    transform: translateY(-1px);
}

.topic-open-link:active {
    box-shadow: 0 2px 5px rgba(117, 72, 12, .2);
    transform: translateY(0);
}

.topic-open-link span {
    font-size: .95rem;
    transition: transform .16s ease;
}

.topic-open-link:hover span,
.topic-open-link:focus-visible span {
    transform: translateX(2px);
}

.private-pill {
    display: inline-flex;
    width: max-content;
    padding: 4px 8px;
    border-radius: 999px;
    background: #f5e8e8;
    color: #8a3030;
    font-size: .72rem;
    font-weight: 700;
}

.empty-state {
    padding: 48px;
    border: 1px dashed var(--tp-border);
    border-radius: 15px;
    color: #666;
    text-align: center;
}

.empty-state span {
    font-size: 2.2rem;
}

.topic-breadcrumb {
    display: flex;
    gap: 8px;
    color: #777;
    font-size: .86rem;
}

.topic-breadcrumb a {
    color: var(--tp-blue);
    text-decoration: none;
}

.topic-detail-count {
    display: grid;
    min-width: 110px;
    place-items: center;
    padding: 16px;
    border-radius: 13px;
    background: #fff7e8;
}

.topic-detail-count strong {
    color: var(--tp-bronze);
    font-size: 1.9rem;
}

.topic-detail-count span {
    color: #6d665d;
    font-size: .8rem;
}

.topic-detail-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.topic-detail-sidebar {
    position: sticky;
    top: 20px;
    display: grid;
    gap: 6px;
    padding: 16px;
    border: 1px solid var(--tp-border);
    border-radius: 14px;
    background: #fff;
}

.topic-detail-sidebar > strong {
    margin-bottom: 4px;
    color: var(--tp-bronze);
}

.topic-detail-sidebar a {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
    border-radius: 7px;
    color: var(--tp-text);
    font-size: .82rem;
    text-decoration: none;
}

.topic-detail-sidebar a:hover {
    background: #fff6e5;
}

.topic-detail-sidebar a span {
    margin-left: auto;
    color: #777;
}

.topic-resource-groups {
    display: grid;
    gap: 18px;
}

.resource-group {
    padding: 20px;
    scroll-margin-top: 18px;
}

.resource-group-heading {
    margin-bottom: 12px;
}

.resource-group-heading > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

.resource-group-icon {
    font-size: 1.7rem;
}

.resource-group h2,
.resource-group p {
    margin: 0;
}

.resource-group p {
    color: #777;
    font-size: .82rem;
}

.compact-resource-list {
    display: grid;
}

.compact-resource-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 13px 0;
    border-top: 1px solid var(--tp-border);
}

.compact-resource-icon {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 9px;
    background: #f4f0e7;
    font-size: 1.25rem;
}

.compact-resource-main h3 {
    margin: 0 0 4px;
    color: var(--tp-bronze);
    font-size: 1rem;
}

.compact-resource-main p,
.compact-resource-main small {
    display: block;
    margin: 0;
    color: #6d665d;
    line-height: 1.4;
}

.danger-button {
    background: #9b1c1c;
}

.ungrouped-panel {
    padding: 16px 20px;
}

.ungrouped-panel summary {
    cursor: pointer;
    font-weight: 700;
}

.ungrouped-panel summary span {
    margin-left: 7px;
    color: #777;
}

.topics-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, .65);
}

.topics-modal.hidden,
.topics-toast.hidden {
    display: none;
}

.topics-modal-card {
    position: relative;
    width: min(760px, 96vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: 16px;
    background: #fff;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 999px;
    background: #777;
    color: #fff;
}

.topics-modal form,
.topics-modal label {
    display: grid;
    gap: 8px;
}

.topics-modal form {
    gap: 16px;
}

.topics-modal input,
.topics-modal select,
.topics-modal textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cfc6b6;
    border-radius: 8px;
    padding: 9px 11px;
    font: inherit;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(240px, 1fr));
    gap: 14px;
}

.upload-drop-zone {
    display: grid;
    min-height: 110px;
    place-items: center;
    padding: 18px;
    border: 2px dashed #d4c5a6;
    border-radius: 12px;
    background: #fffaf0;
    color: #71695e;
    text-align: center;
}

.upload-drop-zone.drag-over {
    border-color: var(--tp-blue);
    background: #eef6ff;
}

.modal-actions {
    justify-content: flex-end;
}

.modal-status {
    margin-right: auto;
    font-weight: 700;
}

.modal-status.success {
    color: #246b2a;
}

.modal-status.error {
    color: #9b1c1c;
}

.topics-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 10000;
    padding: 12px 16px;
    border-radius: 7px;
    background: #244d2d;
    color: #fff;
}

.topics-toast.error {
    background: #8d2424;
}

@media (max-width: 800px) {
    .topics-hero,
    .topic-detail-hero,
    .topic-row-heading,
    .topic-row-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .topic-row {
        grid-template-columns: 100px minmax(0, 1fr);
    }

    .topic-cover {
        min-height: 100%;
    }

    .topic-detail-layout {
        grid-template-columns: 1fr;
    }

    .topic-detail-sidebar {
        position: static;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .topic-search-row,
    .compact-resource-row {
        align-items: stretch;
        grid-template-columns: 1fr;
    }

    .topic-search-row {
        flex-direction: column;
    }

    .topic-row {
        grid-template-columns: 1fr;
    }

    .topic-cover {
        min-height: 130px;
    }

    .compact-resource-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

.topic-cover .topic-cover-text {
    color: var(--tp-bronze);
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.topic-footer-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
    margin-left: auto;
}

.topic-visibility-button,
.topic-delete-button {
    min-width: 76px;
    padding: 6px 11px;
    border: 0;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
}

.topic-visibility-button.is-public {
    background: #dff2e3;
    color: #22662b;
    box-shadow: inset 0 0 0 1px #a7d2ae;
}

.topic-visibility-button.is-private {
    background: #ececec;
    color: #555;
    box-shadow: inset 0 0 0 1px #cfcfcf;
}

.topic-visibility-button:hover {
    filter: brightness(.97);
}

.topic-visibility-button:disabled,
.topic-delete-button:disabled {
    cursor: wait;
    opacity: .65;
}

.topic-delete-button {
    background: #a51f1f;
    color: #fff;
}

.topic-delete-button:hover {
    background: #841818;
}

@media (max-width: 800px) {
    .topic-footer-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        margin-left: 0;
    }
}

\n\n/* Topic management and detail-page enhancements */\n.topic-footer-actions,\n.topic-detail-actions,\n.topic-detail-tools,\n.visibility-filter {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    flex-wrap: wrap;\n}\n.topic-footer-actions { justify-content: flex-end; }\n.topic-detail-tools { justify-content: flex-end; }\n.visibility-filter { padding-top: 5px; }\n.visibility-filter > span { margin-right: 3px; font-size: .78rem; font-weight: 700; color: #5f584e; }\n.visibility-filter-button,\n.topic-add-button,\n.topic-visibility-button,\n.topic-delete-button {\n    padding: 6px 11px;\n    border-radius: 999px;\n    font-size: .75rem;\n    font-weight: 700;\n    line-height: 1;\n}\n.visibility-filter-button { border: 1px solid var(--tp-border); background: #fff; color: #5d554b; }\n.visibility-filter-button.active, .visibility-filter-button:hover { border-color: var(--tp-blue); background: #eef5fc; color: var(--tp-blue); }\n.topic-add-button { border: 1px solid #a76814; background: #a76814; color: #fff; }\n.topic-add-button.secondary { border-color: #d2b57d; background: #fff8e9; color: #8c5913; }\n.topic-visibility-button.is-public { border: 1px solid #9bcda7; background: #e3f4e7; color: #246b2a; }\n.topic-visibility-button.is-private { border: 1px solid #c8c8c8; background: #ededed; color: #555; }\n.topic-delete-button { border: 1px solid #9b1c1c; background: #ad1e1e; color: #fff; }\n.topic-detail-sidebar a { grid-template-columns: 28px minmax(0,1fr) auto; }\n.sidebar-format-icon { margin-left: 0 !important; font-size: 1.15rem; text-align: center; }\n.sidebar-format-name { margin-left: 0 !important; min-width: 0; }\n.resource-group-icon, .compact-resource-icon { font-size: 1.35rem; }\n@media (max-width: 900px) {\n    .topic-row-footer { align-items: flex-start; flex-direction: column; }\n    .topic-footer-actions { justify-content: flex-start; }\n    .topic-detail-tools { align-items: flex-end; flex-direction: column; }\n}\n

/* Topic management refinements */
.topic-row-content {
    position: relative;
}

.topic-row-heading {
    position: relative;
    padding-right: 96px;
}

.topic-card-visibility {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 76px;
    justify-content: center;
}

.topic-row-footer {
    align-items: center;
}

.topic-resource-tile {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
}

.topic-resource-summary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #655d52;
}

.topic-resource-summary strong {
    display: block;
    color: var(--tp-bronze);
    font-size: 1rem;
    line-height: 1;
}

.topic-resource-tile-icon {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 10px;
    background: #fff4da;
    font-size: 1.05rem;
}

.topic-resource-add-actions,
.topic-detail-add-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.resource-add-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid #b97518;
    border-radius: 10px;
    background: linear-gradient(180deg, #bd7a1d, #995b0f);
    color: #fff;
    font-size: .76rem;
    font-weight: 800;
    box-shadow: 0 2px 5px rgba(128, 77, 10, .18);
}

.resource-add-button:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.resource-add-button.is-link {
    border-color: #d2b16e;
    background: linear-gradient(180deg, #fffaf0, #f4e4c2);
    color: #80510f;
}

.topic-detail-resource-tile {
    display: grid;
    gap: 10px;
    min-width: 190px;
    padding: 14px;
    border: 1px solid #e3cfaa;
    border-radius: 15px;
    background: linear-gradient(145deg, #fffaf0, #fff3dc);
    box-shadow: 0 3px 10px rgba(117, 78, 20, .08);
}

.topic-detail-resource-tile .topic-detail-count {
    min-width: 0;
    padding: 4px 8px 8px;
    background: transparent;
}

.topic-detail-add-actions {
    justify-content: center;
}

.resource-title-link {
    color: inherit;
    text-decoration: none;
}

.resource-title-link:hover {
    color: var(--tp-blue);
    text-decoration: underline;
}

.compact-resource-row {
    transition: background .15s ease;
}

.compact-resource-row:hover {
    background: #fffaf1;
}

.compact-resource-actions {
    justify-content: flex-end;
}

@media (max-width: 900px) {
    .topic-row-heading {
        padding-right: 0;
    }

    .topic-card-visibility {
        position: static;
        align-self: flex-start;
    }

    .topic-resource-tile,
    .topic-row-footer {
        align-items: flex-start;
    }
}

/* ==========================================================================
   Topics Explorer hero
   ========================================================================== */

.topics-explorer-hero {
    position: relative;
    min-height: 124px;
    overflow: hidden;
    border-color: #302a20;
    background:
        radial-gradient(
            circle at 91% 50%,
            rgba(183, 123, 34, 0.20),
            transparent 24%
        ),
        linear-gradient(
            135deg,
            #171511,
            #29251e
        );
    color: #fff;
    box-shadow: 0 14px 34px rgba(45, 37, 24, 0.15);
}

.topics-explorer-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(
            90deg,
            transparent 0%,
            transparent 63%,
            rgba(255, 255, 255, 0.025) 100%
        );
}

.topics-hero-copy,
.topics-hero-actions,
.topics-hero-icon {
    position: relative;
    z-index: 1;
}

.topics-hero-copy {
    flex: 1 1 640px;
    min-width: 0;
}

.topics-explorer-hero .eyebrow {
    color: #d3952b;
}

.topics-explorer-hero h1 {
    margin: 6px 0 8px;
    color: #fff;
    font-size: clamp(2rem, 4vw, 3.1rem);
    line-height: 1.03;
    letter-spacing: -0.035em;
}

.topics-hero-intro {
    max-width: 720px;
    margin: 0;
    color: #ddd7cc;
    font-size: 1rem;
    line-height: 1.45;
}

.topics-hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.topics-refresh-button {
    min-width: 90px;
    border: 1px solid rgba(255, 255, 255, 0.27);
    border-radius: 8px;
    padding: 9px 14px;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition:
        background 0.15s ease,
        transform 0.15s ease,
        border-color 0.15s ease;
}

.topics-refresh-button:hover {
    border-color: rgba(255, 255, 255, 0.46);
    background: rgba(255, 255, 255, 0.17);
    transform: translateY(-1px);
}

.topics-hero-icon {
    display: grid;
    flex: 0 0 112px;
    min-height: 92px;
    place-items: center;
    opacity: 0.22;
    font-size: clamp(3.5rem, 7vw, 6rem);
    line-height: 1;
    filter: saturate(0.8);
    pointer-events: none;
}

@media (max-width: 820px) {
    .topics-explorer-hero {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .topics-hero-actions {
        order: 3;
        width: 100%;
        justify-content: flex-start;
    }

    .topics-hero-icon {
        position: absolute;
        top: 18px;
        right: 18px;
        opacity: 0.12;
    }
}

@media (max-width: 560px) {
    .topics-explorer-hero {
        padding: 22px;
    }

    .topics-explorer-hero h1 {
        padding-right: 48px;
    }

    .topics-hero-intro {
        font-size: 0.92rem;
    }

    .topics-hero-icon {
        font-size: 3rem;
    }
}


/* Manual topic creation */
.topic-search-row {
    align-items: center;
}

.topic-create-button {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 9px 16px;
    border: 1px solid #9a6217;
    border-radius: 999px;
    background: linear-gradient(
        180deg,
        #c88a2d,
        #a96812
    );
    color: #fff;
    font: inherit;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(123, 75, 11, .2);
}

.topic-create-button:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.topic-create-modal-card {
    width: min(580px, 96vw);
}

.topic-create-modal-card h2 {
    margin: 0 0 6px;
    color: var(--tp-bronze);
}

.topic-create-modal-card .eyebrow {
    margin-bottom: 6px;
}

@media (max-width: 700px) {
    .topic-search-row {
        align-items: stretch;
        flex-direction: column;
    }

    .topic-create-button {
        width: 100%;
    }
}
