/* Modernized Style CSS */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    --bmkg-blue: #1e40af;
    --bmkg-green: #059669;
    --bmkg-light-blue: #3b82f6;
    --bmkg-light-green: #10b981;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.5);
    --blur: 12px;

    /* Animated background blobs */
    --blob-color-1: rgba(30, 64, 175, 0.07);
    --blob-color-2: rgba(5, 150, 105, 0.06);
    --blob-color-3: rgba(59, 130, 246, 0.04);

    /* Semi-transparent panel backgrounds (lets blobs show through) */
    --sidebar-bg: rgba(248, 250, 252, 0.84);
    --main-chat-bg: rgba(255, 255, 255, 0.87);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;

    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);

    /* Animated background blobs — dark mode */
    --blob-color-1: rgba(59, 130, 246, 0.13);
    --blob-color-2: rgba(16, 185, 129, 0.10);
    --blob-color-3: rgba(99, 102, 241, 0.07);

    /* Semi-transparent panel backgrounds — dark mode */
    --sidebar-bg: rgba(30, 41, 59, 0.82);
    --main-chat-bg: rgba(15, 23, 42, 0.86);
}

/* ================================================================
   ANIMATED BACKGROUND
   Two large blurred orbs drift slowly behind all UI panels.
   Panels use semi-transparent backgrounds so orbs show through.
   ================================================================ */

body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
    will-change: transform;
}

body::before {
    width: 80vmax;
    height: 80vmax;
    top: -30vmax;
    left: -20vmax;
    background: radial-gradient(ellipse at center, var(--blob-color-1) 0%, transparent 68%);
    animation: klimaBlob1 36s ease-in-out infinite;
}

body::after {
    width: 68vmax;
    height: 68vmax;
    bottom: -25vmax;
    right: -18vmax;
    background: radial-gradient(ellipse at center, var(--blob-color-2) 0%, transparent 68%);
    animation: klimaBlob2 44s ease-in-out infinite;
}

@keyframes klimaBlob1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    30%       { transform: translate(7vw, 5vh) scale(1.07); }
    65%       { transform: translate(-5vw, 9vh) scale(0.95); }
}

@keyframes klimaBlob2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    40%       { transform: translate(-8vw, -6vh) scale(1.09); }
    78%       { transform: translate(6vw, -4vh) scale(0.93); }
}

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

button,
input,
textarea,
select {
    font-family: 'Plus Jakarta Sans', sans-serif;
}

/* Default hidden on desktop */
.mobile-toggle {
    display: none;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100vh;
    overflow: hidden;
}

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

/* Glassmorphism Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    transition: width 0.3s ease, padding 0.3s ease;
    z-index: 50;
    position: relative;
    backdrop-filter: blur(10px);
    overflow: hidden;
}

/* Collapsed Sidebar State */
.sidebar.collapsed {
    width: 72px;
    padding: 24px 14px;
}

/* Hide sidebar content when collapsed (but keep sidebar-bottom visible) */
.sidebar.collapsed .quick-topics,
/* Removed sidebar-actions hiding to allow icons */
.sidebar.collapsed .experimental-badge,
.sidebar.collapsed .ai-warning {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    visibility: hidden;
}

/* Sidebar Actions Layout in Collapsed Mode */
.sidebar.collapsed .sidebar-actions {
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
}

/* Show only logo when collapsed, hide title */
.sidebar.collapsed .sidebar-branding {
    flex-direction: column;
    gap: 0;
}

.sidebar.collapsed .sidebar-title {
    display: none;
}

.sidebar.collapsed .bmkg-logo {
    height: 40px;
}

.sidebar.collapsed #btnToggleSidebar {
    opacity: 1;
    pointer-events: auto;
}

.sidebar.collapsed .sidebar-actions {
    justify-content: center;
}

.sidebar.collapsed .sidebar-header {
    margin-bottom: 16px;
}

/* Show sidebar-bottom icons but hide text when collapsed */
.sidebar.collapsed .sidebar-bottom {
    padding-top: 12px;
    border-top: none;
}

.sidebar.collapsed .guide-btn,
.sidebar.collapsed .theme-toggle {
    justify-content: center;
    padding: 10px;
}

.sidebar.collapsed .guide-btn span:last-child,
.sidebar.collapsed .theme-toggle .theme-text {
    display: none;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 48px;
    /* Increased from 24px */
}

