/* 
 * styles.css   
 */

/* Self-hosted Roboto (Regular 400, Medium 500 - latin) */
@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');
}

/* CSS Variables for theming */
:root {
    --background-color: #ffffff;
    --text-color: #000000;
    --link-color: #0d6efd;
    --chatbox-background: #f9f9f9;
    --chatbox-border: #ccc;
    --input-background: #ffffff;
    --input-text-color: #000000;
    --input-border: #ccc;
    --button-background: #0d6efd;
    --button-border: #0d6efd;
    --button-color: #ffffff;
    --placeholder-color: #cccccc;
    --overlay-background: rgba(0, 0, 0, 0.85);
    --chat-scale: 1; /* scales only chat content */
    --gap: 12px; /* unified vertical gap between sections */
    --chatbox-bg-overlay: rgba(255, 255, 255, 0.88);
}

/* Dark theme variables */
[data-theme="dark"] {
    --background-color: #121212;
    --text-color: #ffffff;
    --link-color: #81d4fa;
    --chatbox-background: #1e1e1e;
    --chatbox-border: #333;
    --input-background: #1e1e1e;
    --input-text-color: #ffffff;
    --input-border: #333;
    --button-background: #0b5ed7;
    --button-border: #0a58ca;
    --button-color: #ffffff;
    --placeholder-color: #444444;
    --overlay-background: rgba(0, 0, 0, 0.9);
    --chatbox-bg-overlay: rgba(18, 18, 18, 0.72);
}

/* Base styles */
body {
    /* Prefer self-hosted Roboto; use Regular 400 for body */
    font-family: "Roboto", system-ui, -apple-system, "Segoe UI", "Segoe UI Variable", "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
    font-weight: 400;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    /* Font rendering tweaks (note: WebKit/macOS only honors smoothing props) */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-kerning: normal;
    font-variant-ligatures: common-ligatures contextual;
}

/* Ensure controls inherit the same font and rendering */
input, textarea, button, select {
    font-family: inherit;
    -webkit-font-smoothing: inherit;
    -moz-osx-font-smoothing: inherit;
    text-rendering: inherit;
    font-kerning: inherit;
    font-variant-ligatures: inherit;
}

/* Allow iOS Safari/Chrome to honor text size adjustments */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
}
body {
    font-size: 1rem;
}

body.d-flex.flex-column.min-vh-100 {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    height: 100dvh;
}

@media (pointer: fine) {
    body.d-flex.flex-column.min-vh-100 {
        overflow: hidden;
    }
}

@media (pointer: coarse), (hover: none) {
    body.d-flex.flex-column.min-vh-100 {
        overflow-y: auto;
    }
}

#chat-container.container-fluid.flex-fill {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

#chat-container.container-fluid.flex-fill .text-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    margin-bottom: 0 !important;
}

#chat-container.container-fluid.flex-fill #chatbox {
    background-color: var(--chatbox-background);
    border: 1px solid var(--chatbox-border);
    font-size: calc(1rem * var(--chat-scale));
    width: calc(100% - 30px);
    max-width: none;
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px;
    margin: 0 15px var(--gap) 15px;
    text-align: left;
    box-sizing: border-box;
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 0;
}

#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: 0;
}

#chatbox .chatbox-bg-layer.is-visible {
    opacity: 1;
}

#chatbox > :not(.chatbox-bg-layer) {
    position: relative;
    z-index: 1;
}

.medium-zoom-overlay {
    z-index: 2147483646 !important;
}

.medium-zoom-image--opened {
    z-index: 2147483647 !important;
}

/* Username overlay */
.username-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--overlay-background);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
    color: white;
    z-index: 999;
}

/* Make input group span nearly full width with 15px gutter */
#chat-container .input-group {
    width: calc(100% - 30px) !important;
    /* Use footer top padding for the gap below; avoid double-spacing */
    margin: 0 15px 0 15px !important;
}

