/* Mapa ramificado de capítulos — Livro Vivo */
.story-map {
    margin: 0 0 2rem;
    border: 1px solid #dfe6ee;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
    overflow: hidden;
}

.story-map-summary {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    padding: 14px 18px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.story-map-summary::-webkit-details-marker { display: none; }
.story-map-summary::marker { display: none; content: ""; }

.story-map-summary:hover { background: #f8fafc; }
.story-map-summary:focus-visible { outline: 3px solid rgba(44, 82, 130, .25); outline-offset: -3px; }

.story-map-summary-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    color: #2c5282;
    background: #edf4fb;
    font-size: 1.15rem;
    font-weight: 700;
}

.story-map-summary-copy { min-width: 0; display: grid; gap: 2px; }
.story-map-summary-copy strong { color: #172033; font-size: 1.05rem; font-weight: 650; }
.story-map-summary-copy small { color: #6b7280; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.story-map-summary-stats { display: grid; justify-items: end; gap: 5px; color: #64748b; font-size: .78rem; }
.story-map-progress { display: block; width: 92px; height: 5px; overflow: hidden; border-radius: 999px; background: #e8edf3; }
.story-map-progress i { display: block; height: 100%; border-radius: inherit; background: #2f8533; }

.story-map-summary-chevron { color: #64748b; font-size: 1.3rem; transition: transform .2s ease; }
.story-map[open] .story-map-summary-chevron { transform: rotate(180deg); }

.story-map-body { border-top: 1px solid #e8edf3; background: #f8fafc; padding: 16px 18px 20px; }
.story-map-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.story-map-search { flex: 1 1 280px; max-width: 420px; }
.story-map-search input {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    border: 1px solid #d7dee8;
    border-radius: 999px;
    background: #fff;
    color: #172033;
    font: inherit;
    font-size: .9rem;
}
.story-map-search input:focus { outline: none; border-color: #2c5282; box-shadow: 0 0 0 3px rgba(44, 82, 130, .12); }

.story-map-actions { display: flex; align-items: center; gap: 8px; }
.story-map-actions button {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #d7dee8;
    border-radius: 999px;
    background: #fff;
    color: #475569;
    cursor: pointer;
    font: inherit;
    font-size: .78rem;
    font-weight: 600;
}
.story-map-actions button:hover { border-color: #aeb9c8; color: #172033; }

.story-map-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 14px; color: #64748b; font-size: .76rem; }
.story-map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.story-map-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-current { background: #2c5282; }
.legend-read { background: #2f8533; }
.legend-unread { background: #94a3b8; }
.legend-root { background: #8b5cf6; }
.legend-branch { background: #3182ce; }

.story-tree-viewport {
    max-height: min(62vh, 680px);
    overflow: auto;
    padding: 4px 10px 6px 2px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.story-tree-list { list-style: none; margin: 0; padding: 0; }
.story-tree-children {
    position: relative;
    margin-left: 20px;
    padding-left: 28px;
    border-left: 1px solid #cbd5e1;
}

.story-tree-node { position: relative; margin: 8px 0; }
.story-tree-children > .story-tree-node::before {
    content: "";
    position: absolute;
    left: -28px;
    top: 25px;
    width: 22px;
    border-top: 1px solid #cbd5e1;
}
.story-tree-children > .story-tree-node:last-child::after {
    content: "";
    position: absolute;
    left: -29px;
    top: 26px;
    bottom: -10px;
    width: 3px;
    background: #f8fafc;
}

.story-tree-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 6px; }
.story-tree-toggle,
.story-tree-toggle-spacer { width: 28px; height: 28px; }
.story-tree-toggle {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d7dee8;
    border-radius: 50%;
    background: #fff;
    color: #475569;
    cursor: pointer;
}
.story-tree-toggle span { font-size: 1.2rem; line-height: 1; transform: rotate(90deg); transition: transform .2s ease; }
.story-tree-node.is-collapsed > .story-tree-row .story-tree-toggle span { transform: rotate(0deg); }
.story-tree-node.is-collapsed > .story-tree-children { display: none; }

.story-tree-card {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    min-height: 54px;
    padding: 9px 12px;
    border: 1px solid #dfe6ee;
    border-radius: 12px;
    background: #fff;
    color: inherit;
    text-decoration: none;
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.story-tree-card:hover { transform: translateX(3px); border-color: #aeb9c8; box-shadow: 0 7px 18px rgba(15, 23, 42, .07); }
.story-tree-card:focus-visible { outline: 3px solid rgba(44, 82, 130, .22); outline-offset: 2px; }

.story-tree-dot { width: 11px; height: 11px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 4px #f1f5f9; }
.story-tree-copy { min-width: 0; display: grid; gap: 3px; }
.story-tree-title { color: #172033; font-size: .93rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-tree-synopsis {
    color: #5f6c7b;
    font-size: .76rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.story-tree-author { color: #7b8797; font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-tree-meta { display: grid; justify-items: end; gap: 3px; }
.story-tree-status { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 999px; background: #eef2f6; color: #64748b; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.story-tree-count { color: #8a96a6; font-size: .66rem; white-space: nowrap; }

.story-tree-node.is-current > .story-tree-row .story-tree-card { border-color: #2c5282; background: #eef4fb; box-shadow: 0 0 0 2px rgba(44, 82, 130, .10); }
.story-tree-node.is-current > .story-tree-row .story-tree-dot { background: #2c5282; box-shadow: 0 0 0 4px #dce9f6; }
.story-tree-node.is-current > .story-tree-row .story-tree-status { background: #2c5282; color: #fff; }

.story-tree-node.is-read > .story-tree-row .story-tree-card { border-color: #cfe4d1; }
.story-tree-node.is-read > .story-tree-row .story-tree-dot { background: #2f8533; box-shadow: 0 0 0 4px #e1f2e2; }
.story-tree-node.is-read > .story-tree-row .story-tree-status { background: #e5f5e6; color: #246928; }

.story-tree-node.is-root > .story-tree-row .story-tree-dot { background: #8b5cf6; box-shadow: 0 0 0 4px #ede9fe; }
.story-tree-node.is-root > .story-tree-row .story-tree-status { background: #ede9fe; color: #6d28d9; }
.story-tree-node.is-branch > .story-tree-row .story-tree-dot { background: #3182ce; box-shadow: 0 0 0 4px #e0efff; }
.story-tree-node.is-branch > .story-tree-row .story-tree-status { background: #e8f2fc; color: #245e97; }

.story-tree-empty,
.story-tree-no-results { margin: 18px 0; text-align: center; color: #64748b; font-size: .9rem; }

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

@media (max-width: 700px) {
    .story-map-summary { grid-template-columns: auto minmax(0, 1fr) auto; padding: 12px 14px; }
    .story-map-summary-stats { display: none; }
    .story-map-summary-copy small { white-space: normal; line-height: 1.25; }
    .story-map-body { padding: 14px 12px 16px; }
    .story-map-toolbar { align-items: stretch; flex-direction: column; }
    .story-map-search { max-width: none; flex-basis: auto; }
    .story-map-actions { width: 100%; }
    .story-map-actions button { flex: 1 1 0; }
    .story-tree-viewport { max-height: 66vh; padding-right: 2px; }
    .story-tree-children { margin-left: 8px; padding-left: 20px; }
    .story-tree-children > .story-tree-node::before { left: -20px; width: 16px; }
    .story-tree-children > .story-tree-node:last-child::after { left: -21px; }
    .story-tree-card { grid-template-columns: auto minmax(0, 1fr); }
    .story-tree-meta { grid-column: 2; justify-items: start; display: flex; flex-wrap: wrap; align-items: center; }
    .story-tree-title { white-space: normal; line-height: 1.25; }
    .story-tree-synopsis { -webkit-line-clamp: 3; }
}
