/* ═══════════════════════════════════════════════════════════════════════════════
   Reading Plans — Styles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Plan Grid ────────────────────────────────────────────────────────────────── */
.plans-section {
    margin-bottom: 2rem;
}

.plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ── Plan Card (listing page) ─────────────────────────────────────────────────── */
.plan-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    cursor: pointer;
    display: block;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    border: none;
    background: var(--color-surface-alt);
    outline: 2px solid transparent;
    outline-offset: 3px;
}

.plan-card:hover,
.plan-card:focus-visible {
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
    outline-color: var(--color-primary);
}

.plan-card:focus-visible {
    outline-style: solid;
}

.plan-card__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.plan-card:hover .plan-card__img,
.plan-card:focus-visible .plan-card__img {
    transform: scale(1.05);
}

.plan-card__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,0.05) 0%,
        rgba(0,0,0,0.20) 40%,
        rgba(0,0,0,0.75) 100%
    );
}

.plan-card__content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.plan-card__title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: #fff;
    margin: 0;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.plan-card__desc {
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.85);
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.plan-card__meta {
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.8);
    margin: 0;
}

.plan-card__badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 99px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    margin-top: 4px;
    align-self: flex-start;
    backdrop-filter: blur(4px);
}

/* ── Progress Bar ─────────────────────────────────────────────────────────────── */
.plan-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.plan-progress__track {
    position: relative;
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 99px;
    overflow: visible;
}

.plan-progress__track--lg {
    height: 8px;
    background: var(--color-border);
}

.plan-progress__fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 99px;
    background: var(--color-primary);
    transition: width 0.4s ease;
    min-width: 2px;
}

.plan-progress__fill--complete {
    background: var(--color-success);
}

.plan-progress__marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 14px;
    background: rgba(255,255,255,0.7);
    border-radius: 2px;
    z-index: 1;
    pointer-events: none;
}

.plan-progress__track--lg .plan-progress__marker {
    height: 18px;
    width: 3px;
    background: var(--color-text-3);
}

.plan-progress__label {
    font-size: 0.65rem;
    font-weight: 700;
    color: rgba(255,255,255,0.8);
    min-width: 32px;
    text-align: right;
}

/* ── Plan Detail Page ─────────────────────────────────────────────────────────── */

/* Make the plan main element the scroll container (like .content-feed) */
.plan-detail-page {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100vh;
    scroll-behavior: smooth;
}

/* ── Plan Header (3-column grid, mirrors feed-header) ─────────────────────── */
.plan-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background-color: var(--color-glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* When no location bar follows, the header itself needs a bottom border */
.plan-header:last-child,
.plan-header + .plan-verses {
    border-bottom: 1px solid var(--color-border);
}
/* The + combinator doesn't work for "no location bar between"; use a class instead */
.plan-header--no-location {
    border-bottom: 1px solid var(--color-border);
}

.plan-header__left {
    grid-column: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.plan-header__title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plan-header__right {
    grid-column: 3;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.plan-detail__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--color-text-2);
    transition: background var(--transition);
    flex-shrink: 0;
    text-decoration: none;
}

.plan-detail__back:hover {
    background: var(--color-surface-alt);
}

/* ── Day Navigator (center column of plan-header) ─────────────────────────── */
.plan-day-nav {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.plan-day-nav__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    color: var(--color-text-2);
    text-decoration: none;
    transition: background-color var(--transition), color var(--transition);
    flex-shrink: 0;
    border: 1px solid transparent;
}

.plan-day-nav__arrow:hover {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary-light);
}

.plan-day-nav__arrow--disabled {
    visibility: hidden;
}

.plan-day-nav__center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    min-width: 100px;
}

.plan-day-nav__label {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: border-color var(--transition), background-color var(--transition);
    line-height: 1.3;
}

.plan-day-nav__day {
    font-size: var(--text-sm);
    font-weight: 700;
}

.plan-day-nav__date {
    font-size: 11px;
    font-weight: 400;
    color: var(--color-text-3);
}

.plan-day-nav__label:hover {
    border-color: var(--color-border-strong);
    background-color: var(--color-surface);
}

/* ── Progress Location Bar (mirrors feed-location) ────────────────────────── */
.plan-location {
    position: sticky;
    top: 57px;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 16px;
    background-color: var(--color-glass-bg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--color-text-2);
    letter-spacing: 0.02em;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.plan-location.is-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.plan-location__text {
    white-space: nowrap;
}

.plan-location__track {
    position: relative;
    flex: 1;
    height: 6px;
    background: var(--color-border);
    border-radius: 99px;
    overflow: visible;
}

.plan-location__track .plan-progress__fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 99px;
    background: var(--color-primary);
    transition: width 0.4s ease;
    min-width: 2px;
}