/* Ensure message bubbles inherit chat scale */
#chatbox .message,
#chatbox .message-content,
#chatbox .content {
    font-size: inherit;
}

/* Remove container padding so gutters are exactly 15px */
#chat-container.container,
#chat-container.container-fluid {
    padding-left: 0;
    padding-right: 0;
}

/* Message styles */
.message {
    margin-bottom: 15px;
    width: 100%;
    word-wrap: break-word;
}

.message.user {
    text-align: right;
}

.message.assistant {
    text-align: left;
}

.message.user .message-content {
    display: inline-block;
    background-color: #d1e7dd;
    color: #0f5132;
    padding: 10px;
    border-radius: 10px;
    max-width: 80%;
    word-wrap: break-word;
}

.message.assistant .message-content {
    display: inline-block;
    background-color: #e2e3e5;
    color: #41464b;
    padding: 10px;
    border-radius: 10px;
    max-width: 80%;
    word-wrap: break-word;
}

/* Message status (Delivered/Read) */
#chatbox .message .message-content .status {
    display: block;
    font-size: 0.55rem; /* tiny */
    line-height: 1.1;
    opacity: 0.6; /* more muted */
    margin-top: 1px;
    color: inherit; /* match bubble text color */
    -webkit-text-size-adjust: none; /* prevent iOS auto-upsizing */
    text-size-adjust: none;
}
#chatbox .message.user .message-content .status { text-align: right; }
#chatbox .message.assistant .message-content .status { text-align: left; }

/* Extra tiny status on small screens */
@media (max-width: 576px) {
  #chatbox .message .message-content .status {
    font-size: 10px !important; /* base size before transform */
    line-height: 1.05;
    display: inline-block; /* required for transform */
    transform: scale(1.00); /* larger on mobile */
    transform-origin: top left;
  }
  #chatbox .message.user .message-content .status { transform-origin: top right; }
}

/* Remove extra bottom margin that Markdown elements add */
.message .message-content > :last-child,
.message .message-content .content > :last-child,
.message .message-content p:last-child,
.message .message-content pre:last-child,
.message .message-content ul:last-child,
.message .message-content ol:last-child,
.message .message-content blockquote:last-child {
    margin-bottom: 0 !important;
}

/* (prefix styling removed) */

.message.assistant.typing .message-content {
    background-color: #e2e3e5;
    color: #41464b;
    font-style: italic;
    animation: pulse 2s infinite;
}

/* Dark theme message overrides */
[data-theme="dark"] .message.assistant.typing .message-content {
    background-color: #41464b;
    color: #e2e3e5;
    font-style: italic;
}

[data-theme="dark"] .message.user .message-content {
    background-color: #0f5132;
    color: #d1e7dd;
}

[data-theme="dark"] .message.assistant .message-content {
    background-color: #41464b;
    color: #e2e3e5;
}

/* Typing indicator */
.typing-dots {
    display: inline-block;
    min-width: 20px;
    text-align: left;
    margin-left: 4px;
}

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

/* Input and buttons */
#message {
    background-color: var(--input-background);
    color: var(--input-text-color);
    border: 1px solid var(--input-border);
    min-height: 3em; /* scale with font size */
    line-height: 1.4;
    font-size: calc(1rem * var(--chat-scale));
}

#message::placeholder {
    color: var(--placeholder-color);
}

.send-button {
    background-color: var(--button-background);
    border-color: var(--button-border);
    color: var(--button-color);
}

.send-button:hover {
    background-color: #0b5ed7;
    border-color: #0a58ca;
    color: #ffffff;
}

#themeToggle {
    font-size: 12px;
    padding: 5px 10px;
}

