/* Rich content — конспекти, блог, домашка (Quill + HTML-блоки) */

.rich-content {
    --rc-border: #e5e7eb;
    --rc-muted: #6b7280;
    --rc-blue: #1cb0f6;
    --rc-blue-bg: #eff6ff;
    --rc-green: #58cc02;
    --rc-green-bg: #f0fdf4;
    --rc-yellow: #ffc800;
    --rc-yellow-bg: #fffbeb;
    --rc-red: #ff4b4b;
    --rc-red-bg: #fef2f2;
    line-height: 1.75;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.rich-content > *:first-child { margin-top: 0; }
.rich-content > *:last-child { margin-bottom: 0; }

.rich-content h1,
.rich-content h2,
.rich-content h3 {
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.25;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    color: inherit;
}

.rich-content h1 { font-size: 1.875rem; }
.rich-content h2 { font-size: 1.5rem; border-bottom: 2px solid var(--rc-border); padding-bottom: 0.35rem; }
.rich-content h3 { font-size: 1.25rem; color: var(--rc-blue); }

.rich-content p { margin-bottom: 1rem; }
.rich-content strong, .rich-content b { font-weight: 900; }

.rich-content ul, .rich-content ol {
    margin: 0 0 1.25rem 1.25rem;
    padding-left: 0.25rem;
}

.rich-content li { margin-bottom: 0.35rem; }

.rich-content blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    border-left: 5px solid var(--rc-blue);
    background: var(--rc-blue-bg);
    border-radius: 0 1rem 1rem 0;
    font-weight: 700;
}

.rich-content hr,
.rich-content .rc-divider {
    border: none;
    height: 2px;
    margin: 2rem 0;
    background: linear-gradient(90deg, transparent, var(--rc-border), transparent);
}

.rich-content pre,
.rich-content .ql-code-block {
    margin: 1.25rem 0;
    padding: 1rem 1.15rem;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 1rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.6;
}

.rich-content code {
    background: #f3f4f6;
    color: #be123c;
    padding: 0.15rem 0.4rem;
    border-radius: 0.35rem;
    font-size: 0.9em;
    font-weight: 700;
}

.rich-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.rich-content img,
.rich-content img.rc-img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.25rem auto;
    border-radius: 1rem;
    border: 2px solid var(--rc-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    object-fit: contain;
}

.rich-content img.rc-img-zoomable,
.content-page-prose img.rc-img-zoomable,
.content-page-article img.rc-img-zoomable,
#side-quest-summary img.rc-img-zoomable,
#side-quest-modal-image.rc-img-zoomable {
    cursor: zoom-in;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rich-content img.rc-img-zoomable:hover,
.content-page-prose img.rc-img-zoomable:hover,
.content-page-article img.rc-img-zoomable:hover,
#side-quest-summary img.rc-img-zoomable:hover {
    transform: scale(1.01);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
}

/* Fullscreen image lightbox (острови, конспекти, статті) */
.image-lightbox,
#image-modal.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(6px);
}

.image-lightbox.hidden {
    display: none !important;
}

.image-lightbox .image-modal-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10002;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
}

.image-lightbox .image-modal-close:hover {
    background: rgba(0, 0, 0, 0.65);
}

.image-lightbox .image-modal-stage {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(100%, 56rem);
    max-width: 100%;
    height: min(85vh, calc(100dvh - 5rem));
    padding: 1rem;
    overflow: hidden;
    touch-action: none;
}

.image-lightbox .image-modal-img,
.image-lightbox #fullscreen-image {
    max-width: 100%;
    max-height: 100%;
    border-radius: 1rem;
    border: 2px solid rgba(55, 65, 81, 0.5);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.45);
    object-fit: contain;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;
    transform-origin: center center;
    will-change: transform;
}

.rich-content img.rc-img-p100 { width: 100%; }
.rich-content img.rc-img-p75 { width: 75%; }
.rich-content img.rc-img-p50 { width: 50%; }
.rich-content img.rc-img-p25 { width: 25%; }

/* Старі конспекти: width="100" трактувався браузером як 100px */
.rich-content img[width] {
    width: auto;
    max-width: 100%;
    height: auto;
}

/* Приховати «биті» зображення, якщо вони все ж потрапили в HTML */
.rich-content img:not([src]),
.rich-content img[src=""] {
    display: none;
}

