/* ========================================
   RESET AND BASE STYLES
   ======================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #ffffff;
    color: #1f1f1f;
    height: 100vh;
    overflow: hidden;
}

/* ========================================
   LAYOUT CONTAINERS
   ======================================== */

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.main-width {
    padding: 40px calc((100vw - 800px) / 2) 20px;
}

/* ========================================
   HEADER STYLES
   ======================================== */

.header {
    background: #ffffff;
    border-bottom: 1px solid #e5e5e5;
    padding: 16px 24px;
    display: flex;
    justify-content: center;
}

.header-content {
    width: 100%;
    max-width: 800px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

/* Model Selector */
.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.model-selector label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
}

.model-selector select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    min-width: 100px;
}

/* API Key Section */
.api-key-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.api-key-collapsed {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 20px;
    padding: 8px 12px;
}

.api-key-expanded {
    display: flex;
    align-items: center;
    gap: 12px;
}

.api-key-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.api-key-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-check {
    color: #16a34a;
    font-weight: 600;
    font-size: 14px;
}

.status-text {
    color: #15803d;
    font-size: 14px;
    font-weight: 500;
}

.edit-key-button,
.delete-key-button {
    background: none !important;
    border: none !important;
    cursor: pointer;
    padding: 4px !important;
    border-radius: 4px !important;
    transition: all 0.2s !important;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 0 !important;
}

.edit-key-button {
    color: #16a34a !important;
}

.edit-key-button:hover {
    background: rgba(22, 163, 74, 0.1) !important;
    color: #15803d !important;
    box-shadow: none !important;
    transform: none !important;
}

.delete-key-button {
    color: #dc2626 !important;
}

.delete-key-button:hover {
    background: rgba(220, 38, 38, 0.1) !important;
    color: #b91c1c !important;
    box-shadow: none !important;
    transform: none !important;
}

.api-key-section input {
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #1f2937;
    font-size: 14px;
    width: 280px;
    transition: all 0.2s;
}

.api-key-section input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.05);
}

.api-key-section button {
    padding: 8px 16px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.api-key-section button:hover:not(:disabled) {
    background: #5856eb;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.api-key-section button:disabled {
    background: #e5e5e5 !important;
    color: #999 !important;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: none !important;
}

#delete-key {
    background: #ef4444 !important;
}

#delete-key:hover {
    background: #dc2626 !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15) !important;
}

/* ========================================
   WELCOME MESSAGE
   ======================================== */

.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
}

.welcome-content h2 {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1f2937;
}

.welcome-content > p {
    font-size: 18px;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.billing-warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
    text-align: left;
    font-size: 14px;
    color: #5e4702;
    line-height: 1.5;
}

.billing-warning strong {
    color: #b45309;
}

.billing-warning a {
    color: #b45309;
    text-decoration: none;
    font-weight: 500;
}

.billing-warning a:hover {
    text-decoration: underline;
}

.help-text {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 24px;
    text-align: left;
}

.help-text h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #1f1f1f;
}

.help-text ol {
    margin: 0 0 20px 20px;
    padding: 0;
}

.help-text li {
    margin: 8px 0;
    line-height: 1.5;
    color: #444;
}

.help-text a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.help-text a:hover {
    text-decoration: underline;
}

.help-text .note {
    margin: 0;
    font-size: 14px;
    color: #666;
    font-style: italic;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

/* ========================================
   CHAT MESSAGES
   ======================================== */

.messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    max-height: calc(100vh - 200px);
}

.message {
    display: flex;
    margin-bottom: 32px;
    animation: fadeIn 0.4s ease-out;
    position: relative;
}

.message.user {
    justify-content: flex-end;
}

.message.user .avatar {
    display: none;
}

.message.user .content {
    background: #6366f1;
    color: white;
    margin-left: 0;
    margin-right: 0;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}

.message.user .avatar {
    background: #6366f1;
    color: white;
}

.message.assistant .avatar {
    background: #10b981;
    color: white;
}

.content {
    max-width: 100%;
    padding: 16px 20px;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message.assistant .content {
    background: #f8f9fa;
    color: #1f1f1f;
    border: 1px solid #e9ecef;
    width: 100%;
}

.content pre {
    background: #f1f3f4;
    padding: 16px;
    border-radius: 8px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    border: 1px solid #e8eaed;
}

.content code {
    background: #f1f3f4;
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    color: #1f1f1f;
}

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

.content p {
    margin: 0 0 12px 0;
}

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

.content ul,
.content ol {
    margin: 8px 0 8px 20px;
}

.content li {
    margin: 4px 0;
}

.content blockquote {
    border-left: 3px solid #e8eaed;
    padding-left: 16px;
    margin: 12px 0;
    color: #5f6368;
    font-style: italic;
}

.message-text {
    margin-bottom: 4px;
}

/* ========================================
   MESSAGE EDITING
   ======================================== */

.message.user:hover .edit-btn {
    opacity: 1;
}

.edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    transition: opacity 0.2s;
    z-index: 10;
}

