@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Source+Sans+3:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Variables ─────────────────────────────────────────────────────────────── */
.a23f-root {
    --a23f-accent:    #8B0000;
    --a23f-accent2:   #C0392B;
    --a23f-navy:      #1a1a2e;
    --a23f-navy2:     #16213e;
    --a23f-navy3:     #0f3460;
    --a23f-surface:   #f8f7f4;
    --a23f-surface2:  #eeecea;
    --a23f-border:    #d5d0c8;
    --a23f-text:      #1c1917;
    --a23f-muted:     #78716c;
    --a23f-mono:      'JetBrains Mono', monospace;
    --a23f-sans:      'Source Sans 3', system-ui, sans-serif;
    --a23f-serif:     'Playfair Display', Georgia, serif;
    --a23f-h:         680px;
    --a23f-sidebar-w: 210px;
    --a23f-radius:    10px;
    --a23f-shadow:    0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.08);

    font-family: var(--a23f-sans);
    font-size: 14px;
    line-height: 1.6;
    color: var(--a23f-text);
    box-sizing: border-box;
}
.a23f-root *, .a23f-root *::before, .a23f-root *::after { box-sizing: inherit; }

/* ── Contenedor principal ──────────────────────────────────────────────────── */
.a23f-root {
    border-radius: var(--a23f-radius);
    overflow: hidden;
    box-shadow: var(--a23f-shadow);
    border: 1px solid var(--a23f-border);
    display: flex;
    flex-direction: column;
    height: var(--a23f-h);
    max-width: 960px;
    margin: 2rem auto;
    background: var(--a23f-surface);
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.a23f-header {
    background: var(--a23f-navy);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 2px solid var(--a23f-accent);
}

.a23f-header-left { display: flex; align-items: center; gap: 12px; }

.a23f-logo {
    width: 40px; height: 40px;
    background: var(--a23f-accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; flex-shrink: 0;
}

.a23f-title {
    font-family: var(--a23f-serif);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -.01em;
}
.a23f-title-accent { color: var(--a23f-accent2); }

.a23f-subtitle {
    font-size: 9px;
    letter-spacing: .18em;
    color: rgba(255,255,255,.5);
    font-weight: 500;
    margin-top: 2px;
}

/* Motor blindado */
.a23f-motor {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    border: 1px solid;
}
.a23f-motor-on  { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.35); color: #6ee7b7; }
.a23f-motor-off { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.35);  color: #fca5a5; }

.a23f-motor-dot {
    width: 7px; height: 7px; border-radius: 50%;
    animation: a23f-pulse 2s infinite;
}
.a23f-motor-on  .a23f-motor-dot { background: #10b981; }
.a23f-motor-off .a23f-motor-dot { background: #ef4444; animation: none; }

@keyframes a23f-pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .6; transform: scale(1.3); }
}
.a23f-motor-count { font-size: 10px; opacity: .7; }

/* ── Body ──────────────────────────────────────────────────────────────────── */
.a23f-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.a23f-sidebar {
    width: var(--a23f-sidebar-w);
    flex-shrink: 0;
    background: var(--a23f-navy2);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,.06);
}

.a23f-sidebar-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .14em;
    color: rgba(255,255,255,.35);
    padding: 0 4px;
    margin-top: 4px;
}

.a23f-protocol-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 7px;
    color: rgba(255,255,255,.8);
    font-family: var(--a23f-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background .15s, border-color .15s, color .15s;
}
.a23f-protocol-btn:hover {
    background: rgba(139,0,0,.25);
    border-color: rgba(139,0,0,.5);
    color: #fff;
}
.a23f-protocol-btn.a23f-loading {
    opacity: .6; cursor: wait;
}
.a23f-protocol-icon { font-size: 14px; flex-shrink: 0; }

.a23f-btn-clear {
    display: flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 7px;
    color: rgba(255,255,255,.45);
    font-family: var(--a23f-sans);
    font-size: 11px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all .15s;
    width: 100%;
}
.a23f-btn-clear:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.7); }

/* ── Main area ─────────────────────────────────────────────────────────────── */
.a23f-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ── Messages ──────────────────────────────────────────────────────────────── */
.a23f-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--a23f-surface);
    scroll-behavior: smooth;
}
.a23f-messages::-webkit-scrollbar { width: 4px; }
.a23f-messages::-webkit-scrollbar-thumb { background: var(--a23f-border); border-radius: 4px; }

