/* Dark Mode Default */
:root {
    --bg-gradient-start: #0f0c29;
    --bg-gradient-end: #302b63;
    --app-bg: #1a1a2e;
    --header-bg: rgba(26, 26, 46, 0.95);
    --border-color: rgba(255, 255, 255, 0.2);
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --input-bg: rgba(45, 45, 68, 0.95);
    --message-bot-bg: rgba(45, 45, 68, 0.95);
    --message-bot-text: #e2e8f0;
    --message-user-bg: linear-gradient(135deg, #8b5cf6 0%, #c084fc 100%);
    --avatar-bot-bg: rgba(255, 255, 255, 0.1);
    --gradient-primary: linear-gradient(135deg, #8b5cf6 0%, #c084fc 100%);
    --button-border: rgba(255, 255, 255, 0.3);
    --messages-bg: transparent;
    --pull-bg: rgba(45, 45, 68, 0.95);
}

/* Light Mode */
[data-theme="light"] {
    --bg-gradient-start: #e0eafc;
    --bg-gradient-end: #cfdef3;
    --app-bg: #ffffff;
    --header-bg: rgba(255, 255, 255, 0.95);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #1a1a2e;
    --text-secondary: #6c757d;
    --input-bg: #ffffff;
    --message-bot-bg: #f8f9fa;
    --message-bot-text: #2d3436;
    --message-user-bg: linear-gradient(135deg, #6c5ce7 0%, #a363d9 100%);
    --avatar-bot-bg: #e9ecef;
    --gradient-primary: linear-gradient(135deg, #6c5ce7 0%, #a363d9 100%);
    --button-border: rgba(0, 0, 0, 0.2);
    --messages-bg: transparent;
    --pull-bg: #f8f9fa;
}

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

/* Hide scrollbar */
::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

* {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

/* Pull to refresh styles */
.pull-to-refresh {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60px;
    margin-top: -60px;
    transition: transform 0.3s ease;
    transform: translateY(0);
}

.pull-indicator, .refresh-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--pull-bg);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
}

.pull-icon {
    width: 18px;
    height: 18px;
    stroke: var(--text-secondary);
    transition: transform 0.2s ease;
}

.pull-icon.spinning {
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.refresh-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--gradient-primary);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
    to { transform: rotate(360deg); }
}

/* Image upload button styles */
.image-upload-button {
    background: var(--gradient-primary);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-bottom: 4px;
    position: relative;
}

.image-upload-button:hover {
    transform: scale(1.05);
}

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

.image-upload-button svg {
    stroke: white;
    width: 16px;
    height: 16px;
}

/* Disabled upload button styles */
.image-upload-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.image-upload-button:disabled:hover {
    transform: none;
}

.image-upload-button:disabled:active {
    transform: none;
}

/* ACTIVE STATE - When image is uploaded (green) */
.image-upload-button.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.4);
    animation: pulse-green 0.5s ease;
}

@keyframes pulse-green {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Cancel Upload Button (Red X) - Small badge on top-right corner */
.cancel-upload-button {
    position: absolute;
    top: -6px;
    right: -6px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 2px solid var(--app-bg);
    border-radius: 50%;
    color: white;
    width: 18px;
    height: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
    padding: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.cancel-upload-button:hover {
    transform: scale(1.1);
}

.cancel-upload-button:active {
    transform: scale(0.9);
}

.cancel-upload-button svg {
    stroke: white;
    width: 10px;
    height: 10px;
    stroke-width: 2.5;
}

/* Disabled textarea styles */
.input-field:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: transparent;
}

.input-field:disabled::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

/* Image in message content (data view & practice) */
.message-content img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    margin: 8px 0;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s;
}

.message-content img:hover {
    transform: scale(1.02);
}

