/* ============================================================
   DOCUMENT.CSS — 3-pane document view layout and styling
   ============================================================ */

/* --- Viewport lock: no outer page scroll --- */
body.in-document-mode {
    overflow: hidden;
    height: 100dvh;
    height: 100vh;
    margin: 0;
}
body.in-document-mode footer { display: none; }
body.in-document-mode main.container {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
}

/* --- Document search header --- */
.doc-search-header {
    flex-shrink: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 28px 10px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.doc-search-header .logo {
    text-decoration: none;
    display: flex;
    align-items: baseline;
    gap: 4px;
    white-space: nowrap;
}
.doc-search-header .logo-edu {
    font-size: 26px;
    font-weight: 500;
    color: #3b82f6;
    letter-spacing: -0.3px;
}
.doc-search-header .logo-kompas {
    font-size: 26px;
    font-weight: 700;
    color: #1e3a5f;
    letter-spacing: -0.5px;
}

.doc-search-header .search-wrapper {
    flex: 1;
    max-width: 560px;
    position: relative;
}

.doc-search-header .search-box {
    display: flex;
    align-items: center;
    border: 1.5px solid #cbd5e1;
    border-radius: 24px;
    padding: 5px 6px 5px 18px;
    background: #fff;
    transition: box-shadow 0.2s, border-color 0.15s;
}

.doc-search-header .search-box:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.doc-search-header .search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    padding: 6px 4px;
    color: #1e293b;
}

.doc-search-header .search-btn {
    padding: 8px 22px;
    background: #1e3a5f;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
}

.doc-search-header .search-btn:hover {
    background: #264d73;
}

.doc-search-header .suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #dfe1e5;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-top: 4px;
    z-index: 100;
    display: none;
}

.doc-search-header .suggestions:not(:empty) {
    display: block;
}

/* Header right-side actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}
.header-pill-link {
    font-size: 0.82rem;
    color: #5f6368;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border: 1px solid #dadce0;
    border-radius: 18px;
    background: #fff;
    white-space: nowrap;
    transition: all 0.15s;
}
.header-pill-link:hover {
    color: #202124;
    border-color: #bdc1c6;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* --- Spinner & HTMX indicator --- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #1e3a5f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

/* --- 3-pane document layout --- */
.document-layout {
    display: grid;
    grid-template-columns: 280px 1fr 260px;
    gap: 24px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 12px 24px 0;
}

