:root {
    /* Material Design 3 — Maritime Seed: #0061A4 */

    /* LIGHT THEME TOKENS */
    --md-sys-color-primary: #0061a4;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d1e4ff;
    --md-sys-color-on-primary-container: #001d36;
    --md-sys-color-secondary: #535f70;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d7e3f7;
    --md-sys-color-on-secondary-container: #101c2b;
    --md-sys-color-tertiary: #6b5778;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #f2daff;
    --md-sys-color-on-tertiary-container: #251431;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;
    --md-sys-color-outline: #73777f;
    --md-sys-color-background: #fdfcff;
    --md-sys-color-on-background: #1a1c1e;
    --md-sys-color-surface: #fdfcff;
    --md-sys-color-on-surface: #1a1c1e;
    --md-sys-color-surface-variant: #dfe2eb;
    --md-sys-color-on-surface-variant: #43474e;
    --md-sys-color-inverse-surface: #2f3033;
    --md-sys-color-inverse-on-surface: #f1f0f4;
    --md-sys-color-inverse-primary: #9ecaff;
    --md-sys-color-surface-tint: #0061a4;
    --md-sys-color-outline-variant: #c3c7cf;
    --md-sys-color-surface-rgb: 253, 252, 255;
    --md-sys-color-scrim: #000000;

    /* Premium Effects */
    --m3-elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --m3-elevation-2: 0 1px 3px 1px rgba(0, 0, 0, 0.15), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --m3-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px 0 rgba(0, 0, 0, 0.15);
    --m3-elevation-4: 0 8px 12px 6px rgba(0, 0, 0, 0.15), 0 1px 4px 0 rgba(0, 0, 0, 0.12);
    --m3-radius-xs: 4px;
    --m3-radius-sm: 8px;
    --m3-radius-md: 12px;
    --m3-radius-lg: 16px;
    --m3-radius-xl: 28px;
    --m3-radius-full: 9999px;

    --font-heading: 'Outfit', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;

    --transition-standard: cubic-bezier(0.2, 0, 0, 1);
    --transition-standard-long: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-decelerate: cubic-bezier(0, 0, 0, 1);
    --transition-accelerate: cubic-bezier(0.3, 1, 1, 1);

    --sidebar-width: 320px;
}

[data-theme="dark"] {
    /* DARK THEME TOKENS */
    --md-sys-color-primary: #9ecaff;
    --md-sys-color-on-primary: #003258;
    --md-sys-color-primary-container: #00497d;
    --md-sys-color-on-primary-container: #d1e4ff;
    --md-sys-color-secondary: #bbc7db;
    --md-sys-color-on-secondary: #253140;
    --md-sys-color-secondary-container: #3b4858;
    --md-sys-color-on-secondary-container: #d7e3f7;
    --md-sys-color-tertiary: #d6bee4;
    --md-sys-color-on-tertiary: #3b2948;
    --md-sys-color-tertiary-container: #523f5f;
    --md-sys-color-on-tertiary-container: #f2daff;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;
    --md-sys-color-outline: #8d9199;
    --md-sys-color-background: #1a1c1e;
    --md-sys-color-on-background: #e2e2e6;
    --md-sys-color-surface: #111315;
    --md-sys-color-on-surface: #e2e2e6;
    --md-sys-color-surface-variant: #43474e;
    --md-sys-color-on-surface-variant: #c3c7cf;
    --md-sys-color-inverse-surface: #e2e2e6;
    --md-sys-color-inverse-on-surface: #2f3033;
    --md-sys-color-inverse-primary: #0061a4;
    --md-sys-color-surface-tint: #9ecaff;
    --md-sys-color-outline-variant: #43474e;
    --md-sys-color-surface-rgb: 17, 19, 21;
    --md-sys-color-scrim: #000000;
}

html {
    overflow-x: hidden;
    overflow-y: hidden;
    height: 100%;
    height: 100dvh;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: inherit;
}

body {
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    font-family: var(--font-body);
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    height: 100vh;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: hidden;
    width: 100%;
    max-width: 100vw;
    transition: background-color 0.4s var(--transition-standard), color 0.4s var(--transition-standard);
}

/* ========================================= */
/* AMBIENT MESH BACKGROUND                   */
/* ========================================= */
.ambient-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background: var(--md-sys-color-background);
}

.ambient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    will-change: transform;
    opacity: 0.6;
}

.ambient-orb:nth-child(1) {
    width: 70vw;
    height: 70vw;
    background: radial-gradient(circle, var(--md-sys-color-primary-container) 0%, transparent 70%);
    top: -20%;
    left: -10%;
    animation: orbFloat1 40s ease-in-out infinite;
}

.ambient-orb:nth-child(2) {
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--md-sys-color-secondary-container) 0%, transparent 70%);
    bottom: -15%;
    right: -10%;
    animation: orbFloat2 45s ease-in-out infinite;
}

.ambient-orb:nth-child(3) {
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, var(--md-sys-color-tertiary-container) 0%, transparent 70%);
    top: 30%;
    right: 15%;
    animation: orbFloat3 50s ease-in-out infinite;
}

@keyframes orbFloat1 {

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

    33% {
        transform: translate(5%, 10%) scale(1.2);
    }

    66% {
        transform: translate(-5%, 5%) scale(1);
    }
}

@keyframes orbFloat2 {

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

    33% {
        transform: translate(-8%, -5%) scale(1.1);
    }

    66% {
        transform: translate(5%, 8%) scale(1.05);
    }
}

@keyframes orbFloat3 {

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

    33% {
        transform: translate(10%, -10%) scale(1.1);
    }

    66% {
        transform: translate(-5%, -5%) scale(1.15);
    }
}

/* ========================================= */
/* APP CONTAINER & SHELL                     */
/* ========================================= */
.app-container {
    display: flex;
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    z-index: 1;
    overflow: hidden;
    background-color: transparent;
}

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

/* ========================================= */
/* M3 NAVIGATION DRAWER                      */
/* ========================================= */
.sidebar {
    width: var(--sidebar-width);
    margin-top: 16px;
    margin-right: 16px;
    margin-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    margin-left: 16px;
    background-color: rgba(var(--md-sys-color-surface-rgb), 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--md-sys-color-on-surface);
    display: flex;
    flex-direction: column;
    padding: 4px 12px 12px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 8px));
    transition: all 0.4s var(--transition-standard);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-xl);
    position: relative;
    z-index: 1000;
    /* Higher to stay above content when floating */
    box-shadow: var(--m3-elevation-2);
}

/* Light tonal overlay as per M3 specs for elevation 1 */
.sidebar::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-primary);
    opacity: 0.05;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
    /* Fix: corners bleeding */
}

.sidebar-header {
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    margin-bottom: 4px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: var(--m3-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: transform 0.3s var(--transition-standard);
}@media (hover: hover) {


.logo:hover .logo-icon {
    transform: rotate(-10deg) scale(1.05);
}
}


/* ========================================= */
/* M3 FAB (Floating Action Button)           */
/* ========================================= */
.fab-btn {
    height: 48px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border: none;
    padding: 0 16px;
    border-radius: var(--m3-radius-lg);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s var(--transition-standard);
    margin: 4px 4px 8px 4px;
    box-shadow: var(--m3-elevation-1);
    width: fit-content;
}@media (hover: hover) {


.fab-btn:hover {
    box-shadow: var(--m3-elevation-2);
    /* Surface tint overlay on hover */
    background-image: linear-gradient(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.08));
}
}


.fab-btn:active {
    box-shadow: var(--m3-elevation-1);
    transform: scale(0.98);
}

.fab-btn i {
    font-size: 18px;
}

/* ========================================= */
/* DRAWER ITEMS & SECTIONS                   */
/* ========================================= */
.drawer-section-label {
    padding: 10px 16px 4px 16px;
    font-family: var(--font-heading);
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.7;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Important: allow shrinking to trigger scrollbar */
    display: flex;
    flex-direction: column;
    padding: 0 4px;
    /* Custom scrollbar for premium feel */
    scrollbar-width: thin;
    scrollbar-color: var(--md-sys-color-outline-variant) transparent;
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

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

.chat-list::-webkit-scrollbar-thumb {
    background-color: var(--md-sys-color-outline-variant);
    border-radius: 20px;
    border: none;
}

.chat-item {
    height: 56px;
    min-height: 56px;
    flex-shrink: 0;
    /* Prevent shrinking when list is long */
    padding: 0 16px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s var(--transition-standard);
    margin-bottom: 2px;
    position: relative;
    overflow: hidden;
}

/* Fix: Nav item layout for consistent alignment */
@keyframes navItemAppear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.nav-item {
    animation: navItemAppear 0.4s ease forwards;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 8px;
    flex-shrink: 0;
    /* Prevent shrinking when list is long */
    transition: background-color 0.2s;
    text-decoration: none;
    /* Убираем подчеркивание */
    color: var(--md-sys-color-on-surface-variant);
    border-radius: 4px;
    margin-bottom: 2px;
}@media (hover: hover) {


.nav-item:hover {
    background-color: var(--md-sys-color-surface-variant);
    text-decoration: none;
    color: var(--md-sys-color-on-surface);
}
}


.nav-item.active {
    color: var(--md-sys-color-primary);
    font-weight: 600;
}

.nav-item-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px; /* Slightly smaller gap to save space */
    padding: 12px 0;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    min-width: 0; /* Critical for flex-grow with ellipsis */
}@media (hover: hover) {


.chat-item:hover {
    background-color: var(--md-sys-color-on-surface-variant);
    --op: 0.08;
    background-color: rgba(var(--md-sys-color-on-surface-variant-rgb, 67, 71, 78), 0.08);
    /* Fixed below with vars */
    background-color: var(--md-sys-color-surface-variant);
}
}