.edit-btn:hover {
    background: #fff;
    border-color: #999;
}

.edit-form {
    width: 100%;
    box-sizing: border-box;
}

.edit-textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
    background: white;
    outline: none;
    box-sizing: border-box;
}

.edit-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    padding: 0 8px 8px 8px;
}

.edit-actions button {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.edit-save,
.edit-cancel {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #ced4da;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.edit-save:hover:not(:disabled),
.edit-cancel:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    color: #343a40;
}

.edit-save:focus:not(:disabled),
.edit-cancel:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(108, 117, 125, 0.25);
}

.edit-save:disabled {
    background: #f8f9fa;
    color: #6c757d;
    border-color: #e9ecef;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ========================================
   FILE ATTACHMENTS
   ======================================== */

.file-attachment {
    margin-top: 8px;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    border-left: 3px solid #007bff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.file-attachment:hover {
    background: #f8f9fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.file-attachment .file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.file-attachment .file-icon {
    font-size: 16px;
}

.file-attachment .file-name {
    font-weight: 500;
    color: #333;
}

.file-attachment .file-size {
    color: #666;
    font-size: 12px;
}

/* ========================================
   EXAMPLE PROMPTS
   ======================================== */

.example-prompts {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    width: 100%;
}

.examples-warning {
    grid-column: 1 / -1;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.example-prompt {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 80px;
}

.example-prompt:hover {
    background: #ffffff;
    border-color: #6366f1;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.08);
}

.prompt-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.prompt-text {
    font-size: 14px;
    color: #1f1f1f;
    line-height: 1.4;
    font-weight: 500;
}

/* ========================================
   INPUT AREA
   ======================================== */

.input-container {
    padding-bottom: 40px;
}

.file-preview {
    margin-bottom: 12px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 12px 16px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-icon {
    font-size: 16px;
}

.file-name {
    font-weight: 500;
    color: #1f1f1f;
}

.file-size {
    color: #666;
    font-size: 14px;
}

.remove-file {
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.remove-file:hover {
    background: #e9ecef;
    color: #666;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: #ffffff;
    border: 2px solid #e5e5e5;
    border-radius: 24px;
    padding: 6px;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.input-wrapper:focus-within {
    border-color: #6366f1;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.08);
}

.file-button {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #666;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin: 2px;
}

.file-button:hover {
    background: #f0f0f0;
    color: #333;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #1f1f1f;
    font-size: 16px;
    line-height: 1.5;
    padding: 12px 20px;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    font-family: inherit;
}

#message-input::placeholder {
    color: #9ca3af;
}

#send-button {
    width: 44px;
    height: 44px;
    border: none;
    background: #6366f1;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin: 2px;
}

#send-button:hover:not(:disabled) {
    background: #5856eb;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

#send-button:disabled {
    background: #e5e5e5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#send-button svg {
    transform: rotate(90deg);
}

/* ========================================
   BUTTONS AND COMMON COMPONENTS
   ======================================== */

.btn {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #e9ecef;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: background-color 0.2s;
}

.btn:hover {
    background: #e9ecef;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    gap: 4px;
}

/* Model Preview Components */
.preview-container {
    margin: 20px 0;
}

.preview-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.preview-title {
    flex: 1;
    font-weight: bold;
}

.iframe-preview {
    width: 100%;
    height: 600px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* ========================================
   UTILITY CLASSES AND ANIMATIONS
   ======================================== */

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

.katex-display {
    overflow-x: scroll;
}

hr {
    margin-top: 1.4em;
    margin-bottom: 1.4em;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ========================================
   SCROLLBAR STYLES
   ======================================== */

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: #e5e5e5;
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #d0d0d0;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .header-content {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }

    .header-content h1 {
        font-size: 20px;
        text-align: center;
        flex: 1;
        min-width: 0;
    }

    .header-controls {
        flex-shrink: 0;
    }

    .api-key-section {
        justify-content: center;
    }

    .api-key-section input {
        width: 240px;
    }

    .model-selector label {
        display: none;
    }

    .model-selector select {
        min-width: 80px;
    }

    .content {
        max-width: 85%;
    }

    .input-wrapper {
        border-radius: 20px;
    }

    #send-button {
        width: 40px;
        height: 40px;
    }

    .example-prompts {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .example-prompt {
        min-height: 60px;
    }
}