:root {
    /* Light theme (default) */
    --bg-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-chat: white;
    --bg-header: linear-gradient(135deg, #2c3e50, #34495e);
    --bg-message-bot: white;
    --bg-message-user: #3498db;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-inverse: white;
    --border-color: #e1e5e9;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    --quick-btn-bg: #f8f9fa;
    --quick-btn-hover: #3498db;
    --input-bg: white;
    --scrollbar-track: #f1f1f1;
    --scrollbar-thumb: #c1c1c1;
}

[data-theme="dark"] {
    /* Dark theme */
    --bg-primary: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --bg-chat: #1e1e1e;
    --bg-header: linear-gradient(135deg, #0f3460, #1a1a2e);
    --bg-message-bot: #2d3748;
    --bg-message-user: #2c5282;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-inverse: white;
    --border-color: #4a5568;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    --quick-btn-bg: #2d3748;
    --quick-btn-hover: #4a5568;
    --input-bg: #2d3748;
    --scrollbar-track: #2d3748;
    --scrollbar-thumb: #4a5568;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

html {
    height: 100%;
    height: -webkit-fill-available;
    -webkit-text-size-adjust: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    background: var(--bg-primary, linear-gradient(135deg, #667eea 0%, #764ba2 100%)) !important;
    background-attachment: fixed !important; /* Keep gradient visible on scroll */
    color: var(--text-primary);
    height: 100vh;
    height: -webkit-fill-available;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    overflow-y: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    height: 100vh;
    height: -webkit-fill-available;
    max-height: 100vh;
    max-height: -webkit-fill-available;
    min-height: 500px;
    background: var(--bg-chat) !important;
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    z-index: 1;
    box-sizing: border-box;
}

/* Header */
.chat-header {
    background: var(--bg-header);
    color: var(--text-inverse);
    padding: 20px;
    padding-top: 40px; /* Extra top padding to accommodate status indicator */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-content i {
    font-size: 2rem;
    color: #3498db;
}

.header-text h2 {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.header-text p {
    opacity: 0.8;
    font-size: 0.9rem;
}

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

/* Setup Button */
.setup-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-inverse);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.setup-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Language Selector */
.language-select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-inverse);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    min-width: 120px;
}

.language-select option {
    background: #2c3e50;
    color: white;
    padding: 10px;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-inverse);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.clear-chat-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-inverse);
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-chat-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px;
    border-radius: 10px;
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.7rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: #2ecc71;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

/* Chat Messages */
.chat-messages {
    flex: 1;
    min-height: 0;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-chat);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.message {
    display: flex;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease-in;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.bot-message {
    align-items: flex-start;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 10px;
    flex-shrink: 0;
}

.bot-message .message-avatar {
    background: #3498db;
    color: white;
}

.user-message .message-avatar {
    background: var(--text-primary);
    color: var(--bg-chat);
}

.message-content {
    max-width: 70%;
    padding: 15px;
    border-radius: 18px;
    line-height: 1.5;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.bot-message .message-content {
    background: var(--bg-message-bot);
    border: 1px solid var(--border-color);
    border-top-left-radius: 5px;
}

.user-message .message-content {
    background: var(--bg-message-user);
    color: white;
    border-top-right-radius: 5px;
}

.message-content p {
    margin-bottom: 10px;
}

.message-content ul {
    margin: 10px 0;
    padding-left: 20px;
}

.message-content li {
    margin-bottom: 5px;
}

/* Quick Questions */
.quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
}

.quick-btn {
    background: var(--quick-btn-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: var(--quick-btn-hover);
    color: white;
    border-color: var(--quick-btn-hover);
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 15px;
    padding: 0 20px 20px;
    color: var(--text-secondary);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.chat-input-container {
    padding: 20px;
    padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    background: var(--bg-chat);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
}

#messageInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: border-color 0.3s;
}

#messageInput:focus {
    border-color: #3498db;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.send-button {
    width: 50px;
    height: 50px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.05);
}

.send-button:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.char-count {
    font-weight: 500;
}

.disclaimer {
    font-style: italic;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

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

/* Theme transition smoothness */
.chat-container,
.chat-header,
.chat-messages,
.chat-input-container,
.message-content,
.quick-btn,
#messageInput {
    transition: all 0.3s ease;
}

/* Temporary messages */
.temp-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #2ecc71;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 1000;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideInRight 0.3s ease;
}

.temp-message-error {
    background: #e74c3c;
}

.temp-message-info {
    background: #3498db;
}

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

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

/* Storage indicator */
.storage-indicator {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-left: 10px;
}

/* ================================================ */
/* ADMIN PAGE BUTTON STYLES - ADDED */
/* ================================================ */

/* Danger button for reset */
.btn-danger {
    background: #e74c3c !important;
    border-color: #c0392b !important;
    color: white !important;
}

.btn-danger:hover {
    background: #c0392b !important;
    border-color: #a93226 !important;
}

/* Info button for backup */
.btn-info {
    background: #3498db !important;
    border-color: #2980b9 !important;
    color: white !important;
}

.btn-info:hover {
    background: #2980b9 !important;
    border-color: #1f618d !important;
}

/* Edit mode banner styles */
.edit-mode-banner {
    animation: fadeIn 0.5s ease;
}

/* Button spacing in admin */
.nav-buttons button {
    margin: 0 5px;
}

/* Responsive button adjustments */
@media (max-width: 768px) {
    .nav-buttons {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .nav-buttons button {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }
}

/* ================================================ */
/* RESPONSIVE STYLES */
/* ================================================ */

@media (max-width: 768px) {
    html {
        height: 100dvh;
    }
    
    body {
        padding: 0;
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh; /* Dynamic viewport height */
        min-height: 100vh;
        min-height: -webkit-fill-available;
        min-height: 100dvh;
        display: flex;
        align-items: stretch;
        justify-content: stretch;
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .chat-container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh;
        max-height: 100vh;
        max-height: -webkit-fill-available;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        box-shadow: none;
        overflow: hidden;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 0.95rem;
        padding: 12px 15px;
    }
    
    .chat-header {
        padding: 12px 20px;
        padding-top: max(35px, calc(35px + env(safe-area-inset-top))); /* Increased to accommodate status indicator at top right */
        flex-wrap: wrap;
        gap: 8px;
        min-height: auto;
        border-radius: 0;
        border-bottom-left-radius: 28px;
        border-bottom-right-radius: 28px;
        margin: 0;
        width: 100%;
    }
    
    .header-content {
        flex: 1;
        min-width: 0;
    }
    
    .header-text h2 {
        font-size: 1.1rem;
        margin-bottom: 2px;
    }
    
    .header-text p {
        font-size: 0.8rem;
    }
    
    .header-controls {
        order: 3;
        width: 100%;
        justify-content: space-between;
        margin-top: 8px;
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .setup-btn,
    .language-select,
    .theme-toggle,
    .clear-chat-btn {
        font-size: 0.7rem;
        padding: 6px 10px;
        flex: 1;
        min-width: 0;
    }
    
    .language-select {
        min-width: 100px;
        flex: 1.5;
    }
    
    .status-indicator {
        position: absolute;
        top: 6px;
        right: 6px;
        width: auto;
        justify-content: flex-start;
        margin-top: 0;
        padding: 3px 8px;
        font-size: 0.65rem;
        gap: 3px;
    }
    
    .quick-questions {
        flex-direction: column;
        gap: 8px;
    }
    
    .quick-btn {
        text-align: left;
        padding: 12px 15px;
        font-size: 0.9rem;
        width: 100%;
    }
    
    .quick-appliance-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .appliance-quick-btn {
        padding: 12px;
        font-size: 0.85rem;
    }
    
    .chat-messages {
        padding: 20px;
        padding-top: 24px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: var(--bg-chat);
        margin-top: 0;
        border-radius: 0;
    }
    
    .chat-input-container {
        padding: 12px 20px;
        padding-bottom: max(2px, calc(2px + env(safe-area-inset-bottom))); /* Lowered by another 1/4 inch - now at 2px */
        background: var(--bg-chat);
        border-top: 1px solid var(--border-color);
        border-radius: 0;
        border-top-left-radius: 28px;
        border-top-right-radius: 28px;
        margin: 0;
        width: 100%;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
    }
    
    .chat-messages {
        padding-bottom: 55px; /* Reduced padding to match lower input position */
    }
    
    #messageInput {
        padding: 12px 15px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .send-button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    html {
        height: 100%;
        height: -webkit-fill-available;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        overflow: hidden;
    }
    
    body {
        padding: 0;
        margin: 0;
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh; /* Dynamic viewport height */
        width: 100%;
        overflow: hidden;
        box-sizing: border-box;
        display: flex;
        align-items: stretch;
        justify-content: stretch;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .chat-container {
        border-radius: 0;
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh; /* Dynamic viewport height */
        width: 100%;
        margin: 0;
        position: relative;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        box-shadow: none;
        max-height: 100vh;
        max-height: -webkit-fill-available;
        max-height: 100dvh;
    }
    
    .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0;
        padding: 20px;
        padding-top: 24px;
        padding-bottom: 50px; /* Extra padding to ensure content isn't hidden behind input */
        background: var(--bg-chat);
        display: flex;
        flex-direction: column;
    }
    
    .chat-header {
        border-radius: 0;
        border-bottom-left-radius: 28px;
        border-bottom-right-radius: 28px;
        flex-shrink: 0;
        padding-top: max(12px, calc(12px + env(safe-area-inset-top)));
        width: 100%;
    }
    
    .chat-input-container {
        flex-shrink: 0;
        padding: 12px 20px;
        padding-bottom: max(2px, calc(2px + env(safe-area-inset-bottom))); /* Lowered by another 1/4 inch - now at 2px */
        background: var(--bg-chat);
        border-top: 1px solid var(--border-color);
        border-radius: 0;
        border-top-left-radius: 28px;
        border-top-right-radius: 28px;
        margin: 0;
        position: relative;
        z-index: 10;
        width: 100%;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
        min-height: auto;
        margin-bottom: 0;
    }
    
    .header-controls {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .language-select {
        min-width: 80px;
        font-size: 0.65rem;
    }
    
    .setup-btn,
    .theme-toggle,
    .clear-chat-btn {
        font-size: 0.65rem;
        padding: 6px 8px;
        flex: 1;
    }
    
    /* Mobile touch optimizations */
    .send-button {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }
    
    .quick-btn,
    .appliance-quick-btn {
        min-height: 44px;
        padding: 12px 15px;
        touch-action: manipulation;
    }
    
    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
        padding: 12px 15px;
    }
    
    .message-content {
        padding: 12px 15px;
        font-size: 0.9rem;
        max-width: 90%;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .header-text h2 {
        font-size: 1rem;
    }
    
    .header-text p {
        font-size: 0.75rem;
    }
}

/* Desktop: Keep centered container with margins */
@media (min-width: 769px) {
    body {
        padding: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .chat-container {
        margin: 0 auto;
        border-radius: 20px;
        box-shadow: var(--shadow);
    }
    
    .chat-header {
        border-radius: 20px 20px 0 0;
    }
    
    .chat-input-container {
        border-radius: 0 0 20px 20px;
    }
}

/* Tablet optimizations */
@media (min-width: 481px) and (max-width: 768px) {
    .chat-container {
        max-width: 100%;
        height: 100vh;
    }
    
    .header-controls {
        gap: 8px;
    }
    
    .quick-appliance-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large mobile / Small tablet */
@media (min-width: 481px) and (max-width: 1024px) {
    .chat-container {
        max-width: 90%;
    }
}

/* ================================================ */
/* DESKTOP / LAPTOP OPTIMIZATIONS */
/* ================================================ */
@media (min-width: 769px) {
    body {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 20px !important;
        height: 100vh !important;
        min-height: 100vh !important;
    }
    
    .chat-container {
        max-height: 90vh !important;
        height: auto !important;
        max-width: 800px !important;
    }
    
    /* Make sure content containers can scroll */
    .container, .section, main {
        max-height: 80vh !important;
        overflow-y: auto !important;
    }
}

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

/* ================================================ */
/* AUTHENTICATION STYLES */
/* ================================================ */

#adminLoginModal input:focus {
    outline: none;
    border-color: #3498db;
}

#adminLoginModal button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

#adminLoginModal #loginBtn:hover {
    background: #2980b9 !important;
}

#adminLoginModal button:last-child:hover {
    background: #7f8c8d !important;
}

/* Logout button hover effect */
#adminLogoutBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
