/* ============================================
   CHAT UI - Modern Design 2026
   Light Theme Default + Green Accent
   ============================================ */

/* CSS Variables for easy theming - LIGHT MODE (Default) */
:root {
    /* Theme toggle transition */
    --theme-transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Primary colors - Green accent */
    --primary-color: #4a9d3f;
    --primary-gradient: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    --secondary-gradient: linear-gradient(135deg, #68b35a 0%, #7ac96d 100%);
    --accent-gradient: linear-gradient(135deg, #4a9d3f 0%, #7ac96d 100%);
    --success-gradient: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    
    /* Backgrounds */
    --bg-body: #f5f5f5;
    --bg-body-gradient: 
        radial-gradient(ellipse at 20% 20%, rgba(74, 157, 63, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(74, 157, 63, 0.03) 0%, transparent 50%);
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-input-area: #ffffff;
    --bg-glass: rgba(0, 0, 0, 0.02);
    --bg-glass-light: rgba(0, 0, 0, 0.04);
    --bg-message-bot: #f0f2f5;
    --bg-message-user: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    --bg-input: #f0f2f5;
    
    /* Text colors */
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a68;
    --text-muted: #8c8ca1;
    --text-bubble-user: #ffffff;
    --text-bubble-bot: #1a1a2e;
    
    /* Borders */
    --border-glass: rgba(0, 0, 0, 0.08);
    --border-glow: rgba(74, 157, 63, 0.3);
    --border-input-focus: rgba(74, 157, 63, 0.5);
    
    /* Shadows */
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-glow: 0 0 30px rgba(74, 157, 63, 0.1);
    --shadow-btn: 0 4px 15px rgba(74, 157, 63, 0.3);
    --shadow-btn-hover: 0 8px 25px rgba(74, 157, 63, 0.4);
    
    /* Accent colors for markdown */
    --color-heading: #4a9d3f;
    --color-strong: #2d6a4f;
    --color-link: #4a9d3f;
    --color-link-hover: #68b35a;
    --color-code-bg: #f0f2f5;
    --color-code-text: #2d6a4f;
    --color-online: #4a9d3f;
    
    /* Border radius */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================
   DARK MODE THEME
   ============================================ */
[data-theme="dark"] {
    /* Primary colors - Green accent */
    --primary-color: #4a9d3f;
    --primary-gradient: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    --accent-gradient: linear-gradient(135deg, #4a9d3f 0%, #7ac96d 100%);
    --success-gradient: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    
    /* Backgrounds */
    --bg-body: #0f0f1a;
    --bg-body-gradient: 
        radial-gradient(ellipse at 20% 20%, rgba(74, 157, 63, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(74, 157, 63, 0.08) 0%, transparent 50%);
    --bg-card: rgba(25, 25, 45, 0.85);
    --bg-header: rgba(15, 15, 26, 0.9);
    --bg-input-area: rgba(15, 15, 26, 0.95);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-light: rgba(255, 255, 255, 0.08);
    --bg-message-bot: rgba(255, 255, 255, 0.06);
    --bg-message-user: linear-gradient(135deg, #4a9d3f 0%, #68b35a 100%);
    --bg-input: rgba(255, 255, 255, 0.05);
    
    /* Text colors */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.45);
    --text-bubble-user: #ffffff;
    --text-bubble-bot: #ffffff;
    
    /* Borders */
    --border-glass: rgba(255, 255, 255, 0.1);
    --border-glow: rgba(74, 157, 63, 0.4);
    --border-input-focus: rgba(74, 157, 63, 0.5);
    
    /* Shadows */
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 40px rgba(74, 157, 63, 0.15);
    --shadow-btn: 0 4px 15px rgba(74, 157, 63, 0.4);
    --shadow-btn-hover: 0 8px 25px rgba(74, 157, 63, 0.5);
    
    /* Accent colors for markdown */
    --color-heading: #7ac96d;
    --color-strong: #a8e6cf;
    --color-link: #7ac96d;
    --color-link-hover: #a8e6cf;
    --color-code-bg: rgba(0, 0, 0, 0.4);
    --color-code-text: #a8e6cf;
    --color-online: #68b35a;
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-body);
    background-image: var(--bg-body-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    transition: background var(--theme-transition), color var(--theme-transition);
}

/* Main Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-glass);
    border-right: 1px solid var(--border-glass);
    box-shadow: var(--shadow-soft), var(--shadow-glow);
    position: relative;
    overflow: hidden;
    transition: background var(--theme-transition), border-color var(--theme-transition);
}

.chat-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.08) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
    transition: background var(--theme-transition);
}

[data-theme="light"] .chat-container::before {
    background: linear-gradient(180deg, rgba(74, 157, 63, 0.05) 0%, transparent 100%);
}

[data-theme="light"] .chat-container {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* ============================================
   HEADER
   ============================================ */
.chat-header {
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-glass);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background var(--theme-transition), border-color var(--theme-transition);
}

[data-theme="light"] .chat-header {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.chat-header-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--radius-sm);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--theme-transition);
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 1;
}

.chat-header-info {
    margin-left: 14px;
}

.chat-header-info h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    letter-spacing: -0.3px;
    transition: color var(--theme-transition);
}

.chat-header-info p {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--theme-transition);
}

.chat-header-info p::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--color-online);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--color-online);
    animation: pulse-online 2s infinite;
}

