@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Montserrat:wght@600;700&display=swap');

:root {
    --cobalt: #0F4C81;
    --cobalt-dark: #09355C;
    --cobalt-soft: #EFF6FF;
    --cobalt-border: #BFDBFE;
    --emerald: #10B981;

    --bg-canvas: #EEF2F6;
    --bg-surface: #FFFFFF;
    --bg-subtle: #F8FAFC;

    --border-hairline: #E2E8F0;
    --text-main: #0F172A;
    --text-muted: #475569;
    --text-subtle: #94A3B8;

    --error-bg: #FEF2F2;
    --error-border: #FECACA;
    --error-text: #B91C1C;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-pill: 999px;

    --shadow-shell: 0 24px 60px -20px rgba(15, 23, 42, 0.14), 0 0 1px rgba(15, 23, 42, 0.12);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(15, 76, 129, 0.06), transparent 42%),
        radial-gradient(circle at bottom right, rgba(16, 185, 129, 0.05), transparent 45%),
        var(--bg-canvas);
    color: var(--text-main);
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* ============================================
   Contenedor Amplio y Proporcionado (2 Columnas)
   ============================================ */
.studio-shell {
    width: 100%;
    max-width: 1120px;
    height: min(860px, 94dvh);
    background: var(--bg-surface);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-shell);
    display: grid;
    grid-template-columns: 310px 1fr;
    overflow: hidden;
}

/* ============================================
   Panel Izquierdo: Marca + Dra.
   ============================================ */
.brand-rail {
    background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
    border-right: 1px solid var(--border-hairline);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 18px;
}

.brand-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    max-width: 190px;
    max-height: 80px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.brand-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-subtle);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-hairline);
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--emerald);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.doctor-showcase {
    background: var(--bg-surface);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    flex: 1;
    min-height: 0;
    justify-content: center;
}

.doctor-frame {
    width: 100%;
    max-height: 280px;
    border-radius: var(--radius-sm);
    background: var(--cobalt-soft);
    border: 1px solid var(--cobalt-border);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.doctor-img {
    width: 100%;
    height: 100%;
    max-height: 280px;
    object-fit: contain;
    object-position: top center;
    display: block;
}

.doctor-caption h2 {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.doctor-caption p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.rail-highlights {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.highlight-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-sm);
}

.highlight-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cobalt);
    flex-shrink: 0;
}

/* ============================================
   Panel Derecho: Conversación
   ============================================ */
.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-subtle);
}

.chat-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-hairline);
    padding: 18px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.chat-eyebrow {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cobalt);
    margin-bottom: 2px;
}

.chat-header h1 {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.reset-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    background: var(--bg-surface);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.16s ease;
    flex-shrink: 0;
}

.reset-btn svg {
    width: 15px;
    height: 15px;
}

.reset-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
    border-color: #CBD5E1;
}

/* ============================================
   Feed de Mensajes
   ============================================ */
.messages-feed {
    flex: 1;
    overflow-y: auto;
    padding: 24px 26px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
}

.messages-feed::-webkit-scrollbar {
    width: 6px;
}

.messages-feed::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: var(--radius-pill);
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 82%;
    animation: fadeSlide 0.24s ease;
}

@keyframes fadeSlide {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message--ai {
    align-self: flex-start;
}

.message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message__avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-pill);
    object-fit: cover;
    object-position: top center;
    border: 1.5px solid var(--cobalt-border);
    background: var(--cobalt-soft);
    flex-shrink: 0;
}

.message__user-badge {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-pill);
    background: var(--cobalt);
    color: #FFFFFF;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message--user .message__body {
    align-items: flex-end;
}

.message__bubble {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.message--ai .message__bubble {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-hairline);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.message--user .message__bubble {
    background: var(--cobalt);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.message__bubble p+p {
    margin-top: 10px;
}

.message__bubble ul {
    margin: 8px 0 8px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message__note {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding-top: 8px;
    border-top: 1px solid var(--border-hairline);
}

.message__meta {
    font-size: 0.7rem;
    color: var(--text-subtle);
    padding: 0 4px;
}

/* ============================================
   Escritura y Error
   ============================================ */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 2px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cobalt);
    animation: dotPulse 1.3s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dotPulse {

    0%,
    80%,
    100% {
        transform: scale(0.65);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.error-box {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.error-box strong {
    display: block;
    margin-bottom: 2px;
}

/* ============================================
   Compositor Inferior
   ============================================ */
.composer-dock {
    background: var(--bg-surface);
    border-top: 1px solid var(--border-hairline);
    padding: 14px 26px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    background: var(--bg-subtle);
    border: 1px solid var(--border-hairline);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 13px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all 0.16s ease;
}

.chip:hover {
    background: var(--cobalt-soft);
    border-color: var(--cobalt-border);
    color: var(--cobalt);
}

.composer {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-hairline);
    border-radius: var(--radius-md);
    padding: 6px 6px 6px 16px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.composer:focus-within {
    background: var(--bg-surface);
    border-color: var(--cobalt);
    box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.1);
}

.composer input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--text-main);
    outline: none;
    min-width: 0;
}

.composer input::placeholder {
    color: var(--text-subtle);
}

.send-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--cobalt);
    color: #FFFFFF;
    border: none;
    border-radius: 11px;
    padding: 10px 18px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.send-btn svg {
    width: 16px;
    height: 16px;
}

.send-btn:hover:not(:disabled) {
    background: var(--cobalt-dark);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.send-btn:disabled {
    background: #CBD5E1;
    cursor: not-allowed;
}

.legal-note {
    font-size: 0.74rem;
    color: var(--text-subtle);
    text-align: center;
}

/* ============================================
   Tablet y Móvil
   ============================================ */
@media (max-width: 900px) {
    .studio-shell {
        grid-template-columns: 1fr;
        height: min(900px, 95dvh);
    }

    .brand-rail {
        border-right: none;
        border-bottom: 1px solid var(--border-hairline);
        padding: 14px 18px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .brand-card {
        padding: 8px 12px;
        gap: 6px;
    }

    .brand-logo {
        max-width: 130px;
        max-height: 46px;
    }

    .doctor-showcase {
        flex-direction: row;
        text-align: left;
        padding: 8px 12px;
        gap: 10px;
        flex: 1;
    }

    .doctor-frame {
        width: 52px;
        height: 52px;
        max-height: 52px;
        border-radius: var(--radius-pill);
        flex-shrink: 0;
    }

    .doctor-img {
        width: 100%;
        height: 100%;
        max-height: 52px;
        object-fit: cover;
    }

    .doctor-caption p,
    .rail-highlights {
        display: none;
    }
}

@media (max-width: 560px) {
    body {
        padding: 0;
    }

    .studio-shell {
        height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-header h1 {
        font-size: 1rem;
    }

    .reset-btn span {
        display: none;
    }

    .messages-feed {
        padding: 16px;
    }

    .message {
        max-width: 92%;
    }

    .suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .suggestions::-webkit-scrollbar {
        display: none;
    }

    .chip {
        flex-shrink: 0;
    }

    .composer-dock {
        padding: 12px 16px 14px;
    }

    .send-btn span {
        display: none;
    }

    .send-btn {
        padding: 10px 12px;
    }
}