* {
    box-sizing: border-box;
}

.header {
    position: sticky;
    top: 0;

    z-index: 1000;

    background: white;

    padding: 16px 20px;

    border-bottom: 1px solid #ddd;
}

.header-actions {
    display: flex;
    gap: 10px;
}

#toggle-theme-button {
    font-size: 1rem;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
}

.app {
    max-width: 1000px;
    min-height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: white;
}

body.dark-theme .app {
    background: #1e1e1e;
    color: white;
}

body.dark-theme .conversation {
    background: #1e1e1e;
}

header {
    padding: 18px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

header h1 {
    margin: 0;
    font-size: 1.35rem;
}

#new-conversation-button {
    padding: 9px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    cursor: pointer;
}

#new-conversation-button:hover {
    background: #f9fafb;
}

#conversation {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.welcome {
    padding: 30px 20px;
    text-align: center;
    color: #6b7280;
}

.suggested-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.welcome .suggested-replies { justify-content: center; }

.suggested-reply {
    padding: 7px 11px;
    border: 1px solid var(--primary, #2563eb);
    border-radius: 999px;
    color: var(--primary, #2563eb);
    background: transparent;
    font-size: .82rem;
}

.suggested-reply:hover { color: #fff; background: var(--primary, #2563eb); }
.suggested-reply:disabled { cursor: default; opacity: .55; }

.message {
    margin-bottom: 22px;
}

.message-header {
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #6b7280;
}

.message-content {
    padding: 14px 16px;
    border-radius: 10px;
    white-space: pre-wrap;
    line-height: 1.5;
}

.message.user .message-content {
    margin-left: 12%;
    background: #e8f0fe;
}

.message.assistant .message-content {
    margin-right: 12%;
    background: #f3f4f6;
}

.sources {
    margin-top: 10px;
    margin-right: 12%;
    padding: 12px 14px;
    border-left: 3px solid #9ca3af;
    background: #fafafa;
    font-size: 0.9rem;
}

.sources-title {
    margin-bottom: 8px;
    font-weight: bold;
}

.source-item {
    margin-top: 7px;
    word-break: break-word;
}

.diagnostics {
    margin-top: 8px;
    color: #6b7280;
    font-size: 0.8rem;
}

.diagnostics-line + .diagnostics-line {
    margin-top: 3px;
}

.diagnostics-context-button {
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
}

#sent-context-dialog {
    width: min(840px, calc(100vw - 32px));
    height: min(650px, calc(100vh - 32px));
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 10px;
    color: #1f2937;
    background: #eceff1;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

#sent-context-dialog::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.context-dialog-content {
    display: grid;
    height: 100%;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 15px;
    padding: 0;
}

.context-dialog-heading {
    padding: 22px 22px 0;
}

.context-dialog-heading h2 {
    margin: 0;
}

.context-dialog-status {
    padding: 0 22px;
    color: #6b7280;
}

.context-dialog-text {
    min-height: 0;
    margin: 0 22px;
    overflow: auto;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f7f7f8;
    color: #1f2937;
    font: 0.82rem/1.5 monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.context-dialog-actions {
    display: flex;
    justify-content: center;
    padding: 14px 22px;
    border-top: 1px solid #d4d7db;
    background: #e3e6e8;
}

.context-dialog-actions button {
    padding: 9px 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #ffffff;
    color: #1f2937;
    cursor: pointer;
    font: inherit;
}

.context-dialog-actions button:hover {
    background: #f9fafb;
}

.composer {
    padding: 18px 24px;
    border-top: 1px solid #e5e7eb;
    background: white;
}

textarea {
    width: 100%;
    min-height: 90px;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font: inherit;
    resize: vertical;
}

body.developer-mode #question {
    border-left: 4px solid #e8a093;
    background: #fff9f8;
}

body.support-mode #question {
    border-left: 4px solid #4caf72;
    background: #f4fbf6;
}

.composer-actions {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#conversation-info {
    color: #6b7280;
    font-size: 0.85rem;
}

#ask-button {
    padding: 10px 20px;
    border: 0;
    border-radius: 7px;
    background: #2563eb;
    color: white;
    font-size: 1rem;
    cursor: pointer;
}

#ask-button:hover {
    background: #1d4ed8;
}

#ask-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.error .message-content {
    color: #b91c1c;
    background: #fee2e2;
}

@media (max-width: 700px) {
    header,
    #conversation,
    .composer {
        padding-left: 14px;
        padding-right: 14px;
    }

    .message.user .message-content,
    .message.assistant .message-content {
        margin-left: 0;
        margin-right: 0;
    }

    .sources {
        margin-right: 0;
    }
}

.answer-images {
    margin-top: 14px;
    margin-right: 12%;
    padding: 14px;
    background: #f9fafb;
    border-radius: 8px;
}

.answer-images-title {
    margin-bottom: 12px;
    font-weight: bold;
    color: #374151;
}

.answer-images-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.answer-image {
    min-width: 0;
    margin: 0;
}

.answer-image-button {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    cursor: zoom-in;
}

.answer-image img {
    display: block;
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 7px;
}

