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

:root {
    --bg-primary: #212121;
    --bg-secondary: #2f2f2f;
    --text-primary: #ececf1;
    --text-secondary: #8e8ea0;
    --border-color: #353535;
    --accent-color: #10a37f;
    --hover-color: #d1d1d6;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.container {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    background: rgba(33, 33, 33, 0.95);
    backdrop-filter: blur(10px);
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.header:hover .subtitle {
    opacity: 1;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

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

.messages::-webkit-scrollbar-thumb {
    background-color: #565869;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.messages::-webkit-scrollbar-thumb:hover {
    background-color: #6e6e80;
}

.message {
    display: flex;
    gap: 16px;
    padding: 16px 0;
    animation: fadeIn 0.3s ease-in;
}

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

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

.message-content {
    max-width: 70%;
    line-height: 1.6;
    font-size: 15px;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, #343434 100%);
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.user-message .message-content:hover {
    transform: translateY(-1px);
}

.bot-message .message-content {
    color: #ececf1;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #8e8ea0;
    border-radius: 50%;
    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% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

.input-container {
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    background: rgba(33, 33, 33, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    position: relative;
}

.user-input {
    flex: 1;
    background-color: var(--bg-secondary);
    border: 1px solid #565869;
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 15px;
    color: var(--text-primary);
    resize: none;
    font-family: inherit;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.user-input:focus {
    outline: none;
    border-color: #8e8ea0;
}

.user-input::placeholder {
    color: var(--text-secondary);
    transition: opacity 0.3s ease;
}

.user-input:focus::placeholder {
    opacity: 0.5;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ececf1 0%, #ffffff 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(236, 236, 241, 0.2);
}

.send-button:hover {
    background: linear-gradient(135deg, #d1d1d6 0%, #e1e1e6 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(236, 236, 241, 0.3);
}

.send-button:disabled {
    background: var(--bg-secondary);
    cursor: not-allowed;
    opacity: 0.5;
    transform: scale(1);
    box-shadow: none;
}

.send-button svg {
    color: #212121;
}

.send-button:disabled svg {
    color: #565869;
}

/* Tablet/iPad Responsiveness */
@media (min-width: 768px) and (max-width: 1366px) {
    .container {
        max-width: 100%;
        width: 100%;
    }

    .messages {
        padding: 20px 30px;
    }

    .message-content {
        max-width: 75%;
        font-size: 16px;
    }

    .input-container {
        padding: 20px 30px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .header {
        padding: 20px 30px;
    }
}

/* iPad Pro and larger tablets */
@media (min-width: 1024px) and (max-width: 1366px) {
    .container {
        max-width: 100%;
    }

    .messages {
        padding: 25px 40px;
    }

    .input-container {
        padding: 25px 40px;
        padding-bottom: calc(25px + env(safe-area-inset-bottom));
    }

    .header {
        padding: 25px 40px;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
    }

    .header {
        padding: 15px;
    }

    .header h1 {
        font-size: 18px;
    }

    .subtitle {
        font-size: 12px;
    }

    .messages {
        padding: 15px;
        gap: 15px;
    }

    .message-content {
        max-width: 85%;
        font-size: 14px;
    }

    .input-container {
        padding: 15px;
        gap: 10px;
    }

    .user-input {
        padding: 10px 16px;
        font-size: 14px;
    }

    .send-button {
        width: 36px;
        height: 36px;
    }

    .send-button svg {
        width: 20px;
        height: 20px;
    }
}

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

    .header h1 {
        font-size: 16px;
    }

    .messages {
        padding: 10px;
        gap: 12px;
    }

    .message-content {
        max-width: 90%;
        font-size: 14px;
        padding: 10px 14px;
    }

    .user-message .message-content {
        padding: 10px 14px;
    }

    .input-container {
        padding: 12px;
        gap: 8px;
    }

    .user-input {
        padding: 9px 14px;
        font-size: 14px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .header {
        padding: 10px;
    }

    .header h1 {
        font-size: 16px;
        margin-bottom: 2px;
    }

    .subtitle {
        font-size: 11px;
    }

    .messages {
        padding: 10px;
        gap: 10px;
    }

    .input-container {
        padding: 10px;
    }

    .user-input {
        padding: 8px 14px;
        max-height: 100px;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .container {
        min-height: -webkit-fill-available;
    }

    body {
        min-height: -webkit-fill-available;
    }

    .chat-container {
        flex: 1 1 auto;
        min-height: 0;
    }
}

/* High DPI screen adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .header,
    .input-container {
        backdrop-filter: blur(20px);
    }
}

/* Dark mode preference */
@media (prefers-color-scheme: light) {
    /* Users who prefer light mode still get dark theme
       since this is meant to look like ChatGPT */
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .messages {
        scroll-behavior: auto;
    }
}

/* Image sharing styles */
.image-container {
    margin: 10px 0;
}

.shared-image {
    max-width: 300px;
    width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 10px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}

.shared-image:hover {
    transform: scale(1.02);
}

.image-caption {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    margin: 5px 0 10px 0;
    opacity: 0.8;
}

.image-placeholder {
    padding: 40px 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    border: 2px dashed var(--border-color);
}

/* Mobile image adjustments */
@media (max-width: 768px) {
    .shared-image {
        max-width: 200px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .send-button {
        width: 44px;
        height: 44px;
        -webkit-tap-highlight-color: transparent;
    }

    .user-input {
        font-size: 16px; /* Prevents zoom on iOS */
        transform: translateZ(0); /* Prevents iOS keyboard issues */
        -webkit-appearance: none;
    }

    .messages {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}