:root {
    --bg-color: #131314;
    --sidebar-bg: #1e1f20;
    --text-primary: #e3e3e3;
    --text-secondary: #c4c7c5;
    --accent-color: #a8c7fa;
    --border-color: rgba(255, 255, 255, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.08);
    --user-msg-bg: #282a2c;
    --ai-msg-bg: transparent;
    --transition-speed: 0.3s;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Noto Sans TC', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Material Symbols Adjustments */
.material-symbols-outlined {
    font-size: 24px;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

/* Common IconButton */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-speed);
}

.icon-btn:hover {
    background: var(--hover-bg);
}

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

/* --- Sidebar --- */
.sidebar {
    width: 180px;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 12px;
    transition: width var(--transition-speed) ease;
    overflow: hidden;
    white-space: nowrap;
    border-right: 1px solid var(--border-color);
}

.sidebar:not(.open) {
    width: 80px;
}

.sidebar:not(.open) .text,
.sidebar:not(.open) .recent-chats {
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    margin-bottom: 24px;
    padding-left: 8px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #1a1a1c;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 24px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    margin-bottom: 24px;
}

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

.sidebar:not(.open) .new-chat-btn {
    padding: 12px;
    border-radius: 50%;
    width: 48px;
}

.recent-chats {
    flex: 1;
    overflow-y: auto;
    transition: opacity 0.2s;
}

.recent-chats::-webkit-scrollbar {
    width: 4px;
}

.recent-chats::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.recent-chats h3 {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 0 16px 8px;
    font-weight: 500;
}

.recent-chats ul {
    list-style: none;
}

.recent-chats li {
    padding: 12px 16px;
    border-radius: 20px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
    display: flex;
    gap: 12px;
    align-items: center;
}

.recent-chats li:hover {
    background: var(--hover-bg);
}

.recent-chats li .material-symbols-outlined {
    font-size: 18px;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    background-color: var(--bg-color);
}

.main-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-left h2 {
    font-size: 20px;
    font-weight: 500;
    background: -webkit-linear-gradient(45deg, #a8c7fa, #d3e3fd);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mobile-menu-btn {
    display: none;
}

/* --- Chat Container --- */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.messages {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding-bottom: 40px;
}

/* Greeting Splash Screen */
.greeting-screen {
    text-align: center;
    margin-top: 15vh;
}

.greeting-screen h1 {
    font-size: 52px;
    margin-bottom: 16px;
    font-weight: 500;
    background: linear-gradient(74deg, #4285f4 0, #9b72cb 9%, #d96570 20%, #d96570 24%, #9b72cb 35%, #4285f4 44%, #9b72cb 50%, #d96570 56%, #131314 75%, #131314 100%);
    background-size: 400% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientFlow 8s ease inset;
}

@keyframes gradientFlow {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.greeting-screen p {
    color: var(--text-secondary);
    font-size: 20px;
}

/* Chat Bubbles */
.message {
    display: flex;
    gap: 20px;
    font-size: 16px;
    line-height: 1.6;
    animation: fadeIn 0.4s ease-out forwards;
}

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

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

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

.message.user .content {
    background: var(--user-msg-bg);
    padding: 12px 20px;
    border-radius: 20px;
    max-width: 80%;
    white-space: pre-wrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.message.ai .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a8c7fa, #d3e3fd);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.message.ai .avatar span {
    color: #1a1a1c;
    font-size: 20px;
}

.message.ai .content {
    max-width: 80%;
    color: var(--text-primary);
    padding-top: 5px;
}

/* Markdown styling inside AI response */
.message.ai .content p {
    margin-bottom: 14px;
}

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

.message.ai .content ul,
.message.ai .content ol {
    margin-left: 24px;
    margin-bottom: 14px;
}

.message.ai .content h1,
.message.ai .content h2,
.message.ai .content h3 {
    margin: 20px 0 10px;
    font-weight: 600;
}

.message.ai .content a {
    color: var(--accent-color);
    text-decoration: none;
}

.message.ai .content a:hover {
    text-decoration: underline;
}

.message.ai .content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14.5px;
}

.message.ai .content pre {
    background: #1e1f20;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 14px;
    border: 1px solid var(--border-color);
}

.message.ai .content blockquote {
    border-left: 4px solid var(--text-secondary);
    padding-left: 16px;
    color: var(--text-secondary);
    margin: 14px 0;
}

/* Typing / Loading Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 24px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes bounce {

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

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

/* --- Input Area --- */
.input-area {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(transparent, var(--bg-color) 30%);
    position: relative;
    z-index: 5;
}

.input-wrapper {
    width: 100%;
    max-width: 800px;
    background: #1e1f20;
    border-radius: 28px;
    display: flex;
    align-items: flex-end;
    padding: 12px 16px;
    gap: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.input-wrapper:focus-within {
    background: #232527;
    border-color: rgba(255, 255, 255, 0.1);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 200px;
    padding: 6px 0 6px 8px;
    line-height: 1.5;
}

#chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.send-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:not(:disabled) {
    color: var(--bg-color);
    background-color: var(--text-primary);
}

.send-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

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

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 10;
        height: 100%;
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar:not(.open) {
        transform: translateX(-100%);
        width: 280px;
    }

    .mobile-menu-btn {
        display: flex;
    }

    #menu-btn {
        display: none;
    }

    .greeting-screen h1 {
        font-size: 32px;
    }

    .message {
        gap: 12px;
    }

    .message.user .content {
        max-width: 90%;
    }

    .message.ai .content {
        max-width: 95%;
    }
}

/* --- Login Modal --- */
.modal {
    display: none;
    /* Controlled by JS */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(19, 19, 20, 0.85);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #1e1f20;
    padding: 40px;
    border-radius: 24px;
    width: 90%;
    max-width: 300px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    text-align: center;
    animation: fadeIn 0.4s ease-out;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    background: -webkit-linear-gradient(45deg, #a8c7fa, #d3e3fd);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.input-group {
    margin-bottom: 16px;
    position: relative;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    background: #232527;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    transition: all 0.2s;
}

.login-input:focus {
    border-color: var(--accent-color);
    background: #2a2c2e;
}

.login-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.login-error {
    color: #f28b82;
    font-size: 14px;
    margin-top: -8px;
    margin-bottom: 16px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.login-error.show {
    opacity: 1;
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: var(--text-primary);
    color: var(--bg-color);
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.login-btn:hover {
    background: #fff;
    transform: translateY(-1px);
}

.login-btn:active {
    transform: translateY(1px);
}