:root {
    --mtm-primary: #00466b;
    --mtm-accent: #007bff;
    --mtm-accent-hover: #0a58ca;
    --mtm-light-blue: #0089b6;
    --mtm-teal: #006781;
    --bg-page: #ffffff;
    --bg-input-box: #f8f9fa;
    --bg-message-user: #00466b;
    --bg-message-assistant: #f8f9fa;
    --bg-sidebar: #f3f4f6;
    --bg-hover: rgba(0, 70, 107, 0.06);
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #7f7f7f;
    --border-color: #e0e0e0;
    --border-focus: #00466b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 4px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --sidebar-width: 280px;
    --transition: 200ms ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition), transform var(--transition);
    z-index: 20;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo img {
    height: 36px;
    width: auto;
    display: block;
}

.logo-title {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--mtm-primary);
}

.new-chat-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.new-chat-btn:hover {
    background: var(--bg-hover);
    color: var(--mtm-primary);
    border-color: var(--mtm-primary);
}

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-chats::-webkit-scrollbar { width: 4px; }
.sidebar-chats::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.chat-history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.chat-history-item:hover,
.chat-history-item.active {
    background: var(--bg-hover);
    color: var(--mtm-primary);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

.model-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 6px;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 15;
}

.sidebar-overlay.active {
    display: block;
}

/* ===================== MAIN CHAT ===================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-page);
    z-index: 2;
}

.sidebar-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--mtm-primary);
    border-color: var(--mtm-primary);
}

.chat-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--mtm-primary);
}

.header-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===================== CORNER DECORATIONS ===================== */
.corner-decoration {
    position: fixed;
    z-index: 10;
    pointer-events: none;
    width: 150px;
    height: auto;
}

.corner-bottom-left {
    bottom: 0;
    left: var(--sidebar-width);
    transition: left var(--transition);
}

.sidebar.collapsed ~ .corner-bottom-left {
    left: 0;
}

.corner-bottom-right {
    bottom: 0;
    right: 0;
}

/* ===================== MESSAGES ===================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    scroll-behavior: smooth;
    position: relative;
    z-index: 1;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.message {
    display: flex;
    gap: 14px;
    padding: 16px 24px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    animation: fadeIn 300ms ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 600;
}

.message.user .message-avatar { background: var(--mtm-primary); color: white; }
.message.assistant .message-avatar { background: var(--mtm-light-blue); color: white; }

.message-content {
    flex: 1;
    min-width: 0;
    line-height: 1.7;
    font-size: 0.938rem;
    color: var(--text-primary);
}

.message.user .message-content {
    background: var(--bg-message-user);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border-top-left-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-message-assistant);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-content p { margin-bottom: 0.75em; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 0.5em 0; padding-left: 1.5em; }
.message-content li { margin-bottom: 0.3em; }
.message-content strong { font-weight: 600; color: var(--mtm-primary); }
.message.user .message-content strong { color: white; }
.message-content code { background: rgba(0,70,107,0.08); padding: 2px 6px; border-radius: 4px; font-size: 0.875em; }

.typing-indicator { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-indicator span { width: 6px; height: 6px; background: var(--mtm-light-blue); 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% { opacity: 0.3; transform: scale(1); }
    30% { opacity: 1; transform: scale(1.2); }
}

/* ===================== WELCOME SCREEN ===================== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
}

.welcome-logo {
    height: 70px;
    width: auto;
    display: block;
    margin-bottom: 24px;
}

.welcome-screen h2 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--mtm-primary);
    margin-bottom: 10px;
}

.welcome-screen p {
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 32px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 600px;
    width: 100%;
}

.suggestion-card {
    background: var(--bg-input-box);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    text-align: left;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    transition: all var(--transition);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.suggestion-card:hover {
    background: var(--bg-hover);
    border-color: var(--mtm-primary);
    color: var(--mtm-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.suggestion-icon { font-size: 1.2rem; flex-shrink: 0; }

/* ===================== INPUT AREA ===================== */
.chat-input-area {
    padding: 12px 24px 8px;
    background: var(--bg-page);
    position: relative;
    z-index: 1;
}

.input-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input-box);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-sm);
}

.input-container:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(0,70,107,0.12);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.938rem;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    outline: none;
    padding: 6px 4px;
}

textarea::placeholder { color: #b6b6b6; }

.send-btn, .stop-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}

.send-btn { background: var(--mtm-primary); color: white; }
.send-btn:disabled { background: #d6d6d6; color: #999; cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: var(--mtm-accent-hover); transform: scale(1.05); }
.stop-btn { background: #dc3545; color: white; }
.stop-btn:hover { background: #c82333; }
.hidden { display: none !important; }

/* ===================== FOOTER ===================== */
.chat-footer {
    text-align: center;
    padding: 4px 24px 12px;
    position: relative;
    z-index: 1;
}

.disclaimer {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.footer-links { font-size: 0.75rem; }

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    margin: 0 4px;
    transition: color var(--transition);
}

.footer-links a:hover {
    color: var(--mtm-primary);
    text-decoration: underline;
}

.footer-links .sep { color: var(--text-muted); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        margin-left: 0;
        transform: translateX(-100%);
    }

    .sidebar.collapsed {
        margin-left: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }

    .suggestion-cards { grid-template-columns: 1fr; }
    .message { padding: 12px 16px; }
    .corner-decoration { width: 100px; }

    .corner-bottom-left {
        left: 0;
    }

    .sidebar.collapsed ~ .corner-bottom-left {
        left: 0;
    }
}

@media (max-width: 576px) {
    .corner-decoration { display: none; }
}