.chat-item.active {
    color: var(--md-sys-color-primary);
    font-weight: 600;
}

.chat-item-text {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-text i {
    font-size: 16px;
    opacity: 0.8;
}

.chat-active-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 32px;
    background-color: var(--md-sys-color-primary);
    border-radius: 0 4px 4px 0;
    display: none;
}

.nav-item.active .chat-active-indicator,
.chat-item.active .chat-active-indicator {
    display: block;
}

.del-chat-btn {
    opacity: 0.4;
    width: 28px !important; /* Slightly smaller to save space for text */
    height: 28px !important;
    min-width: 28px !important;
    border-radius: 50%;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s;
    margin-left: 2px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    position: relative;
    z-index: 10;
}@media (hover: hover) {


.nav-item:hover .del-chat-btn {
    opacity: 1; /* Fully visible on hover */
}
}
@media (hover: hover) {


.del-chat-btn:hover {
    opacity: 1 !important;
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}
}


/* ========================================= */
/* DRAWER FOOTER                             */
/* ========================================= */
.sidebar-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
}

.drawer-item, .nav-item {
    height: 48px;
    padding: 0 16px !important;
    border-radius: 4px;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
    width: 100% !important;
    box-sizing: border-box !important;
    position: relative;
}

.sidebar-nav i, .sidebar-footer i, .chat-list i {
    width: 24px !important;
    min-width: 24px !important;
    height: 24px;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important;
    flex-shrink: 0 !important;
}@media (hover: hover) {


.drawer-item:hover {
    background-color: var(--md-sys-color-surface-variant);
}
}


.drawer-item.non-interactive {
    cursor: default;
}@media (hover: hover) {


.drawer-item.non-interactive:hover {
    background-color: transparent;
}
}
@media (hover: hover) {


.logout-btn:hover {
    background-color: var(--md-sys-color-error-container) !important;
    color: var(--md-sys-color-on-error-container) !important;
}
}


/* ========================================= */
/* MAIN CONTENT                              */
/* ========================================= */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    /* Shows ambient bg */
    position: relative;
    overflow: hidden;
    /* Safety padding for mobile navigation bars */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========================================= */
/* M3 TOP APP BAR                            */
/* ========================================= */
.topbar {
    height: 56px;
    margin: 16px 16px 8px 0;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background-color: rgba(var(--md-sys-color-surface-rgb), 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-xl);
    z-index: 2000;
    transition: all 0.3s;
    box-shadow: var(--m3-elevation-1);
}

[data-theme="dark"] .topbar {
    background-color: rgba(30, 32, 35, 0.8);
    border-color: var(--md-sys-color-outline-variant);
}

.mobile-menu-btn,
.theme-toggle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}@media (hover: hover) {


.mobile-menu-btn:hover,
.theme-toggle-btn:hover {
    background-color: var(--md-sys-color-surface-variant);
}
}


.topbar-title {
    flex: 1;
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}


/* ========================================= */
/* MODEL SWITCHER (M3 Premium)               */
/* ========================================= */
.model-switch {
    display: flex;
    position: relative;
    background-color: var(--md-sys-color-surface-variant);
    border-radius: var(--m3-radius-full);
    padding: 4px;
    height: 40px;
    align-items: center;
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-right: 8px;
    overflow: hidden;
}

.model-switch-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background-color: var(--md-sys-color-primary);
    border-radius: var(--m3-radius-full);
    transition: all 0.4s var(--transition-standard);
    z-index: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.model-switch.smart-active .model-switch-slider {
    transform: translateX(100%);
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    background-size: 200% 200%;
    animation: smartGradientPulse 3s ease infinite;
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.4);
}

@keyframes smartGradientPulse {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.model-switch-btn {
    position: relative;
    z-index: 2;
    background: transparent;
    border: none;
    height: 100%;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    transition: color 0.3s var(--transition-standard);
    white-space: nowrap;
}

.model-switch-btn.active {
    color: var(--md-sys-color-on-primary);
}

/* Specific text color for smart mode when active */
.model-switch.smart-active .model-switch-btn[data-mode="smart"].active {
    color: #ffffff;
}

.model-switch-btn i {
    font-size: 14px;
    transition: transform 0.3s var(--transition-standard);
}@media (hover: hover) {


.model-switch-btn:hover i {
    transform: scale(1.15) rotate(10deg);
}
}


/* Subtle pulse for smart icon */
@keyframes smartPulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.model-switch.smart-active .model-switch-btn[data-mode="smart"] i {
    animation: smartPulse 3s infinite var(--transition-standard);
}

@media (max-width: 768px) {
    .model-switch-btn span {
        display: none;
    }

    .model-switch {
        padding: 2px;
        height: 36px;
    }

    .model-switch-btn {
        padding: 0 10px;
    }

    .model-switch-slider {
        top: 2px;
        left: 2px;
        width: calc(50% - 2px);
        height: calc(100% - 4px);
    }
}

@media (max-width: 640px) {
    .topbar {
        gap: 8px;
        padding: 0 12px;
    }
}

@media (max-width: 480px) {
    .topbar-title {
        flex: 1;
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        /* Removed max-width to allow flex: 1 to push elements */
    }

    .topbar-actions {
        display: flex;
        justify-content: flex-end;
        margin-left: auto; /* Force to the right edge */
        gap: 8px;
    }
}

/* ========================================= */
/* MOBILE SPATIAL OPTIMIZATION               */
/* ========================================= */
@media (max-width: 600px) {
    .chat-area {
        padding: 8px 8px 0 8px !important;
    }

    .messages-container {
        gap: 16px !important;
        padding-bottom: 140px !important;
        padding-top: 8px !important;
    }

    .message {
        gap: 10px !important;
    }

    .message-avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
        border-radius: var(--m3-radius-md) !important;
    }

    .message-content {
        max-width: 92% !important;
        font-size: 15px !important;
        padding: 10px 14px !important;
    }

    .message.ai .message-content {
        border-radius: 4px 16px 16px 16px !important;
    }

    .message.user .message-content {
        border-radius: 16px 4px 16px 16px !important;
    }

    .m3-input-card {
        margin: 8px 12px 16px 12px !important;
        border-radius: var(--m3-radius-lg) !important;
    }

    .input-wrapper {
        gap: 8px !important;
        padding: 4px 8px !important;
    }

    #message-input {
        font-size: 15px !important;
        padding: 8px 4px !important;
    }

    .icon-btn-filled {
        width: 42px !important;
        height: 42px !important;
        font-size: 18px !important;
    }

    .input-footer {
        padding: 4px 12px 4px 12px !important;
        font-size: 10px !important;
    }

    .suggestions {
        gap: 8px !important;
    }

    .m3-chip {
        height: 32px !important;
        padding: 0 12px !important;
        font-size: 13px !important;
    }
}

/* ========================================= */
/* CHAT AREA                                 */
/* ========================================= */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 24px 24px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    /* Soft fade-out at the bottom to prevent "sharp" clipping against the input area */
    mask-image: linear-gradient(to bottom, black 0%, black 85%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 85%, transparent 100%);
}

.chat-area::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-thumb {
    background-color: var(--md-sys-color-outline-variant);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

/* ========================================= */
/* EMPTY STATE (M3 PREMIUM)                  */
/* ========================================= */
.empty-state h2 {
    color: var(--md-sys-color-on-surface);
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 22px;
}

.empty-state p {
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.7;
    margin-bottom: 32px;
    font-size: 15px;
}
.empty-state {
    margin: auto;
    text-align: center;
    max-width: 600px;
    padding: 40px 24px;
    animation: m3FadeInUp 0.8s var(--transition-standard) forwards;
}

@keyframes m3FadeInUp {
    from {
        opacity: 0;
        transform: translateY(32px);
    }

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

.empty-icon-container {
    width: 120px;
    height: 120px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: var(--m3-radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 32px auto;
    font-size: 48px;
    box-shadow: var(--m3-elevation-2);
    position: relative;
    overflow: hidden;
    animation: shipFloat 8s ease-in-out infinite;
}

/* Subtle inner glow for premium feel */
.empty-icon-container::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.4) 0%, transparent 60%);
    pointer-events: none;
}

