/* =============================================================================
   VerseFlow — Saved Verses Drawer  (TICKET-921)
   ============================================================================= */

:root {
    --vf-saved-backdrop-bg: rgba(0, 0, 0, 0.45);
    --vf-saved-shell-bg: rgba(255, 255, 255, 0.94);
    --vf-saved-shell-border: rgba(17, 17, 17, 0.12);
    --vf-saved-shell-shadow: -8px 0 40px rgba(0, 0, 0, 0.18);
    --vf-saved-text: rgba(17, 17, 17, 0.94);
    --vf-saved-text-muted: rgba(17, 17, 17, 0.72);
    --vf-saved-text-supporting: rgba(17, 17, 17, 0.62);
    --vf-saved-border: rgba(17, 17, 17, 0.10);
    --vf-saved-card-bg: rgba(255, 255, 255, 0.82);
    --vf-saved-card-hover-bg: rgba(246, 239, 226, 0.88);
    --vf-saved-card-active-bg: rgba(246, 239, 226, 0.96);
    --vf-saved-card-detail-bg: rgba(255, 255, 255, 0.9);
    --vf-saved-card-shadow: 0 10px 24px rgba(17, 17, 17, 0.06);
    --vf-saved-focus-ring: var(--vf-ui-accent, var(--covenant-accent, #7a1e2c));
    --vf-saved-focus-shadow: 0 0 0 3px rgba(122, 30, 44, 0.16);
    --vf-saved-action-bg: rgba(255, 255, 255, 0.86);
    --vf-saved-action-bg-hover: rgba(17, 17, 17, 0.88);
    --vf-saved-action-text: rgba(17, 17, 17, 0.9);
    --vf-saved-action-text-hover: rgba(246, 239, 226, 0.96);
    --vf-saved-action-border: rgba(17, 17, 17, 0.16);
    --vf-saved-close-bg: rgba(255, 255, 255, 0.78);
    --vf-saved-close-bg-hover: rgba(246, 239, 226, 0.96);
    --vf-saved-close-border: rgba(17, 17, 17, 0.14);
    --vf-saved-danger-border: rgba(160, 40, 40, 0.34);
    --vf-saved-danger-bg-hover: rgba(160, 40, 40, 0.08);
    --vf-saved-danger-text: rgba(160, 40, 40, 0.88);
}

/* ── Header toggle button ─────────────────────────────────────────────────── */
.vf-saved-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--vf-ui-bar-border, rgba(0, 0, 0, 0.14));
    border-radius: 20px;
    background: var(--vf-ui-card-bg, rgba(255, 255, 255, 0.42));
    color: var(--vf-ui-text, rgba(17, 17, 17, 0.92));
    font-family: var(--font-primary, serif);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.vf-saved-toggle:hover,
.vf-saved-toggle:focus-visible {
    background: var(--vf-ui-btn-bg, rgba(17, 17, 17, 0.88));
    color: var(--vf-ui-btn-text, rgba(246, 239, 226, 0.96));
    border-color: transparent;
}

.vf-saved-toggle:focus-visible {
    outline: 2px solid var(--vf-ui-accent, var(--covenant-accent, #7a1e2c));
    outline-offset: 2px;
}

/* Bookmark icon prefix (CSS only – no extra HTML) */
.vf-saved-toggle::before {
    content: "🔖";
    font-size: 0.9em;
    line-height: 1;
}

/* ── Backdrop ─────────────────────────────────────────────────────────────── */
.vf-saved-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: var(--vf-saved-backdrop-bg);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.vf-saved-backdrop.is-visible {
    opacity: 1;
}

/* ── Drawer panel ─────────────────────────────────────────────────────────── */
.vf-saved-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1201;
    width: min(420px, 95vw);
    display: flex;
    flex-direction: column;
    background: var(--vf-saved-shell-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--vf-saved-shell-border);
    box-shadow: var(--vf-saved-shell-shadow);
    transform: translateX(110%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    /* children scroll, not the rail */
    color: var(--vf-saved-text);
}

.vf-saved-drawer.is-open {
    transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {

    .vf-saved-drawer,
    .vf-saved-backdrop {
        transition: none !important;
    }
}

/* Inner scroll wrapper — only the list scrolls */
.vf-saved-drawer__panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ── Drawer header ────────────────────────────────────────────────────────── */
.vf-saved-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--vf-saved-border);
    flex-shrink: 0;
}

.vf-saved-drawer__header h2 {
    margin: 0;
    font-family: var(--font-primary, serif);
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--vf-saved-text);
    letter-spacing: -0.01em;
}

.vf-saved-drawer .vf-saved-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--vf-saved-close-border);
    border-radius: 50%;
    background: var(--vf-saved-close-bg);
    color: var(--vf-saved-text);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 6px 18px rgba(17, 17, 17, 0.08);
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.vf-saved-drawer .vf-saved-close:hover,
.vf-saved-drawer .vf-saved-close:focus-visible {
    background: var(--vf-saved-close-bg-hover);
    color: var(--vf-saved-text);
    border-color: var(--vf-saved-focus-ring);
}

