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

:root {
    --bg-base: #FFF5F4;
    --bg-sidebar: #FBE9E7;
    --bg-surface: #FFFFFF;
    --bg-subtle: #F5DAD6;
    --bg-hover: #F0DCD8;
    --border-base: #F0DCD8;
    --text-primary: #2D2A26;
    --text-secondary: #6E6560;
    --text-muted: #8C7B73;
    --accent: #5C6B73;
    --accent-hover: #4A565C;
    --accent-text: #FFFFFF;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --font-sans: 'Plus Jakarta Sans', sans-serif;
    --font-serif: 'Newsreader', serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow-sm: 0 2px 10px rgba(226, 180, 176, 0.15);
    --shadow-md: 0 8px 24px rgba(92, 107, 115, 0.08);
    --composer-width: 800px;
}

[data-theme="dark"] {
    --bg-base: #1C1917; --bg-sidebar: #171412; --bg-surface: #24201D; --bg-subtle: #2D2825;
    --bg-hover: #38322E; --border-base: #332D29; --text-primary: #F5EDE8; --text-secondary: #B5A89F;
    --text-muted: #A89C96; --accent: #9CAF88; --accent-hover: #B3C4A0; --accent-text: #1C1917;
}
[data-theme="classy"] {
    --bg-base: #F8F3EA; --bg-sidebar: #F2EAD9; --bg-surface: #FFFCF5; --bg-subtle: #EDE3CE;
    --bg-hover: #E5D8BE; --border-base: #E5D8BE; --text-primary: #2A231B; --text-secondary: #6E5E4E;
    --text-muted: #9A8875; --accent: #8B6844; --accent-hover: #755535;
}
[data-theme="modern"] {
    --bg-base: #F5FAF8; --bg-sidebar: #EDF5F1; --bg-surface: #FFFFFF; --bg-subtle: #E2EFE9;
    --bg-hover: #D5E7DE; --border-base: #D5E7DE; --text-primary: #152722; --text-secondary: #516D64;
    --text-muted: #829E95; --accent: #148F70; --accent-hover: #0F735A;
}
[data-theme="ocean"] {
    --bg-base: #0F1722; --bg-sidebar: #0B121C; --bg-surface: #162131; --bg-subtle: #1F2E42;
    --bg-hover: #293C54; --border-base: #24374F; --text-primary: #F0F7FF; --text-secondary: #94B5D8;
    --text-muted: #5C7A9A; --accent: #38BDF8; --accent-hover: #14AEF7; --accent-text: #08243A;
}
[data-theme="sunset"] {
    --bg-base: #1F1719; --bg-sidebar: #191214; --bg-surface: #2A1F22; --bg-subtle: #3A2A2E;
    --bg-hover: #4A363B; --border-base: #3F2E33; --text-primary: #FAEDE9; --text-secondary: #C9ADA7;
    --text-muted: #8B706A; --accent: #F37055; --accent-hover: #E25B3E;
}
[data-theme="forest"] {
    --bg-base: #101A15; --bg-sidebar: #0C130F; --bg-surface: #182720; --bg-subtle: #21372C;
    --bg-hover: #2C4638; --border-base: #264032; --text-primary: #EFF9F2; --text-secondary: #99C2A7;
    --text-muted: #5E846B; --accent: #4ADE80; --accent-hover: #22C55E;
}
[data-theme="orchid"] {
    --bg-base: #181220; --bg-sidebar: #120D19; --bg-surface: #22192E; --bg-subtle: #302244;
    --bg-hover: #3E2C58; --border-base: #3A2A52; --text-primary: #F9F3FF; --text-secondary: #BDA7D7;
    --text-muted: #806A9A; --accent: #C084FC; --accent-hover: #A855F7;
}
[data-theme="nebula"] {
    --bg-base: #1C111E; --bg-sidebar: #150C17; --bg-surface: #27172A; --bg-subtle: #3A2240;
    --bg-hover: #4A2C52; --border-base: #442848; --text-primary: #FFF0F7; --text-secondary: #CCA0B9;
    --text-muted: #8E6580; --accent: #F472B6; --accent-hover: #EC4899;
}
[data-theme="slate"] {
    --bg-base: #14171D; --bg-sidebar: #0F1218; --bg-surface: #1D212A; --bg-subtle: #272D39;
    --bg-hover: #333B4A; --border-base: #2E3646; --text-primary: #F1F5F9; --text-secondary: #9AA8BC;
    --text-muted: #65748A; --accent: #94A3B8; --accent-hover: #CBD5E1;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    display: flex;
    overflow: hidden;
}