@keyframes shipFloat {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    25% {
        transform: translateY(-16px) rotate(3deg);
    }

    75% {
        transform: translateY(8px) rotate(-2deg);
    }
}

.empty-state h2 {
    font-family: var(--font-heading);
    color: var(--md-sys-color-on-background);
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 32px;
    letter-spacing: -0.02em;
}

.empty-state p {
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.6;
    margin-bottom: 48px;
    font-size: 17px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

/* ========================================= */
/* M3 CHIPS (Suggestions)                    */
/* ========================================= */
.suggestions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.m3-chip {
    height: 36px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline);
    padding: 0 16px;
    border-radius: var(--m3-radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s var(--transition-standard);
    position: relative;
    overflow: hidden;
}

/* Surface tint for elevation 1 */
.m3-chip::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-primary);
    opacity: 0.05;
    pointer-events: none;
    z-index: 1;
    border-radius: inherit;
}

.m3-chip i {
    font-size: 16px;
    opacity: 0.8;
}

.m3-chip span {
    position: relative;
    z-index: 2;
}@media (hover: hover) {


.m3-chip:hover {
    background-color: var(--md-sys-color-surface-variant);
    border-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-primary);
    box-shadow: var(--m3-elevation-1);
}
}


.m3-chip:active {
    background-color: var(--md-sys-color-primary-container);
    border-color: transparent;
    transform: scale(0.97);
}

/* ========================================= */
/* MESSAGES & BUBBLES                        */
/* ========================================= */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding-bottom: 140px;
}

.message {
    display: flex;
    gap: 16px;
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    animation: m3MsgAppear 0.5s var(--transition-standard) forwards;
}

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

/* Staggered load delays */
.message.stagger-1 {
    animation-delay: 0.05s;
}

.message.stagger-2 {
    animation-delay: 0.1s;
}

.message.stagger-3 {
    animation-delay: 0.15s;
}

.message.stagger-4 {
    animation-delay: 0.2s;
}

.message.stagger-5 {
    animation-delay: 0.25s;
}

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--m3-radius-lg);
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 20px;
    box-shadow: var(--m3-elevation-1);
    transition: all 0.3s var(--transition-standard);
    position: relative;
    z-index: 2;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, var(--md-sys-color-primary), #00497d);
    color: var(--md-sys-color-on-primary);
    box-shadow: 0 4px 12px rgba(0, 97, 164, 0.3);
}

/* AI Avatar Pulse during interaction/loading */
.message.ai.typing-message .message-avatar {
    animation: aiAvatarPulse 2s infinite var(--transition-standard);
}

@keyframes aiAvatarPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 97, 164, 0.4);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(0, 97, 164, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 97, 164, 0);
    }
}

.message-content {
    max-width: 82%;
    font-size: 16px;
    line-height: 1.6;
    color: var(--md-sys-color-on-surface);
    font-weight: 500;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@media (max-width: 640px) {
    .message-content {
        max-width: 92%;
        min-width: 120px;
    }
    .message.ai .message-content,
    .message.user .message-content {
        max-width: 92%;
    }
}

.message.ai .message-content {
    background-color: #f8faff;
    /* Cleaner "Maritime White" instead of default grey */
    color: var(--md-sys-color-on-surface);
    padding: 12px 18px;
    border-radius: 4px 18px 18px 18px;
    box-shadow: 0 2px 8px rgba(0, 97, 164, 0.08);
    /* Softer, blue-tinted shadow */
    border: 1px solid #eef2f8;
    position: relative;
    max-width: 85%;
}

/* Maintain dark mode appearance */
[data-theme="dark"] .message.ai .message-content {
    background-color: var(--md-sys-color-surface-variant);
    border-color: var(--md-sys-color-outline-variant);
}

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

.message.user .message-avatar {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.message.user .message-content {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    padding: 12px 18px;
    border-radius: 18px 4px 18px 18px;
    box-shadow: var(--m3-elevation-1);
    align-self: flex-end;
    position: relative;
    max-width: 85%;
}

/* Better legibility in dark mode: use container color to keep 'light text on dark background' feel */
[data-theme="dark"] .message.user .message-content {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* ========================================= */
/* MARKDOWN IN AI MESSAGES (M3 PREMIUM)      */
/* ========================================= */
.message.ai .message-content p {
    margin-bottom: 20px;
}

.message.ai .message-content h2,
.message.ai .message-content h3 {
    font-family: var(--font-heading);
    color: var(--md-sys-color-on-surface);
    margin: 24px 0 12px 0;
    font-weight: 600;
}

.message.ai .message-content>*:first-child {
    margin-top: 0 !important;
}

.message.ai .message-content h2 {
    font-size: 24px;
    letter-spacing: -0.01em;
}

.message.ai .message-content h3 {
    font-size: 20px;
}

.message.ai .message-content ul,
.message.ai .message-content ol {
    margin: 12px 0 20px 24px;
    padding-left: 0;
}

.message.ai .message-content li {
    margin-bottom: 10px;
    padding-left: 4px;
    line-height: 1.5;
}

/* Nested lists logic */
.message.ai .message-content li ul,
.message.ai .message-content li ol {
    margin: 8px 0 8px 20px;
}

.message.ai .message-content li::marker {
    color: var(--md-sys-color-primary);
    font-weight: 600;
}

.message.ai .message-content strong {
    color: var(--md-sys-color-primary);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s var(--transition-standard);
    padding: 0 4px;
    margin: 0 -2px;
    border-radius: var(--m3-radius-xs);
    display: inline;
}@media (hover: hover) {


.message.ai .message-content strong:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}
}


.message.ai .message-content strong.item-clicked-flash {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.message.ai .message-content a[href^="suggestion:"] {
    color: var(--md-sys-color-primary);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s var(--transition-standard);
    padding: 2px 4px;
    margin: 2px 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: transparent;
    border: none;
    border-bottom: 2px solid var(--md-sys-color-primary-container);
    text-decoration: none;
    vertical-align: middle;
}

.message.ai .message-content a[href^="suggestion:"]::after {
    content: '\f245';
    /* fa-arrow-pointer */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 12px;
    opacity: 0.7;
}@media (hover: hover) {


.message.ai .message-content a[href^="suggestion:"]:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    border-radius: var(--m3-radius-sm);
}
}


.message.ai .message-content a:not([href^="suggestion:"]) {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 600;
    padding: 0 2px;
    background-color: transparent;
    border-radius: 0;
    border-bottom: 1px solid var(--md-sys-color-primary-container);
    transition: all 0.2s;
    display: inline;
    position: relative;
    white-space: normal;
}

.message.ai .message-content a:not([href^="suggestion:"])::after {
    content: '\f245';
    /* fa-arrow-pointer */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 11px;
    opacity: 0.6;
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
}@media (hover: hover) {


.message.ai .message-content a:not([href^="suggestion:"]:hover) {
    border-bottom-color: var(--md-sys-color-primary);
}
}


.message.ai .message-content pre {
    background-color: var(--md-sys-color-surface-variant);
    padding: 24px;
    border-radius: var(--m3-radius-lg);
    margin: 24px 0;
    overflow-x: auto;
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.message.ai .message-content code {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    border-radius: var(--m3-radius-xs);
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
}

.message.ai .message-content pre code {
    background-color: transparent;
    padding: 0;
    border: none;
    color: inherit;
}

.message.ai .message-content table {
    width: 100%;
    max-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 24px 0;
    border-radius: var(--m3-radius-md);
    border: 1px solid var(--md-sys-color-outline-variant);
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.message.ai .message-content th,
.message.ai .message-content td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    border-right: 1px solid var(--md-sys-color-outline-variant);
    min-width: 120px;
}

.message.ai .message-content th:last-child,
.message.ai .message-content td:last-child {
    border-right: none;
}

.message.ai .message-content tr:last-child td {
    border-bottom: none;
}

.message.ai .message-content th {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 600;
    white-space: nowrap;
}

/* ========================================= */
/* INPUT AREA (M3 DOCKED CARD)               */
/* ========================================= */
.m3-input-card {
    background-color: rgba(var(--md-sys-color-surface-rgb), 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    margin: 16px 24px 24px 24px;
    border-radius: var(--m3-radius-xl);
    box-shadow: var(--m3-elevation-3);
    border: 1px solid var(--md-sys-color-outline-variant);
    padding: 8px;
    transition: all 0.3s var(--transition-standard);
    position: relative;
    z-index: 10;
}

/* Surface tint overlay for elevation 3 */
.m3-input-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-primary);
    opacity: 0.11;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
}

.m3-input-card:focus-within {
    border-color: var(--md-sys-color-primary);
    box-shadow: var(--m3-elevation-4);
    /* Slightly higher on focus */
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 8px 12px;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 16px;
    padding: 12px 4px;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

.input-actions {
    display: flex;
    align-items: center;
    padding-bottom: 4px;
}

.icon-btn-filled {
    width: 48px;
    height: 48px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: var(--m3-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.25s var(--transition-standard);
}@media (hover: hover) {


.icon-btn-filled:hover {
    box-shadow: var(--m3-elevation-2);
    filter: brightness(1.1);
    transform: translateY(-2px);
}
}


.icon-btn-filled:active {
    transform: translateY(0) scale(0.95);
}

.icon-btn-filled:disabled {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    cursor: default;
    opacity: 0.5;
    transform: none;
    box-shadow: none;
}

.input-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 4px 16px;
    font-size: 11px;
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.7;
    font-weight: 500;
}

/* ========================================= */
/* CHAT ATTACHMENTS                          */
/* ========================================= */
.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 12px 0 12px;
}

.chat-attachments:empty {
    display: none;
}

.chat-attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 6px 12px;
    border-radius: var(--m3-radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--m3-elevation-1);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.chat-attachment-item i.fa-file {
    color: var(--md-sys-color-primary);
    font-size: 16px;
}

.chat-attachment-item .file-name {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attachment-item .delete-file-btn {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-primary-container);
    cursor: pointer;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.7;
}

.chat-attachment-item .delete-file-btn:hover {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    opacity: 1;
}

.attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 20px;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.attach-btn:hover {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-primary);
}

/* Адаптация вложений для мобильных устройств (горизонтальный скролл) */
@media (max-width: 768px) {
    .chat-attachments {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px 12px 0 12px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        scroll-snap-type: x mandatory;
    }
    
    .chat-attachments::-webkit-scrollbar {
        display: none; /* Chrome/Safari/Edge */
    }
    
    .chat-attachment-item {
        flex: 0 0 auto;
        scroll-snap-align: start;
        padding: 4px 8px;
        font-size: 12px;
        max-width: 140px;
    }
    
    .chat-attachment-item .file-name {
        max-width: 90px;
    }
    
    .chat-attachment-item .delete-file-btn {
        width: 20px;
        height: 20px;
    }
    
    .attach-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* ========================================= */
/* TYPING INDICATOR — SONAR MR               */
/* ========================================= */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 0;
}

.sonar-wrap {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.sonar-beacon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: var(--md-sys-color-primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px var(--md-sys-color-primary), 0 0 14px var(--md-sys-color-primary-container);
}

.sonar-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1.5px solid var(--md-sys-color-primary);
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 0;
    animation: sonarPing 2s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

.sonar-ring:nth-child(2) { animation-delay: 0s; }
.sonar-ring:nth-child(3) { animation-delay: 0.7s; }

@keyframes sonarPing {
    0% {
        transform: translate(-50%, -50%) scale(0.2);
        opacity: 0.6;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0;
    }
}

.typing-text {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    letter-spacing: 0.01em;
    animation: typingTextBreath 2.5s ease-in-out infinite;
}

@keyframes typingTextBreath {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 0.85; }
}


/* Cleanup: Removed old glassmorphism blocks 1056-1460 */

/* ========================================= */
/* M3 MODALS & DIALOGS                       */
/* ========================================= */
.m3-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: all 0.4s var(--transition-standard);
    pointer-events: none;
}