/* Image Modal Styles */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Desktop styles */
@media (min-width: 769px) {
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
        background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
        min-height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 20px;
        position: relative;
        overflow: auto;
    }
    
    .app {
        width: 900px;
        max-width: 90%;
        height: 85vh;
        background: var(--app-bg);
        border-radius: 32px;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        border: 1px solid var(--border-color);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }
    
    .header {
        padding: 14px 20px;
        background: var(--header-bg);
        border-bottom: 1px solid var(--border-color);
        text-align: center;
        position: relative;
        flex-shrink: 0;
    }
    
    .header h1 {
        color: var(--text-primary);
        font-size: 22px;
        font-weight: 700;
    }
    
    .theme-toggle {
        position: absolute;
        top: 50%;
        right: 16px;
        transform: translateY(-50%);
        background: rgba(128, 128, 128, 0.1);
        border: 2px solid var(--button-border);
        width: 38px;
        height: 38px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10;
        padding: 0;
        transition: all 0.2s ease;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .theme-toggle svg {
        width: 18px;
        height: 18px;
        stroke: var(--text-primary);
        stroke-width: 2;
    }
    
    .theme-toggle .sun-icon {
        display: block;
    }
    
    .theme-toggle .moon-icon {
        display: none;
    }
    
    [data-theme="dark"] .theme-toggle .sun-icon {
        display: none;
    }
    
    [data-theme="dark"] .theme-toggle .moon-icon {
        display: block;
    }
    
    .theme-toggle:hover {
        transform: translateY(-50%) scale(1.05);
        background: rgba(128, 128, 128, 0.2);
        border-color: var(--gradient-primary);
    }
    
    .messages-area {
        flex: 1;
        overflow-y: auto;
        padding: 12px 16px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        background: var(--app-bg);
        position: relative;
        scroll-behavior: smooth;
    }
    
    .scroll-anchor {
        height: 1px;
        width: 100%;
        opacity: 0;
        pointer-events: none;
    }
    
    .pull-to-refresh {
        display: none;
    }
    
    .message {
        display: flex;
        animation: fadeIn 0.3s ease;
    }
    
    .message.user {
        justify-content: flex-end;
    }
    
    .message.bot {
        justify-content: flex-start;
    }
    
    .message-content {
        padding: 6px 12px;
        border-radius: 16px;
        line-height: 1.4;
        font-size: 14px;
        font-weight: 500;
        word-wrap: break-word;
        white-space: normal;
        max-width: 70%;
    }
    
    .user .message-content {
        background: var(--message-user-bg);
        color: white;
        border-bottom-right-radius: 3px;
    }
    
    .bot .message-content {
        background: var(--message-bot-bg);
        color: var(--message-bot-text);
        border-bottom-left-radius: 3px;
        border: 1px solid var(--border-color);
    }
    
    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 8px;
        font-size: 14px;
        flex-shrink: 0;
    }
    
    .user .avatar {
        order: 2;
        background: var(--message-user-bg);
        margin: 0 0 0 8px;
    }
    
    .bot .avatar {
        background: var(--avatar-bot-bg);
        margin: 0 8px 0 0;
    }
    
    .input-area {
        padding: 10px 16px 16px;
        border-top: 1px solid var(--border-color);
        background: var(--app-bg);
        flex-shrink: 0;
    }
    
    .input-box {
        display: flex;
        gap: 8px;
        background: var(--input-bg);
        border-radius: 25px;
        padding: 4px 4px 4px 14px;
        border: 1px solid var(--border-color);
        transition: all 0.3s;
        align-items: flex-end;
        position: relative;
    }
    
    .input-box:focus-within {
        border-color: #8b5cf6;
        box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
    }
    
    .input-field {
        flex: 1;
        background: transparent;
        border: none;
        padding: 10px 0;
        color: var(--text-primary);
        font-size: 14px;
        outline: none;
        font-family: inherit;
        resize: none;
        overflow-y: auto;
        max-height: 120px;
        line-height: 1.4;
    }
    
    .input-field::placeholder {
        color: var(--text-secondary);
        font-size: 12px;
    }
    
    .send-button {
        background: var(--gradient-primary);
        border: none;
        color: white;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
        flex-shrink: 0;
        margin-bottom: 4px;
    }
    
    .send-button:hover {
        transform: scale(1.05);
    }
    
    .send-button:active {
        transform: scale(0.95);
    }
    
    .send-button svg {
        stroke: white;
        width: 16px;
        height: 16px;
    }
    
    .cancel-upload-button {
        width: 18px;
        height: 18px;
        top: -6px;
        right: -6px;
    }
    
    .cancel-upload-button svg {
        width: 10px;
        height: 10px;
    }
}

