/* ============================================
   HexAI — Elowen-inspired Minimal Premium UI
   Clean, warm, soft design with hexagon branding
   ============================================ */

/* === Variables === */
:root {
    /* Warm light palette (like elowen) */
    --bg: #f5f3ef;
    --bg-alt: #eae7e1;
    --bg-card: #ffffff;
    --bg-card-hover: #f9f8f6;
    --bg-sidebar: #faf9f7;
    --bg-input: #ffffff;
    --bg-code: #fafafa;

    --text: #1c1917;
    --text-secondary: #78756f;
    --text-muted: #a8a49e;
    --text-faint: #d2cfca;

    --border: #e0ddd8;
    --border-light: #eceae6;
    --border-hover: #ccc9c3;

    --accent: #6d5cff;
    --accent-light: #8b7dff;
    --accent-bg: rgba(109, 92, 255, 0.08);
    --accent-glow: rgba(109, 92, 255, 0.15);

    --glow-color: rgba(109, 92, 255, 0.06);
    --glow-color-strong: rgba(109, 92, 255, 0.12);

    --success: #10b981;
    --error: #ef4444;

    /* Layout */
    --sidebar-w: 260px;
    --topbar-h: 52px;
    --chat-max-w: 740px;
    --input-radius: 24px;

    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-xl: 28px;
    --r-full: 9999px;

    /* Font */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', monospace;
    --fs-xs: 0.6875rem;
    --fs-sm: 0.8125rem;
    --fs-base: 0.9375rem;
    --fs-md: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.375rem;
    --fs-hero: 1.625rem;

    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --t-fast: 150ms;
    --t-mid: 250ms;
    --t-slow: 400ms;
}

/* === Dark theme === */
[data-theme="dark"] {
    --bg: #0a0a0a;
    --bg-alt: #111111;
    --bg-card: #171717;
    --bg-card-hover: #1e1e1e;
    --bg-sidebar: #0f0f0f;
    --bg-input: #171717;
    --bg-code: #111111;

    --text: #eeeae6;
    --text-secondary: #75726e;
    --text-muted: #4a4845;
    --text-faint: #2e2c2a;

    --border: #2a2826;
    --border-light: #1f1e1c;
    --border-hover: #3d3b39;

    --accent: #8b7dff;
    --accent-light: #a99eff;
    --accent-bg: rgba(139, 125, 255, 0.1);
    --accent-glow: rgba(139, 125, 255, 0.15);

    --glow-color: rgba(100, 120, 255, 0.04);
    --glow-color-strong: rgba(100, 120, 255, 0.08);
}

/* === Reset === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    display: flex;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

textarea {
    font-family: inherit;
    resize: none;
}

a {
    color: var(--accent);
    text-decoration: none;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--text-faint);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Ambient glow frame (elowen-style viewport glow) === */
.ambient-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    box-shadow:
        inset 0 0 120px 40px var(--glow-color),
        inset 0 0 300px 80px var(--glow-color);
    transition: box-shadow 1s ease;
}

[data-theme="dark"] .ambient-glow {
    box-shadow:
        inset 0 0 150px 50px rgba(60, 80, 200, 0.03),
        inset 0 0 350px 100px rgba(60, 80, 200, 0.02);
}

/* === Telegram Banner === */
.tg-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 40px 10px 16px;
    background: linear-gradient(135deg, #6d5cff 0%, #8b7dff 100%);
    color: white;
    font-size: var(--fs-sm);
    font-weight: 500;
    animation: bannerSlide 0.4s var(--ease);
}

.tg-banner.hidden {
    display: none;
}

@keyframes bannerSlide {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

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

.tg-banner-icon {
    font-size: 16px;
}

.tg-banner-text {
    text-align: center;
}

.tg-banner-text a {
    color: white;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.tg-banner-text a:hover {
    opacity: 0.85;
}

.tg-banner-close {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    transition: all var(--t-fast);
    cursor: pointer;
    border: none;
    background: none;
}

.tg-banner-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

/* When banner is visible, push content down */
body:has(.tg-banner:not(.hidden)) .main {
    padding-top: 40px;
}

body:has(.tg-banner:not(.hidden)) .sidebar {
    top: 40px;
    height: calc(100dvh - 40px);
}

/* Sidebar TG link */
.sidebar-tg-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    margin-bottom: 8px;
    font-size: var(--fs-xs);
    color: var(--accent);
    font-weight: 500;
    transition: opacity var(--t-fast);
    text-decoration: none;
}

.sidebar-tg-link:hover {
    opacity: 0.8;
    text-decoration: none;
}

.sidebar-tg-link svg {
    color: var(--accent);
    flex-shrink: 0;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-w);
    height: 100dvh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--t-slow) var(--ease);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-mid);
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    overflow: hidden;
}