/* ============ SIDEBAR ============ */

.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border-base);
    transition: width 0.3s cubic-bezier(0.2, 0.9, 0.4, 1), transform 0.3s ease;
    padding: 16px 12px;
    position: relative;
    z-index: 100;
}

.sidebar.collapsed { width: 72px; padding: 16px 8px; }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; padding: 0 8px; height: 32px;
}

.brand-badge {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: var(--text-primary);
    font-size: 1.15rem; font-weight: 700;
}

.brand-logo { width: 28px; height: 28px; object-fit: contain; }

.collapse-btn {
    background: transparent; border: none; color: var(--text-muted);
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: 0.2s; flex-shrink: 0;
}
.collapse-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Collapsed State */
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .brand-badge { display: none; }
.sidebar.collapsed .collapse-btn { margin: 0 auto; }
.sidebar.collapsed .new-chat-btn { padding: 0; justify-content: center; height: 40px; width: 40px; margin: 0 auto 20px auto; border-radius: 50%; }
.sidebar.collapsed .new-chat-btn span { display: none; }
.sidebar.collapsed .section-label, 
.sidebar.collapsed .chat-list-wrapper { display: none; }
.sidebar.collapsed .nav-item span { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.sidebar.collapsed #authArea { display: none; }

.new-chat-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 10px; background: var(--bg-surface);
    border: 1px solid var(--border-base); border-radius: var(--radius-md);
    color: var(--text-primary); font-weight: 600; cursor: pointer;
    transition: 0.2s; margin-bottom: 20px;
}
.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--accent); }

.chat-list-wrapper { flex: 1; overflow-y: auto; overflow-x: hidden; }

.section-label {
    font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
    padding: 0 8px 8px 8px; text-transform: uppercase;
}

.chat-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 8px; border-radius: var(--radius-sm); cursor: pointer;
    color: var(--text-secondary); font-size: 0.85rem; transition: 0.2s;
    margin-bottom: 2px;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-item.active { background: var(--bg-surface); color: var(--text-primary); font-weight: 600; box-shadow: var(--shadow-sm); }

.chat-item-title { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .item-actions { opacity: 0; transition: opacity 0.2s; }
.chat-item:hover .item-actions, .chat-item.active .item-actions { opacity: 1; }
.item-action-trigger { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; }
.item-action-trigger:hover { color: var(--text-primary); }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border-base); }
.nav-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 10px 8px; background: transparent; border: none;
    color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
    cursor: pointer; border-radius: var(--radius-sm); transition: 0.2s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

.user-card { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 6px; border-radius: var(--radius-sm); cursor: pointer; }
.user-card:hover { background: var(--bg-hover); }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-base); }
.user-meta { flex: 1; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 700; }
.user-email { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign-out-btn { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; }
.sign-out-btn:hover { color: var(--text-primary); }

/* ============ MAIN ============ */

.main { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }

.mobile-header { display: none; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg-surface); border-bottom: 1px solid var(--border-base); }
.mobile-title { font-weight: 700; font-size: 1.1rem; }
.icon-btn { background: transparent; border: none; color: var(--text-primary); font-size: 1.4rem; cursor: pointer; }