/* Burbuja genérica */
.a23f-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    animation: a23f-pop .2s ease;
    line-height: 1.65;
}
@keyframes a23f-pop { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

/* Usuario */
.a23f-bubble-user {
    align-self: flex-end;
    background: var(--a23f-navy);
    color: #fff;
    border-bottom-right-radius: 3px;
    font-size: 14px;
}

/* Sistema / IA */
.a23f-bubble-bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--a23f-border);
    border-bottom-left-radius: 3px;
    font-size: 14px;
    max-width: 92%;
}
.a23f-bubble-bot p  { margin: 0 0 .6em; }
.a23f-bubble-bot p:last-child { margin-bottom: 0; }
.a23f-bubble-bot strong { font-weight: 600; }
.a23f-bubble-bot em     { font-style: italic; }
.a23f-bubble-bot ul, .a23f-bubble-bot ol { margin: .4em 0 .4em 1.3em; padding: 0; }
.a23f-bubble-bot li { margin-bottom: .3em; }
.a23f-bubble-bot code {
    font-family: var(--a23f-mono);
    font-size: .85em;
    background: rgba(0,0,0,.05);
    padding: 1px 5px;
    border-radius: 4px;
}

/* Bienvenida */
.a23f-welcome {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--a23f-border);
    border-left: 3px solid var(--a23f-accent);
    border-radius: 0 12px 12px 0;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--a23f-muted);
    max-width: 90%;
    animation: a23f-pop .3s ease;
}

/* Protocolo header */
.a23f-protocol-header {
    align-self: center;
    background: var(--a23f-navy);
    color: rgba(255,255,255,.7);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    padding: 5px 14px;
    border-radius: 20px;
}

/* Thinking */
.a23f-thinking {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--a23f-border);
    border-radius: 12px;
    border-bottom-left-radius: 3px;
    padding: 12px 16px;
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; color: var(--a23f-muted);
}
.a23f-dots { display: flex; gap: 4px; }
.a23f-dots span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--a23f-accent);
    animation: a23f-bounce 1.2s infinite;
}
.a23f-dots span:nth-child(2) { animation-delay:.2s }
.a23f-dots span:nth-child(3) { animation-delay:.4s }
@keyframes a23f-bounce { 0%,60%,100%{transform:none} 30%{transform:translateY(-6px)} }

/* Error */
.a23f-bubble-error {
    color: #c0392b !important;
    border-color: #f5c6cb !important;
    background: #fff5f5 !important;
}

/* ── Citas [N] ─────────────────────────────────────────────────────────────── */
.a23f-cite {
    display: inline-flex;
    align-items: center;
    background: var(--a23f-accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0 5px;
    margin: 0 1px;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--a23f-mono);
    line-height: 17px;
    cursor: pointer;
    vertical-align: middle;
    position: relative; top: -1px;
    transition: background .15s, transform .1s;
}
.a23f-cite:hover { background: #6b0000; transform: scale(1.1); }

/* Barra de fuentes */
.a23f-sources-bar {
    align-self: flex-start;
    width: 100%;
    padding: 8px 12px;
    background: var(--a23f-surface2);
    border: 1px solid var(--a23f-border);
    border-radius: 8px;
    animation: a23f-pop .2s ease;
}
.a23f-sources-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .1em;
    color: var(--a23f-muted);
    text-transform: uppercase;
    margin-bottom: 6px;
    display: block;
}
.a23f-sources-list { display: flex; flex-wrap: wrap; gap: 5px; }
.a23f-source-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px 3px 4px;
    background: #fff;
    border: 1px solid var(--a23f-border);
    border-radius: 20px;
    font-size: 11px;
    font-family: var(--a23f-sans);
    cursor: pointer;
    transition: border-color .15s, background .15s;
    max-width: 240px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.a23f-source-chip:hover { border-color: var(--a23f-accent); background: #fff5f5; }
.a23f-chip-num {
    width: 17px; height: 17px;
    background: var(--a23f-accent);
    color: #fff;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 9px; font-weight: 700; font-family: var(--a23f-mono);
    flex-shrink: 0;
}

/* ── Modal de documento ────────────────────────────────────────────────────── */
.a23f-source-modal {
    position: absolute;
    inset: 0;
    background: rgba(26,26,46,.6);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
    z-index: 100;
    backdrop-filter: blur(2px);
}
.a23f-source-modal.open {
    opacity: 1; pointer-events: all;
}
.a23f-modal-box {
    background: #fff;
    border-radius: 12px;
    width: 100%; max-width: 580px;
    max-height: 80%;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    transform: translateY(12px) scale(.97);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1);
    overflow: hidden;
}
.a23f-source-modal.open .a23f-modal-box { transform: none; }