.sidebar-top {
    margin-bottom: 20px;
}

.sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: all var(--t-fast);
}

.sidebar-new-chat:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.sidebar-section {
    flex: 1;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 0 12px 8px;
}

.sidebar-chat-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: var(--r-xs);
    cursor: pointer;
    transition: background var(--t-fast);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    position: relative;
}

.chat-item:hover {
    background: var(--bg-alt);
    color: var(--text);
}

.chat-item.active {
    background: var(--accent-bg);
    color: var(--accent);
    font-weight: 500;
}

.chat-item-icon {
    font-size: 13px;
    flex-shrink: 0;
}

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

.chat-item-delete {
    opacity: 0;
    width: 22px;
    height: 22px;
    border-radius: var(--r-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--t-fast);
    flex-shrink: 0;
}

.chat-item:hover .chat-item-delete {
    opacity: 1;
}

.chat-item-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.sidebar-bottom {
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
}

.sidebar-model-badge {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================
   MAIN
   ============================================ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    position: relative;
    z-index: 1;
}

/* === Topbar === */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    flex-shrink: 0;
    z-index: 50;
}

.topbar-sidebar-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--t-fast);
}

.topbar-sidebar-toggle:hover {
    background: var(--bg-alt);
    color: var(--text);
}

.topbar-spacer {
    flex: 1;
}

/* Model pill */
.model-selector {
    position: relative;
}

.model-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px 6px 10px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    transition: all var(--t-fast);
}

.model-pill:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--bg-card-hover);
}

.model-pill-icon {
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Model logo images */
.model-logo {
    width: 18px;
    height: 18px;
    object-fit: contain;
    vertical-align: middle;
    display: inline-block;
}

/* Bigger in dropdown */
.model-dropdown-icon .model-logo {
    width: 22px;
    height: 22px;
}

/* In message avatar */
.message-avatar .model-logo {
    width: 20px;
    height: 20px;
}

/* In sidebar chat item */
.chat-item-icon .model-logo {
    width: 16px;
    height: 16px;
}

/* In input model tag */
.input-model-tag .model-logo {
    width: 14px;
    height: 14px;
}

/* Light theme: dark-theme icons need inversion */
:root:not([data-theme="dark"]) .model-logo {
    filter: invert(1) hue-rotate(180deg);
}

.model-pill-name {
    font-weight: 500;
}

.model-pill-arrow {
    color: var(--text-muted);
    transition: transform var(--t-mid) var(--ease);
    margin-left: 2px;
}

.model-selector.open .model-pill-arrow {
    transform: rotate(180deg);
}

/* Dropdown */
.model-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    pointer-events: none;
    transition: all var(--t-mid) var(--ease);
    z-index: 200;
    overflow: hidden;
}

[data-theme="dark"] .model-dropdown {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
}

.model-selector.open .model-dropdown {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.model-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    text-align: left;
    transition: background var(--t-fast);
}

.model-dropdown-item:hover {
    background: var(--bg-alt);
}

.model-dropdown-item.active {
    background: var(--accent-bg);
}

.model-dropdown-item+.model-dropdown-item {
    border-top: 1px solid var(--border-light);
}

.model-dropdown-icon {
    font-size: 20px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    background: var(--bg-alt);
    flex-shrink: 0;
}

.model-dropdown-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-dropdown-name {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
}

.model-dropdown-desc {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* Topbar icon buttons (theme, settings) */
.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: all var(--t-fast);
    margin-left: 4px;
}

.topbar-icon-btn:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.icon-sun {
    display: none;
}

[data-theme="dark"] .icon-moon {
    display: none;
}

[data-theme="dark"] .icon-sun {
    display: block;
}

/* ============================================
   SETTINGS DRAWER
   ============================================ */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 290;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-mid);
}

.settings-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    max-width: 90vw;
    height: 100dvh;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-light);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--t-slow) var(--ease);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .settings-drawer {
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.3);
}

.settings-drawer.open {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
}

.settings-title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
}

.settings-close {
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--t-fast);
}

.settings-close:hover {
    background: var(--bg-alt);
    color: var(--text);
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
}

.settings-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
}

.settings-hint {
    font-size: var(--fs-xs);
    font-weight: 400;
    color: var(--text-muted);
}

.settings-prompt-wrap {
    margin-top: 10px;
}

