/* Modern ChatGPT-like Light Theme Design */
:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #f0f0f0;
    --border-color: #e5e5e6;
    --border-hover: #d1d1d2;

    /* Text Colors */
    --text-primary: #353740;
    --text-secondary: #6e6e80;
    --text-tertiary: #8e8ea0;

    /* Accent Colors */
    --accent-primary: #10a37f;
    --accent-hover: #0d8f6e;
    --accent-light: #e6f7f3;

    /* Message Colors */
    --user-message-bg: #10a37f;
    --bot-message-bg: #f7f7f8;
    --user-text: #ffffff;
    --bot-text: var(--text-primary);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Spacing */
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-top: env(safe-area-inset-top, 0px);

    /* Enforce Light Scheme */
    color-scheme: light;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

html {
    background: #ffffff !important;
    color-scheme: light;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary) !important;
    background-color: #ffffff !important;
    color: var(--text-primary) !important;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    max-width: 100%;
    margin: 0 auto;
    background: var(--bg-primary) !important;
    background-color: #ffffff !important;
    position: relative;
}

/* Header */
.chat-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    padding-top: calc(12px + var(--safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.header-content {
    max-width: 768px;
    margin: 0 auto;
}

.header-content h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Welcome Screen */
.welcome-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: calc(80px + var(--safe-area-inset-top));
    padding-bottom: calc(120px + var(--safe-area-inset-bottom));
    z-index: 10;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-content {
    max-width: 640px;
    width: 100%;
    text-align: center;
    animation: fadeInUp 0.5s ease;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 24px;
    background: var(--accent-light);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
}

.welcome-title {
    font-size: 32px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome-description {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 32px;
}

.welcome-suggestions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.suggestion-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px 20px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 100%;
    text-align: left;
    font-family: inherit;
    width: 100%;
    pointer-events: auto !important;
    -webkit-tap-highlight-color: rgba(83, 52, 131, 0.2);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    position: relative;
    z-index: 10;
}

.suggestion-chip:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.suggestion-chip:active {
    transform: translateY(0);
    background: var(--accent-light);
    border-color: var(--accent-primary);
}

.suggestion-chip:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Messages Container */
.messages-container {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    /* Critical for scrolling in flex items */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px;
    padding-bottom: calc(20px + var(--safe-area-inset-bottom));
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 2;
}

/* .messages-container:empty {
    display: none;
} */

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

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeInUp 0.3s ease;
    max-width: 100%;
    padding: 0 8px;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
}

.message.user .message-avatar {
    background: var(--accent-primary);
}

.message-content {
    max-width: calc(100% - 48px);
    min-width: 0;
}

.message-content p {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.message.bot .message-content p {
    background: var(--bot-message-bg);
    color: var(--bot-text);
    border-top-left-radius: 4px;
}

.message.user .message-content p {
    background: var(--user-message-bg);
    color: var(--user-text);
    border-top-right-radius: 4px;
}

/* Image in Message */
.message-image {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-md);
    display: block;
    max-height: 400px;
    object-fit: contain;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.message-content:has(.message-image) p {
    margin-top: 8px;
}

.message-content:has(.message-image):not(:has(p)) {
    padding: 0;
}

/* Old Overlay Styles Removed */

/* Input Area */
.input-area {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    padding-bottom: max(12px, var(--safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    z-index: 100;
    flex-shrink: 0;
    width: 100%;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
    min-height: auto;
    max-height: none;
    box-sizing: border-box;
    /* Ensure consistent height across browsers */
    height: auto;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 768px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 8px;
    transition: all 0.2s;
    min-height: auto;
    height: auto;
    box-sizing: border-box;
    /* Prevent browser-specific height differences */
    line-height: normal;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    max-height: 44px;
    box-sizing: border-box;
}

/* Inline Image Preview */
.image-preview-container {
    padding: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    overflow: hidden;
    min-height: 60px !important;
    max-height: 76px !important;
    height: auto;
}

.preview-thumbnail-wrapper {
    position: relative;
    display: inline-block;
    width: auto;
    max-width: 200px !important;
    height: 60px !important;
    max-height: 60px !important;
    overflow: hidden;
    flex-shrink: 0;
    box-sizing: border-box;
}

.preview-thumbnail-wrapper img {
    height: 60px !important;
    max-height: 60px !important;
    width: auto !important;
    max-width: 200px !important;
    min-width: 0;
    min-height: 0;
    object-fit: cover !important;
    object-position: center;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

.remove-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #555;
    border: 2px solid var(--bg-secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s;
}

.remove-image-btn:hover {
    background: #333;
    transform: scale(1.1);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Browser-specific fixes for consistent sizing */
@supports (-webkit-appearance: none) {
    .chat-input {
        -webkit-appearance: none;
        -webkit-border-radius: var(--radius-md);
    }
    
    .input-controls {
        -webkit-box-align: center;
    }
}

/* Prevent image from expanding */
.preview-thumbnail-wrapper img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
}

.upload-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    max-width: 36px;
    max-height: 36px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    box-sizing: border-box;
    padding: 0;
}

.upload-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.upload-btn:active {
    transform: scale(0.95);
}

.chat-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 44px;
    min-height: 44px;
    height: 44px;
    line-height: 1.5;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    max-width: 36px;
    max-height: 36px;
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    box-sizing: border-box;
    padding: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    padding-left: 64px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--text-tertiary);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tablet and Desktop */
@media (min-width: 768px) {
    .chat-container {
        max-width: 800px;
        margin: 0 auto;
        box-shadow: 0 0 0 1px var(--border-color);
    }

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

    .preview-thumbnail-wrapper {
        max-width: 300px;
    }

    .welcome-content {
        max-width: 720px;
    }

    .welcome-suggestions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .suggestion-chip {
        width: auto;
        max-width: 300px;
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .chat-header {
        padding: 8px 20px;
        padding-top: calc(8px + var(--safe-area-inset-top));
    }

    .messages-container {
        padding: 12px 16px;
    }

    .welcome-screen {
        padding-top: calc(60px + var(--safe-area-inset-top));
        padding-bottom: calc(80px + var(--safe-area-inset-bottom));
    }
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
    .input-area {
        padding-bottom: max(12px, var(--safe-area-inset-bottom));
    }

    .messages-container {
        padding-bottom: max(20px, var(--safe-area-inset-bottom));
    }

    .welcome-screen {
        padding-bottom: max(120px, calc(120px + var(--safe-area-inset-bottom)));
    }
}

/* Force light theme - override any dark mode preferences */

:root {
    color-scheme: light;
}

/* Force light theme - override any dark mode preferences */
@media (prefers-color-scheme: dark) {
    /* Kept empty or removed entirely to prevent dark mode */
}