/* Mobile styles */
@media (max-width: 768px) {
    html, body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--app-bg);
    }
    
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
        background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
        overflow: hidden;
    }
    
    .app {
        width: 100%;
        height: 100%;
        background: var(--app-bg);
        display: flex;
        flex-direction: column;
        position: relative;
        overflow: hidden;
    }
    
    .header {
        padding: 12px 16px;
        background: var(--header-bg);
        border-bottom: 1px solid var(--border-color);
        text-align: center;
        position: relative;
        flex-shrink: 0;
        min-height: 54px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10;
    }
    
    .header h1 {
        font-size: 18px;
        margin: 0;
        color: var(--text-primary);
        font-weight: 700;
    }
    
    .theme-toggle {
        position: absolute;
        top: 50%;
        right: 12px;
        transform: translateY(-50%);
        background: rgba(128, 128, 128, 0.1);
        border: 2px solid var(--button-border);
        width: 36px;
        height: 36px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 100;
        padding: 0;
        transition: all 0.2s ease;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }
    
    .theme-toggle svg {
        width: 16px;
        height: 16px;
        stroke: var(--text-primary);
        stroke-width: 2;
    }
    
    .theme-toggle .sun-icon {
        display: block;
    }
    
    .theme-toggle .moon-icon {
        display: none;
    }
    
    [data-theme="dark"] .theme-toggle .sun-icon {
        display: none;
    }
    
    [data-theme="dark"] .theme-toggle .moon-icon {
        display: block;
    }
    
    .theme-toggle:active {
        transform: translateY(-50%) scale(0.95);
        background: rgba(128, 128, 128, 0.2);
    }
    
    .messages-area {
        flex: 1;
        overflow-y: auto;
        padding: 8px 10px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
        background: var(--app-bg);
        position: relative;
        overscroll-behavior: contain;
    }
    
    .scroll-anchor {
        height: 1px;
        width: 100%;
        opacity: 0;
        pointer-events: none;
        order: 9999;
    }
    
    .pull-to-refresh {
        position: relative;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 60px;
        margin-top: -60px;
        transform: translateY(0);
        transition: transform 0.2s ease;
        order: -1;
        flex-shrink: 0;
    }
    
    .pull-indicator, .refresh-indicator {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 8px 20px;
        background: var(--pull-bg);
        border-radius: 25px;
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        font-size: 13px;
        backdrop-filter: blur(10px);
        transition: all 0.2s ease;
    }
    
    .pull-icon {
        width: 18px;
        height: 18px;
        stroke: var(--text-secondary);
        transition: transform 0.2s ease;
    }
    
    .pull-icon.pull-active {
        transform: rotate(180deg);
    }
    
    .refresh-spinner {
        width: 16px;
        height: 16px;
        border: 2px solid var(--border-color);
        border-top-color: #8b5cf6;
        border-radius: 50%;
        animation: spinner-rotate 0.8s linear infinite;
    }
    
    .message {
        display: flex;
        animation: fadeIn 0.3s ease;
    }
    
    .message.user {
        justify-content: flex-end;
    }
    
    .message.bot {
        justify-content: flex-start;
    }
    
    .message-content {
        padding: 8px 12px;
        border-radius: 18px;
        line-height: 1.4;
        font-size: 15px;
        font-weight: 500;
        word-wrap: break-word;
        white-space: normal;
        max-width: 85%;
    }
    
    .user .message-content {
        background: var(--message-user-bg);
        color: white;
        border-bottom-right-radius: 4px;
    }
    
    .bot .message-content {
        background: var(--message-bot-bg);
        color: var(--message-bot-text);
        border-bottom-left-radius: 4px;
        border: 1px solid var(--border-color);
    }
    
    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 6px;
        font-size: 14px;
        flex-shrink: 0;
    }
    
    .user .avatar {
        order: 2;
        background: var(--message-user-bg);
        margin: 0 0 0 6px;
    }
    
    .bot .avatar {
        background: var(--avatar-bot-bg);
        margin: 0 6px 0 0;
    }
    
    .input-area {
        padding: 10px 12px;
        border-top: 1px solid var(--border-color);
        background: var(--app-bg);
        flex-shrink: 0;
        z-index: 10;
    }
    
    .input-box {
        display: flex;
        gap: 10px;
        background: var(--input-bg);
        border-radius: 25px;
        padding: 6px 6px 6px 16px;
        border: 1px solid var(--border-color);
        transition: all 0.3s;
        align-items: flex-end;
        position: relative;
    }
    
    .input-box:focus-within {
        border-color: #8b5cf6;
        box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
    }
    
    .input-field {
        flex: 1;
        background: transparent;
        border: none;
        padding: 10px 0;
        color: var(--text-primary);
        font-size: 16px;
        outline: none;
        font-family: inherit;
        resize: none;
        overflow-y: auto;
        max-height: 120px;
        line-height: 1.4;
    }
    
    .input-field::placeholder {
        color: var(--text-secondary);
        font-size: 14px;
        opacity: 0.7;
    }
    
    .send-button {
        background: var(--gradient-primary);
        border: none;
        color: white;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
        flex-shrink: 0;
        margin-bottom: 4px;
    }
    
    .send-button:active {
        transform: scale(0.92);
    }
    
    .send-button svg {
        stroke: white;
        width: 16px;
        height: 16px;
    }
    
    .image-upload-button {
        width: 38px;
        height: 38px;
    }
    
    .image-upload-button svg {
        width: 16px;
        height: 16px;
    }
    
    .cancel-upload-button {
        width: 20px;
        height: 20px;
        top: -6px;
        right: -6px;
    }
    
    .cancel-upload-button svg {
        width: 11px;
        height: 11px;
    }
    
    .typing-indicator {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 8px 12px;
        background: var(--message-bot-bg);
        border-radius: 18px;
        width: fit-content;
        border: 1px solid var(--border-color);
        font-size: 13px;
        color: var(--text-secondary);
    }
    
    .typing-indicator span {
        width: 6px;
        height: 6px;
        background: var(--gradient-primary);
        border-radius: 50%;
        animation: typing 1.4s infinite;
    }
    
    .typing-indicator span:nth-child(2) {
        animation-delay: 0.2s;
    }
    
    .typing-indicator span:nth-child(3) {
        animation-delay: 0.4s;
    }
    
    @keyframes typing {
        0%, 60%, 100% {
            transform: translateY(0);
            opacity: 0.5;
        }
        30% {
            transform: translateY(-6px);
            opacity: 1;
        }
    }
    
    /* Safe area support */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .input-area {
            padding-bottom: calc(10px + env(safe-area-inset-bottom));
        }
        .header {
            padding-top: calc(12px + env(safe-area-inset-top));
        }
    }
}