.m3-modal-overlay.open {
    display: flex;
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    pointer-events: auto;
}

/* Scrim opacity 0.32 as per M3 */
/* Scrim overlay handling */
.m3-modal-overlay.open::before {
    display: none;
    /* Relying on main overlay bg for blur consistency */
}

.m3-dialog {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    border-radius: var(--m3-radius-xl);
    padding: 24px;
    max-width: 560px;
    width: 90%;
    box-shadow: var(--m3-elevation-3);
    position: relative;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s var(--transition-standard), opacity 0.3s;
    opacity: 0;
}

/* Surface tint for elevation 3 */
.m3-dialog::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-primary);
    opacity: 0.11;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
}

.m3-modal-overlay.open .m3-dialog {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.m3-modal-overlay.closing .m3-dialog {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
}

.m3-dialog-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.header-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--md-sys-color-primary);
}

.header-icon.error {
    color: var(--md-sys-color-error);
}

.m3-dialog-title {
    flex: 1;
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 500;
}

.m3-dialog-body {
    margin-bottom: 24px;
}

#ai-suggestion-modal .m3-dialog-body {
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
}

#ai-suggestion-modal .m3-dialog-body::-webkit-scrollbar {
    width: 6px;
}

#ai-suggestion-modal .m3-dialog-body::-webkit-scrollbar-thumb {
    background-color: var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-full);
}

/* Suggestion modal layout: answer + sources side panel */
.suggestion-layout {
    display: flex;
    gap: 1.5rem;
}
.suggestion-answer {
    flex: 1 1 60%;
    min-width: 0;
}
.suggestion-sources {
    flex: 1 1 35%;
    min-width: 0;
    border-left: 1px solid var(--md-sys-color-outline-variant);
    padding-left: 1.5rem;
}
.sources-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.source-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--md-sys-color-surface-variant);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
    min-width: 0;
}
.source-item:hover {
    background: var(--md-sys-color-secondary-container);
}
.source-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.source-info {
    min-width: 0;
    flex: 1 1 auto;
}
.source-title {
    font-weight: 500;
    font-size: 0.85rem;
    line-height: 1.3;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.source-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.15rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}
@media (max-width: 768px) {
    .suggestion-layout {
        flex-direction: column;
    }
    .suggestion-sources {
        border-left: none;
        border-top: 1px solid var(--md-sys-color-outline-variant);
        padding-left: 0;
        padding-top: 1rem;
    }
}

/* Markdown rendering inside remark modal */
.remark-answer-markdown {
    line-height: 1.6;
    color: var(--md-sys-color-on-surface);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.remark-answer-markdown p {
    margin: 0.5rem 0;
}

.remark-answer-markdown p:first-child {
    margin-top: 0;
}

.remark-answer-markdown strong {
    color: var(--md-sys-color-primary);
    font-weight: 600;
}

.remark-answer-markdown ul,
.remark-answer-markdown ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.remark-answer-markdown li {
    margin: 0.25rem 0;
}

.remark-answer-markdown h1,
.remark-answer-markdown h2,
.remark-answer-markdown h3,
.remark-answer-markdown h4 {
    font-family: var(--font-heading);
    margin: 1rem 0 0.5rem;
    color: var(--md-sys-color-on-surface);
}

.remark-answer-markdown code {
    background: var(--md-sys-color-surface-variant);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: monospace;
}

.remark-answer-markdown pre {
    background: var(--md-sys-color-surface-variant);
    padding: 1rem;
    border-radius: var(--m3-radius-md);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.remark-answer-markdown pre code {
    background: transparent;
    padding: 0;
}



/* Remark row actions */
.remark-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Inline answer editing */
.inline-edit-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.inline-edit-textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-md);
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 0.85rem;
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}
.inline-edit-textarea:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
}
.inline-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.m3-body-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 16px;
}

.m3-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ========================================= */
/* M3 BUTTONS VARIATIONS                     */
/* ========================================= */
.m3-btn-filled {
    height: 40px;
    padding: 0 24px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: var(--m3-radius-full);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}@media (hover: hover) {


.m3-btn-filled:hover {
    box-shadow: var(--m3-elevation-1);
    filter: brightness(1.1);
}
}


.m3-btn-filled.error {
    background-color: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
}

.m3-btn-text {
    height: 40px;
    padding: 0 12px;
    background: transparent;
    color: var(--md-sys-color-primary);
    border: none;
    border-radius: var(--m3-radius-full);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}@media (hover: hover) {


.m3-btn-text:hover {
    background-color: var(--md-sys-color-primary-container);
    opacity: 0.1;
    /* Fix: should be background with opacity */
    background-color: rgba(var(--md-sys-color-primary-rgb, 0, 97, 164), 0.08);
    background-color: var(--md-sys-color-surface-variant);
}
}

.m3-btn-tonal {
    height: 40px;
    padding: 0 20px;
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border: none;
    border-radius: var(--m3-radius-full);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}@media (hover: hover) {

.m3-btn-tonal:hover {
    box-shadow: var(--m3-elevation-1);
    filter: brightness(1.05);
}
}

.icon-btn-ghost {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}@media (hover: hover) {


.icon-btn-ghost:hover {
    background-color: var(--md-sys-color-surface-variant);
}
}