@keyframes pulse-online {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

/* Header Buttons */
.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chatModalThemeToggle, #chatModalLogoutBtn, #chatModalDeleteBtn {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 15px;
    cursor: pointer;
    transition: var(--transition-smooth);
    backdrop-filter: blur(10px);
    color: var(--text-secondary);
    position: relative;
}

#chatModalThemeToggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
}

/* Custom Tooltips - Aparecen instantáneamente */
#chatModalThemeToggle::after,
#chatModalDeleteBtn::after,
#chatModalLogoutBtn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    background: var(--bg-header);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--border-glass);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Flechita del tooltip */
#chatModalThemeToggle::before,
#chatModalDeleteBtn::before,
#chatModalLogoutBtn::before {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    border: 6px solid transparent;
    border-bottom-color: var(--border-glass);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
    pointer-events: none;
    z-index: 1001;
}

#chatModalThemeToggle:hover::after,
#chatModalDeleteBtn:hover::after,
#chatModalLogoutBtn:hover::after,
#chatModalThemeToggle:hover::before,
#chatModalDeleteBtn:hover::before,
#chatModalLogoutBtn:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

#chatModalThemeToggle:hover, #chatModalLogoutBtn:hover, #chatModalDeleteBtn:hover {
    background: var(--bg-glass-light);
    border-color: var(--border-glow);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

#chatModalDeleteBtn:hover {
    border-color: rgba(245, 87, 108, 0.5);
    box-shadow: 0 8px 20px rgba(245, 87, 108, 0.15);
}

#chatModalLogoutBtn:hover {
    border-color: rgba(255, 100, 100, 0.5);
    box-shadow: 0 8px 20px rgba(255, 100, 100, 0.15);
}

#chatModalThemeToggle:active, #chatModalLogoutBtn:active, #chatModalDeleteBtn:active {
    transform: translateY(0) scale(0.98);
}

/* Theme toggle icon animation */
.theme-icon {
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#chatModalThemeToggle:hover .theme-icon {
    transform: rotate(180deg);
}

[data-theme="light"] #chatModalThemeToggle,
[data-theme="light"] #chatModalLogoutBtn,
[data-theme="light"] #chatModalDeleteBtn {
    backdrop-filter: none;
}

/* Theme toggle del buscador-portal-web (sin recuadro) */
#themeToggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-smooth);
    position: relative;
}

#themeToggle:hover {
    background: var(--bg-glass-light);
    transform: translateY(-1px);
}

#themeToggle:active {
    transform: translateY(0) scale(0.95);
}

#themeToggle .theme-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#themeToggle:hover .theme-icon {
    transform: rotate(20deg);
}

#themeToggle .icon-sun { color: #f5b800; }
#themeToggle .icon-moon { color: #c8c8e0; }

/* Mostrar solo el icono correspondiente al tema actual */
[data-theme="light"] #themeToggle .icon-moon,
:root:not([data-theme="dark"]) #themeToggle .icon-moon { display: none; }
[data-theme="dark"] #themeToggle .icon-sun { display: none; }

/* ============================================
   MESSAGES AREA
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    position: relative;
    z-index: 1;
    transition: background var(--theme-transition);
    overflow-anchor: none; /* Deshabilita scroll anchoring nativo del browser */
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: var(--radius-full);
    transition: background 0.3s;
}

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

/* Message Base */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageSlideIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

/* Message Avatar */
.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--bg-glass-light);
    border: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    overflow: hidden;
    transition: var(--transition-smooth);
}

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

.message.user .message-avatar {
    background: var(--primary-gradient);
    color: white;
    border: none;
    box-shadow: var(--shadow-btn);
}

