/* ─── Parallel Reader ───
   Module-specific styling.
   Layout utilities provided by IBIS CSS framework (flex, gap, spacing, etc.).
   This file contains only what's truly module-specific. */

/* ─── Reader Container ─── */
.torah-reader {
    width: 100vw;
    margin-left: calc(50% - 50vw);
}

.torah-reader .hero-banner {
    display: block;
    margin: var(--sp-4) auto var(--sp-6);
    max-width: min(1152px, 92vw);
    height: auto;
}

/* ─── Controls: compact select overrides ─── */
.tr-passage select,
.tr-versions select {
    padding: var(--sp-1) var(--sp-2);
    font-size: var(--fs-300);
}
.tr-passage select[name="bv"] {
    min-width: 120px;
}
.tr-passage select[name="book"] {
    min-width: 100px;
    max-width: 160px;
}
.tr-passage select[name="chapter"] {
    min-width: 80px;
    max-width: 80px;
}
.tr-passage select[name="verse_from"],
.tr-passage select[name="verse_to"] {
    min-width: 95px;
    max-width: 100px;
}
.tr-versions select {
    min-width: 110px;
    max-width: 130px;
}

/* ─── Disabled controls ─── */
select:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* ─── Buttons (compact overrides for control-bar context) ─── */
.tr-controls .button {
    margin: 0;
    padding: var(--sp-1) var(--sp-4);
    font-weight: var(--fw-semibold);
}
.tr-controls .button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}
.tr-reload-btn {
    font-size: var(--fs-500);
    line-height: 1;
    padding-top: var(--sp-1);
    padding-bottom: var(--sp-1);
}

/* ─── Mode Toggle (segmented button group) ─── */
.mode-btn {
    padding: var(--sp-2) var(--sp-4);
    border: 1px solid var(--border-default);
    background: var(--surface-page);
    cursor: pointer;
    font-size: var(--fs-300);
    border-radius: 0;
    margin: 0;
}
.mode-btn:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}
.mode-btn:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}
.mode-btn.active {
    background: var(--brand);
    color: var(--brand-contrast);
    border-color: var(--brand);
}
.mode-btn-table {
    display: inline-block;
}
.mode-btn-stack {
    display: none;
}
@media (max-width: 479px) {
    .mode-btn-table {
        display: none;
    }
    .mode-btn-stack {
        display: inline-block;
    }
}

/* ─── Verse colours toggle button ─── */
.mode-btn.verse-highlight-toggle-btn {
    background: #fff3a3;
    color: #1f2937;
    border-color: #fff3a3;
}

/* Keep the bookmark form aligned with the mode buttons in the toggle row.
   Override the global `form { width: 100% }` so the form shrink-wraps its
   content instead of filling the row (which breaks justify-content: center). */
.mode-toggle .bookmark-action {
    align-items: center;
    display: flex;
    margin: 0;
    width: auto;
}

/* ─── Reader Area ─── */
.reader-area {
    padding: 0 60px;
}

/* ─── Scroll Buttons (fixed at 50vh) ─── */
.torah-scroll-btn {
    position: fixed;
    top: 50vh;
    transform: translateY(-50%);
    z-index: 100;
    width: 54px;
    height: 54px;
    border: none;
    background: none;
    box-shadow: none;
    color: var(--brand);
    font-size: 3.5rem;
    line-height: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.2s;
    padding: 0;
}
.torah-scroll-btn:hover {
    background-color: transparent;
    box-shadow: none;
    opacity: 1;
}
.torah-scroll-left {
    left: 0;
}
.torah-scroll-right {
    right: 0;
}
@media (max-width: 768px) {
    .torah-scroll-btn {
        display: none;
    }
}
@media (min-width: 1500px) {
    .torah-scroll-left {
        left: 0;
    }
    .torah-scroll-right {
        right: 0;
    }
    .torah-reader {
        width: 100vw;
        margin-left: calc(50% - 50vw);
    }
}

/* ─── Scroll Wrap ─── */
.torah-scroll-wrap {
    overflow-y: visible;
    scroll-behavior: smooth;
    border: 1px solid var(--border-default);
    border-radius: var(--radius);
}

/* ─── Columns ─── */
.torah-col {
    width: 450px;
    min-width: 450px;
    max-width: 450px;
    flex: 0 0 auto;
    background: var(--surface-page);
    border: 1px solid var(--border-default);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}