.announcement-bar {
    background: var(--bg-surface); border-bottom: 1px solid var(--border-base);
    padding: 10px 16px 10px 20px; display: flex; align-items: center; gap: 12px;
    font-size: 0.85rem; box-shadow: var(--shadow-sm); z-index: 10;
}
.announcement-bar span { flex: 1; }
.text-accent { color: var(--accent); }

.close-announcement {
    background: transparent; border: none; color: var(--text-muted);
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.close-announcement:hover { background: var(--bg-hover); color: var(--text-primary); }

.messages-scroll {
    flex: 1; overflow-y: auto; padding: 32px 24px 180px 24px;
    display: flex; flex-direction: column;
}
.messages-container {
    max-width: var(--composer-width); margin: 0 auto; width: 100%;
    display: flex; flex-direction: column; gap: 32px;
}

.msg-row { display: flex; gap: 16px; width: 100%; align-items: flex-start; position: relative; }
.msg-row.user { justify-content: flex-end; }

.msg-avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: var(--bg-surface); border: 1px solid var(--border-base);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.msg-body { flex: 1; min-width: 0; }
.msg-row.user .msg-body {
    flex: 0 1 auto; max-width: 80%; background: var(--bg-surface);
    padding: 14px 20px; border-radius: var(--radius-lg); border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-base);
}

.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.msg-author { font-size: 0.85rem; font-weight: 700; }
.msg-time { font-size: 0.75rem; color: var(--text-muted); }

.msg-controls { display: flex; gap: 4px; margin-left: auto; opacity: 0; transition: opacity 0.2s; }
.msg-row:hover .msg-controls { opacity: 1; }
.msg-row.user .msg-controls { position: absolute; left: -46px; top: 10px; }

.msg-text { font-size: 0.95rem; line-height: 1.65; word-break: break-word; }
.msg-text p { margin-bottom: 12px; }
.msg-text h1, .msg-text h2, .msg-text h3 { font-family: var(--font-serif); margin: 16px 0 8px; }
.msg-text pre { background: var(--bg-sidebar); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; margin: 12px 0; }
.msg-text code { font-family: var(--font-mono); background: var(--bg-sidebar); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }
.msg-text table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.msg-text th, .msg-text td { padding: 10px; border: 1px solid var(--border-base); text-align: left; }
.msg-text th { background: var(--bg-sidebar); }
.msg-text blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 12px 0; color: var(--text-secondary); }

/* ============ COMPOSER ============ */

.composer-dock {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 20px 24px 32px 24px;
    background: linear-gradient(180deg, transparent 0%, var(--bg-base) 40%);
    display: flex; justify-content: center;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
}
.composer-card {
    max-width: var(--composer-width); width: 100%;
    background: var(--bg-surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); border: 1px solid var(--border-base);
    padding: 16px 20px; display: flex; flex-direction: column; gap: 12px;
    transition: border-color 0.2s;
}
.composer-card:focus-within { border-color: var(--accent); }

.composer-textarea {
    width: 100%; background: transparent; border: none; outline: none;
    font-family: inherit; font-size: 1rem; line-height: 1.5;
    color: var(--text-primary); resize: none; max-height: 200px;
}

.composer-bottom {
    display: flex; align-items: center; justify-content: space-between;
    border-top: 1px solid var(--border-base); padding-top: 12px;
}
.composer-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.model-select {
    background: var(--bg-base); border: 1px solid var(--border-base);
    border-radius: var(--radius-sm); color: var(--text-secondary);
    font-family: inherit; font-size: 0.8rem; font-weight: 600;
    padding: 6px 10px; cursor: pointer; outline: none;
}
.model-select:hover { border-color: var(--accent); color: var(--text-primary); }

.composer-tool-btn { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; padding: 6px; }
.composer-tool-btn:hover { color: var(--text-primary); }

.send-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: var(--accent); color: var(--accent-text); border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1.2rem; transition: 0.2s;
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }

/* ============ UTILS & DIALOGS ============ */

