:root {
    --bg-dark: #0a0a0f;
    --card-bg: rgba(25, 25, 30, 0.4);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent-1: #8a2be2;
    /* Purple */
    --accent-2: #ff00ff;
    /* Pink/Magenta */
    --accent-3: #00ffff;
    /* Cyan */
    --msg-user: rgba(138, 43, 226, 0.08);
    --msg-ai: transparent;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top right, #1a1a2e, #0a0a0f 60%);
    background-attachment: fixed;
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    /* Dynamic viewport for mobile */
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.app-layout {
    display: flex;
    height: 100%;
}

/* Sidebar: History Style */
.sidebar {
    width: 280px;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(40px);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--card-border);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
    padding: 20px 15px;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.sidebar-menu {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

.section-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-left: 10px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.model-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-option input {
    display: none;
}

.model-option .model-details {
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.model-option:hover .model-details {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: var(--card-border);
}

.model-option input:checked+.model-details {
    background: linear-gradient(45deg, rgba(0, 255, 255, 0.15), rgba(138, 43, 226, 0.15));
    border-color: var(--accent-3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.model-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.model-desc {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    padding: 12px 15px;
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.delete-chat-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: 0.2s;
    display: none;
}

.history-item:hover .delete-chat-btn {
    display: flex;
}

.delete-chat-btn:hover {
    color: #ff4d4d;
    background: rgba(255, 0, 0, 0.1);
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.history-item.active {
    background: rgba(0, 255, 255, 0.1);
    color: var(--accent-3);
    font-weight: 500;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--card-border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    width: 100%;
    max-width: 100vw;
    background: transparent;
    overflow: hidden;
    /* Prevent horizontal scrolling */
}

.mobile-header {
    display: flex;
    /* Always visible to provide menu access */
    padding: 12px 20px;
    background: rgba(10, 10, 15, 0.4);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    align-items: center;
    justify-content: space-between;
}

.mobile-header h1 {
    font-size: 1.1rem;
    font-weight: 800;
    background: linear-gradient(45deg, var(--accent-3), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 5px;
}

/* Chat Area */
.chat-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 0;
    scroll-behavior: smooth;
}

.welcome-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

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

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

.ai-logo {
    width: 70px;
    height: 70px;
    background: linear-gradient(45deg, var(--accent-3), var(--accent-1));
    color: white;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 20px;
    box-shadow: 0 10px 40px rgba(0, 255, 255, 0.2);
    animation: pulse 3s infinite alternate;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 10px 40px rgba(0, 255, 255, 0.3);
    }

    100% {
        transform: scale(1.05);
        box-shadow: 0 15px 60px rgba(138, 43, 226, 0.5);
    }
}

.welcome-screen h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    max-width: 300px;
}

/* Chat Messages */
.message {
    padding: 24px 20px;
    transition: background 0.3s;
    width: 100%;
}

.message.user {
    background: var(--msg-user);
}

.message.ai {
    background: transparent;
}

.message-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 16px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.avatar.user {
    background: #5436da;
}

.avatar.ai {
    background: linear-gradient(45deg, var(--accent-3), var(--accent-1));
}

.content {
    line-height: 1.6;
    font-size: 1rem;
    flex-grow: 1;
    overflow-x: auto;
    white-space: pre-wrap;
    color: rgba(255, 255, 255, 0.9);
}

/* Loading effect */
.thinking {
    display: flex;
    gap: 8px;
    align-items: center;
    height: 30px;
}

.dot {
    width: 10px;
    height: 10px;
    background: var(--accent-3);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    box-shadow: 0 0 10px var(--accent-3);
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
    background: var(--accent-3);
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
    background: var(--accent-2);
}

.dot:nth-child(3) {
    background: var(--accent-1);
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.3;
    }

    40% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* Input Area: Gemini Style */
.input-area {
    padding: 10px 15px calc(15px + env(safe-area-inset-bottom));
    max-width: 900px;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    background: transparent;
}

.input-container-glass {
    background: rgba(30, 30, 40, 0.6);
    border: 1px solid var(--card-border);
    border-radius: 28px;
    padding: 8px;
    backdrop-filter: blur(20px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    transition: border-color 0.3s;
}

.input-container-glass:focus-within {
    border-color: rgba(0, 255, 255, 0.3);
}

.input-box {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 8px 12px;
}

textarea {
    flex-grow: 1;
    background: none;
    border: none;
    color: white;
    font-size: 1.05rem;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    padding: 10px 0;
    outline: none;
}

textarea::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    background: linear-gradient(45deg, var(--accent-3), var(--accent-1));
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(0, 255, 255, 0.2);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(138, 43, 226, 0.4);
}

.send-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

/* Model Chips BELOW input */
.model-selector-container {
    padding: 10px 12px 5px;
}

.model-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    scrollbar-width: none;
    /* Hide scrollbar Firefox */
}

.model-chips::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar Chrome/Safari */
}

.model-chip input {
    display: none;
}

.chip-label {
    display: inline-block;
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.model-chip input:checked+.chip-label {
    background: rgba(0, 255, 255, 0.1);
    border-color: var(--accent-3);
    color: var(--accent-3);
}

.disclaimer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 12px;
    opacity: 0.6;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Mobile Tweaks (Android/iPhone) */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
        /* Default hidden */
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 80px rgba(0, 0, 0, 0.8);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 999;
        display: none;
    }

    .sidebar.open+.sidebar-overlay {
        display: block;
    }

    .message {
        padding: 16px 14px;
    }

    .message-inner {
        flex-direction: row;
        gap: 12px;
    }

    .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .input-area {
        padding: 10px 10px 20px;
    }

    .input-container-glass {
        border-radius: 20px;
    }

    .chat-area {
        padding: 15px 0;
        width: 100%;
        overflow-x: hidden;
    }

    .mobile-header h1 {
        font-size: 1rem;
    }

    .disclaimer {
        margin-top: 8px;
        font-size: 0.65rem;
    }

    .message {
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
    }

    .content {
        max-width: calc(100vw - 70px);
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}