/* ============================================
   HJCYBERX GPT — Premium Dark Theme
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
    --bg-primary: #06060f;
    --bg-secondary: #0c0c1d;
    --bg-tertiary: #12122a;
    --bg-card: rgba(18, 18, 42, 0.6);
    --bg-glass: rgba(18, 18, 42, 0.45);
    --bg-input: rgba(22, 22, 50, 0.7);
    --bg-hover: rgba(167, 139, 250, 0.08);
    --bg-user-msg: linear-gradient(135deg, rgba(167, 139, 250, 0.15), rgba(6, 182, 212, 0.1));
    --bg-bot-msg: rgba(18, 18, 42, 0.5);
    --border-primary: rgba(167, 139, 250, 0.12);
    --border-focus: rgba(167, 139, 250, 0.4);
    --border-glass: rgba(255, 255, 255, 0.06);
    --text-primary: #e8e6f0;
    --text-secondary: #9896a8;
    --text-tertiary: #6b6980;
    --text-accent: #a78bfa;
    --accent-violet: #a78bfa;
    --accent-cyan: #06b6d4;
    --accent-emerald: #34d399;
    --gradient-accent: linear-gradient(135deg, #a78bfa, #06b6d4);
    --gradient-glow: radial-gradient(circle, rgba(167, 139, 250, 0.15), transparent 70%);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(167, 139, 250, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --sidebar-width: 280px;
    --topbar-height: 64px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    line-height: 1.6;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(167, 139, 250, 0.2);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(167, 139, 250, 0.35);
}

/* --- Animated Background --- */
.bg-animation {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: orbFloat 20s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.25), transparent 70%);
    top: -150px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.2), transparent 70%);
    bottom: -100px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(52, 211, 153, 0.15), transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(50px, -30px) scale(1.1); }
    50% { transform: translate(-30px, 50px) scale(0.9); }
    75% { transform: translate(-50px, -20px) scale(1.05); }
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(167, 139, 250, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(167, 139, 250, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, rgba(0,0,0,0.3), transparent 80%);
}

/* --- App Container --- */
.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-slow), opacity var(--transition-slow);
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border-glass);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.3)); }
    50% { filter: drop-shadow(0 0 14px rgba(167, 139, 250, 0.6)); }
}

.logo-text {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 12px 8px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
}
.new-chat-btn:hover {
    background: rgba(167, 139, 250, 0.12);
    border-color: var(--accent-violet);
    box-shadow: var(--shadow-glow);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.history-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-tertiary);
    padding: 8px 8px 6px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.835rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}
.history-item::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, rgba(12, 12, 29, 0.95));
    pointer-events: none;
}
.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.history-item.active {
    background: rgba(167, 139, 250, 0.1);
    color: var(--text-accent);
}
.history-item svg {
    flex-shrink: 0;
}

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

.model-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.model-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-emerald);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
    animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- Chat Main --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    height: var(--topbar-height);
    background: rgba(6, 6, 15, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-glass);
    z-index: 10;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.menu-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.top-bar-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-title h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--accent-emerald);
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-emerald);
    animation: dotPulse 2s ease-in-out infinite;
}

.clear-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.clear-btn:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

/* --- Chat Messages --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    scroll-behavior: smooth;
}

/* --- Welcome Screen --- */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    text-align: center;
    padding: 40px 20px;
    position: relative;
    animation: fadeInUp 0.6s ease;
}

.welcome-glow {
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.1), transparent 70%);
    border-radius: 50%;
    filter: blur(60px);
    top: 10%;
    pointer-events: none;
}

.welcome-icon {
    margin-bottom: 24px;
    animation: floatBounce 4s ease-in-out infinite;
}

@keyframes floatBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.gradient-text {
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 460px;
    margin-bottom: 40px;
    line-height: 1.7;
}

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 520px;
    width: 100%;
}