/* ========================================= */
/* SUPPORT SPECIFIC STYLES                   */
/* ========================================= */
.m3-textarea-field {
    background-color: var(--md-sys-color-surface-variant);
    border-radius: var(--m3-radius-xs) var(--m3-radius-xs) 0 0;
    padding: 12px 16px;
    position: relative;
    margin-bottom: 24px;
    transition: background-color 0.3s;
}

.m3-textarea-field:focus-within {
    background-color: var(--md-sys-color-surface-variant);
}

.m3-textarea-field textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 16px;
    resize: none;
}

.field-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--md-sys-color-on-surface-variant);
    transition: height 0.2s, background-color 0.2s;
}

.m3-textarea-field:focus-within .field-indicator {
    height: 2px;
    background-color: var(--md-sys-color-primary);
}

.m3-upload-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 1px dashed var(--md-sys-color-outline);
    border-radius: var(--m3-radius-md);
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--md-sys-color-surface-variant);
    opacity: 0.8;
}@media (hover: hover) {


.m3-upload-card:hover {
    opacity: 1;
    border-color: var(--md-sys-color-primary);
    background-color: var(--md-sys-color-primary-container);
}
}


.m3-upload-card i {
    font-size: 24px;
    color: var(--md-sys-color-primary);
}

.upload-info {
    display: flex;
    flex-direction: column;
}

.upload-title {
    font-size: 14px;
    font-weight: 500;
}

.upload-hint {
    font-size: 12px;
    opacity: 0.7;
}

.m3-image-previews {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.support-preview-item {
    width: 72px;
    height: 72px;
    border-radius: var(--m3-radius-sm);
    overflow: hidden;
    position: relative;
    box-shadow: var(--m3-elevation-1);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.support-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-img {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ========================================= */
/* AUTH PAGES (M3 PREMIUM)                   */
/* ========================================= */
.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--md-sys-color-surface);
    position: relative;
    overflow: hidden;
    padding: 24px;
}

.auth-page .ambient-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(circle at 0% 0%, var(--md-sys-color-primary-container) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, var(--md-sys-color-secondary-container) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, var(--md-sys-color-surface-variant) 0%, transparent 70%);
    opacity: 0.6;
    animation: authMeshMove 20s ease-in-out infinite alternate;
}

@keyframes authMeshMove {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.1) rotate(2deg);
    }
}

.m3-auth-card {
    background-color: var(--md-sys-color-surface);
    border-radius: var(--m3-radius-xl);
    padding: 48px;
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 10;
    box-shadow: var(--m3-elevation-3);
    text-align: center;
    animation: m3FadeInUp 0.6s var(--transition-standard) forwards;
}

/* Surface tint for elevation 3 */
.m3-auth-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--md-sys-color-primary);
    opacity: 0.11;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
}

.auth-logo {
    margin-bottom: 32px;
}

.premium-logo {
    height: 48px;
    filter: drop-shadow(0 4px 8px rgba(0, 97, 164, 0.2));
}

.m3-auth-card h2 {
    font-family: var(--font-heading);
    color: var(--md-sys-color-on-surface);
    font-size: 28px;
    margin-bottom: 12px;
    font-weight: 600;
}

.m3-auth-card p.subtitle {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 15px;
    margin-bottom: 32px;
}

.auth-form {
    text-align: left;
}

.m3-field {
    margin-bottom: 20px;
}

.m3-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 8px;
    margin-left: 4px;
}

.m3-text-field {
    background-color: var(--md-sys-color-surface-variant);
    border-radius: var(--m3-radius-sm) var(--m3-radius-sm) 0 0;
    padding: 12px 16px;
    position: relative;
    transition: background-color 0.3s;
}@media (hover: hover) {


.m3-text-field:hover {
    background-color: var(--md-sys-color-outline-variant);
}
}


.m3-text-field:focus-within {
    background-color: var(--md-sys-color-surface-variant);
}

.m3-text-field input {
    width: 100%;
    height: 32px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 500;
}

.m3-text-field input::placeholder {
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.6;
}

.m3-field-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--md-sys-color-outline);
    transition: all 0.3s var(--transition-standard);
}

.m3-text-field:focus-within .m3-field-indicator {
    height: 2px;
    background-color: var(--md-sys-color-primary);
}

.auth-btn-container {
    margin-top: 32px;
}

.auth-submit-btn {
    width: 100%;
    height: 52px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: var(--m3-radius-full);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--m3-elevation-2);
}@media (hover: hover) {


.auth-submit-btn:hover {
    box-shadow: var(--m3-elevation-3);
    filter: brightness(1.1);
    transform: translateY(-2px);
}
}


.auth-submit-btn:active {
    transform: translateY(0);
}

.auth-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    font-size: 14px;
    color: var(--md-sys-color-on-surface-variant);
}

.auth-footer a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 600;
}@media (hover: hover) {


.auth-footer a:hover {
    text-decoration: underline;
}
}