.welcome-view { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 50vh; text-align: center; }
.welcome-title { font-size: 2.2rem; font-weight: 700; margin-bottom: 10px; }
.welcome-title span { color: var(--accent); }
.welcome-sub { color: var(--text-muted); }

.dropdown {
    position: fixed; display: none; background: var(--bg-surface);
    border: 1px solid var(--border-base); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); z-index: 1000; min-width: 160px; padding: 4px;
}
.dropdown-item {
    padding: 8px 12px; font-size: 0.85rem; cursor: pointer;
    display: flex; justify-content: space-between; border-radius: 4px;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: #B56576; }

.attachment-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attachment-chip { display: flex; align-items: center; gap: 8px; background: var(--bg-base); border: 1px solid var(--border-base); padding: 6px 10px; border-radius: var(--radius-sm); font-size: 0.8rem; }
.attachment-chip .att-remove { background: transparent; border: none; cursor: pointer; color: var(--text-muted); }

.settings-dialog { border: none; padding: 0; background: transparent; max-width: 650px; width: 100%; margin: auto; }
.settings-dialog::backdrop { background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); }
.dialog-shell { background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); display: flex; flex-direction: column; overflow: hidden; max-height: 85vh; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border-base); }
.dialog-title { font-size: 1.1rem; font-weight: 700; }
.dialog-subtitle { font-size: 0.8rem; color: var(--text-muted); }
.dialog-tabs { display: flex; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--border-base); overflow-x: auto; }
.dialog-tab { background: transparent; border: none; padding: 8px 16px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm); white-space: nowrap; }
.dialog-tab.active { background: var(--bg-base); color: var(--text-primary); border: 1px solid var(--border-base); }
.dialog-body { padding: 24px; overflow-y: auto; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.theme-card { border: 1px solid var(--border-base); border-radius: var(--radius-sm); padding: 8px; cursor: pointer; text-align: center; }
.theme-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.theme-mini-ui { height: 40px; border-radius: 4px; display: flex; overflow: hidden; margin-bottom: 8px; }
.theme-mini-sidebar { width: 30%; }
.theme-mini-canvas { flex: 1; padding: 4px; display: flex; flex-direction: column; justify-content: space-between; }
.theme-mini-bubble { height: 8px; border-radius: 2px; }
.theme-mini-accent { width: 8px; height: 8px; border-radius: 50%; align-self: flex-end; }

.action-btn { background: var(--accent); color: var(--accent-text); border: none; padding: 8px 16px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }
.action-btn.secondary { background: var(--bg-base); border: 1px solid var(--border-base); color: var(--text-primary); }
.action-btn.danger { background: #B56576; color: white; }
.data-card { border: 1px solid var(--border-base); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; background: var(--bg-base); }

/* ============ RESPONSIVE MOBILE ============ */

.mobile-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(2px);
    z-index: 90; opacity: 0; transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        width: 280px !important;
        box-shadow: var(--shadow-md);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    
    /* Show overlay when sidebar is open */
    .sidebar.mobile-open + .mobile-overlay { display: block; opacity: 1; }

    .mobile-header { display: flex; }
    
    .announcement-bar { font-size: 0.75rem; padding: 8px 12px; }
    
    .messages-scroll { padding: 20px 16px 160px 16px; }
    
    .msg-row { gap: 12px; }
    .msg-row.user .msg-body { max-width: 90%; padding: 12px 16px; }
    .msg-row.user .msg-controls { position: static; margin-top: 4px; margin-left: 0; justify-content: flex-end; opacity: 1; }
    
    .composer-dock { padding: 12px 16px 20px 16px; }
    .composer-card { padding: 12px 16px; }
    .composer-textarea { font-size: 0.95rem; }

    .settings-dialog { max-width: 100%; height: 100%; margin: 0; }
    .dialog-shell { height: 100%; max-height: 100%; border-radius: 0; }
    .dialog-head { padding: 16px 20px; }
    .dialog-body { padding: 16px 20px 40px 20px; }
}