.suggestion-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    text-align: left;
    font-family: var(--font-sans);
    color: var(--text-primary);
}
.suggestion-card:hover {
    background: rgba(167, 139, 250, 0.08);
    border-color: rgba(167, 139, 250, 0.25);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.suggestion-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.suggestion-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.suggestion-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.suggestion-desc {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Message Bubbles --- */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    max-width: 780px;
    margin-left: auto;
    margin-right: auto;
    animation: fadeInUp 0.35s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
}

.message.bot .message-avatar {
    background: var(--gradient-accent);
    color: white;
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.3);
}

.message.user .message-avatar {
    background: rgba(167, 139, 250, 0.15);
    color: var(--accent-violet);
    border: 1px solid var(--border-primary);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message.user .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.message.user .message-bubble {
    background: var(--bg-user-msg);
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-top-right-radius: 4px;
    max-width: 85%;
}

.message.bot .message-bubble {
    background: rgba(14, 14, 34, 0.92);
    border: 1px solid var(--border-glass);
    border-top-left-radius: 4px;
}

.message-time {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-top: 6px;
    padding: 0 4px;
}

/* Code blocks in messages */
.message-bubble pre {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 10px 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
}

.message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.84rem;
    background: rgba(167, 139, 250, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-violet);
}

.message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 8px 4px;
    align-items: center;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* --- Input Area --- */
.input-area {
    padding: 12px 20px 16px;
    background: linear-gradient(to top, var(--bg-primary), transparent);
}

.input-container {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    transition: all var(--transition-base);
    backdrop-filter: blur(10px);
}
.input-container:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.08), var(--shadow-glow);
}

.input-container textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    padding: 4px 0;
}
.input-container textarea::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--gradient-accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-base);
    opacity: 0.4;
    transform: scale(0.9);
}
.send-btn:not(:disabled) {
    opacity: 1;
    transform: scale(1);
}
.send-btn:not(:disabled):hover {
    box-shadow: 0 0 20px rgba(167, 139, 250, 0.4);
    transform: scale(1.05);
}
.send-btn:not(:disabled):active {
    transform: scale(0.95);
}
.send-btn:disabled {
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 8px;
    max-width: 780px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Error Message Styling --- */
.message-bubble.error {
    border-color: rgba(248, 113, 113, 0.25);
    background: rgba(248, 113, 113, 0.05);
}

.error-text {
    color: #f87171;
}

/* ============================================
   RESPONSIVE — All Device Sizes
   ============================================ */

/* --- Safe area insets for notched devices (iPhone X+, etc.) --- */
@supports (padding: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-left: env(safe-area-inset-left);
    }
    .top-bar {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--topbar-height) + env(safe-area-inset-top));
    }
}

/* --- Use dvh for mobile browsers with dynamic address bar --- */
@supports (height: 100dvh) {
    .app-container {
        height: 100dvh;
    }
}

/* --- Touch-friendly defaults for all touch devices --- */
@media (pointer: coarse) {
    .suggestion-card {
        min-height: 56px;
    }
    .history-item {
        min-height: 44px;
        padding: 12px;
    }
    .send-btn {
        width: 44px;
        height: 44px;
    }
    .clear-btn,
    .menu-btn,
    .sidebar-toggle {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .menu-btn {
        display: none;
    }
    .sidebar-toggle {
        display: none;
    }
}

/* --- Ultra-wide desktops (1440px+) --- */
@media (min-width: 1440px) {
    .message {
        max-width: 860px;
    }
    .input-container {
        max-width: 860px;
    }
    .input-hint {
        max-width: 860px;
    }
    .welcome-subtitle {
        max-width: 520px;
    }
    .suggestion-grid {
        max-width: 600px;
    }
    .chat-messages {
        padding: 28px 32px;
    }
}

/* --- Standard desktops / Large tablets landscape (1024px–1439px) --- */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }
    .message {
        max-width: 680px;
    }
    .input-container {
        max-width: 680px;
    }
}