.plan-location__track .plan-progress__fill--complete {
    background: var(--color-success);
}

.plan-location__track .plan-progress__marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 12px;
    background: var(--color-text-3);
    border-radius: 2px;
    z-index: 1;
    pointer-events: none;
}

.plan-location__pct {
    white-space: nowrap;
}

/* ── Verse Cards Feed Area ────────────────────────────────────────────────── */
.plan-verses {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    padding-bottom: calc(var(--bottom-nav-height, 64px) + 40px);
}

/* Verse cards inside plans are server-rendered — skip JS entrance animation */
.plan-verses .verse-card {
    opacity: 1;
    transform: none;
}

.plan-range-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.plan-range-section__title {
    font-size: var(--text-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-3);
    margin: 0;
    padding: 8px 0 0;
    border-top: 1px solid var(--color-border);
}

.plan-range-section:first-child .plan-range-section__title {
    border-top: none;
    padding-top: 0;
}

.plan-range-section__empty {
    font-size: var(--text-sm);
    color: var(--color-text-3);
    font-style: italic;
    padding: 12px 0;
}

/* ── Complete Day Button ──────────────────────────────────────────────────────── */
.plan-day__action {
    margin-top: 8px;
    margin-bottom: 40px;
}

.btn--block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn--success {
    background: var(--color-success);
    color: #fff;
    border: none;
}

.btn--success:hover {
    background: #15803d;
}

.btn--outline {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
}

.btn--outline:hover {
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

/* ── Empty state ──────────────────────────────────────────────────────────────── */
.plan-day__empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-3);
}

/* ── Leap Year Rest Day ──────────────────────────────────────────────────────── */
.plan-rest-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    padding: 3rem 1.5rem;
}

.plan-rest-day__icon {
    color: var(--color-primary);
    opacity: 0.6;
    margin-bottom: 4px;
}

.plan-rest-day__title {
    font-size: var(--text-xl, 1.25rem);
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.plan-rest-day__text {
    font-size: var(--text-sm);
    color: var(--color-text-3);
    max-width: 400px;
    line-height: 1.6;
    margin: 0;
}

/* ── Plan-page notes editor (inside study-tools Reflect panel) ───────────── */
.plan-note-editor {
    width: 100%;
    min-height: 80px;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    color: var(--color-text);
    background: var(--color-surface);
    resize: vertical;
    margin-bottom: 8px;
}

.plan-note-save {
    margin-right: 8px;
}

.plan-note-status {
    font-size: var(--text-xs);
    color: var(--color-text-3);
}

/* ── Day Picker Dialog ───────────────────────────────────────────────────────── */
.plan-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: plan-fade-in 0.15s ease;
}

@keyframes plan-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.plan-dialog-backdrop[hidden] {
    display: none;
}

.plan-dialog {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 360px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: plan-dialog-in 0.2s ease;
}

@keyframes plan-dialog-in {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.plan-dialog__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--color-border);
}

.plan-dialog__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.plan-dialog__close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-3);
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
}

.plan-dialog__close:hover {
    color: var(--color-text);
}

.plan-dialog__body {
    overflow-y: auto;
    padding: 0 12px 8px;
    max-height: 60vh;
}

.plan-dialog__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
}

/* Day picker month groups */
.plan-month-group {
    margin-bottom: 8px;
}

.plan-month-group__title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text-2);
    padding: 12px 8px 6px;
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 2;
    border-bottom: 1px solid var(--color-border);
}

.plan-day-list {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    padding: 0 4px 4px;
    position: relative;
    z-index: 1;
}

.plan-day-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text);
    transition: background-color var(--transition), border-color var(--transition);
    min-height: 40px;
}

.plan-day-btn:hover {
    background: var(--color-surface-alt);
    border-color: var(--color-border);
}

.plan-day-btn--active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.plan-day-btn--active:hover {
    background: var(--color-primary);
}

.plan-day-btn--complete {
    color: var(--color-success);
}

.plan-day-btn--today {
    border: 2px solid var(--color-primary);
}

.plan-day-btn--today:not(.plan-day-btn--active)::after {
    content: 'Today';
    display: block;
    font-size: 0.5rem;
    font-weight: 600;
    color: var(--color-primary);
    line-height: 1;
    margin-top: 1px;
}