/* Flash Messages (M3 Snacks) */
.auth-error,
.auth-success {
    padding: 12px 16px;
    border-radius: var(--m3-radius-sm);
    margin-bottom: 24px;
    font-size: 14px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-error {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.auth-success {
    background-color: #d1fae5;
    color: #065f46;
}

.m3-status-label {
    margin-top: 12px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    min-height: 16px;
}

.m3-status-label.success {
    color: #10b981;
}

.m3-status-label.error {
    color: var(--md-sys-color-error);
}

.highlight-text {
    color: var(--md-sys-color-primary);
    font-weight: 600;
}

/* ========================================= */
/* M3 RIPPLE & GLOBAL ANIMATIONS             */
/* ========================================= */
.m3-btn-filled,
.m3-btn-text,
.m3-chip,
.icon-btn-filled,
.icon-btn-ghost,
.nav-item,
.fab-btn,
.chat-item {
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Pseudo-ripple simulation */
.m3-btn-filled::after,
.m3-btn-text::after,
.m3-chip::after,
.icon-btn-filled::after,
.icon-btn-ghost::after,
.nav-item::after,
.fab-btn::after,
.chat-item::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background-color: currentColor;
    border-radius: inherit;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.5s var(--transition-standard), opacity 0.3s;
    pointer-events: none;
    z-index: 5;
}

.m3-btn-filled:active::after,
.m3-btn-text:active::after,
.m3-chip:active::after,
.icon-btn-filled:active::after,
.icon-btn-ghost:active::after,
.nav-item:active::after,
.fab-btn:active::after,
.chat-item:active::after {
    opacity: 0.12;
    transform: translate(-50%, -50%) scale(2);
}@media (hover: hover) {


/* Premium micro-interactions */
.nav-item:hover i,
.fab-btn:hover i {
    animation: m3IconBounce 0.4s var(--transition-standard);
}
}


@keyframes m3IconBounce {

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

    50% {
        transform: scale(1.2) rotate(-5deg);
    }
}

/* Scrollbar Styling (M3) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 100px;
    border: 2px solid transparent;
    background-clip: padding-box;
}@media (hover: hover) {


::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
    border: 2px solid transparent;
    background-clip: padding-box;
}
}


/* Content Loading Animation */
.m3-fade-in {
    animation: m3FadeInUp 0.6s var(--transition-standard) forwards;
}

@keyframes m3FadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

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

/* ========================================= */
/* RESPONSIVE & MOBILE NAVIGATION DRAWERS    */
/* ========================================= */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

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

/* Default state: visible on desktop */
.mobile-menu-btn {
    display: none;
}

@media (max-width: 1024px) {
    .mobile-menu-btn {
        display: flex;
    }

    .sidebar {
        position: fixed !important;
        left: calc(-1 * var(--sidebar-width)) !important;
        top: 0 !important;
        bottom: 0 !important;
        margin: 0 !important;
        border-radius: 0 var(--m3-radius-xl) var(--m3-radius-xl) 0;
        z-index: 1100;
        box-shadow: none;
        transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.45s cubic-bezier(0.32, 0.72, 0, 1), background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease !important;
        will-change: transform;
    }

    .sidebar.open {
        transform: translateX(var(--sidebar-width)) !important;
        box-shadow: var(--m3-elevation-4);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .topbar {
        margin: 8px !important;
        top: 8px;
        width: calc(100% - 16px) !important;
        border-radius: var(--m3-radius-lg);
    }
    
    .mobile-menu-btn {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        color: var(--md-sys-color-primary) !important;
    }

    /* Compact sidebar for narrow screens */
    .sidebar {
        max-height: 100dvh;
        padding: 8px;
        padding-bottom: env(safe-area-inset-bottom, 8px);
    }

    .sidebar-header {
        height: 48px;
        margin-bottom: 4px;
        padding: 0 8px;
    }

    .logo {
        font-size: 14px;
        gap: 8px;
    }

    .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .nav-item {
        padding: 8px 10px;
        font-size: 14px;
        min-height: 44px;
    }

    .nav-item i {
        font-size: 16px;
    }

    .fab-btn {
        height: 40px;
        padding: 0 14px;
        font-size: 13px;
        margin: 4px 2px 8px 2px;
        gap: 8px;
    }

    .fab-btn i {
        font-size: 14px;
    }

    /* Hide check-updates on narrow screens */
    #check-updates-btn {
        display: none !important;
    }

    .drawer-section-label {
        padding: 8px 10px 4px 10px;
        font-size: 10px;
    }

    #chat-search {
        margin: 4px 8px;
        padding: 8px 12px;
        font-size: 13px;
    }

    .chat-list {
        padding: 0 2px;
    }

    .chat-item {
        padding: 0 10px;
        min-height: 44px;
    }

    .sidebar-footer {
        gap: 2px;
        padding-top: 4px;
        margin-top: auto;
    }

    .sidebar-footer .drawer-item {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 44px;
    }

    .sidebar-footer .drawer-item i {
        font-size: 16px;
    }

    .del-chat-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* iOS zoom fix + touch targets */
    input, textarea, select {
        font-size: 16px !important;
    }

    /* Safe area for input card */
    .input-area.m3-input-card {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Staggered entrance animation for drawer items */
    @keyframes drawerItemEnter {
        from {
            opacity: 0;
            transform: translateX(-18px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    .sidebar.open .sidebar-header,
    .sidebar.open .nav-item,
    .sidebar.open .fab-btn,
    .sidebar.open .drawer-item,
    .sidebar.open .drawer-section-label,
    .sidebar.open #chat-search,
    .sidebar.open .chat-item {
        animation: drawerItemEnter 0.35s cubic-bezier(0.32, 0.72, 0, 1) forwards;
        opacity: 0;
    }

    .sidebar.open .sidebar-header          { animation-delay: 0.04s; }
    .sidebar.open .nav-item:nth-child(1)   { animation-delay: 0.07s; }
    .sidebar.open .nav-item:nth-child(2)   { animation-delay: 0.10s; }
    .sidebar.open .fab-btn                 { animation-delay: 0.13s; }
    .sidebar.open #check-updates-btn       { animation-delay: 0.16s; }
    .sidebar.open .drawer-section-label    { animation-delay: 0.19s; }
    .sidebar.open #chat-search             { animation-delay: 0.22s; }
    .sidebar.open .chat-item:nth-child(1)  { animation-delay: 0.25s; }
    .sidebar.open .chat-item:nth-child(2)  { animation-delay: 0.28s; }
    .sidebar.open .chat-item:nth-child(3)  { animation-delay: 0.31s; }
    .sidebar.open .chat-item:nth-child(4)  { animation-delay: 0.34s; }
    .sidebar.open .chat-item:nth-child(5)  { animation-delay: 0.37s; }
    .sidebar.open .chat-item:nth-child(6)  { animation-delay: 0.40s; }
    .sidebar.open .chat-item:nth-child(7)  { animation-delay: 0.43s; }
    .sidebar.open .chat-item:nth-child(8)  { animation-delay: 0.46s; }
    .sidebar.open .chat-item:nth-child(9)  { animation-delay: 0.49s; }
    .sidebar.open .chat-item:nth-child(10) { animation-delay: 0.52s; }
    .sidebar.open .sidebar-footer .drawer-item:nth-child(1) { animation-delay: 0.30s; }
    .sidebar.open .sidebar-footer .drawer-item:nth-child(2) { animation-delay: 0.33s; }
    .sidebar.open .sidebar-footer .drawer-item:nth-child(3) { animation-delay: 0.36s; }
}

/* Extra Premium Touch: Sidebar Collapsed state for desktop (Optional) */
@media (min-width: 1025px) {
    .sidebar {
        position: sticky;
        top: 12px;
        margin-top: 12px;
        margin-right: 16px;
        margin-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
        margin-left: 16px;
        height: calc(100vh - 36px);
        height: calc(100dvh - 36px);
    }
}

/* ========================================= */
/* SCROLL TO BOTTOM BUTTON                   */
/* ========================================= */
.scroll-actions-wrapper {
    position: absolute;
    bottom: calc(100% + 16px);
    right: 16px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.scroll-to-bottom-btn {

    /* Size & shape */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;

    /* Colors — light theme */
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: 0 4px 16px rgba(0, 97, 164, 0.35), var(--m3-elevation-2);

    /* Icon */
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Hidden by default, shown when scrolled away from bottom */
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.85);
    transition:
        opacity 0.25s var(--transition-standard),
        transform 0.25s var(--transition-standard),
        background-color 0.25s,
        box-shadow 0.25s;
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}@media (hover: hover) {


.scroll-to-bottom-btn:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    box-shadow: 0 6px 20px rgba(0, 97, 164, 0.45), var(--m3-elevation-3);
    transform: translateY(-2px) scale(1.05);
}
}


.scroll-to-bottom-btn:active {
    transform: scale(0.95);
    box-shadow: var(--m3-elevation-1);
}

/* Dark theme */
[data-theme="dark"] .scroll-to-bottom-btn {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: 0 4px 20px rgba(158, 202, 255, 0.3), var(--m3-elevation-2);
}@media (hover: hover) {


[data-theme="dark"] .scroll-to-bottom-btn:hover {
    box-shadow: 0 6px 28px rgba(158, 202, 255, 0.45), var(--m3-elevation-3);
}
}


/* "New reply" indicator dot */
.scroll-to-bottom-btn::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    background: var(--md-sys-color-error);
    border: 2px solid var(--md-sys-color-surface);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s, transform 0.2s var(--transition-standard);
}

.scroll-to-bottom-btn.has-new::after {
    opacity: 1;
    transform: scale(1);
    animation: newMsgDotPulse 1.8s ease-in-out infinite;
}

@keyframes newMsgDotPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(186, 26, 26, 0.5);
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 0 0 5px rgba(186, 26, 26, 0);
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .scroll-actions-wrapper {
        right: 8px;
        bottom: calc(100% + 12px);
    }
    .scroll-to-bottom-btn, #scroll-to-top-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .scroll-actions-wrapper {
        right: 4px;
        bottom: calc(100% + 8px);
    }
}

/* ========================================= */
/* NEW AI RESPONSE ANIMATION                 */
/* ========================================= */

/* Fresh responses get this class — loaded history does NOT */
@keyframes aiResponseReveal {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
        filter: blur(6px);
    }

    55% {
        opacity: 1;
        filter: blur(0);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

.message.ai.new-response {
    animation: aiResponseReveal 0.55s cubic-bezier(0.2, 0, 0, 1) forwards !important;
    animation-delay: 0s !important;
}

/* Soft glow on the bubble that fades out */
@keyframes aiContentGlow {
    0% {
        box-shadow: 0 0 0 2px var(--md-sys-color-primary),
            0 4px 24px rgba(0, 97, 164, 0.25),
            var(--m3-elevation-2);
    }

    100% {
        box-shadow: var(--m3-elevation-1);
    }
}

/* ========================================= */
/* PREMIUM COMPONENTS (BUTTONS, MODALS, ETC) */
/* ========================================= */

.btn-primary {
    background-color: var(--md-sys-color-primary) !important;
    color: var(--md-sys-color-on-primary) !important;
    border: none !important;
    padding: 12px 24px !important;
    border-radius: var(--m3-radius-full) !important;
    font-weight: 600 !important;
    font-family: var(--font-heading) !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    transition: all 0.2s var(--transition-standard) !important;
    box-shadow: var(--m3-elevation-1) !important;
    text-decoration: none !important;
}@media (hover: hover) {


.btn-primary:hover {
    box-shadow: var(--m3-elevation-2) !important;
    opacity: 0.9 !important;
    transform: translateY(-1px) !important;
}
}


.btn-secondary {
    background-color: var(--md-sys-color-secondary-container) !important;
    color: var(--md-sys-color-on-secondary-container) !important;
    border: none !important;
    padding: 12px 24px !important;
    border-radius: var(--m3-radius-full) !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    transition: all 0.2s !important;
}

.btn-ghost {
    background: transparent !important;
    border: 1px solid var(--md-sys-color-outline-variant) !important;
    color: var(--md-sys-color-on-surface-variant) !important;
    padding: 10px 20px !important;
    border-radius: var(--m3-radius-full) !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    transition: all 0.2s !important;
    font-weight: 500 !important;
}@media (hover: hover) {


.btn-ghost:hover {
    background-color: var(--md-sys-color-surface-variant) !important;
}
}


/* Modals Refactor */
.modal-overlay {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(10px) !important;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000 !important;
    padding: 20px;
}

.modal-overlay.open {
    display: flex !important;
}

.modal-content {
    background-color: var(--md-sys-color-surface) !important;
    color: var(--md-sys-color-on-surface) !important;
    padding: 2.5rem !important;
    border-radius: var(--m3-radius-xl) !important;
    width: 100% !important;
    max-width: 500px !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3) !important;
    border: 1px solid var(--md-sys-color-outline-variant) !important;
    position: relative !important;
    animation: modalEntrance 0.3s var(--transition-standard) !important;
}

@keyframes modalEntrance {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

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

/* REMARKS SYSTEM */
.logo {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    font-family: var(--font-heading) !important;
    font-weight: 700 !important;
    font-size: 1.1rem !important;
    color: var(--md-sys-color-primary) !important;
}

.logo-icon {
    width: 40px !important;
    height: 40px !important;
    background-color: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-on-primary-container) !important;
    border-radius: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.2rem !important;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.current-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.sidebar-footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
}

.theme-toggle-btn {
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    border: 1px solid var(--md-sys-color-outline-variant) !important;
    background: var(--md-sys-color-surface-variant) !important;
    color: var(--md-sys-color-on-surface-variant) !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    font-size: 1.1rem !important;
}@media (hover: hover) {


.theme-toggle-btn:hover {
    background: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-on-primary-container) !important;
    border-color: var(--md-sys-color-primary) !important;
}
}