/* --- Tablets portrait & small laptops (768px–1023px) --- */
@media (max-width: 768px) {
    /* Sidebar becomes overlay drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        min-width: 280px;
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: block;
    }
    .menu-btn {
        display: block;
    }
    
    /* Sidebar overlay backdrop */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 150;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-base);
    }
    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    /* Welcome screen adjustments */
    .suggestion-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 440px;
        gap: 10px;
    }
    .welcome-title {
        font-size: 1.5rem;
    }
    .welcome-subtitle {
        font-size: 0.9rem;
        max-width: 380px;
        margin-bottom: 30px;
    }
    .welcome-icon svg {
        width: 48px;
        height: 48px;
    }

    /* Chat area */
    .chat-messages {
        padding: 16px 14px;
    }
    .input-area {
        padding: 10px 14px 16px;
    }
    .top-bar {
        padding: 12px 14px;
    }

    /* Messages */
    .message {
        gap: 10px;
        margin-bottom: 16px;
    }
    .message-avatar {
        width: 32px;
        height: 32px;
    }
    .message-bubble {
        padding: 12px 16px;
    }
    .message.user .message-bubble {
        max-width: 88%;
    }

    /* Kill all backdrop-filter on mobile — causes blur/rendering bugs */
    .sidebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: #11112a;
    }
    .sidebar-overlay {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(0, 0, 0, 0.6);
    }
    .top-bar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(6, 6, 15, 0.95);
    }
    .input-container {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(16, 16, 40, 0.95);
    }
    .message.bot .message-bubble {
        background: rgba(14, 14, 34, 0.98);
    }
    .history-item::after {
        background: linear-gradient(to right, transparent, #11112a);
    }
    .sidebar-header {
        border-bottom: 1px solid rgba(167, 139, 250, 0.1);
    }
    .sidebar-footer {
        border-top: 1px solid rgba(167, 139, 250, 0.1);
    }
}

/* --- Large phones (641px–767px) --- */
@media (max-width: 640px) {
    .suggestion-grid {
        grid-template-columns: 1fr;
        max-width: 360px;
    }
    .welcome-title {
        font-size: 1.35rem;
    }
    .welcome-screen {
        padding: 30px 16px;
    }
    .top-bar-title h1 {
        font-size: 0.9rem;
    }
    .status-indicator span {
        display: none;
    }
    .message-bubble pre {
        padding: 10px 12px;
        font-size: 0.78rem;
    }
}

/* --- Medium phones (481px–640px) --- */
@media (max-width: 480px) {
    .welcome-title {
        font-size: 1.2rem;
    }
    .welcome-subtitle {
        font-size: 0.82rem;
        margin-bottom: 24px;
        padding: 0 8px;
    }
    .welcome-icon svg {
        width: 42px;
        height: 42px;
    }
    .welcome-icon {
        margin-bottom: 18px;
    }
    .suggestion-card {
        padding: 12px 14px;
    }
    .suggestion-title {
        font-size: 0.8rem;
    }
    .suggestion-desc {
        font-size: 0.7rem;
    }
    .suggestion-icon {
        font-size: 1.2rem;
    }
    .message-bubble {
        padding: 10px 14px;
        font-size: 0.85rem;
        line-height: 1.6;
    }
    .message-avatar {
        width: 28px;
        height: 28px;
    }
    .message-avatar svg {
        width: 14px;
        height: 14px;
    }
    .message.bot .message-avatar {
        font-size: 0.7rem;
    }
    .message.user .message-avatar {
        font-size: 0.65rem;
    }
    .message {
        gap: 8px;
        margin-bottom: 14px;
    }
    .message.user .message-bubble {
        max-width: 90%;
    }
    .message-time {
        font-size: 0.62rem;
    }
    .input-container {
        padding: 8px 10px;
        border-radius: var(--radius-md);
    }
    .input-container textarea {
        font-size: 0.88rem;
    }
    .input-hint {
        font-size: 0.65rem;
    }
    .chat-messages {
        padding: 12px 10px;
    }
    .input-area {
        padding: 8px 10px 12px;
    }
    .top-bar {
        padding: 10px 12px;
        height: 56px;
    }
    .top-bar-title h1 {
        font-size: 0.85rem;
    }
    /* Reduce background orb sizes on mobile */
    .orb-1 {
        width: 280px;
        height: 280px;
    }
    .orb-2 {
        width: 220px;
        height: 220px;
    }
    .orb-3 {
        width: 160px;
        height: 160px;
    }
}