.vf-saved-drawer .vf-saved-close:focus-visible {
    outline: 2px solid var(--vf-saved-focus-ring);
    outline-offset: 2px;
    box-shadow: var(--vf-saved-focus-shadow);
}

/* ── Action bar ───────────────────────────────────────────────────────────── */
.vf-saved-drawer__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--vf-saved-border);
    flex-shrink: 0;
}

.vf-saved-drawer .vf-saved-export,
.vf-saved-drawer .vf-saved-copy,
.vf-saved-drawer .vf-saved-clear {
    padding: 0.3rem 0.75rem;
    border-radius: 16px;
    font-family: var(--font-primary, serif);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    box-shadow: none;
}

.vf-saved-drawer .vf-saved-export,
.vf-saved-drawer .vf-saved-copy {
    border: 1px solid var(--vf-saved-action-border);
    background: var(--vf-saved-action-bg);
    color: var(--vf-saved-action-text);
}

.vf-saved-drawer .vf-saved-export:hover,
.vf-saved-drawer .vf-saved-copy:hover,
.vf-saved-drawer .vf-saved-export:focus-visible,
.vf-saved-drawer .vf-saved-copy:focus-visible {
    background: var(--vf-saved-action-bg-hover);
    color: var(--vf-saved-action-text-hover);
    border-color: transparent;
}

.vf-saved-drawer .vf-saved-clear {
    border: 1px solid var(--vf-saved-danger-border);
    background: transparent;
    color: var(--vf-saved-danger-text);
    margin-left: auto;
}

.vf-saved-drawer .vf-saved-clear:hover,
.vf-saved-drawer .vf-saved-clear:focus-visible {
    background: var(--vf-saved-danger-bg-hover);
    border-color: rgba(160, 40, 40, 0.7);
    color: rgb(140, 30, 30);
}

.vf-saved-drawer .vf-saved-export:focus-visible,
.vf-saved-drawer .vf-saved-copy:focus-visible,
.vf-saved-drawer .vf-saved-clear:focus-visible {
    outline: 2px solid var(--vf-saved-focus-ring);
    outline-offset: 2px;
    box-shadow: var(--vf-saved-focus-shadow);
}

/* Status line */
.vf-saved-status {
    flex-basis: 100%;
    margin: 0;
    font-size: 0.75rem;
    color: var(--vf-saved-text-supporting);
    min-height: 1rem;
    transition: opacity 0.3s;
}

/* ── Item list ────────────────────────────────────────────────────────────── */
.vf-saved-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1 1 auto;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.vf-saved-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--vf-saved-text-supporting);
    font-family: var(--font-primary, serif);
    gap: 0.75rem;
}

.vf-saved-empty__icon {
    font-size: 2.5rem;
    opacity: 0.4;
}

.vf-saved-empty p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

/* ── Each saved item ──────────────────────────────────────────────────────── */
.vf-saved-item {
    border-bottom: 1px solid var(--vf-saved-border);
}

.vf-saved-item:last-child {
    border-bottom: none;
}

/* Row toggle button */
.vf-saved-item__toggle {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 0.5rem;
    row-gap: 0.15rem;
    padding: 0.85rem 1.25rem;
    text-align: left;
    background: var(--vf-saved-card-bg);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    color: var(--vf-saved-text);
    box-shadow: var(--vf-saved-card-shadow);
    transition: background 0.15s, box-shadow 0.15s, color 0.15s;
}

.vf-saved-item__toggle:hover {
    background: var(--vf-saved-card-hover-bg);
}

.vf-saved-item__toggle[aria-expanded="true"] {
    background: var(--vf-saved-card-active-bg);
}

.vf-saved-item__toggle:focus-visible {
    outline: 2px solid var(--vf-saved-focus-ring);
    outline-offset: -2px;
    box-shadow: var(--vf-saved-focus-shadow);
}

.vf-saved-item__ref {
    font-family: var(--font-primary, serif);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--vf-saved-text);
    grid-column: 1;
    grid-row: 1;
    unicode-bidi: plaintext;
}

.vf-saved-item__meta {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.68rem;
    color: var(--vf-saved-text-supporting);
    white-space: nowrap;
    align-self: start;
    padding-top: 0.2rem;
    unicode-bidi: plaintext;
}

.vf-saved-item__excerpt {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 0.85rem;
    color: var(--vf-saved-text-muted);
    font-style: normal;
    line-height: 1.55;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    unicode-bidi: plaintext;
}

/* Expand indicator arrow */
.vf-saved-item__toggle::after {
    /* Arrow drawn with border trick to avoid extra element */
    content: '';
    display: none;
    /* We'll use a simple chevron via aria-expanded in JS */
}