.table-container {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1.5rem;
    box-shadow: var(--m3-elevation-1);
}

.remarks-table {
    width: 100%;
    border-collapse: collapse;
}

.remarks-table th {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    padding: 1rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.remarks-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
}

/* Project Cards Grid */
#projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.project-card {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s var(--transition-standard);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--m3-elevation-1);
    animation: cardEntrance 0.5s ease backwards;
}@media (hover: hover) {


.project-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--m3-elevation-2);
    border-color: var(--md-sys-color-primary);
}
}


.project-card h3 {
    font-family: var(--font-heading);
    margin: 0;
    font-size: 1.25rem;
    color: var(--md-sys-color-on-surface);
}

.project-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface-variant);
}

.project-meta span {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Field Groups & Inputs */
.field-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--md-sys-color-primary);
}

#editor-remark-text {
    background: var(--md-sys-color-surface-variant);
    padding: 1.5rem;
    border-radius: var(--m3-radius-md);
    line-height: 1.6;
    font-size: 0.95rem;
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface-variant);
}

textarea#editor-answer-text {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border-radius: var(--m3-radius-md);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

.btn-ai {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--m3-radius-full);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
    transition: all 0.3s;
}@media (hover: hover) {


.btn-ai:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
}
}


.m3-select {
    width: 100%;
    padding: 12px;
    border-radius: var(--m3-radius-md);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    cursor: pointer;
}

/* Upload & Field Inputs */
.upload-zone {
    border: 2px dashed var(--md-sys-color-outline-variant);
    padding: 2.5rem;
    border-radius: var(--m3-radius-lg);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--md-sys-color-surface-variant);
}@media (hover: hover) {


.upload-zone:hover {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
}
}


#project-name-input {
    width: 100%;
    padding: 14px;
    margin-bottom: 1.5rem;
    border-radius: var(--m3-radius-md);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    font-size: 1rem;
}

/* Status Badges & Dropdown */
.status-badge,
.status-dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--m3-radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, color 0.2s;
}

.status-open {
    background: #fee2e2;
    color: #991b1b;
}

.status-work {
    background: #fef3c7;
    color: #92400e;
}

.status-done {
    background: #dcfce7;
    color: #166534;
}

.status-rejected {
    background: #e5e7eb;
    color: #374151;
}

[data-theme="dark"] .status-open {
    background: #450a0a;
    color: #fca5a5;
}

[data-theme="dark"] .status-work {
    background: #451a03;
    color: #fcd34d;
}

[data-theme="dark"] .status-done {
    background: #064e3b;
    color: #6ee7b7;
}

[data-theme="dark"] .status-rejected {
    background: #374151;
    color: #d1d5db;
}

/* Custom Status Dropdown */
.status-dropdown {
    position: relative;
    display: inline-block;
}

.status-dropdown-trigger {
    white-space: nowrap;
}

.status-dropdown-trigger i {
    font-size: 0.6rem;
    opacity: 0.7;
}

.status-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 100;
    min-width: 160px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    box-shadow: var(--m3-elevation-2);
    padding: 6px;
    gap: 2px;
    flex-direction: column;
}

.status-dropdown-menu.open {
    display: flex;
}

.status-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--m3-radius-md);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.status-dropdown-item:hover {
    background: var(--md-sys-color-surface-variant);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.status-open { background: #ef4444; }
.status-dot.status-work { background: #f59e0b; }
.status-dot.status-done { background: #22c55e; }
.status-dot.status-rejected { background: #9ca3af; }

[data-theme="dark"] .status-dot.status-open { background: #fca5a5; }
[data-theme="dark"] .status-dot.status-work { background: #fcd34d; }
[data-theme="dark"] .status-dot.status-done { background: #6ee7b7; }
[data-theme="dark"] .status-dot.status-rejected { background: #9ca3af; }

/* Premium Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none !important; /* Hide old floating button */
}

/* Mobile Adaptation Overhaul */
@media (max-width: 768px) {
    .content-view {
        padding: 1rem;
    }

    .view-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .view-header h2 {
        font-size: 1.5rem;
    }

    .detail-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .detail-header h2 {
        font-size: 1.25rem;
        order: -1;
        width: 100%;
    }

    .detail-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .remarks-filter-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .remarks-filter-panel input,
    .remarks-filter-panel select {
        width: 100%;
    }

    .remarks-table {
        min-width: 700px;
        font-size: 0.85rem;
    }

    .remarks-table th,
    .remarks-table td {
        padding: 0.75rem 0.5rem;
    }

    .m3-dialog {
        padding: 16px;
        max-width: calc(100vw - 32px);
        width: 100%;
    }

    .remark-actions {
        gap: 8px;
    }

    .inline-edit-textarea {
        font-size: 16px; /* Prevent iOS zoom */
    }


}

@media (max-width: 480px) {
    #projects-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 480px) {
    .hide-mobile {
        display: inline !important;
    }
}

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

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

.message.ai.new-response .message-content {
    animation: aiContentGlow 1.8s ease forwards;
}

[data-theme="dark"] .message.ai.new-response .message-content {
    animation: aiContentGlowDark 1.8s ease forwards;
}

.content-view {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.view-header h2 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.75rem;
    color: var(--md-sys-color-on-surface);
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.detail-header h2 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--md-sys-color-on-surface);
    flex: 1;
    min-width: 200px;
}

.detail-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.m3-surface {
    background: var(--md-sys-color-surface);
    border-radius: var(--m3-radius-lg);
    border: 1px solid var(--md-sys-color-outline-variant);
    overflow: hidden;
}

@keyframes aiContentGlowDark {
    0% {
        box-shadow: 0 0 0 2px var(--md-sys-color-primary),
            0 4px 24px rgba(158, 202, 255, 0.2),
            var(--m3-elevation-2);
    }

    100% {
        box-shadow: var(--m3-elevation-1);
    }
}

/* ========================================= */
/* MESSAGE ACTIONS                           */
/* ========================================= */
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s var(--transition-standard);
    justify-content: flex-end;
}@media (hover: hover) {


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


.msg-action-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    border-radius: var(--m3-radius-md);
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 14px;
}@media (hover: hover) {


.msg-action-btn:hover {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-primary);
}
}


@media (max-width: 768px), (hover: none) {
    .message-actions {
        opacity: 1;
    }
}

/* ========================================= */
/* SIDEBAR VERTICAL COMPRESSION (MOBILE)     */
/* ========================================= */
@media (max-width: 768px) {
    .drawer-item, .nav-item {
        height: 40px !important;
        min-height: 40px !important;
    }
    
    .chat-item {
        height: 44px !important;
        min-height: 44px !important;
    }
    
    .fab-btn {
        height: 44px !important;
        min-height: 44px !important;
        margin: 8px 16px !important;
    }
    
    .sidebar-header {
        height: 56px !important;
        padding: 12px 16px !important;
        margin-bottom: 0 !important;
    }
    
    .drawer-section-label {
        padding: 12px 16px 4px 16px !important;
    }
    
    .sidebar-footer {
        padding: 8px 16px !important;
        gap: 4px !important;
        margin-top: auto !important;
    }
}

/* ========================================= */
/* TACTILE FEEDBACK (M3 PREMIUM)             */
/* ========================================= */
.icon-btn-filled:active, .m3-btn-filled:active, .m3-btn-text:active, 
.icon-btn-ghost:active, .mobile-menu-btn:active, .theme-toggle-btn:active, 
.fab-btn:active, .model-switch-btn:active, .m3-chip:active, .nav-item:active, .chat-item:active {
    transform: scale(0.96) !important;
    transition: transform 0.1s cubic-bezier(0, 0, 0, 1) !important;
}

/* ========================================= */
/* 1. AUTO-RESIZE TEXTAREA (already in JS)   */
/* ========================================= */
/* No extra CSS needed, max-height handled by existing #message-input */

/* ========================================= */
/* 2. COPY CODE BUTTON                       */
/* ========================================= */
pre {
    position: relative;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(var(--md-sys-color-surface-rgb), 0.9);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-sm);
    color: var(--md-sys-color-on-surface-variant);
    padding: 4px 10px;
    font-size: 12px;
    font-family: var(--font-body);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(4px);
}

pre:hover .copy-code-btn {
    opacity: 1;
}

.copy-code-btn:hover {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.copy-code-btn.copied {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    opacity: 1;
}

/* ========================================= */
/* 3. TOAST NOTIFICATIONS                    */
/* ========================================= */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.m3-toast {
    background: rgba(var(--md-sys-color-surface-rgb), 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    padding: 14px 18px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: var(--m3-elevation-3);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    animation: toastSlideIn 0.35s var(--transition-standard) forwards;
}

.m3-toast.toast-out {
    animation: toastSlideOut 0.3s var(--transition-standard) forwards;
}

.m3-toast.toast-success {
    border-left: 4px solid var(--md-sys-color-primary);
}

.m3-toast.toast-error {
    border-left: 4px solid var(--md-sys-color-error);
}

.m3-toast.toast-info {
    border-left: 4px solid var(--md-sys-color-secondary);
}

@keyframes toastSlideIn {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes toastSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(120%); opacity: 0; }
}

/* ========================================= */
/* 4. DRAG & DROP OVERLAY                    */
/* ========================================= */
.drag-active-overlay {
    position: fixed;
    inset: 0;
    border: 2px dashed var(--md-sys-color-primary);
    background: rgba(var(--md-sys-color-primary-container), 0.4);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.drag-active-overlay.visible {
    opacity: 1;
}

.drag-active-overlay span {
    font-size: 18px;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    background: rgba(var(--md-sys-color-surface-rgb), 0.9);
    padding: 16px 28px;
    border-radius: var(--m3-radius-xl);
    box-shadow: var(--m3-elevation-2);
}

/* ========================================= */
/* 5. SYSTEM THEME (no extra CSS)            */
/* ========================================= */

/* ========================================= */
/* 6. MESSAGE APPEAR ANIMATION               */
/* ========================================= */
.message {
    animation: messageAppear 0.3s var(--transition-standard) forwards;
}

.message.user {
    animation: messageAppear 0.25s var(--transition-standard) forwards;
}

.typing-message {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
}

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

/* ========================================= */
/* 7. SKELETON LOADING                       */
/* ========================================= */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--md-sys-color-surface-variant) 25%,
        var(--md-sys-color-outline-variant) 50%,
        var(--md-sys-color-surface-variant) 75%
    );
    background-size: 200% 100%;
    border-radius: var(--m3-radius-sm);
    animation: shimmer 1.5s infinite;
}

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

.chat-skeleton-item {
    height: 48px;
    margin: 4px 0;
    border-radius: 8px;
}

/* ========================================= */
/* 8. CHAT SEARCH INPUT                      */
/* ========================================= */
#chat-search {
    margin: 4px 12px 2px 12px;
    padding: 8px 14px;
    border-radius: var(--m3-radius-full);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: rgba(var(--md-sys-color-surface-rgb), 0.6);
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: calc(100% - 24px);
}

#chat-search:focus {
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 3px rgba(0, 97, 164, 0.15);
}

#chat-search::placeholder {
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.6;
}