/* --- Small phones (381px–480px) --- */
@media (max-width: 380px) {
    .welcome-title {
        font-size: 1.05rem;
    }
    .welcome-subtitle {
        font-size: 0.78rem;
        margin-bottom: 20px;
    }
    .welcome-icon svg {
        width: 36px;
        height: 36px;
    }
    .suggestion-card {
        padding: 10px 12px;
        gap: 10px;
    }
    .suggestion-icon {
        font-size: 1.1rem;
    }
    .suggestion-title {
        font-size: 0.75rem;
    }
    .suggestion-desc {
        font-size: 0.65rem;
    }
    .message-bubble {
        padding: 9px 12px;
        font-size: 0.82rem;
    }
    .message-bubble pre {
        padding: 8px 10px;
        font-size: 0.72rem;
    }
    .top-bar-title h1 {
        font-size: 0.8rem;
        letter-spacing: 0;
    }
    .new-chat-btn {
        padding: 10px 14px;
        font-size: 0.8rem;
    }
    .logo-text {
        font-size: 0.82rem;
    }
}

/* --- Ultra-small phones (≤320px, e.g., iPhone SE / Galaxy Fold) --- */
@media (max-width: 320px) {
    .welcome-title {
        font-size: 0.95rem;
    }
    .welcome-subtitle {
        font-size: 0.72rem;
    }
    .suggestion-grid {
        gap: 8px;
    }
    .suggestion-card {
        padding: 8px 10px;
    }
    .message-bubble {
        padding: 8px 10px;
        font-size: 0.78rem;
    }
    .message {
        gap: 6px;
    }
    .message-avatar {
        width: 24px;
        height: 24px;
    }
    .input-container textarea {
        font-size: 0.82rem;
    }
    .send-btn {
        width: 36px;
        height: 36px;
    }
    .input-container {
        padding: 6px 8px;
    }
    .top-bar {
        padding: 8px 10px;
        height: 48px;
        gap: 8px;
    }
}

/* --- Landscape orientation on phones --- */
@media (max-height: 500px) and (orientation: landscape) {
    .welcome-screen {
        padding: 16px 20px;
        min-height: auto;
    }
    .welcome-icon {
        margin-bottom: 10px;
    }
    .welcome-icon svg {
        width: 32px;
        height: 32px;
    }
    .welcome-title {
        font-size: 1.1rem;
        margin-bottom: 6px;
    }
    .welcome-subtitle {
        font-size: 0.78rem;
        margin-bottom: 16px;
    }
    .suggestion-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        max-width: 480px;
    }
    .suggestion-card {
        padding: 8px 12px;
    }
    .chat-messages {
        padding: 8px 12px;
    }
    .input-area {
        padding: 6px 12px 8px;
    }
    .input-hint {
        display: none;
    }
    .top-bar {
        height: 44px;
        padding: 6px 12px;
    }
    .message {
        margin-bottom: 10px;
    }
    .welcome-glow {
        display: none;
    }
}

/* --- Accessibility: Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .orb {
        animation: none;
    }
    .welcome-icon {
        animation: none;
    }
    .logo-icon {
        animation: none;
    }
}

/* --- Print styles --- */
@media print {
    .sidebar,
    .bg-animation,
    .input-area,
    .top-bar,
    .sidebar-overlay {
        display: none !important;
    }
    .chat-main {
        width: 100%;
    }
    .chat-messages {
        overflow: visible;
        padding: 0;
    }
    .message-bubble {
        border: 1px solid #ccc;
        box-shadow: none;
    }
    body {
        background: white;
        color: black;
    }
}

/* --- Utility Animations --- */
.fade-in {
    animation: fadeInUp 0.35s ease;
}

/* --- Skeleton Loading --- */
.skeleton-line {
    height: 14px;
    background: linear-gradient(90deg, 
        rgba(167, 139, 250, 0.05), 
        rgba(167, 139, 250, 0.12), 
        rgba(167, 139, 250, 0.05)
    );
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.5s ease-in-out infinite;
    margin-bottom: 8px;
}
.skeleton-line:last-child {
    width: 65%;
    margin-bottom: 0;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