/* Sidebar Branding - Logo + Title */
.sidebar-branding {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.bmkg-logo {
    height: 50px;
    width: auto;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.sidebar-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    font-size: 2rem;
    background: linear-gradient(to right, #1e40af, #059669);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--bmkg-blue), var(--bmkg-green));
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.95rem;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Sidebar Action Buttons (Icon Style) */
.sidebar-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.sidebar-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-icon-btn:hover {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.1), rgba(5, 150, 105, 0.1));
    border-color: var(--bmkg-blue);
    transform: translateY(-2px);
}

.sidebar-icon-btn svg {
    stroke: var(--text-primary);
}

/* Chat History Box Styling */
.chat-history {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    background: var(--bg-primary);
    /* Use primary bg for contrast in sidebar */
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chat-history-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 700;
    padding-left: 4px;
    /* Align with items */
}

/* Quick Topics - Replaces Chat History */
.quick-topics {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(30, 64, 175, 0.2) transparent;
}

/* Webkit scrollbar styling for elegant appearance */
.quick-topics::-webkit-scrollbar {
    width: 6px;
}

.quick-topics::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.quick-topics::-webkit-scrollbar-thumb {
    background: rgba(30, 64, 175, 0.15);
    border-radius: 10px;
    transition: background 0.2s ease;
}

.quick-topics::-webkit-scrollbar-thumb:hover {
    background: rgba(30, 64, 175, 0.3);
}

/* Smooth scroll behavior */
.quick-topics {
    scroll-behavior: smooth;
}

.quick-topics-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* BMKG Portal Links */
.bmkg-portal-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.portal-link-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
}

.portal-link-card:hover {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.06), rgba(5, 150, 105, 0.06));
    border-color: #1e40af;
    transform: translateX(4px);
    color: var(--text-primary);
}

.portal-link-card:active {
    transform: translateX(2px);
}

/* ... existing code ... */

/* Input Area - Fixed at Bottom */
/* Input Area - Floating at Bottom */
.chat-input-container {
    position: fixed;
    bottom: 30px;
    left: calc(280px + (100% - 280px - 840px) / 2);
    right: auto;
    width: 100%;
    max-width: 840px;
    padding: 0;
    background: transparent;
    transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100;
}

/* Initial State (Floating Centered) */
.chat-input-container.centered {
    bottom: 50%;
    transform: translateY(50%);
}

.history-item {
    padding: 12px;
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.history-item:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.experimental-badge {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    font-size: 0.7rem;
    padding: 6px 12px;
    border-radius: 20px;
    text-align: center;
    font-weight: 700;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.2);
}

.ai-warning {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 8px;
    background-color: var(--bg-primary);
}

.guide-btn,
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    background: transparent;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    font-weight: 500;
}

.guide-btn:hover,
.theme-toggle:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

.theme-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Main Content Wrapper - contains both scrollable chat and fixed input */
.main-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Main Chat Area - scrollable message container */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--main-chat-bg);
    overflow-y: auto;
    /* Move scroll to main-chat so scrollbar is at edge */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    scroll-behavior: smooth;
    transition: all 0.3s ease;
}

