/* ==========================================================================
   hifz.css — ركن الحفظ
   ========================================================================== */

.hifz-page {
    padding-bottom: 4rem;
}

.hifz-page__hero {
    text-align: center;
    margin-bottom: 2rem;
    padding-top: 1rem;
}

.hifz-page__title {
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    font-weight: 700;
    color: var(--color-heading);
    margin-bottom: 0.5rem;
}

.hifz-page__intro {
    max-width: 42rem;
    margin: 0 auto;
    color: var(--color-muted);
    line-height: 1.85;
    font-size: 0.98rem;
}

.hifz-layout {
    display: grid;
    grid-template-columns: minmax(280px, 340px) 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* غلاف sticky منفصل عن التمرير الداخلي */
.hifz-sidebar {
    align-self: start;
    position: sticky;
    top: calc(var(--header-height, 62px) + 1rem);
    z-index: 5;
    width: 100%;
    max-height: calc(100dvh - var(--header-height, 62px) - 2rem);
}

.hifz-panel {
    max-height: calc(100dvh - var(--header-height, 62px) - 2rem);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    background: var(--color-surface);
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    color: var(--color-on-surface);
}

.hifz-fieldset {
    border: none;
    margin: 0 0 1.25rem;
    padding: 0;
}

.hifz-fieldset__legend {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 0.65rem;
    padding: 0;
}

.hifz-label {
    display: block;
    font-size: 0.82rem;
    color: var(--color-on-surface-muted);
    margin-bottom: 0.35rem;
}

.hifz-select,
.hifz-input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
    color: var(--color-on-surface);
    font-family: var(--font-body);
    font-size: 0.92rem;
    margin-bottom: 0.65rem;
}

.hifz-select:focus,
.hifz-input:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
    border-color: var(--color-accent);
}

.hifz-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0.75rem;
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.hifz-mode-tab {
    flex: 1;
    padding: 0.45rem 0.5rem;
    border: none;
    background: transparent;
    color: var(--color-on-surface-muted);
    font-family: var(--font-body);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.hifz-mode-tab.is-active {
    background: var(--color-accent);
    color: #fff;
}

.hifz-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.hifz-field {
    min-width: 0;
}

.hifz-hint {
    font-size: 0.78rem;
    color: var(--color-on-surface-muted);
    line-height: 1.6;
    margin: 0;
}

.hifz-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    color: var(--color-on-surface);
}

.hifz-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.hifz-actions .btn {
    flex: 1 1 auto;
    min-width: 7rem;
}

.hifz-form-error {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: #922b21;
    background: #fdecea;
    border: 1px solid #f5c6c2;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
}

[data-color-theme="ashiy"] .hifz-form-error {
    color: #fca5a5;
    background: rgba(146, 43, 33, 0.25);
    border-color: rgba(245, 198, 194, 0.35);
}

.hifz-preview-wrap {
    min-width: 0;
}

.hifz-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.hifz-preview-toolbar__label {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-heading);
}

.hifz-preview-toolbar__count {
    font-size: 0.8rem;
    color: var(--color-muted);
}

.hifz-preview {
    --hifz-a4-width: min(210mm, 100%);
    background: color-mix(in srgb, var(--color-muted) 12%, var(--color-surface-alt));
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1rem;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    overflow-x: auto;
    overflow-y: visible;
}

.hifz-preview-empty {
    text-align: center;
    color: var(--color-muted);
    padding: 3rem 1rem;
    margin: auto 0;
    max-width: 24rem;
}

.hifz-error {
    color: #922b21;
    text-align: center;
    padding: 2rem;
}

/* ورقة A4 — المعاينة على الشاشة */
.hifz-preview-page {
    width: var(--hifz-a4-width);
    min-height: 297mm;
    box-sizing: border-box;
    background: #fff;
    color: #1a1a1a;
    border-radius: 2px;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.08),
        0 6px 24px rgba(0, 0, 0, 0.12);
    padding: 14mm 12mm;
    flex-shrink: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

.hifz-preview-page + .hifz-preview-page {
    margin-top: 0;
}

.hifz-sheet {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(297mm - 28mm);
}

.hifz-sheet__brand {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
    max-width: 100%;
}

.hifz-sheet__brand-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.hifz-sheet__brand-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: #5a4a3a;
    line-height: 1.35;
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hifz-sheet__main {
    flex: 1 1 auto;
    min-width: 0;
}

