/* --- General Styles & Fonts --- */
:root {
    --primary-color: #1a237e; /* Ciemny niebieski, kojarzący się z powagą */
    --secondary-color: #c5b358; /* Złoty, dodający prestiżu */
    --background-color: #f4f6f8;
    --surface-color: #ffffff;
    --text-color: #333333;
    --light-gray: #e0e0e0;
    --ai-feature-color: #673ab7;
    --doc-viewer-width: 400px;
}

body {
    font-family: 'Lato', sans-serif;
    margin: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s;
}

.beta-badge {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 10000;
    background: #dc2626;
    color: #fff;
    font-weight: 900;
    letter-spacing: 1px;
    padding: 4px 8px;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

h1, h2, h3, h4 {
    font-family: 'Merriweather', serif;
}

.hidden {
    display: none !important;
}

/* --- Landing Page --- */
#landingPage { transition: opacity 0.5s; }

.landing-header {
    background-color: var(--surface-color);
    padding: 20px 0;
    border-bottom: 1px solid var(--light-gray);
    position: sticky;
    top: 0;
    z-index: 100;
}

.landing-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
    font-family: 'Merriweather', serif;
    text-decoration: none;
}
.logo .logo-symbol {
    font-family: 'Playfair Display', serif;
    font-size: 40px;
    font-weight: 700;
    color: var(--secondary-color);
    line-height: 1;
}

.landing-header nav a {
    text-decoration: none;
    color: var(--text-color);
    margin-left: 25px;
    font-weight: 700;
    transition: color 0.3s;
}
.landing-header nav a:hover {
    color: var(--primary-color);
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}
.btn-primary:hover {
    background-color: #0d124f;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}
.btn-secondary:hover {
    background-color: #a08c40;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.hero {
    text-align: center;
    padding: 100px 0;
    background: linear-gradient(rgba(26, 35, 126, 0.8), rgba(26, 35, 126, 0.8)), url('https://images.unsplash.com/photo-1589216532372-1c2a36790049?q=80&w=2070&auto=format&fit=crop') no-repeat center center;
    background-size: cover;
    color: white;
}
.hero h1 {
    font-size: 48px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
.hero p {
    font-size: 20px;
    max-width: 700px;
    margin: 20px auto 40px;
    line-height: 1.6;
}

.features { padding: 80px 0; }
.features h2 { text-align: center; font-size: 36px; margin-bottom: 60px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 40px; }
.feature-item { text-align: center; background: var(--surface-color); padding: 30px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.feature-item svg { width: 48px; height: 48px; color: var(--primary-color); margin-bottom: 20px; }
.feature-item h3 { font-size: 22px; margin-bottom: 10px; }

.pricing { background-color: var(--surface-color); padding: 80px 0; }
.pricing h2 { text-align: center; font-size: 36px; margin-bottom: 60px; }
.pricing-cards { display: flex; justify-content: center; gap: 30px; flex-wrap: wrap; }
.pricing-card {
    border: 1px solid var(--light-gray);
    border-radius: 10px;
    padding: 40px;
    width: 320px;
    text-align: center;
    background: white;
    transition: transform 0.3s, box-shadow 0.3s;
}
.pricing-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.pricing-card.featured {
    border-color: var(--secondary-color);
    border-width: 2px;
    transform: scale(1.05);
}
.pricing-card h3 { font-size: 24px; }
.pricing-card .price { font-size: 42px; font-weight: 700; margin: 20px 0; color: var(--primary-color); }
.pricing-card .price span { font-size: 16px; font-weight: 400; color: var(--text-color); }
.pricing-card ul { list-style: none; padding: 0; margin: 30px 0; text-align: left; }
.pricing-card ul li { margin-bottom: 15px; display: flex; align-items: center; }
.pricing-card ul li svg { color: var(--secondary-color); margin-right: 10px; width: 20px; height: 20px; }

.landing-footer { text-align: center; padding: 40px 0; background-color: #1c1c1c; color: #aaa; }
.landing-footer a { color: var(--secondary-color); text-decoration: none; cursor: pointer; }
.landing-footer a:hover { text-decoration: underline; }

/* --- Site Access Modal --- */
#siteAccessModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

#siteAccessModal.hidden {
    display: none;
}

#siteAccessModal .modal-content {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    text-align: center;
    min-width: 400px;
}

#siteAccessModal h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

#siteAccessModal input {
    width: 100%;
    padding: 12px;
    margin: 15px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    box-sizing: border-box;
}

#siteAccessModal .error-message {
    color: #f44336;
    margin-top: 15px;
    padding: 10px;
    background: #ffebee;
    border-radius: 5px;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}
