/* UCA Branding & Modern Variables */
:root {
    /* UCA Colors */
    /* UCA Colors */
    --uca-blue: #384850;
    /* Main institutional color (testu.uca.es body.portal_uca --uca-main-color-1) */
    --uca-accent: #f2efe6;
    /* Off-white accent (diverges from testu.uca.es's olive-gold by request) */
    --uca-button-bg: #455a64;
    /* testu.uca.es --uca-main-color-2 */
    --uca-button-hover: #2e3d43;
    /* testu.uca.es --uca-main-color-3 */
    --uca-cta-bg: #007888;
    /* Background of .btn.primary / #send-btn, by request */

    /* Theme Mapping */
    --primary-color: var(--uca-blue);
    --accent-color: var(--uca-accent);
    --bg-color: #f0f0f0;
    /* Light grey background */
    --chat-bg: #ffffff;

    /* Component Colors */
    --header-bg: var(--uca-blue);
    --header-text: #ffffff;

    --message-user-bg: var(--uca-button-bg);
    --message-user-text: #ffffff;

    --message-bot-bg: #f8f9fa;
    --message-bot-text: #333333;
    /* Slightly off-white for contrast against white chat area? Wait, chat-bg is white. 
       Let's make bot message light grey or keep white with border. 
       Official style has backgrounds like #f0f0f0. Let's start with white to be safe. */
    --message-bot-bg: #ffffff;
    --message-bot-border: #e1e4e8;

    --input-bg: #ffffff;
    --border-color: #dadee3;
}

.grecaptcha-badge {
    visibility: hidden;
}

body {
    font-family: 'Lato', Arial, Helvetica, sans-serif;
    /* Matches www.uca.es (theme_main_uca) so the widget blends into the host page */
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    color: #333;
}