.hifz-preview-page:last-child {
    margin-bottom: 0;
}

.hifz-sheet__head {
    text-align: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #c9b79c;
}

.hifz-sheet__badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #8b5e3c;
    background: #f5f0e6;
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    margin-bottom: 0.5rem;
}

.hifz-sheet__title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
    line-height: 1.35;
}

.hifz-sheet__poet {
    font-size: 0.92rem;
    color: #5a4a3a;
    margin: 0;
}

.hifz-sheet__date {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: #666;
}

.hifz-sheet__date-line {
    flex: 1;
    max-width: 8rem;
    height: 1px;
    background: #999;
    border-bottom: 1px dashed #999;
}

.hifz-sheet__verses {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.hifz-verse {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.5rem 0;
    border-bottom: 1px dotted #ddd;
}

.hifz-verse:last-child {
    border-bottom: none;
}

.hifz-verse__num {
    flex-shrink: 0;
    width: 1.6rem;
    height: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #8b5e3c;
    border: 1.5px solid #c9b79c;
    border-radius: 50%;
}

.hifz-verse__body {
    flex: 1;
    min-width: 0;
}

.hifz-verse__line {
    display: flex;
    flex-direction: row;
    direction: rtl;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0;
    font-family: var(--font-primary);
    font-size: 1.05rem;
    line-height: 1.85;
    margin: 0;
    text-align: center;
}

.hifz-verse__shatr {
    display: inline;
    margin: 0;
}

.hifz-verse__sep {
    flex-shrink: 0;
    display: inline-block;
    padding: 0 1.35em;
    color: #c9b79c;
    font-size: 0.55em;
    line-height: 1;
    vertical-align: middle;
    user-select: none;
}

.hifz-verse__explain {
    margin-top: 0.45rem;
    padding-top: 0.45rem;
    border-top: 1px dashed #e0d5c5;
    font-size: 0.78rem;
    line-height: 1.7;
    color: #444;
    text-align: right;
}

.hifz-verse__explain p {
    margin: 0 0 0.35rem;
}

.hifz-sheet__notes {
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid #ddd;
}

.hifz-sheet__notes-label {
    display: block;
    font-size: 0.82rem;
    color: #666;
    margin-bottom: 0.35rem;
}

.hifz-sheet__notes-area {
    min-height: 3.5rem;
    border: 1px dashed #bbb;
    border-radius: var(--radius-sm);
}

.selection-bar__hifz {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

.selection-bar__hifz:hover {
    background: var(--color-accent-dark);
    border-color: var(--color-accent-dark);
    color: #fff;
}

@media (max-width: 900px) {
    .hifz-layout {
        grid-template-columns: 1fr;
    }

    .hifz-sidebar {
        position: static;
        max-height: none;
    }

    .hifz-panel {
        max-height: none;
        overflow: visible;
    }

    .hifz-preview {
        padding: 1rem 0.5rem;
    }

    .hifz-preview-page {
        padding: 10mm 8mm;
        min-height: calc(var(--hifz-a4-width) * 297 / 210);
    }

    .hifz-sheet {
        min-height: calc(var(--hifz-a4-width) * 297 / 210 - 18mm);
    }
}

@media print {
    body.hifz-printing .site-wrapper,
    body.hifz-printing .scroll-top-btn {
        display: none !important;
    }

    body.hifz-printing #hifz-print-root {
        display: block !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        margin: 0;
        padding: 0;
        background: #fff;
    }

    body.hifz-printing .hifz-preview-page {
        width: auto;
        min-height: auto;
        box-shadow: none;
        border-radius: 0;
        background: #fff;
        color: #1a1a1a;
        padding: 0;
        margin: 0;
        display: block;
        page-break-before: always;
        break-before: page;
        page-break-after: always;
        break-after: page;
    }

    body.hifz-printing .hifz-preview-page:first-child {
        page-break-before: auto;
        break-before: auto;
    }

    body.hifz-printing .hifz-preview-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    body.hifz-printing .hifz-sheet {
        min-height: auto;
        display: block;
    }

    body.hifz-printing .hifz-verse__line {
        flex-wrap: nowrap;
    }

    body.hifz-printing .hifz-sheet__brand {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: A4 portrait;
        margin: 14mm 12mm;
    }
}