.torah-col.reference {
    border-color: var(--brand);
    border-width: 2px;
}
.torah-col-header {
    padding: var(--sp-3) var(--sp-4);
    font-weight: var(--fw-bold);
    font-size: var(--fs-300);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

/* ─── Drag Handle ─── */
.drag-handle {
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    opacity: 0.35;
    font-size: var(--fs-400);
    line-height: 1;
    transition: opacity 0.15s;
    touch-action: none;
}
.drag-handle:hover {
    opacity: 0.8;
}
.drag-handle:active {
    cursor: grabbing;
}

/* ─── Drag states ─── */
.torah-col.dragging,
.torah-table th.dragging {
    opacity: 0.35;
}
.torah-col.drag-over {
    border-color: var(--brand);
    border-style: dashed;
    border-width: 2px;
}
.torah-table th.drag-over {
    outline: 2px dashed var(--brand);
    outline-offset: -2px;
}

/* ─── Column Text ─── */
.torah-col .chapter-text {
    flex: 1;
    margin: 0;
    padding: 0 var(--sp-3) var(--sp-3);
    font-size: var(--fs-300);
    line-height: 1.7;
    text-align: justify;
}

/* Verse-by-verse mode: hanging indent pulls verse number left */
.chapter-text.mode-verse {
    text-indent: -1rem;
}
.mode-verse .verse-num {
    margin-right: 0;
}

/* ─── Table View ─── */
.torah-table-container {
    margin: var(--sp-6) 0;
}
/* When inside reader-area's flex layout (table mode) */
.reader-area .torah-table-container {
    flex: 1;
    margin: 0;
}
.torah-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}
.torah-table th,
.torah-table td {
    min-width: 450px;
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border-default);
    vertical-align: top;
    text-align: left;
    font-size: var(--fs-300);
}
.torah-table th {
    background: #1a1a2e url("../images/moroccan-flower-dark.png");
    color: #fff;
    font-weight: var(--fw-bold);
    position: sticky;
    top: 0;
    z-index: 1;
}
.torah-table .verse-num {
    font-weight: var(--fw-bold);
    color: var(--brand);
    margin-right: 0.4rem;
}

