* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --zeiss-blue: #003366;
    --zeiss-light: #0066cc;
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #4a9eff;
    --user-msg: #2d4a6f;
    --assistant-msg: #1e3a5f;
    --border: #334466;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.logo h1 {
    font-size: 1.5rem;
    color: var(--accent);
    font-weight: 600;
}

.logo .subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.clear-btn, .export-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
}

.clear-btn:hover, .export-btn:hover {
    background: var(--user-msg);
    color: var(--text-primary);
}

.lang-toggle {
    display: flex;
    gap: 0.25rem;
}

.lang-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
}

.lang-btn:hover {
    background: var(--user-msg);
}

.lang-btn.active {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

/* Main Chat Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 400px;
    max-height: calc(100vh - 280px);
}

/* Messages */
.message {
    display: flex;
    gap: 0.75rem;
}

.message.user {
    flex-direction: row-reverse;
}

.message-content {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
}

.message.user .message-content {
    background: var(--user-msg);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--assistant-msg);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content em {
    color: var(--text-secondary);
}

.message-content strong {
    color: var(--accent);
}

/* Input Area */
#input-area {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

#user-input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    font-family: inherit;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent);
}

#user-input::placeholder {
    color: var(--text-secondary);
}

#send-btn {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#send-btn:hover {
    background: var(--zeiss-light);
    transform: scale(1.05);
}

#send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
    transform: none;
}

#send-btn svg {
    color: var(--bg-dark);
}

/* Status Bar */
#status-bar {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#loading {
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 500;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.hidden {
    display: none !important;
}

/* Footer */
footer {
    padding: 1rem 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Error message */
.error {
    background: #4a1c1c !important;
    border: 1px solid #8b3a3a;
}

/* Page reference buttons */
.page-refs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.page-ref-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.page-ref-btn:hover {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

/* Page image modal */
#page-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
}

.modal-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    font-weight: 500;
    gap: 0.5rem;
}

.modal-header span {
    flex: 1;
    text-align: center;
}

.modal-header .nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-header .nav-btn:hover:not(:disabled) {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

.modal-header .nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.modal-header .close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
    margin-left: 0.5rem;
}

.modal-header .close-btn:hover {
    color: var(--text-primary);
}

.modal-content img {
    display: block;
    width: auto;
    height: auto;
    max-width: 90vw;
    max-height: calc(95vh - 60px);
    object-fit: contain;
    margin: 0 auto;
}

/* PDF viewer iframe */
.pdf-modal {
    width: 90vw;
    height: 90vh;
}

.pdf-viewer {
    width: 100%;
    height: calc(90vh - 50px);
    border: none;
    background: #fff;
}

/* Open in new tab button */
.open-tab-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
}

.open-tab-btn:hover {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

/* Version toggle (Original/Modern) */
.version-toggle {
    display: flex;
    gap: 0.25rem;
    margin: 0 0.5rem;
}

.version-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
}

.version-btn:hover {
    background: var(--user-msg);
    color: var(--text-primary);
}

.version-btn.active {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: var(--accent);
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 0.5rem;
    }

    header {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .message-content {
        max-width: 90%;
    }

    #messages {
        min-height: 300px;
        max-height: calc(100vh - 320px);
    }
}