.settings-textarea {
    width: 100%;
    padding: 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: var(--fs-sm);
    font-family: var(--font);
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    outline: none;
    transition: border-color var(--t-fast);
}

.settings-textarea:focus {
    border-color: var(--accent);
}

.settings-textarea::placeholder {
    color: var(--text-muted);
}

.settings-save-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 9px 16px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: white;
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: all var(--t-fast);
}

.settings-save-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Toggle switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--text-faint);
    border-radius: 24px;
    transition: background var(--t-mid);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform var(--t-mid) var(--ease);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.toggle input:checked+.toggle-slider {
    background: var(--accent);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

/* Pill option group */
.pill-group {
    display: flex;
    gap: 4px;
    background: var(--bg-alt);
    border-radius: var(--r-full);
    padding: 3px;
}

.pill-option {
    padding: 5px 14px;
    border-radius: var(--r-full);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-muted);
    transition: all var(--t-fast);
}

.pill-option:hover {
    color: var(--text-secondary);
}

.pill-option.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* Image options in input toolbar */
.input-img-opts {
    display: flex;
    gap: 4px;
}

.input-img-opts.hidden {
    display: none;
}

.input-opt-pill {
    padding: 3px 10px;
    border-radius: var(--r-full);
    background: var(--accent-bg);
    color: var(--accent);
    font-size: var(--fs-xs);
    font-weight: 600;
    transition: all var(--t-fast);
    border: 1px solid transparent;
}

.input-opt-pill:hover {
    background: var(--accent-glow);
}

/* Image in messages */
.message-text img {
    max-width: 100%;
    border-radius: var(--r-sm);
    margin: 8px 0;
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: transform var(--t-fast);
}

.message-text img:hover {
    transform: scale(1.01);
}

/* Attachment preview */
.attach-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    max-width: var(--chat-max-w);
    margin: 0 auto 6px;
    overflow-x: auto;
}

.attach-preview.hidden {
    display: none;
}

.attach-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: var(--r-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.attach-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attach-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    border: none;
    line-height: 1;
}

.attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 3px 8px !important;
}

.attach-btn svg {
    color: var(--accent);
}

/* Attachment preview */
.attach-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    max-width: var(--chat-max-w);
    margin: 0 auto 6px;
    overflow-x: auto;
}

.attach-preview.hidden {
    display: none;
}

.attach-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: var(--r-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.attach-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attach-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
    border: none;
    line-height: 1;
}

.attach-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 4px 10px !important;
    font-size: 13px;
}

.attach-btn.hidden {
    display: none;
}

.attach-btn svg {
    color: var(--accent);
}

.attach-btn:hover {
    background: var(--accent-glow);
}

/* Media loader (image/video generation) */
.media-loader {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg, var(--accent-glow), transparent 60%);
    border: 1px solid var(--border);
    animation: mediaLoaderFadeIn 0.4s var(--ease);
}

@keyframes mediaLoaderFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

/* Icon wrapper: ring + logo */
.media-loader-icon-wrap {
    position: relative;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
}

.media-loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    animation: mediaLoaderSpin 1.2s linear infinite;
}

.media-loader-logo {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-card);
}

.media-loader-logo .model-logo {
    width: 28px;
    height: 28px;
}

@keyframes mediaLoaderSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Text info */
.media-loader-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.media-loader-model {
    font-size: var(--fs-base);
    font-weight: 700;
    color: var(--text);
}

.media-loader-text {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 2px;
}

.media-loader-dots {
    display: inline-flex;
    gap: 1px;
    margin-left: 2px;
}

.media-loader-dots span {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    animation: mediaLoaderDot 1.4s ease-in-out infinite;
    line-height: 1;
}

.media-loader-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.media-loader-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes mediaLoaderDot {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

/* Generation stopped */
.generation-stopped {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: var(--r-md);
    background: rgba(255, 152, 0, 0.08);
    border: 1px solid rgba(255, 152, 0, 0.2);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-style: italic;
}

.generation-stopped svg {
    color: #ff9800;
    flex-shrink: 0;
}

/* ============================================
   CHAT AREA
   ============================================ */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* === Welcome === */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 24px 120px;
    text-align: center;
    animation: welcomeIn 0.7s var(--ease);
}

.welcome.hidden {
    display: none;
}

@keyframes welcomeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

/* Hexagon canvas */
.hex-container {
    width: 160px;
    height: 160px;
    margin-bottom: 28px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#hexCanvas {
    width: 160px;
    height: 160px;
}