/* ─── Stacked View (mobile verse-by-verse) ─── */
.stacked-view {
    border: 1px solid var(--border-subtle);
    margin: 0.75em;
    padding: 0 0.75em;
    border-radius: 0.5em;
}
.sv-group {
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border-subtle);
}
.sv-group:last-child {
    border-bottom: none;
}
.sv-verse-header {
    color: var(--brand);
}
.sv-line {
    display: flex;
    gap: var(--sp-2);
    padding: 0.4rem 0;
    line-height: 1.6;
}
.sv-line + .sv-line {
    border-top: 1px solid var(--border-default);
    padding-top: 0.7rem;
    margin-top: 0.15rem;
}
.sv-version-label {
    flex: 0 0 6rem;
    font-size: var(--fs-200);
    font-weight: var(--fw-semibold);
    color: var(--content-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.sv-text {
    flex: 1;
    font-size: var(--fs-300);
}

/* ─── Responsive ─── */

/* Tablet: passage on row 1, versions + buttons on row 2 */
@media (max-width: 1024px) {
    div.tr-passage {
        flex: 1 1 100%;
    }
}

/* Tablet and larger: pull the hero banner up */
@media (min-width: 768px) {
    .torah-reader .hero-banner {
        margin-top: -50px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .torah-reader .hero-banner {
        margin-top: var(--sp-8);
    }
    .reader-area {
        padding: 0 10px;
    }
    .torah-col {
        min-width: 100%;
        max-width: 100%;
        width: 100%;
        flex: none;
    }
    .torah-col.reference {
        position: static;
    }
    .torah-scroll-inner {
        flex-direction: column;
        gap: var(--sp-3);
        padding: 0;
    }
    div.tr-passage,
    div.tr-versions,
    div.tr-btns {
        flex: 1 1 100%;
    }
    .tr-passage {
        flex-wrap: wrap;
    }
    .tr-passage select,
    .tr-versions select {
        min-width: 0;
        max-width: 100%;
    }
    .tr-versions {
        flex-wrap: wrap;
    }
    .tr-controls {
        margin: 0 10px;
        width: calc(100% - 20px);
    }
}

/* Verse highlighting toolbar (mirrors /books/show compact toolbar) */
.verse-highlight-toolbar {
    align-items: center;
    background: var(--surface-raised, #ffffff);
    border: 1px solid var(--border-default, #dbe3ef);
    border-radius: var(--radius, 0.75rem);
    display: flex;
    flex-wrap: nowrap;
    gap: var(--sp-2, 0.5rem);
    margin: var(--sp-3, 0.75rem) auto var(--sp-4, 1rem);
    max-width: min(1180px, calc(100vw - 1rem));
    overflow-x: auto;
    padding: var(--sp-2, 0.5rem);
    white-space: nowrap;
    width: fit-content;
}
.verse-highlight-toolbar__main,
.verse-highlight-palette,
.verse-highlight-custom {
    align-items: center;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: var(--sp-2, 0.5rem);
    margin: 0;
    width: auto;
}
.verse-highlight-toolbar__main span,
.verse-highlight-toolbar p {
    color: var(--content-muted, #64748b);
    font-size: var(--fs-300, 0.9rem);
    margin: 0;
}
.verse-highlight-swatch,
.verse-highlight-remove,
.verse-highlight-custom button {
    border: 1px solid var(--border-default, #dbe3ef);
    border-radius: 999px;
    cursor: pointer;
    flex: 0 0 auto;
    font-size: var(--fs-200, 0.8rem);
    font-weight: var(--fw-semibold, 700);
    margin: 0;
}
.verse-highlight-swatch {
    background: var(--swatch-bg, #fff3a3);
    color: transparent;
    height: 1.55rem;
    padding: 0;
    width: 1.55rem;
}
.verse-highlight-remove,
.verse-highlight-custom button {
    padding: 0.3rem 0.6rem;
}
.verse-highlight-custom button {
    height: 1.75rem;
    line-height: 1;
    padding: 0 0.6rem;
    width: max-content;
}
.verse-highlight-remove {
    background: #ffffff;
    color: #991b1b;
    height: 1.7rem;
    line-height: 1;
    padding: 0;
    width: 1.7rem;
}
.verse-highlight-swatch.is-selected,
.verse-highlight-remove.is-selected {
    outline: 3px solid var(--brand, #0f3460);
    outline-offset: 2px;
}
.verse-highlight-custom label {
    align-items: center;
    display: flex;
    flex: 0 0 auto;
    font-size: var(--fs-200, 0.8rem);
    gap: 0.35rem;
    height: 1.75rem;
    line-height: 1;
    margin: 0;
    width: auto;
}
.verse-highlight-custom input[type="color"] {
    flex: 0 0 2.1rem;
    height: 1.75rem;
    min-width: 2.1rem;
    padding: 0.1rem;
    width: 2.1rem !important;
}
.verse-highlight-status {
    color: var(--content-muted, #64748b);
    flex: 0 0 auto;
    font-size: var(--fs-200, 0.8rem);
    margin: 0;
}
.verse-highlight-status.is-error {
    color: #991b1b;
}
.verse-line[data-highlight-ref],
.sv-line[data-highlight-ref],
.torah-table-verse[data-highlight-ref] {
    cursor: pointer;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.verse-line[data-highlight-ref]:hover,
.sv-line[data-highlight-ref]:hover,
.torah-table-verse[data-highlight-ref]:hover {
    box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.14);
}
.verse-line.is-verse-highlighted,
.sv-line.is-verse-highlighted,
.torah-table-verse.is-verse-highlighted {
    background: var(--verse-highlight-bg, #fff3a3);
    color: var(--verse-highlight-text, #1f2937);
    border-radius: 0.35rem;
}
.verse-line.is-verse-highlighted {
    padding: 0.15rem 0.35rem;
}
.sv-line.is-verse-highlighted {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
}
@media (max-width: 640px) {
    .verse-highlight-toolbar {
        margin-left: 0;
        margin-right: 0;
    }
}

/* ── Phase 4: study-mode dock (⅔ content + ⅓ notes) ── */
.study-dock {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    align-items: start;
}
.study-dock__content {
    min-width: 0;
}
.study-dock__notes {
    position: sticky;
    top: 3.5rem;
    max-height: calc(100vh - 4.5rem);
    overflow-y: auto;
}
.study-dock__notes-inner {
    background: #f8fafc;
    border: 1px solid #dbeafe;
    border-radius: 0.85rem;
    padding: 1rem;
}
.study-dock__notes-inner h2 {
    font-size: 1.1rem;
    margin: 0 0 0.25rem;
}
.study-dock__passage {
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
}
.study-dock-note-form {
    display: grid;
    gap: 0.85rem;
}
.study-dock-note-form label {
    color: #334155;
    display: grid;
    font-size: 0.9rem;
    font-weight: 900;
    gap: 0.35rem;
}
.study-dock-note-form input,
.study-dock-note-form textarea {
    border: 1px solid #cbd5e1;
    border-radius: 0.65rem;
    color: #0f172a;
    font: inherit;
    font-weight: 500;
    padding: 0.65rem 0.75rem;
}
.study-dock-note-status-row {
    align-items: center;
    display: flex;
    gap: 0.6rem;
    justify-content: space-between;
}
.study-dock-notes-list {
    border-top: 1px solid #e2e8f0;
    margin-top: 1rem;
    padding-top: 0.75rem;
}
.study-dock-notes-list h3 {
    font-size: 0.9rem;
    margin: 0 0 0.5rem;
}
.study-dock-notes-list__item {
    border: 1px solid #e2e8f0;
    border-radius: 0.6rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.6rem;
}
.study-dock-notes-list__item a {
    color: #1e3a8a;
    font-weight: 700;
    text-decoration: none;
}
.study-dock-notes-list__ref {
    color: #64748b;
    display: block;
    font-size: 0.8rem;
}
.study-dock-toggle {
    margin-bottom: 0.75rem;
    text-align: right;
}
.study-dock-toggle .button-small.is-active {
    background: #1e3a8a;
    border-color: #1e3a8a;
    color: #fff;
}
@media (max-width: 900px) {
    .study-dock {
        grid-template-columns: 1fr;
    }
    .study-dock__notes {
        position: static;
        max-height: none;
    }
}