/* Footer */
.footer {
    background-color: rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

[data-theme="dark"] .footer {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Kill Bootstrap's mt-auto on the footer so it doesn't create extra space on tall viewports */
.footer.mt-auto {
    margin-top: 0 !important;
}

/* Ensure gap between input and footer equals --gap on all viewports */
.footer.py-3 {
    /* Move spacing above footer to margin, not padding */
    padding-top: 0;
    padding-bottom: var(--gap);
}

/* Visual gap between input and footer */
.footer {
    margin-top: var(--gap);
}

.footer-link {
    color: var(--text-color);
    text-decoration: underline;
}

[data-theme="dark"] .footer-link {
    color: #81d4fa;
}

/* Connection controls: disabled badge looks muted and not clickable */
.connection-controls .badge.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Responsive design */
@media (max-width: 576px) {
    #chatbox {
        min-height: 390px; /* allow flex growth while ensuring usability */
    }
    /* Add some top spacing below the fixed auth bar on small screens */
    #chat-container .text-center {
        padding-top: 36px;
    }
    .message.user .message-content,
    .message.assistant .message-content {
        max-width: 100%;
    }
}

/* Special styling for summary messages */
.message.assistant.summary .message-content {
    background-color: #cfe2ff;
    color: #084298;
    font-style: italic;
    border-left: 3px solid #084298;
}

[data-theme="dark"] .message.assistant.summary .message-content {
    background-color: #084298;
    color: #cfe2ff;
    border-left: 3px solid #cfe2ff;
}

/* System messages */
.message.system .message-content {
    background-color: #f8d7da;
    color: #842029;
    font-style: italic;
    text-align: center;
    margin: 0 auto;
}

[data-theme="dark"] .message.system .message-content {
    background-color: #842029;
    color: #f8d7da;
}

/* Connected system message - higher specificity to override default system style */
[data-theme] .message.system.connected .message-content {
    background-color: #d1e7dd;
    color: #0f5132;
    font-style: italic;
    text-align: center;
    margin: 0 auto;
}

[data-theme="dark"] .message.system.connected .message-content {
    background-color: #0f5132;
    color: #d1e7dd;
}

/* Connecting system message - higher specificity to override default system style */
body .message.system.connecting .message-content {
    background-color: #fff3cd;
    color: #664d03;
    font-style: italic;
    text-align: center;
    margin: 0 auto;
}

[data-theme="dark"] .message.system.connecting .message-content {
    background-color: #664d03;
    color: #fff3cd;
}

/* Connection control buttons */
.connection-controls .badge {
    cursor: pointer;
}

.connection-controls .badge-new-convo {
    background-color: #fd7e14;
    color: #ffffff;
}

.connection-controls .badge-new-convo.disabled,
.connection-controls .badge-new-convo.disabled:hover {
    opacity: 0.6;
    cursor: not-allowed;
}

[data-theme="dark"] .connection-controls .badge-new-convo {
    background-color: #f08c28;
    color: #1a1a1a;
}

/* Auth bar */
.auth-bar {
    width: 90%;
    margin: 0 auto 8px auto;
    color: #6c757d;
}
.auth-bar .auth-link {
    text-decoration: underline;
    color: inherit;
}
[data-theme="dark"] .auth-bar { color: #adb5bd; }

/* Improve readability of muted text in dark mode (e.g., signin subtext) */
[data-theme="dark"] .text-muted {
    color: #e6edf3 !important; /* brighter muted tone for better contrast */
}
[data-theme="dark"] .text-muted strong {
    color: #ffffff !important;
}

.auth-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
}

.theme-icon {
    cursor: pointer;
    user-select: none;
    opacity: 0.9;
}

.font-icon {
    cursor: pointer;
    user-select: none;
}


/* Top-right bar positioning with 15px side gap */
.auth-topbar {
    position: fixed;
    top: 5px; /* 5px top margin */
    right: 15px;
    z-index: 1000;
}
.auth-topbar .auth-bar {
    width: auto;
    margin: 0;
}
.auth-topbar .fontbar {
    width: auto;
    margin: 4px 0 0 0; /* a line under the theme toggle */
}
#chat-container.container-fluid.flex-fill #chatbox {
    z-index: 0;
}
