*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: #f3f4f6;
    color: #1a1a2e;
}

/* -- App Shell -- */
.chat-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* -- Setup Panel (Left) -- */
.setup-panel {
    width: 340px;
    min-width: 280px;
    max-width: 400px;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.setup-header {
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.setup-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #374151;
}

.setup-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.setup-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setup-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.system-prompt-input {
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

.system-prompt-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
    outline: none;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.param-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.param-label {
    font-size: 0.8125rem;
    color: #6b7280;
}

.param-input {
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    max-width: 100px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.slider-row .form-range {
    flex: 1;
    accent-color: #6366f1;
}

.param-small {
    width: 68px;
    font-size: 0.8125rem;
    padding: 0.3rem 0.4rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    text-align: center;
}

.setup-footer {
    padding: 0.75rem 1.25rem 1rem;
    border-top: 1px solid #e5e7eb;
}

/* -- Chat Panel (Right) -- */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f9fafb;
}

.chat-header {
    padding: 1rem 1.5rem 0.75rem;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

.chat-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: #374151;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* -- Empty state -- */
.empty-chat-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #9ca3af;
    text-align: center;
    gap: 0.5rem;
    padding: 3rem;
}

.empty-icon {
    font-size: 2.5rem;
}

/* -- Chat Bubbles -- */
.chat-bubble {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    gap: 0.25rem;
}

.chat-bubble-user {
    align-self: flex-end;
}

.chat-bubble-assistant {
    align-self: flex-start;
}

.bubble-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9ca3af;
    padding: 0 0.5rem;
}

.chat-bubble-user .bubble-label { text-align: right; }

.bubble-text {
    padding: 0.65rem 1rem;
    border-radius: 12px;
    font-size: 0.9375rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-bubble-user .bubble-text {
    background: #6366f1;
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.chat-bubble-assistant .bubble-text {
    background: #ffffff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.error-text {
    color: #dc2626 !important;
    background: #fef2f2 !important;
    border-color: #fecaca !important;
}

/* -- Thinking dots animation -- */
.thinking-dots {
    display: inline-block;
    animation: blink 1.2s steps(3, end) infinite;
    color: #9ca3af;
    letter-spacing: 2px;
}

@keyframes blink {
    0%   { opacity: 0; }
    50%  { opacity: 1; }
    100% { opacity: 0; }
}

/* -- Chat Input Area -- */
.chat-input-area {
    padding: 1rem 2rem 0.75rem;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 0.65rem 1rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    max-height: 160px;
    overflow-y: auto;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
    outline: none;
}

.send-btn {
    background: #6366f1;
    border: none;
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { background: #4f46e5; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-disclaimer {
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: center;
    margin: 0.4rem 0 0;
}

/* -- Attachment UI -- */
.attach-btn {
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
}
.attach-btn:hover { background: #f3f4f6; border-color: #9ca3af; }

.attachment-preview-area {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    font-size: 0.8125rem;
    max-width: 200px;
}

.attachment-thumb {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-icon { font-size: 1.1rem; }

.attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    color: #374151;
}

.attachment-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.attachment-remove:hover { color: #ef4444; }

.bubble-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.bubble-img {
    max-width: 220px;
    max-height: 180px;
    border-radius: 8px;
    object-fit: cover;
    display: block;
}

.bubble-file-chip {
    background: rgba(0,0,0,0.08);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}

/* -- Scrollbar styling -- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* -- Responsive -- */
@media (max-width: 768px) {
    .chat-app { flex-direction: column; }
    .setup-panel { width: 100%; max-width: 100%; height: auto; border-right: none; border-bottom: 1px solid #e5e7eb; }
    .setup-body { max-height: 220px; }
    .chat-panel { flex: 1; min-height: 0; }
}