.welcome-heading {
    font-size: var(--fs-hero);
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.03em;
}

.welcome-brand {
    color: var(--accent);
}

.welcome-sub {
    font-size: var(--fs-base);
    color: var(--text-secondary);
    margin-bottom: 36px;
}

/* Suggestion pills */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 600px;
}

.suggestion-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 20px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    transition: all var(--t-fast);
    white-space: nowrap;
}

.suggestion-pill:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--bg-card-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.suggestion-pill:active {
    transform: translateY(0);
}

@keyframes suggestIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.suggestion-pill svg {
    color: var(--accent);
    flex-shrink: 0;
}

/* === Cloud notice (local storage reminder) === */
.cloud-notice {
    margin-top: 32px;
    max-width: 440px;
    width: 100%;
    animation: cloudFloat 0.8s var(--ease) 0.5s both;
}

.cloud-notice.hidden {
    display: none;
}

@keyframes cloudFloat {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.96);
    }

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

@keyframes cloudFadeOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.96);
    }
}

.cloud-notice-inner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--r-md);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    box-shadow:
        0 4px 24px rgba(109, 92, 255, 0.04),
        0 1px 6px rgba(0, 0, 0, 0.03);
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

[data-theme="dark"] .cloud-notice-inner {
    background: rgba(30, 30, 30, 0.6);
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow:
        0 4px 24px rgba(139, 125, 255, 0.06),
        0 1px 6px rgba(0, 0, 0, 0.15);
}

.cloud-notice-icon {
    flex-shrink: 0;
    color: var(--accent);
    margin-top: 1px;
    opacity: 0.7;
}

.cloud-notice-text {
    font-size: var(--fs-xs);
    line-height: 1.55;
    color: var(--text-secondary);
    text-align: left;
}

.cloud-notice-text strong {
    color: var(--text);
    font-weight: 600;
}

.cloud-notice-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: var(--r-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--t-fast);
    cursor: pointer;
    border: none;
    background: none;
    opacity: 0.5;
}

.cloud-notice-close:hover {
    opacity: 1;
    background: var(--bg-alt);
    color: var(--text);
}

/* === Messages === */
.messages {
    padding: 20px;
    max-width: var(--chat-max-w);
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 14px;
    padding: 18px 0;
    animation: msgIn 0.35s var(--ease);
}

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

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

.message+.message {
    border-top: 1px solid var(--border-light);
}

/* Avatar */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 700;
}

.message-avatar.user {
    background: var(--accent);
    color: white;
    border-radius: var(--r-full);
}

.message-avatar.assistant {
    background: var(--bg-alt);
    border: 1px solid var(--border-light);
    font-size: 16px;
}

.message-content {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
    overflow-x: hidden;
}

.message-role {
    font-size: var(--fs-xs);
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.message-text {
    color: var(--text);
    line-height: 1.7;
    font-size: var(--fs-base);
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow-x: auto;
}

/* Markdown */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4 {
    margin: 18px 0 8px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}

.message-text h1 {
    font-size: 1.35em;
}

.message-text h2 {
    font-size: 1.2em;
}

.message-text h3 {
    font-size: 1.08em;
}

.message-text p {
    margin: 6px 0;
}

.message-text ul,
.message-text ol {
    margin: 8px 0;
    padding-left: 22px;
}

.message-text li {
    margin: 4px 0;
}

.message-text blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    border-left: 3px solid var(--accent);
    background: var(--accent-bg);
    border-radius: 0 var(--r-xs) var(--r-xs) 0;
    color: var(--text-secondary);
}

.message-text a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--accent-glow);
}

.message-text a:hover {
    text-decoration-color: var(--accent);
}

.message-text code:not(pre code) {
    background: var(--bg-alt);
    border: 1px solid var(--border-light);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.86em;
    color: var(--accent);
}

.message-text pre {
    margin: 14px 0;
    border-radius: var(--r-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-code);
    max-width: 100%;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border-light);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.copy-code-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--r-xs);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    transition: all var(--t-fast);
    font-family: var(--font);
}

.copy-code-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.copy-code-btn.copied {
    color: var(--success);
}

.message-text pre code {
    display: block;
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 0.84em;
    line-height: 1.6;
    overflow-x: auto;
    background: transparent;
}

.message-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    overflow: hidden;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.message-text th,
.message-text td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: var(--fs-sm);
}

.message-text th {
    background: var(--bg-alt);
    font-weight: 600;
}

.message-text tr:hover td {
    background: var(--bg-card-hover);
}

.message-text hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 18px 0;
}

