/* 
 * styles.css - Cleaned up for V2 UI
 */

.history-item {
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}
.history-item:hover {
    background-color: rgba(0,0,0,0.05);
}
[data-theme="dark"] .history-item:hover {
    background-color: rgba(255,255,255,0.05);
}
.history-item.active {
    background-color: rgba(13, 110, 253, 0.1); /* Primary tint */
    font-weight: 500;
}
[data-theme="dark"] .history-item.active {
    background-color: rgba(13, 110, 253, 0.2);
}

.history-item .rename-btn,
.history-item .delete-btn {
    opacity: 0;
    transition: opacity 0.2s;
}
.history-item:hover .rename-btn,
.history-item:hover .delete-btn {
    opacity: 1;
}
/* Always show buttons on touch devices or active item */
@media (hover: none) {
    .history-item .rename-btn, .history-item .delete-btn { opacity: 0.5; }
}
.history-item.active .rename-btn,
.history-item.active .delete-btn { opacity: 0.7; }

/* Delete button hover color */
.delete-btn:hover {
    color: var(--bs-danger) !important;
}

/* Self-hosted Roboto */
@font-face {
    font-family: 'Roboto';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/static/fonts/roboto/roboto-latin-400.woff2') format('woff2');
}
@font-face {
    font-family: 'Roboto';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/static/fonts/roboto/roboto-latin-500.woff2') format('woff2');
}

:root {
    --chatbox-background: transparent; /* Let container bg show through */
    --input-background: #ffffff;
    --input-text-color: #000000;
    --input-border: #dee2e6;
    --button-background: #0d6efd;
    --button-color: #ffffff;
    --user-bubble-bg: #0d6efd;
    --user-bubble-text: #ffffff;
    --ai-bubble-bg: #e9ecef;
    --ai-bubble-text: #212529;
    --chat-scale: 1;
}

[data-theme="dark"] {
    --input-background: #2b3035;
    --input-text-color: #ffffff;
    --input-border: #495057;
    --button-background: #0d6efd;
    --user-bubble-bg: #0d6efd;
    --user-bubble-text: #ffffff;
    --ai-bubble-bg: #343a40;
    --ai-bubble-text: #e9ecef;
}

body {
    font-family: "Roboto", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Main Chat Container */
#chatbox {
    scroll-behavior: smooth; /* Optional: smooth scrolling for programmatic scrollTo */
    overflow-anchor: auto;   /* Explicitly enable scroll anchoring for smooth history loading */
}

#chatbox.loading {
    opacity: 0;
    pointer-events: none;
}

#chatbox .chatbox-bg-layer {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    opacity: 0;
    transition: opacity 240ms ease;
    z-index: -1;
}

#chatbox .chatbox-bg-layer.is-visible {
    opacity: 0.15; /* Make it subtle in the new clean UI */
}

/* Message Bubbles */
.message {
    margin-bottom: 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    /* Ensure no whole-row highlight exists */
    background-color: transparent !important;
}
.message:hover {
    background-color: transparent !important;
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message.system { align-items: center; }

.message-content {
    max-width: 85%;
    padding: 10px 16px;
    border-radius: 18px;
    font-size: calc(1rem * var(--chat-scale));
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    transition: filter 0.2s ease; /* Smooth hover transition */
}

/* Hover Effects for Bubbles Only */
.message-content:hover {
    filter: brightness(0.95); /* Slightly darker in light mode */
}
[data-theme="dark"] .message-content:hover {
    filter: brightness(1.1); /* Slightly lighter in dark mode */
}

/* Remove old copy-btn styles since we switched to badge classes inline/bootstrap */
.message-content:hover .copy-badge {
    opacity: 0.8 !important;
}
.copy-badge:hover {
    opacity: 1 !important;
}
/* Always show copy badge on touch devices */
@media (hover: none) {
    .copy-badge { opacity: 0.6 !important; }
}

.message.user .message-content {
    background-color: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background-color: var(--ai-bubble-bg);
    color: var(--ai-bubble-text);
    border-bottom-left-radius: 4px;
}

.message.system .message-content {
    background-color: rgba(0,0,0,0.05);
    color: #6c757d;
    font-size: calc(0.85rem * var(--chat-scale));
    padding: 4px 12px;
    border-radius: 12px;
}
[data-theme="dark"] .message.system .message-content {
    background-color: rgba(255,255,255,0.1);
    color: #adb5bd;
}

/* Status (Read/Delivered) */
.status {
    font-size: calc(0.65rem * var(--chat-scale));
    margin-top: 2px;
    opacity: 0.7;
}
.message.user .status { text-align: right; color: rgba(255,255,255,0.8); }
.message.assistant .status { text-align: left; }

/* Typing Indicator */
.message.assistant.typing .message-content {
    font-style: italic;
    opacity: 0.8;
}

/* Input Area */
#message {
    font-size: calc(1rem * var(--chat-scale));
    line-height: 1.4;
    padding: 10px;
}