/* --- Left pane: TOC --- */
.toc-pane {
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toc-search-bar {
    flex-shrink: 0;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
}

.toc-search-wrapper {
    position: relative;
}

.toc-search-input {
    width: 100%;
    padding: 9px 32px 9px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #4a5568;
    background: #f7fafc;
    transition: all 0.15s;
}

.toc-search-input:focus {
    outline: none;
    border-color: #3182ce;
    background: white;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.toc-search-input::placeholder {
    color: #a0aec0;
}

.toc-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    display: none;
}

.toc-search-clear:hover {
    color: #4a5568;
}

.toc-search-input:not(:placeholder-shown) + .toc-search-clear {
    display: block;
}

/* Scrollable TOC content */
.toc-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 16px 16px;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
.toc-scroll:hover { scrollbar-color: #cbd5e1 transparent; }
.toc-scroll::-webkit-scrollbar { width: 6px; background: transparent; }
.toc-scroll::-webkit-scrollbar-track { background: transparent; }
.toc-scroll::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.toc-scroll:hover::-webkit-scrollbar-thumb { background: #cbd5e1; }
.toc-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.toc-header {
    padding-bottom: 10px;
    margin-bottom: 8px;
}

.toc-title {
    font-weight: 600;
    color: #1a365d;
    font-size: 0.9rem;
}

.toc-no-results {
    font-size: 0.8rem;
    color: #a0aec0;
    text-align: center;
    padding: 12px 0;
}

.toc-item.hidden {
    display: none;
}

/* Search match highlighting */
.search-match {
    background: #dbeafe;
    color: #1e40af;
    padding: 1px 2px;
    border-radius: 2px;
}

.toc-link.has-match::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #3b82f6;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item {
    margin: 2px 0;
}

.toc-link {
    display: block;
    padding: 6px 8px;
    color: #4a5568;
    text-decoration: none;
    font-size: 0.85rem;
    border-radius: 4px;
    transition: all 0.15s;
}

.toc-link:hover {
    background: #f7fafc;
    color: #3182ce;
}

.toc-link.active {
    background: #ebf8ff;
    color: #2b6cb0;
    font-weight: 500;
}

/* Nested TOC tree */
.toc-children {
    list-style: none;
    padding-left: 0;
    margin: 0;
}
.toc-level-1 { font-weight: 600; }
.toc-level-2 { padding-left: 16px; }
.toc-level-3 { padding-left: 16px; font-size: 0.9rem; color: #4a5568; }
.toc-level-4 { padding-left: 16px; font-size: 0.85rem; color: #718096; }

/* --- Center pane: Content --- */
.content-pane {
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    padding: 32px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
.content-pane:hover { scrollbar-color: #cbd5e1 transparent; }
.content-pane::-webkit-scrollbar { width: 6px; background: transparent; }
.content-pane::-webkit-scrollbar-track { background: transparent; }
.content-pane::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.content-pane:hover::-webkit-scrollbar-thumb { background: #cbd5e1; }
.content-pane::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.doc-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.doc-title {
    font-size: 1.4rem;
    color: #1a365d;
    line-height: 1.4;
    margin-bottom: 12px;
}

.doc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.doc-id-badge {
    font-family: monospace;
    background: #f7fafc;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #4a5568;
}

/* Anchor targets */
.anchor-target {
    display: block;
    position: relative;
    height: 0;
    visibility: hidden;
    scroll-margin-top: 20px;
}

.section {
    margin-bottom: 4px;
    padding: 14px 20px;
    scroll-margin-top: 20px;
    border-left: 3px solid transparent;
    border-radius: 8px;
}

.section-label {
    font-weight: 700;
    color: #1e3a5f;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.section-content {
    line-height: 1.85;
    color: #334155;
}

.section-content p {
    margin-bottom: 12px;
}

/* Punctuation-only sections (stray quotes/semicolons from amendment acts) */
.section-punct {
    margin-bottom: 0;
    padding: 0 20px;
}
.section-punct .section-content {
    line-height: 1.4;
    color: #94a3b8;
    font-size: 0.85rem;
}

/* Legal content formatting */
.section-content .legal-ref {
    color: #718096;
    font-size: 0.9em;
}

.section-content .attachment-header {
    color: #1e3a5f;
    font-size: 1.05em;
    display: inline-block;
    margin: 8px 0 4px 0;
}

/* Highlight when navigating via anchor */
.section:target,
.section.highlight {
    background: #fffbeb;
    border-left-color: #f59e0b;
}

/* --- Right pane: Rail --- */
.right-pane {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
.right-pane:hover { scrollbar-color: #cbd5e1 transparent; }
.right-pane::-webkit-scrollbar { width: 6px; background: transparent; }
.right-pane::-webkit-scrollbar-track { background: transparent; }
.right-pane::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.right-pane:hover::-webkit-scrollbar-thumb { background: #cbd5e1; }
.right-pane::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.rail-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    padding: 16px;
    margin-bottom: 16px;
    overflow: hidden;
}

.rail-title {
    font-weight: 600;
    color: #4a5568;
    font-size: 0.85rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.rail-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    padding: 10px 12px;
    margin: 0 -12px;
    border-radius: 8px;
    transition: background 0.15s, box-shadow 0.15s;
}

.rail-link:hover {
    background: #f0f7ff;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.15);
}

.rail-link-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    color: #3b82f6;
    transition: color 0.15s;
}
.rail-link:hover .rail-link-icon {
    color: #1e3a5f;
}

.rail-link-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.2;
}
.rail-link:hover .rail-link-text {
    color: #1e3a5f;
}

.rail-link-source {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-left: auto;
    white-space: nowrap;
}
.rail-link:hover .rail-link-source {
    color: #64748b;
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-in-force {
    background: #c6f6d5;
    color: #276749;
}

.status-repealed {
    background: #fed7d7;
    color: #c53030;
}

/* Related items (przepisy + wytyczne) — scoped to rail-card to beat base.html legacy styles */
.rail-card .related-item {
    display: block;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 8px;
    background: #f8fafc;
    border: none;
    border-left: none;
    text-decoration: none;
    transition: background 0.15s;
}
.rail-card .related-item:last-child {
    margin-bottom: 0;
}
.rail-card .related-item:hover {
    background: #eef4ff;
}

.rail-card .related-item-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1e293b;
    display: block;
    line-height: 1.4;
    text-decoration: none;
}
.rail-card .related-item:hover .related-item-title {
    color: #2563eb;
}

.rail-card .related-item-meta {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: 2px;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    .document-layout {
        grid-template-columns: 240px 1fr;
    }
    .right-pane {
        display: none;
    }
    .scroll-top-btn {
        left: calc(240px + 24px);
        right: 24px;
    }
}

@media (max-width: 900px) {
    /* Mobile: release viewport lock, allow normal page scroll */
    body.in-document-mode {
        overflow: auto;
        height: auto;
    }
    body.in-document-mode main.container {
        height: auto;
        overflow: visible;
    }
    .scroll-top-btn {
        left: 24px;
        right: 24px;
    }
    .document-layout {
        grid-template-columns: 1fr;
        overflow: visible;
    }
    .toc-pane {
        position: static;
        max-height: none;
        margin-bottom: 16px;
    }
    .content-pane {
        overflow-y: visible;
    }
    .toc-header {
        cursor: pointer;
    }
    .toc-list.collapsed {
        display: none;
    }
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* Full HTML content styling */
.full-html-content {
    line-height: 1.8;
}

.full-html-content h1,
.full-html-content h2,
.full-html-content h3 {
    color: #1a365d;
    margin-top: 24px;
    margin-bottom: 12px;
}

.full-html-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.full-html-content th,
.full-html-content td {
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: left;
}

.full-html-content th {
    background: #f7fafc;
}

.full-html-content ul,
.full-html-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

/* Section header with share button */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}

.section-label {
    margin-bottom: 0;
}

.section-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}

.section:hover .section-actions {
    opacity: 1;
}

.share-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    color: #718096;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}

.share-btn:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
    color: #4a5568;
}

.share-btn svg {
    width: 18px;
    height: 18px;
}

.share-btn i {
    font-size: 14px;
    color: #2563eb;
}

/* Share popover */
.share-popover {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border: 1px solid #e2e8f0;
    padding: 6px 0;
    min-width: 200px;
    z-index: 100;
    display: none;
}

.share-popover.active {
    display: block;
}

.share-popover hr {
    margin: 4px 0;
    border: none;
    border-top: 1px solid #f1f5f9;
}

.share-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 0.82rem;
    color: #3c4043;
    cursor: pointer;
    transition: background 0.15s;
}

.share-action:hover {
    background: #f1f5f9;
}

.share-action i {
    width: 18px;
    text-align: center;
    color: #4a5568;
}

.share-action i.fa-brands {
    font-size: 15px;
}

.share-action i.fa-whatsapp { color: #25D366; }
.share-action i.fa-facebook-messenger { color: #0084FF; }
.share-action i.fa-microsoft { color: #5059C9; }
.share-action i.fa-facebook { color: #1877F2; }
.share-action i.fa-linkedin { color: #0A66C2; }
.share-action i.fa-x-twitter { color: #000; }

/* Doc header share button */
.doc-header-actions {
    margin-top: 12px;
}

.share-act-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: #718096;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}

.share-act-btn:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
    color: #4a5568;
}

.share-act-btn i {
    font-size: 14px;
    color: #2563eb;
}

/* Act share dropdown */
.act-share-dropdown {
    position: relative;
    display: inline-flex;
}

.act-share-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    min-width: 200px;
    margin-top: 4px;
    z-index: 1000;
    padding: 6px 0;
}

.act-share-menu.open {
    display: block;
}

.act-share-menu button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: none;
    text-align: left;
    font-size: 0.82rem;
    color: #3c4043;
    cursor: pointer;
}

.act-share-menu button:hover {
    background: #f1f5f9;
}

.act-share-menu button i {
    width: 18px;
    text-align: center;
    margin-right: 6px;
    color: #4a5568;
}

.act-share-menu button i.fa-brands {
    font-size: 15px;
}

.act-share-menu button i.fa-whatsapp { color: #25D366; }
.act-share-menu button i.fa-facebook-messenger { color: #0084FF; }
.act-share-menu button i.fa-microsoft { color: #5059C9; }
.act-share-menu button i.fa-facebook { color: #1877F2; }
.act-share-menu button i.fa-linkedin { color: #0A66C2; }
.act-share-menu button i.fa-x-twitter { color: #000; }

.act-share-menu hr {
    margin: 4px 0;
    border: none;
    border-top: 1px solid #f1f5f9;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1a202c;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Section prev/next navigation */
.section-nav {
    display: flex;
    justify-content: space-between;
    padding: 20px 0;
    margin-top: 24px;
    border-top: 1px solid #e2e8f0;
}

.section-nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #4a5568;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
    max-width: 45%;
}

.section-nav-link:hover {
    background: #ebf8ff;
    border-color: #3182ce;
    color: #2b6cb0;
}

.section-nav-arrow {
    font-size: 1.1rem;
    color: #718096;
}

.section-nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-nav-prev {
    margin-right: auto;
}

.section-nav-next {
    margin-left: auto;
}

@media (max-width: 600px) {
    .section-nav-label {
        max-width: 100px;
    }
}

/* Scroll to top — centered in content column */
.scroll-top-btn {
    position: fixed;
    bottom: 24px;
    /* Center between TOC (280+24) and rail (260+24) */
    left: calc(280px + 24px);
    right: calc(260px + 24px);
    width: 44px;
    height: 44px;
    margin: 0 auto;
    background: #3182ce;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 99;
}

.scroll-top-btn:hover {
    background: #2c5282;
    transform: translateY(0) scale(1.05);
}

.scroll-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Iframe adjustments --- */
html.in-iframe .doc-search-header,
html.in-iframe .scroll-top-btn {
    display: none !important;
}
html.in-iframe main.container {
    padding-top: 0 !important;
    padding: 0 !important;
    max-width: none !important;
}
html.in-iframe .document-layout {
    grid-template-columns: 1fr !important;
    height: 100vh;
    gap: 0;
}
html.in-iframe .toc-pane,
html.in-iframe .right-pane {
    display: none !important;
}
html.in-iframe .content-pane {
    padding: 20px 28px;
    border-radius: 0;
}