/* ── Expanded detail pane ─────────────────────────────────────────────────── */
.vf-saved-item__detail {
    padding: 0 1.25rem 1rem;
    border-top: 1px solid var(--vf-saved-border);
    background: var(--vf-saved-card-detail-bg);
}

.vf-saved-item__fulltext {
    font-family: var(--font-primary, serif);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--vf-saved-text);
    padding: 1rem 0 0.75rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    unicode-bidi: plaintext;
}

.vf-saved-item__detail-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.vf-saved-drawer .vf-saved-item__open {
    font-size: 0.78rem;
    color: var(--vf-ui-accent, var(--covenant-accent, #7a1e2c));
    text-decoration: none;
    font-family: var(--font-primary, serif);
    letter-spacing: 0.03em;
}

.vf-saved-drawer .vf-saved-item__open:hover,
.vf-saved-drawer .vf-saved-item__open:focus-visible {
    text-decoration: underline;
}

.vf-saved-drawer .vf-saved-item__open:focus-visible,
.vf-saved-drawer .vf-saved-item__remove:focus-visible {
    outline: 2px solid var(--vf-saved-focus-ring);
    outline-offset: 2px;
    box-shadow: var(--vf-saved-focus-shadow);
}

.vf-saved-drawer .vf-saved-item__remove {
    margin-left: auto;
    padding: 0.25rem 0.65rem;
    border: 1px solid var(--vf-saved-danger-border);
    border-radius: 12px;
    background: transparent;
    color: var(--vf-saved-danger-text);
    font-size: 0.72rem;
    font-family: var(--font-primary, serif);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.vf-saved-drawer .vf-saved-item__remove:hover,
.vf-saved-drawer .vf-saved-item__remove:focus-visible {
    background: var(--vf-saved-danger-bg-hover);
    color: rgb(140, 30, 30);
}

/* ── Body scroll lock ─────────────────────────────────────────────────────── */
body.vf-drawer-open {
    overflow: hidden;
}

/* ── Night mode overrides ─────────────────────────────────────────────────── */
body.atmosphere-night {
    --vf-saved-backdrop-bg: rgba(1, 4, 10, 0.66);
    --vf-saved-shell-bg: rgba(9, 13, 20, 0.96);
    --vf-saved-shell-border: rgba(255, 255, 255, 0.14);
    --vf-saved-shell-shadow: -18px 0 42px rgba(0, 0, 0, 0.42);
    --vf-saved-text: rgba(255, 255, 255, 0.97);
    --vf-saved-text-muted: rgba(238, 242, 247, 0.86);
    --vf-saved-text-supporting: rgba(213, 221, 231, 0.76);
    --vf-saved-border: rgba(255, 255, 255, 0.14);
    --vf-saved-card-bg: rgba(21, 28, 39, 0.92);
    --vf-saved-card-hover-bg: rgba(31, 40, 55, 0.98);
    --vf-saved-card-active-bg: rgba(49, 40, 52, 0.98);
    --vf-saved-card-detail-bg: rgba(14, 20, 29, 0.98);
    --vf-saved-card-shadow: 0 14px 26px rgba(0, 0, 0, 0.24);
    --vf-saved-focus-ring: rgba(243, 179, 195, 0.95);
    --vf-saved-focus-shadow: 0 0 0 3px rgba(243, 179, 195, 0.22);
    --vf-saved-action-bg: rgba(20, 27, 38, 0.96);
    --vf-saved-action-bg-hover: rgba(244, 246, 250, 0.96);
    --vf-saved-action-text: rgba(255, 255, 255, 0.94);
    --vf-saved-action-text-hover: rgba(17, 17, 17, 0.94);
    --vf-saved-action-border: rgba(255, 255, 255, 0.18);
    --vf-saved-close-bg: rgba(20, 27, 38, 0.96);
    --vf-saved-close-bg-hover: rgba(31, 40, 55, 1);
    --vf-saved-close-border: rgba(255, 255, 255, 0.18);
    --vf-saved-danger-border: rgba(255, 153, 153, 0.38);
    --vf-saved-danger-bg-hover: rgba(183, 58, 58, 0.18);
    --vf-saved-danger-text: rgba(255, 176, 176, 0.94);
}

body.atmosphere-night .vf-saved-item__toggle:hover {
    background: var(--vf-saved-card-hover-bg);
}

body.atmosphere-night .vf-saved-item__detail {
    background: var(--vf-saved-card-detail-bg);
}

body.atmosphere-night .vf-saved-item__toggle[aria-expanded="true"] {
    background: var(--vf-saved-card-active-bg);
}

body.atmosphere-night .vf-saved-item__excerpt,
body.atmosphere-night .vf-saved-item__fulltext {
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}