/* Scrollbar Polish */
#chatbox::-webkit-scrollbar {
    width: 6px;
}
#chatbox::-webkit-scrollbar-track {
    background: transparent;
}
#chatbox::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 3px;
}
[data-theme="dark"] #chatbox::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.2);
}

/* Custom Google Sign-In Button */
.google-btn-legacy {
    display: block;
    height: 42px;
    width: 100%;
    background-color: #4285F4;
    position: relative;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    text-decoration: none !important;
    border: none;
    outline: none;
}

.google-btn-legacy:hover {
    box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
    background-color: #357ae8;
    color: #fff;
}

.google-icon-wrapper {
    position: absolute;
    top: 1px;
    left: 1px;
    width: 40px;
    height: 40px;
    border-radius: 3px;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.google-icon {
    width: 20px;
    height: 20px;
    display: block;
}

.google-btn-text {
    color: #fff;
    font-size: 16px;
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    line-height: 42px;
    text-align: center;
    display: block;
    padding-left: 44px; /* Offset for icon */
}

/* Connect button fixed width to prevent jitter */
#connect-toggle {
    min-width: 110px;
    text-align: center;
}

/* --- Responsive Sidebar & Layout Logic --- */

/* Mobile: Sidebar is an overlay */
@media (max-width: 576px) {
    .message-content {
        max-width: 90%;
    }
    .navbar {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    #sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%); /* Hidden by default */
        box-shadow: 4px 0 12px rgba(0,0,0,0.1);
    }
    
    #sidebar.show {
        transform: translateX(0);
    }
    
    /* Fix sticky hover on mobile touch */
    @media (hover: none), (pointer: coarse) {
        #connect-toggle:hover { background-color: transparent !important; }
        #connect-toggle.btn-outline-success:hover { color: var(--bs-success) !important; border-color: var(--bs-success) !important; }
        #connect-toggle.btn-outline-danger:hover { color: var(--bs-danger) !important; border-color: var(--bs-danger) !important; }
        #connect-toggle.btn-outline-success:active { color: #fff !important; background-color: var(--bs-success) !important; }
        #connect-toggle.btn-outline-danger:active { color: #fff !important; background-color: var(--bs-danger) !important; }

        #sidebar-new-chat:hover { background-color: transparent !important; color: var(--bs-primary) !important; }
        #sidebar-new-chat:active { background-color: var(--bs-primary) !important; color: #fff !important; }
    }
}

/* Desktop: Sidebar is persistent but collapsible */
@media (min-width: 577px) {
    #sidebar {
        position: relative !important;
        transform: none !important;
        box-shadow: none !important;
        width: 200px;
        transition: width 0.3s ease-in-out, opacity 0.2s ease-in-out;
        white-space: nowrap;
    }
    
    #sidebar.collapsed {
        width: 0 !important;
        border-right: none !important;
        overflow: hidden;
    }
    
    #sidebar.collapsed > * {
        opacity: 0;
        pointer-events: none;
    }
    
    /* Sidebar toggle button is ALWAYS visible to allow collapsing */
    #sidebar-toggle {
        display: inline-block !important;
    }
}