.chat-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 10;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .chat-header {
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    font-size: 2rem;
    /* Increased size */
    background: linear-gradient(to right, #1e40af, #059669);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.chat-messages {
    flex: 1;
    overflow-y: visible;
    /* Let parent handle scroll */
    padding: 30px 20px 180px 20px;
    /* Reduced top padding since header is removed */
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 840px;
    /* Match input container width */
    width: 100%;
    margin: 0 auto;
}

.chat-messages.centered {
    justify-content: center;
    padding-bottom: 24px;
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    width: 100%;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    background-color: white;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

.message-content {
    flex: 1;
    line-height: 1.7;
    font-size: 1rem;
    color: var(--text-primary);
}

/* User Message: DOM is [Content, Avatar]. Default flex is Row. 
   So Visual is [Content, Avatar] (Avatar Right).
   We remove/reset flex-direction just to be safe. */
.message.user {
    flex-direction: row;
    justify-content: flex-end;
    /* Push to right */
}

.message.user .message-content {
    background-color: var(--bg-tertiary);
    padding: 16px 20px;
    border-radius: 20px 20px 4px 20px;
    max-width: 80%;
    flex: initial;
    box-shadow: var(--shadow-sm);
}

.message.assistant .message-content {
    padding-top: 8px;
}

/* Input Area */
.chat-input-container {
    position: absolute;
    bottom: 40px;
    /* Center using same method as chat-messages */
    left: 0;
    right: 0;
    margin: 0 auto;
    width: calc(100% - 40px);
    max-width: 840px;
    transition: all 0.3s ease;
    z-index: 20;
}

.chat-input-container.centered {
    bottom: 50%;
    transform: translateY(50%);
    /* Only vertical adjust */
}

.input-wrapper {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 12px 16px;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.input-wrapper.glow-blue {
    box-shadow: 0 0 20px rgba(54, 162, 235, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(54, 162, 235, 0.6);
}

.input-wrapper.glow-green {
    box-shadow: 0 0 20px rgba(75, 192, 192, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(75, 192, 192, 0.6);
}

.input-wrapper.glow-red {
    box-shadow: 0 0 20px rgba(255, 99, 71, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 99, 71, 0.6);
}

.input-wrapper.glow-purple {
    box-shadow: 0 0 20px rgba(147, 51, 234, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(147, 51, 234, 0.6);
}



[data-theme="dark"] .input-wrapper {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .input-wrapper.glow-blue {
    box-shadow: 0 0 25px rgba(54, 162, 235, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(54, 162, 235, 0.8);
}

[data-theme="dark"] .input-wrapper.glow-green {
    box-shadow: 0 0 25px rgba(75, 192, 192, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(75, 192, 192, 0.8);
}

[data-theme="dark"] .input-wrapper.glow-red {
    box-shadow: 0 0 25px rgba(255, 99, 71, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 99, 71, 0.8);
}

[data-theme="dark"] .input-wrapper.glow-purple {
    box-shadow: 0 0 25px rgba(147, 51, 234, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(147, 51, 234, 0.8);
}

.input-wrapper:focus-within {
    border-color: var(--bmkg-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Input Options Container (Holds both dropdowns) */
.input-options {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

/* Tone Dropdown (Mode Respon) */
.tone-dropdown,
.data-dropdown {
    position: relative;
    display: flex;
    flex-shrink: 0;
}

/* Button Styles for both dropdowns */
.tone-dropdown-btn,
.data-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.tone-dropdown-btn:hover,
.data-dropdown-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--bmkg-blue);
    color: var(--text-primary);
}

.tone-dropdown-icon,
.data-dropdown-icon {
    font-size: 1rem;
}

.tone-dropdown-chevron,
.data-dropdown-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.tone-dropdown.open .tone-dropdown-chevron,
.data-dropdown.open .data-dropdown-chevron {
    transform: rotate(180deg);
}

/* Dropdown Menus */
.tone-dropdown-menu,
.data-dropdown-menu {
    position: absolute;
    /* top: 100%; handled by shared logic or specific overrides */
    left: 0;
    margin-top: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: all 0.2s ease;
    z-index: 100;
    overflow: hidden;
}

.tone-dropdown.open .tone-dropdown-menu,
.data-dropdown.open .data-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Dropdown opens upward when chat box is at bottom */
.chat-input-container:not(.centered) .tone-dropdown-menu,
.chat-input-container:not(.centered) .data-dropdown-menu {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 6px;
}

/* Menu Options */
.tone-menu-option,
.data-menu-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.tone-menu-option:hover,
.data-menu-option:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tone-menu-option.active,
.data-menu-option.active {
    background: linear-gradient(135deg, var(--bmkg-blue), var(--bmkg-green));
    color: white;
}

.tone-menu-option span {
    font-size: 1.1rem;
}

/* Preload Database Button */
.preload-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.preload-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.preload-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--bmkg-blue);
    color: var(--text-primary);
}

.preload-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.preload-btn.loading {
    background: var(--bg-tertiary);
    border-color: var(--bmkg-blue);
}

.preload-btn.complete {
    background: linear-gradient(135deg, var(--bmkg-green), #22c55e);
    border-color: var(--bmkg-green);
    color: white;
}

.preload-icon {
    font-size: 1rem;
}

.preload-label {
    font-weight: 500;
}

.preload-progress {
    display: none;
    align-items: center;
    gap: 6px;
    min-width: 80px;
}

.preload-progress.visible {
    display: flex;
}

.preload-progress-bar {
    width: 50px;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.preload-progress-bar::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: var(--progress, 0%);
    background: linear-gradient(90deg, var(--bmkg-blue), var(--bmkg-green));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.preload-progress-text {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 32px;
    text-align: right;
}

.preload-progress-text.complete {
    color: var(--bmkg-green);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 18px;
    font-family: inherit;
    font-size: 1.05rem;
    resize: none;
    max-height: 200px;
    min-height: 52px;
    color: var(--text-primary);
    outline: none;
}

.send-btn {
    background: linear-gradient(135deg, var(--bmkg-blue), var(--bmkg-green));
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(59, 130, 246, 0.3);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

.send-btn:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 1;
    box-shadow: none;
}

.tone-selector-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    /* Reduced from 20px for tighter layout */
    opacity: 1;
    transition: opacity 0.3s;
}

.chat-input-container:not(.centered) .tone-selector-container {
    margin-top: 10px;
    transform: scale(0.9);
    opacity: 0.9;
}

/* --- Chat Message Styling (Strict) --- */
.chat-message-row {
    display: flex;
    width: 100%;
    margin-bottom: 24px;
    align-items: flex-start;
}

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

.chat-message-row.assistant {
    justify-content: flex-start;
}

.chat-avatar-container {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-avatar-container.user-bg {
    margin-left: 12px;
    order: 2;
    font-size: 1.5rem;
    /* Avatar to right for user */
}

.chat-avatar-container.ai-bg {
    margin-right: 12px;
    order: 1;
    /* Avatar to left for AI */
}

.chat-avatar-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    /* Invert filter for white icons if needed, but MEGO is colored. We might need logic. */
}

.chat-bubble {
    max-width: 80%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    order: 1;
    /* Default for AI */
}

.chat-message-row.user .chat-bubble {
    background-color: #eff6ff;
    /* Blue-50 */
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #1e3a8a;
    /* Dark Blue Text */
    border-bottom-right-radius: 4px;
    order: 1;
    /* Bubble to left of avatar */
}

.chat-message-row.assistant .chat-bubble {
    background: rgba(255, 255, 255, 0.85);
    /* White-ish */
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: #0f172a;
    /* Dark Text */
    border-bottom-left-radius: 4px;
    order: 2;
    /* Bubble to right of avatar */
}

/* --- Chart Container --- */
.chart-container {
    width: 100%;
    max-width: 100%;
    height: 400px;
    margin: 16px 0;
    padding: 16px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chart-container canvas {
    height: 100% !important;
    width: 100% !important;
}

/* --- Tables in Chat --- */
.chat-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9rem;
    border-radius: 8px;
    overflow: hidden;
}

.chat-bubble th,
.chat-bubble td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.chat-bubble th {
    background: linear-gradient(135deg, var(--bmkg-blue), var(--bmkg-green));
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}

.chat-bubble tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

.chat-bubble tr:hover {
    background-color: rgba(30, 64, 175, 0.05);
}

/* --- Markdown Content Spacing --- */
.chat-bubble p {
    margin: 0 0 8px 0;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul,
.chat-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-bubble li {
    margin: 4px 0;
}

/* Typing Indicator Logic */
.typing-dots {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 4px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #0f766e;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

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

@keyframes bounce {

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

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

.tone-label {
    position: absolute;
    bottom: 4px;
    left: 0;
    right: 0;
    font-size: 0.55rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    text-align: center;
}

.tone-selector {
    display: inline-flex;
    flex-wrap: nowrap;
    position: relative;
    background: var(--bg-primary);
    padding: 6px;
    padding-bottom: 22px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    gap: 4px;
}

.tone-option {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.3rem;
    position: relative;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    color: var(--text-secondary);
}

.tone-option:hover {
    background-color: var(--bg-tertiary);
    transform: scale(1.1);
}

.tone-option.active {
    background: linear-gradient(135deg, var(--bmkg-blue), var(--bmkg-blue));
    color: white;
    box-shadow: 0 2px 5px rgba(30, 64, 175, 0.3);
}

.tone-tooltip {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background-color: var(--text-primary);
    color: var(--bg-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s;
    box-shadow: var(--shadow-lg);
    z-index: 30;
}

.tone-option:hover .tone-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Markdown Styling */
.prose h1,
.prose h2,
.prose h3 {
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.prose p {
    margin-bottom: 1.25em;
}

.prose ul,
.prose ol {
    margin-left: 1.5em;
    margin-bottom: 1.25em;
}

.prose strong {
    color: var(--bmkg-blue);
    font-weight: 700;
}

.prose code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.9em;
    font-family: 'Consolas', 'Monaco', monospace;
    border: 1px solid var(--border-color);
}

.prose pre {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    margin-bottom: 1.5em;
    border: 1px solid var(--border-color);
}

.prose img {
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin: 1em 0;
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.95em;
}

.prose th,
.prose td {
    padding: 10px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.prose th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
}

/* Smart Badge */
.smart-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--bmkg-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.smart-badge svg {
    height: 14px;
    width: 14px;
}

/* Response Time Badge */
.response-time {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-primary);
    width: 90%;
    max-width: 700px;
    /* Increased from 550px */
    border-radius: 24px;
    padding: 0;
    /* Padding moved to children to keep scrollbar at edge */
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Children handle scroll */
    border: 1px solid var(--border-color);
}

.modal-overlay.open .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding: 24px 32px;
    /* Added padding here */
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-close {
    background: var(--bg-tertiary);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background-color: var(--border-color);
}

.guide-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 32px;
    /* Side padding matches header */
    overflow-y: auto;
    /* Scrollable list */
    flex: 1;
}

.guide-list::-webkit-scrollbar {
    width: 6px;
}

.guide-list::-webkit-scrollbar-track {
    background: transparent;
}

.guide-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.guide-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.guide-item-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.guide-item-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    padding: 20px 32px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
        border-right: 1px solid var(--border-color);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.2);
    }

    .mobile-toggle {
        display: block;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 60;
        background: var(--bg-primary);
        padding: 10px;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        cursor: pointer;
        box-shadow: var(--shadow-md);
        color: var(--text-primary);
    }

    .main-chat {
        padding-top: 0;
    }

    .chat-header {
        position: absolute;
    }

    /* keep header */
    .chat-messages {
        padding-top: 80px;
        padding-bottom: 100px;
    }

    .chat-input-container {
        left: 16px;
        /* Reset for mobile - no sidebar */
        right: 16px;
        width: calc(100% - 32px);
        bottom: 20px;
    }

    .tone-selector-container {
        overflow-x: auto;
        padding-bottom: 4px;
        justify-content: flex-start;
    }

    .tone-label {
        display: none;
    }
}

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

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

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

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

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

@keyframes typingBounce {

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

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

/* Force layout consistency */
.chat-input-container {
    display: block;
    /* Ensure it stays block */
    width: 100%;
    /* Ensure full width for centering */
}

/* Ensure sidebar items have consistent font size */
.sidebar .sidebar-bottom button,
.sidebar .sidebar-bottom .theme-toggle {
    font-size: 0.95rem;
}

/* Force layout consistency for input container */
.chat-input-container {
    display: block;
    /* Ensure it stays block */
    width: 100%;
    /* Ensure full width for centering */
}

/* Ensure sidebar items have consistent font size */
.sidebar .sidebar-bottom button,
.sidebar .sidebar-bottom .theme-toggle {
    font-size: 0.95rem;
}

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

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

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

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

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

@keyframes typingBounce {

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

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

/* History Modal Styles */
.history-modal {
    max-width: 800px;
    /* Even wider for history */
    height: 70vh;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 32px;
    /* Padding on sides for list */
    scrollbar-width: thin;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.history-item-modal {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item-modal:hover {
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.1), rgba(5, 150, 105, 0.1));
    border-color: var(--bmkg-blue);
    transform: translateX(4px);
}

.history-item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-modal-footer {
    padding: 24px 32px;
    border-top: 1px solid var(--border-color);
}

.history-clear-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.history-clear-btn:hover {
    background: #ef4444;
    color: white;
}

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-style: italic;
}

/* --- Intro Animation Overlay --- */
#intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-primary);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s ease;
}

#intro-overlay .intro-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.6s ease;
}

#intro-overlay .intro-title {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    font-size: 4rem;
    background: linear-gradient(135deg, #1e40af, #059669);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

/* Animation State: Zoom Out and Fade */
#intro-overlay.zoom-out {
    opacity: 0;
    pointer-events: none;
}

#intro-overlay.zoom-out .intro-content {
    transform: scale(0.5);
    opacity: 0;
}

/* ── Tone selector descriptions ────────────────────────────────────────────── */
.tone-desc {
    display: block;
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.3;
    font-weight: 400;
}

/* ── Copy button on assistant messages ─────────────────────────────────────── */
.chat-bubble {
    position: relative;
}
.msg-copy-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 7px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    transition: background 0.15s, border-color 0.15s;
    margin-left: 6px;
    line-height: 1;
}
.msg-copy-btn:hover { background: var(--bg-secondary); border-color: var(--text-secondary); }
.chat-message-row:hover .msg-copy-btn { opacity: 1; }

/* ── Feedback buttons on assistant messages ─────────────────────────────────── */
.msg-feedback-row {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}
.chat-message-row:hover .msg-feedback-row { opacity: 1; }
.fb-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 7px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    transition: background 0.15s, border-color 0.15s;
}
.fb-btn:hover { background: var(--bg-secondary); border-color: var(--text-secondary); }

/* ── History modal search ──────────────────────────────────────────────────── */
.history-search-row {
    padding: 0 16px 12px;
}
#historySearch {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
#historySearch:focus { border-color: var(--accent-color, #4a9eff); }