/* ══════════════════════════════════════════════════════════════════════════
   ManualBot — Chat UI Stylesheet
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    /* Colores principales — cámbia estos para tu marca */
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-light: #dbeafe;
    --accent-text: #1e40af;

    /* Neutros */
    --bg: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-chat: #f1f5f9;
    --bg-bubble-user: var(--accent);
    --bg-bubble-bot: #ffffff;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-on-accent: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    /* Layout */
    --sidebar-width: 280px;
    --header-height: 56px;
    --input-height: 72px;
    --radius: 12px;
    --radius-sm: 8px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    /* Transitions */
    --transition: 150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.rds-logo-link {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.rds-logo {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    transition: transform var(--transition);
}

.rds-logo:hover {
    transform: scale(1.08);
}

.logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
}

.brand-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.brand-accent {
    color: var(--accent);
}

.sidebar-section {
    padding: 16px 20px;
}

.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.sidebar-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 6px;
}

.manuals-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.manual-card {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.manual-card:hover {
    background: var(--border-light);
}

.manual-card.active {
    background: var(--accent-light);
    color: var(--accent-text);
}

.manual-card-content {
    flex: 1;
    min-width: 0;
}

.manual-card .manual-name {
    font-weight: 600;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manual-card .manual-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.manual-download {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: all var(--transition);
    text-decoration: none;
}

.manual-download:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.manual-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.manual-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.session-info {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.6;
}

.sidebar-copyright {
    margin-top: 12px;
    text-align: center;
}

.sidebar-copyright a {
    font-size: 11px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.sidebar-copyright a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary:hover {
    background: var(--border-light);
    border-color: var(--accent);
    color: var(--accent);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-sidebar);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

/* ── Chat main ──────────────────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    background: var(--bg-chat);
}

.chat-header {
    height: var(--header-height);
    min-height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
}

.status-dot.error {
    background: #ef4444;
}

/* ── Messages area ──────────────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Welcome screen */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    max-width: 500px;
    margin: auto;
}

.welcome-icon {
    margin-bottom: 20px;
}

.welcome-message h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.suggestion {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-sidebar);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.suggestion:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

/* Message bubbles */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.25s ease;
}

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

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

.message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent);
    color: white;
}

.message.bot .message-avatar {
    background: var(--accent-light);
    color: var(--accent);
}

.message-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.55;
    font-size: 14px;
    word-break: break-word;
}

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

.message.bot .message-bubble {
    background: var(--bg-bubble-bot);
    color: var(--text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message.bot .message-bubble p {
    margin-bottom: 8px;
}

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

.message.bot .message-bubble ul,
.message.bot .message-bubble ol {
    margin: 8px 0;
    padding-left: 0;
    list-style: none;
    counter-reset: list-counter;
}

.message.bot .message-bubble ol.styled-list {
    /* counter-reset se controla via style inline para respetar start="N" */
}

.message.bot .message-bubble ol.styled-list > li {
    counter-increment: list-counter;
}

.message.bot .message-bubble ol.styled-list > li::before {
    content: counter(list-counter);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: var(--accent);
    color: var(--text-on-accent);
    font-size: 11px;
    font-weight: 700;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
}

.message.bot .message-bubble ul.styled-list > li::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
    vertical-align: middle;
}

.message.bot .message-bubble li {
    margin-bottom: 8px;
    padding: 6px 10px;
    background: var(--border-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: flex-start;
    line-height: 1.5;
}

.message.bot .message-bubble li:last-child {
    margin-bottom: 0;
}

/* ── Inline images within answer ────────────────────────────────────── */
.inline-image-wrapper {
    margin: 10px 0;
    text-align: center;
}

.inline-image {
    max-width: 320px;
    max-height: 260px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    object-fit: contain;
    background: white;
    box-shadow: var(--shadow-sm);
}

.inline-image:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-md);
}

.message.bot .message-bubble strong {
    font-weight: 600;
}

.message.bot .message-bubble code {
    background: var(--border-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* ── Sources & images ───────────────────────────────────────────────────── */
.message-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 4px;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--accent-light);
    color: var(--accent-text);
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
}

.source-badge svg {
    width: 12px;
    height: 12px;
}

.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px;
}

.message-image {
    max-width: 220px;
    max-height: 180px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    object-fit: contain;
    background: white;
}

.message-image:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-md);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 10px;
}

.confidence-badge.high   { background: #dcfce7; color: #166534; }
.confidence-badge.medium { background: #fef3c7; color: #92400e; }
.confidence-badge.low    { background: #fee2e2; color: #991b1b; }

/* ── Loading indicator ──────────────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-bubble-bot);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.loading-dot {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 8px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Input area ─────────────────────────────────────────────────────────── */
.chat-input-area {
    padding: 12px 24px 20px;
    background: var(--bg-chat);
}

.chat-form {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 8px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Language selector ─────────────────────────────────────────────────── */
.lang-selector {
    position: relative;
    flex-shrink: 0;
}

.lang-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all var(--transition);
    padding: 0;
}

.lang-btn:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.lang-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 50;
    min-width: 140px;
    overflow: hidden;
}

.lang-dropdown.open {
    display: block;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition);
    text-align: left;
}

.lang-option:hover {
    background: var(--border-light);
}

.lang-option.active {
    background: var(--accent-light);
    color: var(--accent-text);
    font-weight: 600;
}

.lang-option .lang-flag {
    font-size: 18px;
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    resize: none;
    max-height: 120px;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.btn-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), transform var(--transition);
}

.btn-send:hover {
    background: var(--accent-dark);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    padding: 6px 4px 0;
}

.input-hint, .input-model {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ── Lightbox ───────────────────────────────────────────────────────────── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.lightbox.visible {
    display: flex;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    background: white;
}

.lightbox-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: white;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .chat-header {
        padding-left: 60px;
    }

    .message {
        max-width: 95%;
    }

    .message-image {
        max-width: 180px;
        max-height: 140px;
    }

    .chat-input-area {
        padding: 8px 12px 12px;
    }
}

@media (max-width: 480px) {
    .welcome-suggestions {
        flex-direction: column;
    }

    .suggestion {
        width: 100%;
        text-align: center;
    }
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ── Error toast ────────────────────────────────────────────────────────── */
.error-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #991b1b;
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 500;
    animation: fadeIn 0.3s ease;
}

/* ── Extra questions accordion ─────────────────────────────────────────── */
.extra-questions-wrapper {
    margin-top: 16px;
    width: 100%;
    max-width: 500px;
}

.extra-questions-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    margin: 0 auto;
}

.extra-questions-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.extra-questions-toggle svg {
    transition: transform 0.2s ease;
}

.extra-questions-toggle.open svg {
    transform: rotate(180deg);
}

.extra-questions-list {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 12px;
    padding: 0 8px;
}

.extra-questions-list.open {
    display: flex;
}

.suggestion-sm {
    font-size: 12px;
    padding: 6px 12px;
}