.answer-image-button:hover img,
.answer-image-button:focus-visible img {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.answer-image figcaption {
    margin-top: 6px;
    color: #6b7280;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(0, 0, 0, 0.82);
}

.image-lightbox.open {
    display: flex;
}

body.lightbox-open {
    overflow: hidden;
}

.image-lightbox-content {
    max-width: min(1200px, 92vw);
    max-height: 90vh;
    margin: 0;
    text-align: center;
}

.image-lightbox-image {
    display: block;
    max-width: 100%;
    max-height: 82vh;
    margin: 0 auto;
    border-radius: 8px;
    background: white;
    object-fit: contain;
}

.image-lightbox-caption {
    margin-top: 10px;
    color: white;
    font-size: 0.95rem;
}

.image-lightbox-close {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: white;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
}

.image-lightbox-nav {
    position: absolute;
    top: 50%;
    z-index: 1;
    width: 52px;
    height: 64px;
    padding: 0;
    transform: translateY(-50%);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.35);
    color: white;
    font-size: 3rem;
    line-height: 1;
    cursor: pointer;
}

.image-lightbox-nav:hover,
.image-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.18);
}

.image-lightbox-previous {
    left: 22px;
}

.image-lightbox-next {
    right: 22px;
}

@media (max-width: 950px) {
    .answer-images-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    .answer-images {
        margin-right: 0;
    }

    .answer-images-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .image-lightbox {
        padding: 16px;
    }

    .image-lightbox-nav {
        width: 42px;
        height: 52px;
        font-size: 2.4rem;
    }

    .image-lightbox-previous {
        left: 8px;
    }

    .image-lightbox-next {
        right: 8px;
    }
}

@media (max-width: 420px) {
    .answer-images-grid {
        grid-template-columns: 1fr;
    }
}

#conversation-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;

    margin-top: 12px;

    color: #666;
    font-size: 0.85rem;
}

.conversation-separator {
    color: #bbb;
}

.debug-link {
    border: 0;
    background: transparent;

    color: #2563eb;

    cursor: pointer;

    font: inherit;

    padding: 0;

    text-decoration: underline;
}

.debug-link:hover {
    color: #1d4ed8;
}

.sources,
.diagnostics {
    display: none;
}

body.show-debug .sources,
body.show-debug .diagnostics {
    display: block;
}

.message.user.developer .message-content {
    background: #fde2dc;
}

.message.user.support .message-content {
    background: #dff3e5;
}

.message.assistant.support .message-content {
    border-left: 4px solid #4caf72;
}

.message.assistant.developer .message-content {
    border-left: 4px solid #e8a093;
}

body.dark-theme {
    background: #1e1e1e;
    color: #f2f2f2;
}

body.dark-theme .header {
    background: #2b2b2b;
    border-bottom: 1px solid #555;
}

body.dark-theme .composer {
    background: #1e1e1e;
    border-top-color: #555;
}

body.dark-theme #new-conversation-button {
    background: #2d2d2d;
    color: white;
    border-color: #666;
}

body.dark-theme #new-conversation-button:hover {
    background: #3a3a3a;
}

body.dark-theme .answer-images {
    background: #2d2d2d;
}

body.dark-theme .answer-images-title {
    color: #f2f2f2;
}

body.dark-theme .answer-image img {
    border-color: #666;
}

body.dark-theme .answer-image figcaption {
    color: #bbb;
}

body.dark-theme .message.assistant .message-content {
    background: #2d2d2d;
    color: white;
}

body.dark-theme .message.user .message-content {
    background: #2b5ea8;
    color: white;
}

body.dark-theme .message.user.developer .message-content {
    background: #7a4b46;
}

body.dark-theme .message.user.support .message-content {
    background: #285c3a;
}

body.dark-theme .sources {
    background: #2d2d2d;
    border-left-color: #888;
    color: #ddd;
}

body.dark-theme .diagnostics {
    color: #bbb;
}

body.dark-theme .diagnostics-context-button {
    color: #93c5fd;
}

body.dark-theme #sent-context-dialog {
    color: #f2f2f2;
    background: #252b34;
}

body.dark-theme .context-dialog-status {
    color: #bbb;
}

body.dark-theme .context-dialog-text {
    border-color: #4b5563;
    background: #2d3440;
    color: #f2f2f2;
}

body.dark-theme .context-dialog-actions {
    border-top-color: #414957;
    background: #202630;
}

body.dark-theme .context-dialog-actions button {
    border-color: #374151;
    background: #111827;
    color: #f3f4f6;
}

body.dark-theme .context-dialog-actions button:hover {
    background: #263244;
}

body.dark-theme textarea,
body.dark-theme input {
    background: #2d2d2d;
    color: white;
    border-color: #666;
}

body.dark-theme.developer-mode #question {
    background: #3b2927;
    color: #f8eeee;
    border-color: #8f5d57;
    border-left-color: #d28b81;
}

body.dark-theme.developer-mode #question::placeholder {
    color: #c9aaa6;
}

body.dark-theme.support-mode #question {
    background: #203a29;
    color: #edf8f0;
    border-color: #487658;
    border-left-color: #65b981;
}

body.dark-theme.support-mode #question::placeholder {
    color: #a9cbb3;
}

body.dark-theme #ask-button {
    background: #2563eb;
    color: white;
}

body.dark-theme button {
    background: #3a3a3a;
    color: white;
}

body.dark-theme .debug-link,
body.dark-theme #toggle-debug-button,
body.dark-theme #toggle-mode-button {
    background: transparent;
    color: #8ecbff;
    border: 0;
}

body.dark-theme a {
    color: #8ecbff;
}
