/* Message styling */
.message {
    margin-bottom: 3px;
    padding: 5px;
    border-radius: 4px;
    max-width: 80%;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.user-message {
    background-color: #3a3a3a;
    align-self: flex-end;
    text-align: right;
}

/* Ensure user messages sit flush to the right edge and don't rely only on flex container behavior */
.user-message {
    margin-left: auto;
    margin-right: 0;
}

/* AI messages should be left-aligned */
.ai-message {
    margin-right: auto;
    margin-left: 0;
}

.ai-message {
    background-color: #2c3e50;
    align-self: flex-start;
    text-align: left;
    display: block;
}

.ai-message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    display: block;
    width: 100%;
}

.error-message {
    background-color: #555555;
    display: block;
    margin: 0.5rem auto;
    font-style: italic;
    text-align: center;
    max-width: 90%;
    color: #e06a6a;
}

.regenerate-container {
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    margin-top: 8px;
}

.regenerate-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #6d6d6d;
    color: #d0d0d0;
    border: none;
    padding: 8px 12px;
    min-width: 56px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.2;
    z-index: 1;
    white-space: nowrap;
}

.regenerate-button:hover {
    background-color: #4a4a4a;
    transform: scale(1.05);
}

.play-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #6d6d6d;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    min-width: 56px;
    margin-left: 0;
    font-size: 14px;
    line-height: 1.2;
    color: #d0d0d0;
    border-radius: 6px;
    white-space: nowrap;
}

/* Delete (trash) button for user messages */
.delete-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #6d6d6d;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    min-width: 56px;
    font-size: 14px;
    line-height: 1.2;
    color: #d0d0d0;
    border-radius: 6px;
    white-space: nowrap;
}

/* Hover state for delete button */
.delete-button:hover {
    background-color: #4a4a4a;
    transform: scale(1.05);
}

.delete-icon {
    /* keep icon sizing consistent with other control icons */
    font-size: 1em;
    line-height: 1;
}

.play-button:hover {
    background-color: #4a4a4a;
    transform: scale(1.03);
}

.play-button:disabled {
    background-color: #2a2a2a;
    color: #444;
    cursor: not-allowed;
}

/* When audio is playing, show a distinct stop-state on the button */
.play-button.playing {
    background-color: #3a3a3a;
    color: #d0d0d0;
    transform: none;
}

.play-button.playing:hover {
    background-color: #4a4a4a;
}

.system-message {
    background-color: #555555;
    display: block;
    margin: 0.5rem auto;
    font-style: italic;
    text-align: center;
    max-width: 90%;
}

/* Tier badge styling */
.tier-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.9em;
}
.tier-badge.premium {
    background-color: #2c5e50;
}
.tier-badge.free {
    background-color: #4a4a4a;
}

/* Make certain select controls narrower and right-aligned */
/* Removed .select-right in favor of grid columns for consistent select widths */

/* Upgrade button */
.upgrade-btn {
    margin-left: 8px;
    padding: 4px 12px;
    background-color: #3a5e50;
    border: none;
    border-radius: 4px;
    color: #d0d0d0;
    cursor: pointer;
}

/* Premium alert banner */
.premium-alert-banner {
    background: #fff3e0;
    border: 1px solid #ffb74d;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    color: #ef6c00;
    text-align: center;
}

.premium-alert-banner a {
    color: #d32f2f;
    font-weight: bold;
    text-decoration: underline;
}

/* Center the navbar brand while keeping left/right controls visible */
.navbar-brand-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* ensure clicks go to controls on the sides */
}

/* Ensure brand remains visible above other elements */
.navbar .navbar-brand-center {
    z-index: 1;
}

/* Make navbar links use Bootstrap primary color (sign in/out etc.) */
.navbar .nav-link { /* keep default navbar link behavior intact */ }

/* Make all anchors use Bootstrap primary color by default */
a {
    color: var(--bs-primary);
}
a:hover, a:focus {
    color: var(--bs-primary);
    opacity: 0.85;
    text-decoration: underline;
}

/* Ensure navbar links use the primary color even with .navbar-dark defaults */
.navbar .nav-link {
    color: var(--bs-primary) !important;
}
.navbar .nav-link:hover,
.navbar .nav-link:focus {
    color: var(--bs-primary) !important;
    opacity: 0.9;
}

/* Thinking text styles */
.thinking-container {
    margin: 10px 0;
    border-left: 3px solid #666;
    padding-left: 10px;
    color: #888;
    font-size: 0.9em;
}

.toggle-thinking {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
    font-size: 0.8em;
}

.toggle-thinking:hover {
    color: #fff;
}

.thinking-content {
    margin-top: 5px;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .message {
        max-width: 100%;
    }
    
    .regenerate-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .delete-button, .play-button, .regenerate-button {
        min-width: 40px;
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .delete-icon {
        font-size: 20px !important;
    }
}

/* Mobile tweaks: keep control buttons inline, slightly larger, and right-justified */
@media (max-width: 767.98px) {
    .regenerate-container {
        flex-direction: row !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100%;
    }

    .regenerate-button, .play-button, .delete-button {
        padding: 10px 14px !important;
        min-width: 72px !important;
        font-size: 16px !important;
    }

    .delete-icon {
        font-size: 20px !important;
    }
}

@media (max-width: 576px) {
    .message {
        max-width: 100%;
    }
    
    .regenerate-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .delete-button, .play-button, .regenerate-button {
        min-width: 36px;
        padding: 5px 8px;
        font-size: 11px;
    }
    
    .delete-icon {
        font-size: 18px !important;
    }
}

/* Ensure chat area has usable height on small screens when settings are open */
@media (max-width: 767.98px) {
    /* Make the messages container tall enough (~20 text lines) so users don't see a single-line chat */
    #chat-content {
        min-height: 24em;
    }
    /* Ensure the chat card respects that minimum */
    #chat-box {
        min-height: 24em;
    }
}