.message-text strong {
    font-weight: 600;
}

/* Message actions */
.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    opacity: 0;
    transition: opacity var(--t-fast);
}

.message:hover .message-actions {
    opacity: 1;
}

.msg-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--r-xs);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    transition: all var(--t-fast);
}

.msg-action-btn:hover {
    background: var(--bg-alt);
    color: var(--text);
}

/* Typing */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

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

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

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.35;
    }

    30% {
        transform: translateY(-7px);
        opacity: 1;
    }
}

/* ============================================
   INPUT AREA
   ============================================ */
.input-area {
    padding: 0 20px 24px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.input-box {
    max-width: var(--chat-max-w);
    margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--input-radius);
    padding: 14px 18px 10px;
    transition: all var(--t-mid) var(--ease);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03), 0 1px 4px rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .input-box {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 1px 4px rgba(0, 0, 0, 0.15);
}

.input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow), 0 4px 20px rgba(0, 0, 0, 0.03);
}

.input-textarea {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: var(--fs-base);
    line-height: 1.5;
    max-height: 160px;
    min-height: 24px;
    padding: 0;
    scrollbar-width: thin;
}

.input-textarea::placeholder {
    color: var(--text-muted);
}

.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding-top: 4px;
}

.input-toolbar-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-model-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--r-full);
    background: var(--bg-alt);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    font-weight: 500;
    border: 1px solid var(--border-light);
}

.input-send {
    width: 34px;
    height: 34px;
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--text-faint);
    color: var(--bg);
    transition: all var(--t-fast);
}

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

.input-send:not(:disabled):hover {
    transform: scale(1.06);
}

.input-send:not(:disabled):active {
    transform: scale(0.95);
}

.input-send .hidden {
    display: none;
}

.input-send.streaming .send-icon {
    display: none;
}

.input-send.streaming .stop-icon {
    display: block !important;
}

/* ============================================
   TOASTS
   ============================================ */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: var(--r-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    font-size: var(--fs-sm);
    color: var(--text);
    animation: toastIn 0.3s var(--ease);
    max-width: 350px;
}

[data-theme="dark"] .toast {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.toast.removing {
    animation: toastOut 0.25s var(--ease) forwards;
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.2);
}

.toast.success {
    border-color: rgba(16, 185, 129, 0.2);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

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

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(30px);
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
    :root {
        --topbar-h: 48px;
        --input-radius: 20px;
    }

    .suggestions {
        gap: 8px;
    }

    .suggestion-pill {
        padding: 8px 16px;
        font-size: var(--fs-xs);
    }

    .welcome-heading {
        font-size: var(--fs-xl);
    }

    .welcome-sub {
        font-size: var(--fs-sm);
        margin-bottom: 28px;
    }

    .hex-container {
        width: 120px;
        height: 120px;
    }

    #hexCanvas {
        width: 120px;
        height: 120px;
    }

    .messages {
        padding: 10px;
    }

    .message {
        gap: 8px;
        padding: 12px 0;
        overflow: hidden;
    }

    .message-avatar {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    .message-content {
        max-width: calc(100vw - 70px);
        overflow-x: hidden;
    }

    .message-text {
        font-size: var(--fs-sm);
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .message-text pre {
        margin: 8px 0;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .message-text pre code {
        font-size: 0.76em;
        padding: 12px;
        white-space: pre;
        display: block;
        overflow-x: auto;
    }

    .message-text table {
        font-size: var(--fs-xs);
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .message-text th,
    .message-text td {
        padding: 6px 8px;
        white-space: nowrap;
    }

    .message-text blockquote {
        padding: 8px 12px;
        margin: 8px 0;
    }

    .message-text code:not(pre code) {
        word-break: break-all;
    }

    .input-area {
        padding: 0 10px 12px;
    }

    .input-box {
        padding: 10px 12px 8px;
    }

    .toast-container {
        right: 10px;
        left: 10px;
    }

    .toast {
        max-width: 100%;
    }

    .message-actions {
        opacity: 1;
    }

    .model-dropdown {
        min-width: 260px;
        right: -20px;
    }

    .cloud-notice {
        margin-top: 20px;
        max-width: 100%;
    }

    .cloud-notice-inner {
        padding: 10px 12px;
        gap: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print */
@media print {

    .sidebar,
    .topbar,
    .input-area,
    .sidebar-overlay,
    .toast-container,
    .message-actions,
    .welcome,
    .ambient-glow {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .main {
        height: auto;
        overflow: visible;
    }

    .chat-area {
        overflow: visible;
    }
}