/* ========================================= */
/* 9. REMARKS FILTER PANEL                   */
/* ========================================= */
.remarks-filter-panel {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    background: rgba(var(--md-sys-color-surface-rgb), 0.7);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.remarks-filter-panel input,
.remarks-filter-panel select {
    padding: 8px 12px;
    border-radius: var(--m3-radius-full);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: rgba(var(--md-sys-color-surface-rgb), 0.8);
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-body);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease;
}

.remarks-filter-panel input:focus,
.remarks-filter-panel select:focus {
    border-color: var(--md-sys-color-primary);
}

.remarks-filter-panel input {
    flex: 1;
    min-width: 200px;
}

.remarks-filter-panel select {
    min-width: 140px;
}

/* Batch Progress Panel */
.batch-progress-panel {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--md-sys-color-primary-container);
    border-radius: var(--m3-radius-lg);
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.batch-progress-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

.batch-progress-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-sys-color-on-primary-container);
}

.batch-progress-text {
    font-size: 0.75rem;
    color: var(--md-sys-color-on-primary-container);
    opacity: 0.8;
}

.batch-progress-bar-bg {
    flex: 1;
    height: 6px;
    background: var(--md-sys-color-surface);
    border-radius: var(--m3-radius-full);
    overflow: hidden;
    min-width: 100px;
}

.batch-progress-bar {
    height: 100%;
    background: var(--md-sys-color-primary);
    border-radius: var(--m3-radius-full);
    transition: width 0.3s ease;
}

.generate-btn-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border: none;
    border-radius: var(--m3-radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.generate-btn-row:hover {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.generate-btn-row:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================= */
/* 10. SCROLL TO TOP BUTTON                  */
/* ========================================= */
#scroll-to-top-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    box-shadow: var(--m3-elevation-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.85);
    transition: opacity 0.25s var(--transition-standard), transform 0.25s var(--transition-standard);
}

#scroll-to-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ========================================= */
/* 11. SMOOTH THEME TRANSITIONS              */
/* ========================================= */
body,
.sidebar,
.topbar,
.m3-input-card,
.message-content,
.m3-dialog,
.m3-auth-card,
.remarks-filter-panel,
.project-card,
.m3-btn-filled,
.m3-btn-text,
.m3-btn-tonal {
    transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

/* ========================================= */
/* 12. HAPTIC (no CSS needed)                */
/* ========================================= */

/* ========================================= */
/* 13. NAV BADGE                             */
/* ========================================= */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    font-size: 10px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}

.nav-badge.hidden {
    display: none;
}

/* ========================================= */
/* 14. CONTEXT MENU                          */
/* ========================================= */
#chat-context-menu {
    position: fixed;
    z-index: 10001;
    background: rgba(var(--md-sys-color-surface-rgb), 0.98);
    backdrop-filter: blur(12px);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--m3-radius-lg);
    box-shadow: var(--m3-elevation-3);
    padding: 6px 0;
    min-width: 180px;
    display: none;
    flex-direction: column;
    animation: contextMenuAppear 0.15s ease-out forwards;
    overflow: hidden;
}

#chat-context-menu.open {
    display: flex;
}

.context-menu-item {
    padding: 10px 16px;
    font-size: 14px;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-body);
}

.context-menu-item:hover {
    background: var(--md-sys-color-surface-variant);
}

.context-menu-item.delete {
    color: var(--md-sys-color-error);
}

.context-menu-item.delete:hover {
    background: var(--md-sys-color-error-container);
}

@keyframes contextMenuAppear {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}


/* ========================================= */
/* MOBILE UX IMPROVEMENTS                    */
/* ========================================= */

/* Remove 300ms tap delay globally */
button, a, .nav-item, .chat-item, .drawer-item, .m3-chip, .icon-btn-ghost, .icon-btn-filled {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ========================================= */
/* PULL-TO-REFRESH INDICATOR                 */
/* ========================================= */
.pull-refresh-wrapper {
    position: absolute;
    top: -50px;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 100;
    transition: top 0.2s ease;
}

.pull-refresh-wrapper.visible {
    top: 8px;
}

.pull-refresh-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--md-sys-color-outline-variant);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: pullSpin 0.8s linear infinite;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.pull-refresh-wrapper.visible .pull-refresh-spinner {
    opacity: 1;
}

@keyframes pullSpin {
    to { transform: rotate(360deg); }
}

/* Typing message bubble has no bottom padding gap */
.message.typing-message .message-content {
    padding: 10px 14px;
}

/* ========================================= */
/* 15. CHAT FILE CARD & ATTACHMENT LINKS     */
/* ========================================= */

/* Chat File Card - Premium M3 styled card inside chat bubbles */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 10px 14px;
    min-width: 240px;
    max-width: 340px;
    margin: 4px 0;
    transition: all 0.2s ease-in-out;
    text-align: left;
}

[data-theme="light"] .message.user .chat-file-card {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-file-card:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.25);
}

.file-card-icon {
    font-size: 20px;
    color: inherit;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.file-card-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
}

.file-card-status {
    font-size: 11px;
    opacity: 0.75;
}

.file-card-download-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: inherit;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.file-card-download-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.08);
}

.file-card-download-btn i {
    font-size: 12px;
}

/* Sidebar attachment link styling */
.chat-attachment-item .file-name-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    flex: 1;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.2s;
}

.chat-attachment-item .file-name-link:hover {
    text-decoration: underline;
    opacity: 0.85;
}