/* On md+ make settings panel content stretch vertically and let the two cards share space */
@media (min-width: 768px) {
    #settingsCollapse {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    /* container that holds the two cards */
    .settings-cards {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        gap: 1rem;
        min-height: 0;
    }
    .settings-cards .card {
        flex: 1 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
    .settings-cards .card .card-body {
        overflow: auto;
    }
    /* Make textarea fill available card-body space and keep Save button at bottom */
    .settings-cards .card .card-body {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    .settings-cards .card .card-body textarea {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        resize: none;
        margin-bottom: 0.5rem;
    }
    .settings-cards .card .card-body .btn {
        flex: 0 0 auto;
    }
}

/* On small screens do not force fixed heights; on md+ keep full-height layout */
@media (min-width: 768px) {
    #settings-col, #settingsCollapse, #chat-area, #chat-box {
        height: 100%;
    }
}

/* Ensure chat-box retains a reasonable minimum height even when settings are open */
#chat-box {
    min-height: max(220px, 30vh);
}

/* Remove extra bottom padding to keep chat content flush with the chat box */
#chat-box, #chat-content {
    padding-bottom: 0 !important;
}

/* On small screens reserve extra padding so the fixed input doesn't overlap last messages */
@media (max-width: 767.98px) {
    /* Reserve space on the chat-area instead of the chat-box so the fixed input doesn't overlap
       and to avoid extra space inside the chat card itself. */
    #chat-area {
        padding-bottom: calc(var(--chat-input-height, 56px) + env(safe-area-inset-bottom, 0) + 12px) !important;
    }
    /* Ensure the chat-box uses any remaining space without extra internal padding */
    #chat-box {
        padding-bottom: 0 !important;
    }
}

/* Mobile: pin the input to the bottom and reserve space in the chat box so virtual keyboard and browser chrome don't hide it */
:root { --chat-input-height: 56px; }

@media (max-width: 767.98px) {
    #chat-area .input-group {
        position: fixed;
        left: 0;
        right: 0;
        bottom: env(safe-area-inset-bottom, 0);
        padding: 0.5rem;
        background: rgba(0,0,0,0.04);
        z-index: 1050;
    }

    /* Reserve space so chat messages are not covered by the pinned input */
    #chat-box {
        padding-bottom: calc(var(--chat-input-height) + env(safe-area-inset-bottom, 0));
    }
}

/* Prevent the chat content from growing without bound. Limit to roughly 100 lines. */
#chat-content {
    max-height: 120em; /* ~100 lines at ~1.2em line-height */
    overflow: auto;
}

/* On small screens, allow the chat to grow naturally (avoid nested scrolling). */
@media (max-width: 767.98px) {
    #chat-content {
        max-height: none;
        /* Let the page scroll instead of producing an inner scrollbar */
        overflow: visible;
    }
}

/* Make chat area and input use dark backgrounds (mobile-friendly, not blinding white) */
#chat-box, #chat-box .card-body {
    background-color: #1e1f21; /* dark gray */
    color: #e6e6e6;
}

#chat-area .form-control, #user-input {
    background-color: #2a2a2a;
    color: #e6e6e6;
    border-color: #444;
}

#chat-area .form-control::placeholder, #user-input::placeholder {
    color: #9aa0a6;
}

/* Settings panel cards and controls should also use dark backgrounds */
.settings-cards .card,
.settings-cards .card .card-body,
.settings-cards .card .card-header {
    background-color: #1e1f21; /* dark gray */
    color: #e6e6e6;
    border-color: #2a2a2a;
}

.settings-cards .card .card-header {
    background-color: #242526;
}

.settings-cards .card .card-body textarea,
.settings-cards .card .card-body .form-control {
    background-color: #2a2a2a;
    color: #e6e6e6;
    border-color: #444;
}

/* Ensure select controls match dark inputs inside settings and chat areas */
#settingsCollapse .form-select,
#chat-area .form-select {
    background-color: #2a2a2a;
    color: #e6e6e6;
    border-color: #444;
}
#settingsCollapse .form-select option,
#chat-area .form-select option {
    background-color: #2a2a2a;
    color: #e6e6e6;
}

/* Make outline-light buttons on the navbar stay transparent/dark on mobile */
.navbar .btn-outline-light {
    background-color: transparent;
    color: #e6e6e6;
    border-color: rgba(255,255,255,0.6);
}
.navbar .btn-outline-light:active,
.navbar .btn-outline-light:focus {
    background-color: rgba(255,255,255,0.05);
}

/* Fix flexbox overflow on initial load: ensure containers can shrink/grow and allow children to fill available height */
.container-fluid.flex-grow-1.d-flex {
    flex: 1 1 auto;
    min-height: 0;
}

#chat-area {
    flex: 1 1 auto;
    min-height: 0;
}

/* Prefer Bootstrap utilities but provide fallback sizing for chat layout */
#chat-box {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}

#chat-content {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}

/* Ensure body fills the viewport, supporting WebKit safe-area handling */
body {
    height: 100vh;
    height: -webkit-fill-available;
    min-height: -webkit-fill-available;
}