.message:hover .message-avatar {
    transform: scale(1.05);
}

/* Message Content */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 100%;
}

/* Message Bubble */
.message-bubble {
    background: var(--bg-message-bot);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
    padding: 14px 18px;
    color: var(--text-bubble-bot);
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    position: relative;
    transition: var(--transition-smooth);
}

[data-theme="light"] .message-bubble {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.message-bubble:hover {
    background: var(--bg-glass-light);
    border-color: var(--border-glow);
}

.message.user .message-bubble {
    background: var(--bg-message-user);
    border: none;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
    box-shadow: var(--shadow-btn);
    color: var(--text-bubble-user);
}

.message.user .message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-btn-hover);
}

/* Message Time */
.message-time {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
}

/* ============================================
   MESSAGE CONTENT STYLING (Markdown)
   ============================================ */
.message-bubble h3 {
    color: var(--color-heading);
    font-size: 15px;
    font-weight: 600;
    margin: 12px 0 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color var(--theme-transition);
}

.message-bubble h3:first-child {
    margin-top: 0;
}

.message-bubble h3::before {
    content: '';
    width: 4px;
    height: 16px;
    background: var(--accent-gradient);
    border-radius: 2px;
}

.message-bubble strong {
    color: var(--color-strong);
    font-weight: 600;
    transition: color var(--theme-transition);
}

.message-bubble ul, 
.message-bubble ol {
    margin: 10px 0;
    padding-left: 0;
    list-style: none;
}

.message-bubble li {
    margin: 8px 0;
    padding-left: 20px;
    position: relative;
    line-height: 1.6;
}

.message-bubble li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    width: 6px;
    height: 6px;
    background: var(--accent-gradient);
    border-radius: 50%;
}

.message-bubble a {
    color: var(--color-link);
    text-decoration: none;
    font-weight: 500;
    position: relative;
    transition: color var(--transition-fast);
}

.message-bubble a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--color-link);
    transition: width 0.3s ease;
}

.message-bubble a:hover {
    color: var(--color-link-hover);
}

.message-bubble a:hover::after {
    width: 100%;
}

/* Enlaces en mensajes del usuario (con fondo verde) */
.message.user .message-bubble a {
    color: #ffffff;
    font-weight: 600;
}

.message.user .message-bubble a::after {
    background: rgba(255, 255, 255, 0.7);
}

.message.user .message-bubble a:hover {
    color: rgba(255, 255, 255, 0.9);
}

.message-bubble code {
    background: var(--color-code-bg);
    color: var(--color-code-text);
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    border: 1px solid var(--border-glass);
    transition: background var(--theme-transition), color var(--theme-transition);
}

.message-bubble p {
    margin: 8px 0;
}

.message-bubble p:first-child {
    margin-top: 0;
}

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

/* Property Cards */
.property-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 16px;
    margin: 12px 0;
    transition: var(--transition-smooth);
}

.property-card:hover {
    background: var(--bg-glass-light);
    border-color: var(--border-glow);
    transform: translateY(-2px);
}

.property-card-title {
    color: var(--color-heading);
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.property-card-title::before {
    content: '🏠';
    font-size: 16px;
}

.property-card-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 8px 0;
    padding: 8px 12px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.property-card-label {
    color: var(--text-muted);
}

.property-card-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Bot Images */
.bot-image-row {
    display: flex;
    flex-direction: row;
    gap: 10px;
    margin-top: 12px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.bot-image-thumb {
    max-width: 120px;
    max-height: 100px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-glass);
    cursor: pointer;
    transition: var(--transition-smooth);
    object-fit: cover;
}

.bot-image-thumb:hover {
    transform: scale(1.08);
    border-color: var(--border-glow);
    box-shadow: var(--shadow-btn);
}

/* ============================================
   INPUT AREA
   ============================================ */
.chat-input-container {
    background: var(--bg-input-area);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-glass);
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    gap: 12px;
    align-items: center;
    position: sticky;
    bottom: 0;
    z-index: 100;
    transition: background var(--theme-transition), border-color var(--theme-transition);
}

.scroll-to-bottom-btn {
    position: absolute;
    bottom: 90px;
    right: 20px;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary, #2e7d32);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22);
    transition: opacity 0.2s, transform 0.2s;
    opacity: 0.95;
}

.scroll-to-bottom-btn:hover {
    opacity: 1;
    transform: translateY(-2px);
}