/* Small phones */
@media (max-width: 480px) {
    .message-content {
        padding: 6px 10px;
        font-size: 14px;
        border-radius: 16px;
    }
    
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
        margin: 0 4px;
    }
    
    .user .avatar {
        margin: 0 0 0 4px;
    }
    
    .bot .avatar {
        margin: 0 4px 0 0;
    }
    
    .send-button {
        width: 36px;
        height: 36px;
    }
    
    .send-button svg {
        width: 14px;
        height: 14px;
    }
    
    .image-upload-button {
        width: 36px;
        height: 36px;
    }
    
    .image-upload-button svg {
        width: 14px;
        height: 14px;
    }
    
    .cancel-upload-button {
        width: 18px;
        height: 18px;
        top: -5px;
        right: -5px;
    }
    
    .cancel-upload-button svg {
        width: 10px;
        height: 10px;
    }
    
    .theme-toggle {
        width: 34px;
        height: 34px;
        right: 10px;
    }
    
    .theme-toggle svg {
        width: 14px;
        height: 14px;
    }
    
    .pull-to-refresh {
        min-height: 50px;
        margin-top: -50px;
    }
    
    .pull-indicator, .refresh-indicator {
        padding: 6px 16px;
        font-size: 12px;
    }
}

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

.theme-toggle:focus {
    outline: none;
}

.message-content {
    word-wrap: break-word;
    white-space: pre-wrap;
}