/* Header with UCA Styling */
header {
    background: linear-gradient(135deg, rgba(56, 72, 80, 0.95) 0%, rgba(69, 90, 100, 0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.75rem 2rem;
    box-shadow: 0 4px 30px rgba(0, 51, 102, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    border-bottom: 2px solid rgba(242, 239, 230, 0.8);
    position: sticky;
    top: 0;
}

header h1 {
    margin: 0;
    font-size: 1.4rem;
    color: var(--header-text);
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

.version-info {
    font-size: 0.6em;
    color: rgba(255, 255, 255, 0.6);
    font-weight: normal;
}

.debug-badge {
    font-size: 0.5em;
    color: #ff4d4d;
    border: 1px solid #ff4d4d;
    background-color: rgba(255, 77, 77, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 5px;
    vertical-align: middle;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.beta-badge {
    font-size: 0.5em;
    color: var(--uca-accent);
    border: 1px solid var(--uca-accent);
    background-color: rgba(242, 239, 230, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 5px;
    vertical-align: middle;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Header Actions & Buttons */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-pill {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.5rem 1.25rem;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05);
}

.user-greeting {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.user-name {
    color: var(--uca-accent);
    font-weight: 700;
    margin-left: 4px;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.icon-btn span {
    display: inline-block;
}

.btn.primary {
    background: var(--uca-cta-bg);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 120, 136, 0.3);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 120, 136, 0.4);
    filter: brightness(1.05);
}

.btn.primary:active {
    transform: translateY(0);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn.secondary:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

#clear-btn {
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
}

#logout-btn {
    color: #fff;
}

/* Chat Container */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    background-image: radial-gradient(#e6e9f0 1px, transparent 1px);
    background-size: 20px 20px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 1rem 1.5rem;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 1rem;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* User Message: UCA Blue */
.message.user .message-content {
    background-color: var(--message-user-bg);
    color: var(--message-user-text);
    border-bottom-right-radius: 2px;
}

/* Assistant Message: White with Border */
.message.assistant .message-content {
    background-color: var(--message-bot-bg);
    color: var(--message-bot-text);
    border: 1px solid var(--message-bot-border);
    border-bottom-left-radius: 2px;
}

/* Markdown Styles */
.message-content p {
    margin: 0 0 0.5rem 0;
}

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

.message-content pre {
    background: #f8f9fa;
    padding: 0.8rem;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid #e1e4e8;
    color: #24292e;
}

.message-content code {
    font-family: 'Consolas', 'Monaco', monospace;
    background: rgba(0, 0, 0, 0.06);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    padding: 1rem 2rem;
    align-self: center;
    justify-content: center;
}

.typing-indicator span {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-color: var(--uca-blue);
    border-radius: 50%;
    margin-right: 6px;
    opacity: 0.6;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Input Area */
#input-area {
    background-color: var(--chat-bg);
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

#input-container {
    display: flex;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
    background: #fff;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    /* Slightly sharper radius for academic look */
    padding: 0.5rem;
    transition: border-color 0.2s;
}

#input-container:focus-within {
    border-color: var(--uca-blue);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

#user-input {
    flex: 1;
    box-sizing: border-box;
    /* Without this, ui.js's scrollHeight-based auto-resize double-counts
       padding on every call (content-box height excludes padding, but
       scrollHeight includes it) and the field grows a little on every use. */
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    max-height: 150px;
    padding: 0.8rem 0.5rem;
    color: #333;
}

/* Send Button: off-white with blue icon */
#send-btn,
#stop-btn {
    border: none;
    border-radius: 6px;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

#send-btn {
    background: var(--uca-cta-bg);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 120, 136, 0.3);
}

#send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 120, 136, 0.4);
    filter: brightness(1.05);
}

#send-btn:disabled {
    background: #e9ecef;
    color: #adb5bd;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

#stop-btn {
    background: linear-gradient(135deg, #ff4d4d 0%, #dc3545 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

#stop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4);
    filter: brightness(1.1);
}

/* Feedback Stars */
.feedback-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    background: #f8f9fa;
    padding: 5px 10px;
    border-radius: 20px;
    display: inline-flex;
}

.star-rating {
    display: flex;
    flex-direction: row-reverse;
    font-size: 1.25rem;
}

.star-rating input {
    display: none;
}

.star-rating label {
    cursor: pointer;
    color: #ddd;
    padding: 0 2px;
    transition: color 0.2s;
}

.star-rating label:before {
    content: "★";
}

.star-rating input:checked~label,
.star-rating label:hover,
.star-rating label:hover~label {
    /* Hardcoded, not tied to --uca-accent: star ratings are conventionally
       gold regardless of brand color, and --uca-accent is now off-white. */
    color: #f5b301;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Auth Modal enforcement */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(56, 72, 80, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.modal-content {
    background: white;
    padding: 3rem 2rem;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: modalBounce 0.5s cubic-bezier(0.17, 0.89, 0.32, 1.28);
}

.modal-icon {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.modal-content h2 {
    color: var(--uca-blue);
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.modal-content p {
    color: #555;
    margin-bottom: 2rem;
    font-size: 1rem;
    line-height: 1.5;
}

.modal-content .btn.primary {
    padding: 0.8rem 2rem;
    font-size: 1rem;
}

.modal-content .btn.secondary,
.login-card .btn.secondary {
    width: 100%;
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
    background: transparent;
    border: 1.5px solid var(--uca-blue);
    color: var(--uca-blue);
    box-shadow: none;
}

.modal-content .btn.secondary:hover,
.login-card .btn.secondary:hover {
    background: rgba(56, 72, 80, 0.06);
    border-color: var(--uca-blue);
    color: var(--uca-blue);
    box-shadow: 0 4px 12px rgba(56, 72, 80, 0.12);
}

.modal-separator {
    display: flex;
    align-items: center;
    margin: 1.25rem 0;
    color: #bbb;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-separator::before,
.modal-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e8e8e8;
}

.modal-separator span {
    padding: 0 0.85rem;
}


@keyframes modalBounce {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* AI Disclaimer overlay */
.disclaimer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(56, 72, 80, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.disclaimer-content {
    background: white;
    padding: 2rem 2rem 1.75rem;
    border-radius: 16px;
    max-width: 460px;
    width: 92%;
    text-align: left;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    animation: fadeIn .2s ease-out;
}

@keyframes fadeIn {
    0% { opacity: 0; }
}

.disclaimer-icon {
    margin-bottom: 1rem;
}

/* ── SSO-complete page (see widget_sso_complete.html) ────────────────── */
.sso-icon-success {
    color: #2e8b57;
}

.sso-icon-failure {
    color: #c0392b;
}

.disclaimer-content h2 {
    color: var(--uca-blue);
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 1rem 0;
}

.disclaimer-list {
    color: #444;
    font-size: 0.88rem;
    line-height: 1.6;
    padding-left: 1.25rem;
    margin: 0 0 1.5rem 0;
}

.disclaimer-list li {
    margin-bottom: 0.5rem;
}

.disclaimer-btn {
    width: 100%;
    padding: 0.8rem 1.5rem;
    font-size: 0.95rem;
}

.models-health-debug {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px dashed rgba(56, 72, 80, 0.15);
}

.models-health-debug-title {
    margin: 0 0 0.6rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #8a8f98;
}

.models-health-debug ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.model-status {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.7rem;
    border-radius: 8px;
    background: rgba(56, 72, 80, 0.04);
    font-size: 0.8rem;
}

.model-status-icon {
    display: flex;
    flex-shrink: 0;
}

.model-status-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: "SFMono-Regular", Consolas, monospace;
    color: #333;
}

.model-status-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.model-status-ok .model-status-icon,
.model-status-ok .model-status-label {
    color: #2e7d32;
}

.model-status-fail .model-status-icon,
.model-status-fail .model-status-label {
    color: #c0392b;
}
/* Standalone login page */
/* ── Login page ─────────────────────────────────────── */
body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--header-bg);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    background: white;
    border-radius: 16px;
    padding: 2.5rem 2rem;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    animation: modalBounce 0.4s cubic-bezier(0.17, 0.89, 0.32, 1.28);
}

.login-card h1 {
    color: var(--uca-blue);
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
}

.login-card > p {
    color: #555;
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.75rem;
}

/* Primary button takes full width; secondary is already covered by the grouped rule above */
.login-card .btn.primary {
    width: 100%;
    box-sizing: border-box;
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
}

/* ── Widget panel page (rendered inside the loader's iframe) ────────── */
body.widget-page {
    height: 100vh;
    background: var(--chat-bg);
}

/* ── Help/demo page ("how to embed" page, see help.html) ─────────────── */
body.help-page {
    display: block;
    height: auto;
    background: var(--bg-color);
}

.widget-header {
    background: linear-gradient(135deg, rgba(56, 72, 80, 0.95) 0%, rgba(69, 90, 100, 0.95) 100%);
    color: #fff;
    padding: 0.85rem 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.widget-header-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.widget-header-title .version-info {
    font-size: 0.65rem;
    opacity: 0.7;
    font-weight: 400;
}

.widget-header-title .debug-badge {
    background: #c0392b;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    vertical-align: middle;
}

.widget-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.widget-user {
    color: #fff;
    opacity: 0.85;
    font-size: 0.78rem;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.25rem;
}

.widget-header-actions .icon-btn {
    background: transparent;
    color: #fff;
    border: none;
    padding: 0.35rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
}

.widget-header-actions .icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Tighter header/input padding in the compact panel — #chat-container,
   #input-area, #input-container and #user-input are shared with the
   full-page chat (home.html), which has room to breathe; the panel doesn't. */
body.widget-page .widget-header {
    padding: 0.6rem 0.85rem;
}

body.widget-page #chat-container {
    padding: 1rem 1.1rem;
    gap: 1rem;
}

body.widget-page #input-area {
    padding: 0.75rem 0.9rem;
}

body.widget-page #input-container {
    padding: 0.3rem;
}

body.widget-page #user-input {
    padding: 0.5rem 0.4rem;
}

body.widget-page #send-btn,
body.widget-page #stop-btn {
    width: 40px;
    height: 40px;
}

/* Auth / maintenance cards fill the panel below the header */
.widget-state-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1.75rem;
    text-align: center;
    overflow-y: auto;
}

.widget-state-card h2 {
    color: var(--uca-blue);
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0.75rem 0 0.5rem;
}

.widget-state-card > p {
    color: #555;
    font-size: 0.88rem;
    line-height: 1.5;
    margin: 0 0 1.5rem;
}

.widget-state-card .login-btn,
.widget-state-card form {
    width: 100%;
    box-sizing: border-box;
}

.widget-state-card .modal-separator {
    width: 100%;
}

.widget-state-card .models-health-debug {
    width: 100%;
    text-align: left;
}

.widget-error {
    color: #c0392b;
    font-size: 0.82rem;
    margin-top: 0.5rem;
    text-align: center;
}

.widget-hint {
    color: #999;
    font-size: 0.75rem;
    margin-top: 1.25rem;
}

.recaptcha-attribution {
    color: #999;
    font-size: 0.7rem;
    margin-top: 0.75rem;
    line-height: 1.4;
}

.recaptcha-attribution a {
    color: inherit;
    text-decoration: underline;
}