.plan-day-btn__num {
    font-size: var(--text-sm);
    font-weight: 700;
    line-height: 1;
}

.plan-day-btn__date {
    font-size: 0.6rem;
    font-weight: 400;
    color: var(--color-text-3);
    line-height: 1;
    margin-top: 1px;
}

.plan-day-btn--active .plan-day-btn__date {
    color: rgba(255,255,255,0.7);
}

/* Catch-up dialog */
.plan-catchup-text {
    font-size: var(--text-sm);
    color: var(--color-text-2);
    line-height: 1.6;
    padding: 8px 0;
    margin: 0;
}

/* ── Today's Reading — Featured Panel Section ──────────────────────────────── */
.plan-today-summary__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.plan-today-summary__list li {
    font-size: var(--text-sm);
    color: var(--color-text-2);
    padding: 6px 10px;
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
}

.plan-today-summary__rest {
    font-size: var(--text-sm);
    color: var(--color-text-3);
    font-style: italic;
}

/* ── Responsive ───────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .plan-grid {
        grid-template-columns: 1fr;
    }

    .plan-card {
        aspect-ratio: 2 / 1;
    }

    /* Mirror feed-header mobile: hide left title + right button, single-column */
    .plan-header__title {
        display: none;
    }

    .plan-header__right {
        display: none;
    }

    .plan-header {
        grid-template-columns: auto 1fr auto;
        padding: 8px 12px;
    }

    .plan-header__left {
        grid-column: 1;
        justify-self: start;
    }

    .plan-day-nav {
        grid-column: 2;
        justify-self: center;
    }

    /* Invisible spacer to balance the back button so nav is truly centered */
    .plan-header::after {
        content: '';
        grid-column: 3;
        width: 32px; /* same as back button */
    }

    .plan-verses {
        padding: 16px 12px calc(var(--bottom-nav-height, 64px) + 24px);
    }

    .plan-location {
        gap: 8px;
        padding: 5px 12px;
        font-size: var(--text-xs);
    }
}

/* ── Plan Card TOC Button ─────────────────────────────────────────────────────── */
.plan-card__toc-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: rgba(0,0,0,0.45);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    opacity: 0;
    transition: opacity .2s ease, background .15s ease;
    backdrop-filter: blur(4px);
}
.plan-card:hover .plan-card__toc-btn,
.plan-card:focus-within .plan-card__toc-btn {
    opacity: 1;
}
.plan-card__toc-btn:hover {
    background: rgba(0,0,0,0.7);
    color: #fff;
}

/* ── TOC Modal ────────────────────────────────────────────────────────────────── */
.plan-toc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px);
    animation: planTocFadeIn .15s ease;
}
@keyframes planTocFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.plan-toc-dialog {
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg, 0 12px 40px rgba(0,0,0,.2));
    overflow: hidden;
    animation: planTocSlideUp .2s ease;
}
@keyframes planTocSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.plan-toc-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    gap: 12px;
}

.plan-toc-dialog__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--color-text-1);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.plan-toc-dialog__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--color-text-3);
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .12s, color .12s;
}
.plan-toc-dialog__close:hover {
    background: var(--color-surface-alt);
    color: var(--color-text-1);
}

.plan-toc-dialog__body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    overscroll-behavior: contain;
}

.plan-toc-dialog__loading,
.plan-toc-dialog__error {
    text-align: center;
    padding: 32px 20px;
    color: var(--color-text-3);
    font-size: var(--text-sm);
}

/* ── TOC List ─────────────────────────────────────────────────────────────────── */
.plan-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: none;
}

.plan-toc-list__item {
    border-bottom: 1px solid var(--color-border);
}
.plan-toc-list__item:last-child {
    border-bottom: none;
}

.plan-toc-list__link {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 10px 20px;
    text-decoration: none;
    color: var(--color-text-1);
    transition: background .12s ease;
}
.plan-toc-list__link:hover {
    background: var(--color-surface-alt);
}

.plan-toc-list__day {
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--color-primary);
    min-width: 50px;
    flex-shrink: 0;
}

.plan-toc-list__detail {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-width: 0;
}

.plan-toc-list__title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text-2);
}

.plan-toc-list__reading {
    font-size: var(--text-xs);
    color: var(--color-text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Mobile tweaks for TOC ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .plan-card__toc-btn {
        opacity: 1;
    }
    .plan-toc-dialog {
        width: 95%;
        max-height: 85vh;
        border-radius: 14px 14px 0 0;
    }
    .plan-toc-backdrop {
        align-items: flex-end;
    }
}