.a23f-modal-header {
    background: var(--a23f-navy);
    padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 2px solid var(--a23f-accent);
}
.a23f-modal-title {
    color: #fff;
    font-family: var(--a23f-serif);
    font-size: 15px;
    font-weight: 600;
}
.a23f-modal-close {
    background: rgba(255,255,255,.15);
    border: none; color: #fff;
    width: 28px; height: 28px;
    border-radius: 6px; font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.a23f-modal-close:hover { background: rgba(255,255,255,.3); }

.a23f-modal-meta {
    padding: 14px 16px;
    font-size: 13px;
    flex: 1;
    overflow-y: auto;
    line-height: 1.7;
}
.a23f-modal-meta::-webkit-scrollbar { width: 4px; }
.a23f-modal-meta::-webkit-scrollbar-thumb { background: var(--a23f-border); border-radius: 4px; }

.a23f-modal-meta .a23f-meta-row {
    display: flex; gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--a23f-surface2);
}
.a23f-modal-meta .a23f-meta-label {
    font-weight: 600; color: var(--a23f-muted);
    min-width: 80px; font-size: 11px;
    text-transform: uppercase; letter-spacing: .05em;
    padding-top: 2px;
}
.a23f-modal-meta .a23f-meta-val { color: var(--a23f-text); }

.a23f-modal-footer {
    background: var(--a23f-surface2);
    border-top: 1px solid var(--a23f-border);
    padding: 8px 16px;
    font-size: 10px;
    color: var(--a23f-muted);
    letter-spacing: .05em;
    font-family: var(--a23f-mono);
    flex-shrink: 0;
}

/* ── Input ─────────────────────────────────────────────────────────────────── */
.a23f-input-wrap {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid var(--a23f-border);
    display: flex; gap: 10px; align-items: flex-end;
    flex-shrink: 0;
}
.a23f-input {
    flex: 1;
    border: 1px solid var(--a23f-border);
    border-radius: 8px;
    padding: 9px 12px;
    font-family: var(--a23f-sans);
    font-size: 14px;
    color: var(--a23f-text);
    background: var(--a23f-surface);
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color .2s, box-shadow .2s;
}
.a23f-input:focus {
    border-color: var(--a23f-accent);
    box-shadow: 0 0 0 3px rgba(139,0,0,.1);
    background: #fff;
}
.a23f-send {
    width: 38px; height: 38px; flex-shrink: 0;
    background: var(--a23f-accent);
    border: none; border-radius: 8px; color: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .15s;
}
.a23f-send:hover:not(:disabled) { background: #6b0000; transform: scale(1.05); }
.a23f-send:disabled { opacity: .4; cursor: not-allowed; }

.a23f-input-footer {
    text-align: center;
    font-size: 10px;
    color: var(--a23f-muted);
    padding: 4px 16px 8px;
    background: #fff;
    font-family: var(--a23f-mono);
    letter-spacing: .03em;
    flex-shrink: 0;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .a23f-sidebar { display: none; }
    .a23f-subtitle { display: none; }
    .a23f-motor-label { display: none; }
}

/* ── Fragmento del documento en modal ───────────────────────────────────────── */
.a23f-fragmento {
    margin: 14px 0 8px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--a23f-border);
}

.a23f-fragmento-label {
    background: var(--a23f-navy);
    color: rgba(255,255,255,.75);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .1em;
    padding: 7px 12px;
    font-family: var(--a23f-mono);
}

.a23f-fragmento-text {
    margin: 0;
    padding: 14px 16px;
    background: #fffef8;
    font-family: var(--a23f-mono);
    font-size: 12px;
    line-height: 1.75;
    color: var(--a23f-text);
    white-space: pre-wrap;
    word-break: break-word;
    border-left: 3px solid var(--a23f-accent);
    max-height: 320px;
    overflow-y: auto;
}
.a23f-fragmento-text::-webkit-scrollbar { width: 4px; }
.a23f-fragmento-text::-webkit-scrollbar-thumb { background: var(--a23f-border); border-radius: 4px; }

/* ── Cita sin documento disponible ──────────────────────────────────────────── */
.a23f-cite-nodoc {
    display: inline-flex;
    align-items: center;
    background: #e2e8f0;
    color: #94a3b8;
    border-radius: 4px;
    padding: 0 5px;
    margin: 0 1px;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--a23f-mono);
    line-height: 17px;
    vertical-align: middle;
    position: relative; top: -1px;
    cursor: not-allowed;
}

/* ── Burbuja de docs disponibles ─────────────────────────────────────────────── */
.a23f-welcome-docs {
    align-self: flex-start;
    background: rgba(139,0,0,.06);
    border: 1px solid rgba(139,0,0,.15);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12px;
    color: var(--a23f-muted);
    max-width: 90%;
    animation: a23f-pop .3s ease .1s both;
}