.modal-content {
    background: white;
    padding: 40px;
    border-radius: 10px;
    width: 100%;
    text-align: left;
    position: relative;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
}
.modal-close:hover { color: #000; }
.modal-content h2 { margin-top: 0; text-align: center; }

/* Login/Register Modal */
#loginModal .modal-content { max-width: 400px; text-align: center; }
.login-btn {
    display: block; width: 100%; padding: 15px; margin-bottom: 15px; border-radius: 8px;
    border: 1px solid var(--light-gray); font-size: 16px; cursor: pointer; text-align: left;
    display: flex; align-items: center; gap: 15px;
}
.login-btn svg { width: 24px; height: 24px; }
.or-divider { margin: 20px 0; }
.auth-form input {
    width: 100%; padding: 12px; margin-bottom: 15px; border: 1px solid var(--light-gray); border-radius: 5px; box-sizing: border-box;
}
.form-toggle { margin-top: 20px; }
.form-toggle a { color: var(--primary-color); cursor: pointer; text-decoration: underline; }

/* Subscription Modal */
#subscriptionModal .modal-content { max-width: 500px; }
.sub-details p { display: flex; justify-content: space-between; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 10px; }
.sub-details p strong { color: var(--primary-color); }
.sub-actions { display: flex; gap: 15px; margin-top: 30px; }
.sub-actions .btn { flex: 1; text-align: center; }
.btn-danger { background-color: #d32f2f; color: white; }
.btn-danger:hover { background-color: #b71c1c; }

/* Legal Modals */
.legal-modal .modal-content { max-width: 800px; }
.legal-modal-body { max-height: 70vh; overflow-y: auto; line-height: 1.7; padding-right: 15px; }
.legal-modal-body h4 { margin-top: 2em; margin-bottom: 0.5em; }
.legal-modal-body p, .legal-modal-body li { color: #555; }
.legal-modal-body ul { padding-left: 20px; }

/* --- Chat View --- */
#chatPage { display: flex; height: 100vh; overflow: hidden; }
.sidebar, .document-viewer { transition: all 0.3s ease-in-out; }

.sidebar { width: 280px; background-color: #171717; color: white; display: flex; flex-direction: column; padding: 15px; flex-shrink: 0; }
.sidebar.collapsed { width: 0; padding: 0; overflow: hidden; }
.sidebar-header { padding-bottom: 15px; }
.new-chat-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; background-color: var(--surface-color); color: var(--primary-color); border: 1px solid var(--primary-color); }
.search-bar { padding: 15px 0; }
.search-bar input { box-sizing: border-box; width: 100%; padding: 10px; border-radius: 5px; border: none; background-color: #333; color: white; }
.chat-history { flex-grow: 1; overflow-y: auto; margin: 0 -15px; padding: 0 15px; }
.chat-history ul { list-style: none; padding: 0; margin: 0; }
.chat-history li { padding: 12px 15px; cursor: pointer; border-radius: 8px; margin-bottom: 5px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chat-history li .chat-title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-grow: 1; }
.chat-history li:hover, .chat-history li.active { background-color: #333; }
.chat-item-actions { display: none; flex-shrink: 0; }
.chat-history li:hover .chat-item-actions { display: flex; gap: 8px; }
.chat-item-actions button { background: none; border: none; color: #aaa; cursor: pointer; padding: 2px;}
.sidebar-footer { padding-top: 15px; border-top: 1px solid #333; }
.user-menu { position: relative; padding-bottom: 10px; margin-bottom: -10px; }
.user-menu .username { cursor: pointer; padding: 10px; display: block; background-color: #333; border-radius: 8px; text-align: center; }
.user-menu .dropdown-menu { display: none; position: absolute; bottom: 100%; left: 0; width: 100%; background: #333; border-radius: 5px; padding: 10px; z-index: 10; box-sizing: border-box; }
.user-menu:hover .dropdown-menu { display: block; }
.dropdown-menu a { display: block; color: white; text-decoration: none; padding: 10px; border-radius: 5px; }
.dropdown-menu a:hover { background-color: #555; }

.chat-container { flex-grow: 1; display: flex; flex-direction: column; background-color: var(--surface-color); position: relative; }
.chat-header { padding: 15px 25px; border-bottom: 1px solid var(--light-gray); display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.chat-header .chat-logo { display: flex; align-items: center; margin-right: 12px; }
.chat-header .chat-logo .logo-symbol { font-family: 'Playfair Display', serif; font-size: 24px; color: var(--secondary-color); font-weight: 700; }
.chat-window { flex-grow: 1; overflow-y: auto; padding: 30px; display: flex; flex-direction: column; }
.message { max-width: 75%; margin-bottom: 10px; display: flex; flex-direction: column; }
.message-content { padding: 15px 20px; border-radius: 18px; line-height: 1.6; position: relative; word-wrap: break-word; }
.message-content p { margin: 0 0 10px 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { font-weight: bold; }
.message-content em { font-style: italic; }
.message-content code { background-color: rgba(0,0,0,0.1); padding: 2px 4px; border-radius: 3px; font-family: monospace; font-size: 0.9em; }
.message-ai .message-content code { background-color: rgba(0,0,0,0.1); }
.message-user .message-content code { background-color: rgba(255,255,255,0.2); }
.message-user { align-self: flex-end; }
.message-user .message-content { background-color: var(--primary-color); color: white; border-bottom-right-radius: 4px; }
.message-ai { align-self: flex-start; }
.message-ai .message-content { background-color: #e9e9eb; border-bottom-left-radius: 4px; }
.message-ai.streaming .message-content::after { content: '▍'; display: inline-block; animation: blink 1s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.legal-ref { color: var(--ai-feature-color); text-decoration: underline; cursor: pointer; font-weight: bold; }

/* AI Features */
.ai-actions, .related-questions { margin-top: 15px; display: flex; flex-wrap: wrap; gap: 10px; }
.ai-actions { align-self: flex-start; margin-left: 10px; }
.related-questions { align-self: flex-start; flex-direction: column; width: 100%; max-width: 75%; margin-left: 10px; margin-bottom: 20px; }
.ai-btn, .related-q-btn { background-color: #f0f4ff; border: 1px solid #d9e2ff; color: var(--primary-color); padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 13px; transition: background-color 0.3s; }
.ai-btn:hover, .related-q-btn:hover { background-color: #e3eaff; }
.simplified-answer { background-color: #f3e5f5; color: #4a148c; border: 1px solid #e1bee7; border-radius: 10px; padding: 15px; margin-top: 10px; font-size: 15px; }
.simplified-answer strong { color: var(--ai-feature-color); display: block; margin-bottom: 5px; }

.chat-input-area { padding: 20px; border-top: 1px solid var(--light-gray); background: var(--surface-color); }
.disclaimer { font-size: 12px; text-align: center; color: #888; margin-bottom: 10px; }
.chat-form { display: flex; align-items: flex-end; max-width: 800px; margin: 0 auto; }
#userInput { flex-grow: 1; padding: 15px; border-radius: 10px; border: 1px solid var(--light-gray); resize: none; font-family: 'Lato', sans-serif; font-size: 16px; max-height: 200px; overflow-y: auto; }
.input-actions { display: flex; align-items: center; margin-left: 10px; gap: 10px; }
.send-btn { background: var(--primary-color); border: none; border-radius: 10px; padding: 12px; cursor: pointer; color: white; display: flex; align-items: center; justify-content: center; transition: background-color 0.3s; }
.action-btn { background: none; border: 1px solid var(--light-gray); padding: 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* Document Viewer */
.document-viewer { width: var(--doc-viewer-width); border-left: 1px solid var(--light-gray); background-color: var(--surface-color); display: flex; flex-direction: column; flex-shrink: 0; }
.document-viewer.collapsed { width: 0; overflow: hidden; border-left: none; }
.doc-header { padding: 15px 20px; border-bottom: 1px solid var(--light-gray); display: flex; justify-content: space-between; align-items: center; }
.doc-header h3 { margin: 0; font-size: 18px; }
.doc-content { padding: 20px; overflow-y: auto; line-height: 1.7; flex-grow: 1; }
.doc-content .highlight { background-color: #fff59d; }

/* Panel Toggles */
.panel-toggle { 
    position: absolute; 
    z-index: 50; 
    background: var(--surface-color); 
    border: 1px solid var(--light-gray); 
    border-radius: 6px; 
    width: 24px; 
    height: 40px; 
    cursor: pointer; 
    display: flex; 
    justify-content: center; 
    align-items: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.panel-toggle:hover {
    background: var(--light-gray);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

#left-panel-toggle { 
    left: 280px; 
    top: 50%; 
    transform: translateY(-50%);
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    transition: left 0.3s ease;
}

/* When sidebar is collapsed, move toggle button to the left edge */
#chatPage.sidebar-collapsed #left-panel-toggle {
    left: 0px;
}

#right-panel-toggle { 
    right: var(--doc-viewer-width); 
    top: 50%; 
    transform: translateY(-50%); 
    border-right: none;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* Resizer between chat and right panel */
.vertical-resizer {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
}
.vertical-resizer::after {
    content: "";
    position: absolute;
    left: 2px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}
.vertical-resizer:hover::after {
    background: #cbd5e1;
}
.vertical-resizer.hidden { display: none; }

/* Cookie Banner */
.cookie-banner { position: fixed; bottom: 20px; left: 20px; background-color: #263238; color: white; padding: 20px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; z-index: 1000; max-width: 400px; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.cookie-banner p { margin: 0 20px 0 0; }
.cookie-banner a { color: var(--secondary-color); cursor: pointer; }

/* Chat Accordion Styles */
.chat-accordion { display: flex; flex-direction: column; width: 100%; }

.load-older-messages-btn {
    background-color: #f5f5f5;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    padding: 12px 20px;
    margin: 0 0 20px 0;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    align-self: center;
}

.load-older-messages-btn:hover {
    background-color: #e8e8e8;
    border-color: var(--primary-color);
}

.load-older-messages-btn:disabled {
    background-color: #f0f0f0;
    color: #999;
    cursor: not-allowed;
    border-color: #ddd;
}

.accordion-section { margin-bottom: 20px; }

.accordion-header {
    background-color: #f8f9fa;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background-color 0.2s ease;
}

.accordion-header:hover {
    background-color: #e9ecef;
}

.accordion-toggle {
    font-weight: bold;
    color: var(--primary-color);
    transition: transform 0.2s ease;
}

.accordion-content {
    border: 1px solid var(--light-gray);
    border-top: none;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.accordion-content:not(.collapsed) {
    max-height: 2000px; /* Large enough for typical message batches */
}

.accordion-content.collapsed {
    max-height: 0;
    border: none;
}

.accordion-section .messages-container {
    padding: 15px;
    background-color: #fafbfc;
}

.recent-messages .messages-container {
    padding: 0; /* Recent messages don't need extra padding */
    background-color: transparent;
}

.older-messages .message {
    opacity: 0.9;
    margin-bottom: 15px;
}

.older-messages .message:last-child {
    margin-bottom: 0;
}

/* Sources panel (tabs + codes accordion) */
.sources-tabs {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--light-gray);
}
.tab-btn {
    background: #f5f6fa;
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
}
.tab-btn.active {
    background: #eef2ff;
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.sources-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.tab-panel { height: 100%; overflow-y: auto; }

.codes-accordion { padding: 10px; }
.code-section { border: 1px solid var(--light-gray); border-radius: 8px; overflow: hidden; }
.code-header { background: #f7f7fb; padding: 12px 14px; font-weight: 700; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.code-content { max-height: 70vh; overflow: auto; transition: max-height 0.2s ease; }
.code-content.collapsed { max-height: 0; padding: 0; border: none; }
.code-controls { display: flex; justify-content: flex-end; gap: 8px; padding: 8px; border-bottom: 1px solid var(--light-gray); }
.nav-btn { background: #f0f4ff; border: 1px solid #d9e2ff; color: var(--primary-color); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.nav-btn:hover { background: #e3eaff; }
.code-body { padding: 12px 14px; line-height: 1.7; }
.code-body .highlight { background: #fff59d; }

/* Code panel segment headers and main highlight */
.code-seg-header { font-weight: 700; margin: 6px 0 4px; color: #2b2b2b; }
.code-seg.main-segment { box-shadow: none; }
.code-seg .main-highlight { background: #fff59d; border-radius: 6px; padding: 4px; display: block; }

.chat-accordion .messages-container { display: flex; flex-direction: column; }
.chat-accordion .messages-container .message { max-width: 75%; }