[data-theme="light"] .chat-input-container {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    padding: 14px 24px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: var(--transition-smooth);
    backdrop-filter: blur(10px);
}

[data-theme="light"] .chat-input {
    backdrop-filter: none;
}

.chat-input:focus {
    background: var(--bg-glass-light);
    border-color: var(--border-input-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15), 0 4px 20px rgba(102, 126, 234, 0.1);
}

[data-theme="light"] .chat-input:focus {
    box-shadow: 0 0 0 3px rgba(74, 157, 63, 0.15), 0 4px 20px rgba(74, 157, 63, 0.1);
}

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

.chat-send-btn {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
    flex-shrink: 0;
    box-shadow: var(--shadow-btn);
    position: relative;
    overflow: hidden;
}

.chat-send-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.chat-send-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: var(--shadow-btn-hover);
}

.chat-send-btn:hover::before {
    opacity: 1;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 0;
}

.typing-indicator.active {
    display: flex;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-gradient);
    animation: typingBounce 1.4s infinite;
}

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

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

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

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

/* Loading message */
.message.loading .message-bubble {
    background: var(--bg-glass);
    padding: 16px 20px;
}

/* ============================================
   USER FORM (if visible)
   ============================================ */
.user-form {
    max-width: 400px;
    margin: 80px auto;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft), var(--shadow-glow);
    padding: 40px 36px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: formFadeIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: background var(--theme-transition), border-color var(--theme-transition);
}

[data-theme="light"] .user-form {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

@keyframes formFadeIn {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.user-form h2 {
    text-align: center;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
}

.user-form label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 6px;
    transition: color var(--theme-transition);
}

.user-form input[type="text"],
.user-form input[type="tel"] {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition-smooth);
    margin-bottom: 8px;
}

.user-form input[type="text"]:focus,
.user-form input[type="tel"]:focus {
    border-color: var(--border-input-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
    background: var(--bg-glass-light);
}

[data-theme="light"] .user-form input[type="text"]:focus,
[data-theme="light"] .user-form input[type="tel"]:focus {
    box-shadow: 0 0 0 3px rgba(74, 157, 63, 0.15);
}

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

.user-form button[type="submit"] {
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 0;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    margin-top: 12px;
    box-shadow: var(--shadow-btn);
}

.user-form button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-btn-hover);
}

.user-form button[type="submit"]:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 700px) {
    .chat-container {
        max-width: 100vw;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .chat-header {
        padding: 12px 14px;
    }
    
    .chat-header-avatar {
        width: 42px;
        height: 42px;
    }
    
    .chat-header-info h2 {
        font-size: 15px;
    }
    
    .chat-messages {
        padding: 16px 12px;
        gap: 14px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .message-avatar {
        width: 36px;
        height: 36px;
    }
    
    .message-bubble {
        padding: 12px 14px;
        font-size: 14px;
        border-radius: var(--radius-md) var(--radius-md) var(--radius-md) var(--radius-sm);
    }
    
    .message.user .message-bubble {
        border-radius: var(--radius-md) var(--radius-md) var(--radius-sm) var(--radius-md);
    }
    
    .chat-input-container {
        padding: 12px 14px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        gap: 10px;
    }
    
    .chat-input {
        padding: 12px 18px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .chat-send-btn {
        width: 46px;
        height: 46px;
    }
    
    #chatModalThemeToggle, #chatModalLogoutBtn, #chatModalDeleteBtn {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    #chatModalThemeToggle {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 400px) {
    .chat-header-info h2 {
        font-size: 14px;
        max-width: 140px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .chat-header-info p {
        font-size: 11px;
    }
    
    .message-bubble {
        padding: 10px 12px;
    }
    
    .bot-image-thumb {
        max-width: 90px;
        max-height: 75px;
    }
    
    .header-actions {
        gap: 4px;
    }
    
    #chatModalThemeToggle, #chatModalLogoutBtn, #chatModalDeleteBtn {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    #chatModalThemeToggle {
        width: 36px;
        height: 36px;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    .chat-container {
        max-width: 900px;
    }
    
    .message {
        max-width: 75%;
    }
}

/* ============================================
   ACCESSIBILITY & MISC
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--border-input-focus);
    outline-offset: 2px;
}

/* Selection color */
::selection {
    background: rgba(102, 126, 234, 0.4);
    color: white;
}

[data-theme="light"] ::selection {
    background: rgba(74, 157, 63, 0.3);
    color: #1a1a2e;
}

/* Smooth font rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .chat-input-container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}