.rich-content a {
    color: var(--rc-blue);
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.rich-content .rc-table-wrap {
    margin: 1.5rem 0;
    overflow-x: auto;
    border: 2px solid var(--rc-border);
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.rich-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    min-width: 280px;
}

.rich-content th,
.rich-content td {
    border: 1px solid var(--rc-border);
    padding: 0.65rem 0.85rem;
    text-align: left;
    vertical-align: top;
}

.rich-content th {
    background: var(--rc-blue-bg);
    font-weight: 900;
    color: #1e3a8a;
}

.rich-content tr:nth-child(even) td {
    background: #f9fafb;
}

.rich-content .rc-callout {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    border: 2px solid var(--rc-border);
    font-weight: 700;
}

.rich-content .rc-callout-info {
    background: var(--rc-blue-bg);
    border-color: #bfdbfe;
}

.rich-content .rc-callout-tip {
    background: var(--rc-green-bg);
    border-color: #bbf7d0;
}

.rich-content .rc-callout-warn {
    background: var(--rc-yellow-bg);
    border-color: #fde68a;
}

.rich-content .rc-callout-success {
    background: var(--rc-green-bg);
    border-color: #86efac;
}

.rich-content .rc-callout > *:first-child { margin-top: 0; }
.rich-content .rc-callout > *:last-child { margin-bottom: 0; }

.rich-content .rc-grid {
    display: grid;
    gap: 1rem;
    margin: 1.5rem 0;
}

.rich-content .rc-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rich-content .rc-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

@media (max-width: 640px) {
    .rich-content .rc-grid-2,
    .rich-content .rc-grid-3 {
        grid-template-columns: 1fr;
    }
}

.rich-content .rc-card {
    background: #fff;
    border: 2px solid var(--rc-border);
    border-radius: 1rem;
    padding: 1rem 1.15rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.rich-content .rc-card > *:first-child { margin-top: 0; }
.rich-content .rc-card > *:last-child { margin-bottom: 0; }

.rich-content .rc-frame {
    margin: 1.5rem 0;
    padding: 1.25rem 1.5rem;
    border: 3px double var(--rc-blue);
    border-radius: 1.25rem;
    background: linear-gradient(135deg, #fff 0%, var(--rc-blue-bg) 100%);
}

.rich-content .rc-text-center { text-align: center; }
.rich-content .rc-text-right { text-align: right; }

.rich-content .rc-video {
    margin: 1.5rem 0;
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: 1rem;
    border: 2px solid var(--rc-border);
    background: #0f172a;
}

.rich-content .rc-video iframe,
.rich-content .rc-video video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.rich-content .ql-align-center { text-align: center; }
.rich-content .ql-align-right { text-align: right; }
.rich-content .ql-align-justify { text-align: justify; }

.rich-content .ql-indent-1 { padding-left: 3em; }
.rich-content .ql-indent-2 { padding-left: 6em; }
.rich-content .ql-indent-3 { padding-left: 9em; }

.rich-content .ql-size-0\.85em { font-size: 0.85em; }
.rich-content .ql-size-1em { font-size: 1em; }
.rich-content .ql-size-1\.15em { font-size: 1.15em; }
.rich-content .ql-size-1\.35em { font-size: 1.35em; }
.rich-content .ql-size-1\.6em { font-size: 1.6em; }

/* Заголовки з класом розміру Quill — вища специфічність, ніж у h1/h2/h3 */
.rich-content :is(h1, h2, h3, h4, h5, h6).ql-size-0\.85em { font-size: 0.85em; }
.rich-content :is(h1, h2, h3, h4, h5, h6).ql-size-1em { font-size: 1em; }
.rich-content :is(h1, h2, h3, h4, h5, h6).ql-size-1\.15em { font-size: 1.15em; }
.rich-content :is(h1, h2, h3, h4, h5, h6).ql-size-1\.35em { font-size: 1.35em; }
.rich-content :is(h1, h2, h3, h4, h5, h6).ql-size-1\.6em { font-size: 1.6em; }

/* Quill editor preview mirrors public styles */
.admin-quill-wrap .ql-editor {
    font-family: 'Nunito', sans-serif;
}

.admin-quill-wrap .ql-editor.rich-content,
.admin-quill-wrap .ql-editor {
    line-height: 1.75;
}

.admin-quill-html-panel {
    display: none;
    border-top: 2px solid #f3f4f6;
}

.admin-quill-wrap.is-html-mode .ql-toolbar,
.admin-quill-wrap.is-html-mode .ql-container {
    display: none !important;
}

.admin-quill-wrap.is-html-mode .admin-quill-html-panel {
    display: block;
}

.admin-quill-html-panel textarea {
    width: 100%;
    min-height: 220px;
    padding: 1rem 1.15rem;
    border: none;
    outline: none;
    resize: vertical;
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.82rem;
    line-height: 1.55;
    color: #1e293b;
    background: #f8fafc;
    border-bottom: 2px solid #e5e7eb;
}

.admin-quill-html-preview {
    padding: 1.25rem 1.5rem 1.5rem;
    background: #fff;
    min-height: 120px;
}

.admin-quill-html-preview.hidden {
    display: none;
}

[data-theme="dark"] .admin-quill-html-preview {
    background: #0f172a;
}

[data-theme="dark"] .rich-content {
    --rc-border: #334155;
    --rc-muted: #94a3b8;
    --rc-blue-bg: rgba(28, 176, 246, 0.12);
    --rc-green-bg: rgba(88, 204, 2, 0.12);
    --rc-yellow-bg: rgba(255, 200, 0, 0.12);
    --rc-red-bg: rgba(255, 75, 75, 0.12);
    color: var(--site-text-muted, #94a3b8);
}

[data-theme="dark"] .rich-content p,
[data-theme="dark"] .rich-content li {
    color: var(--site-text-muted, #94a3b8);
}

[data-theme="dark"] .rich-content strong,
[data-theme="dark"] .rich-content b {
    color: var(--site-text, #f1f5f9);
}

[data-theme="dark"] .rich-content blockquote {
    color: #e2e8f0;
}

[data-theme="dark"] .rich-content th {
    color: #bae6fd;
}

[data-theme="dark"] .rich-content tr:nth-child(even) td {
    background: rgba(15, 23, 42, 0.5);
}

[data-theme="dark"] .rich-content .rc-card {
    background: #1e293b;
}

[data-theme="dark"] .rich-content .rc-frame {
    background: linear-gradient(135deg, #1e293b 0%, rgba(28, 176, 246, 0.08) 100%);
}

[data-theme="dark"] .rich-content code {
    background: #334155;
    color: #fda4af;
}

[data-theme="dark"] .admin-quill-html-panel textarea {
    background: #0f172a;
    color: #e2e8f0;
}
