/* ══════════════════════════════════
   IA JUSTICIA — Estilos (Tema Claro)
══════════════════════════════════ */

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

:root {
    --bg:          #f4f6fb;
    --bg2:         #ffffff;
    --bg3:         #eef1f8;
    --sidebar-bg:  #1a1d2e;
    --sidebar-bg2: #13151f;
    --border:      #dde2ee;
    --border-dark: #2a2d40;
    --blue:        #2a7cff;
    --blue-hover:  #1a6ce8;
    --blue-light:  #e8f0ff;
    --text:        #1a1d2e;
    --text-muted:  #5a6380;
    --text-dim:    #9099b5;
    --sidebar-text:#e8ecf4;
    --sidebar-muted:#888ea8;
    --sidebar-dim: #4a5068;
    --white:       #ffffff;
    --shadow:      0 2px 12px rgba(42,124,255,.08);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    height: 100vh;
    overflow: hidden;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* LOGIN */
.login-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0ff 100%);
}
.login-card {
    background: var(--white); border: 1px solid var(--border);
    border-radius: 20px; padding: 2.5rem; width: 100%; max-width: 420px;
    box-shadow: 0 8px 40px rgba(42,124,255,.12);
}
.login-icon  { font-size: 3.5rem; text-align: center; margin-bottom: 1rem; }
.login-title { font-size: 1.8rem; font-weight: 700; text-align: center; color: var(--text); }
.login-sub   { color: var(--text-muted); text-align: center; font-size: .9rem; margin-bottom: 2rem; }
.login-footer{ color: var(--text-dim); font-size: .78rem; text-align: center; margin-top: 1.5rem; line-height: 1.6; }
.field { margin-top: 1.2rem; }
.field label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .4rem; font-weight: 500; }
.field input {
    width: 100%; background: var(--bg3); border: 1px solid var(--border);
    border-radius: 10px; padding: .75rem 1rem; color: var(--text);
    font-size: .9rem; transition: border-color .2s, box-shadow .2s;
}
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(42,124,255,.12); }
.btn-primary {
    width: 100%; background: var(--blue); color: #fff; border: none;
    border-radius: 10px; padding: .85rem; font-size: 1rem; font-weight: 600;
    cursor: pointer; margin-top: 1.5rem; transition: background .2s, box-shadow .2s;
    box-shadow: 0 4px 16px rgba(42,124,255,.3);
}
.btn-primary:hover    { background: var(--blue-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.alert { border-radius: 8px; padding: .85rem 1rem; font-size: .88rem; margin-bottom: 1rem; }
.alert-error { background: #fff1f1; border: 1px solid #ffc5c5; color: #c0392b; }

/* APP */
.app-screen { display: flex; height: 100vh; overflow: hidden; }

/* SIDEBAR oscura */
.sidebar {
    width: 256px; flex-shrink: 0;
    background: var(--sidebar-bg2);
    border-right: 1px solid var(--border-dark);
    display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-brand { padding: 1rem; border-bottom: 1px solid var(--border-dark); display: flex; align-items: center; gap: .75rem; }
.brand-icon { font-size: 1.5rem; }
.brand-name { font-size: .85rem; font-weight: 700; color: var(--sidebar-text); }
.brand-sub  { font-size: .72rem; color: var(--sidebar-dim); }
.sidebar-section     { padding: .75rem; }
.sidebar-chats-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-dim); padding: .5rem .75rem .25rem; }
.btn-new-chat { width: 100%; background: var(--blue); color: #fff; border: none; border-radius: 8px; padding: .65rem; font-size: .85rem; font-weight: 600; cursor: pointer; transition: background .2s; }
.btn-new-chat:hover { background: var(--blue-hover); }
.chat-list  { flex: 1; overflow-y: auto; padding: 0 .5rem; }
.chat-item  { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; border-radius: 8px; cursor: pointer; margin-bottom: 2px; transition: background .15s; color: var(--sidebar-muted); font-size: .8rem; }
.chat-item:hover  { background: rgba(255,255,255,.06); color: var(--sidebar-text); }
.chat-item.active { background: rgba(42,124,255,.2); color: var(--sidebar-text); }
.chat-item-icon   { flex-shrink: 0; }
.chat-item-title  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-del    { opacity: 0; font-size: 1.1rem; color: var(--sidebar-dim); background: none; border: none; cursor: pointer; padding: 0 2px; transition: all .15s; flex-shrink: 0; }
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: #f87171; }
.sidebar-recursos { border-top: 1px solid var(--border-dark); padding: .6rem; }
.recursos-toggle  { width: 100%; display: flex; align-items: center; justify-content: space-between; background: none; border: none; color: var(--sidebar-muted); font-size: .78rem; padding: .4rem .5rem; border-radius: 6px; cursor: pointer; }
.recursos-toggle:hover { color: var(--sidebar-text); }
.recursos-menu { margin-top: 2px; }
.recurso-item  { display: flex; align-items: center; gap: .5rem; font-size: .78rem; color: var(--sidebar-dim); padding: .4rem .5rem; border-radius: 6px; text-decoration: none; transition: all .15s; }
.recurso-item:hover { color: var(--sidebar-text); background: rgba(255,255,255,.06); }
.cuota-bar   { border-top: 1px solid var(--border-dark); padding: .75rem; }
.cuota-label { display: flex; justify-content: space-between; font-size: .72rem; color: var(--sidebar-dim); margin-bottom: .4rem; }
.cuota-track { background: rgba(255,255,255,.1); border-radius: 99px; height: 4px; }
.cuota-fill  { background: var(--blue); height: 4px; border-radius: 99px; transition: width .3s; }
.cuota-fill.warn   { background: #f59e0b; }
.cuota-fill.danger { background: #f87171; }
.user-panel  { border-top: 1px solid var(--border-dark); padding: .75rem; display: flex; align-items: center; gap: .6rem; }
.user-avatar { width: 32px; height: 32px; background: var(--blue); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; color: #fff; flex-shrink: 0; }
.user-info   { flex: 1; min-width: 0; }
.user-name   { font-size: .8rem; font-weight: 600; color: var(--sidebar-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-rol    { font-size: .72rem; color: var(--sidebar-dim); text-transform: capitalize; }
.btn-logout  { background: none; border: none; color: var(--sidebar-dim); cursor: pointer; font-size: .9rem; transition: color .15s; flex-shrink: 0; }
.btn-logout:hover { color: #f87171; }
.admin-link { border-top: 1px solid var(--border-dark); padding: .6rem; text-align: center; }
.admin-link a { font-size: .75rem; color: var(--sidebar-dim); text-decoration: none; transition: color .15s; }
.admin-link a:hover { color: var(--blue); }

/* MAIN clara */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.main-header {
    border-bottom: 1px solid var(--border); padding: .75rem 1.5rem;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0; background: var(--white); box-shadow: var(--shadow);
}
.header-left  { display: flex; align-items: center; gap: .6rem; }
.header-dot   { width: 8px; height: 8px; background: #22c55e; border-radius: 50%; }
.header-title { font-size: .9rem; font-weight: 600; color: var(--text); }
.header-actions { display: flex; gap: .5rem; }
.header-btn { font-size: .75rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .65rem; text-decoration: none; background: var(--white); transition: all .15s; }
.header-btn:hover { color: var(--blue); border-color: var(--blue); background: var(--blue-light); }

/* Mensajes */
.messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; background: var(--bg); }

/* Welcome */
.welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; flex: 1; padding: 2rem; min-height: 300px; }
.welcome-icon { font-size: 4rem; margin-bottom: 1rem; }
.welcome h2   { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-bottom: .6rem; }
.welcome p    { color: var(--text-muted); font-size: .9rem; max-width: 480px; line-height: 1.7; margin-bottom: 1.5rem; }
.welcome-tags { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: 1.25rem; }
.welcome-tags span {
    font-size: .82rem; background: var(--blue-light); border: 1px solid #c8d9ff;
    color: var(--blue); border-radius: 99px; padding: .35rem 1rem;
    font-weight: 500; cursor: pointer; transition: all .15s;
}
.welcome-tags span:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.welcome-disclaimer {
    font-size: .78rem; color: #92700a;
    background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 8px; padding: .6rem 1rem; max-width: 420px; line-height: 1.5;
}

/* Burbujas */
.msg      { display: flex; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg.ai   { justify-content: flex-start; }
.msg-avatar {
    width: 30px; height: 30px; background: var(--blue-light);
    border: 1px solid #c8d9ff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem; margin-right: .65rem; flex-shrink: 0; margin-top: 2px;
}
.msg-bubble { max-width: 72%; border-radius: 16px; padding: .9rem 1.15rem; font-size: .88rem; line-height: 1.65; }
.msg.user .msg-bubble { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 2px 8px rgba(42,124,255,.25); }
.msg.ai   .msg-bubble { background: var(--white); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); color: var(--text); }
.msg-fuentes { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .65rem; padding-top: .65rem; border-top: 1px solid var(--border); }
.fuente-badge { font-size: .72rem; background: var(--blue-light); color: var(--blue); border-radius: 4px; padding: .15rem .5rem; font-weight: 500; }

/* Typing */
.msg-typing .msg-bubble { padding: .75rem 1.15rem; }
.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span { width: 7px; height: 7px; background: var(--blue); border-radius: 50%; animation: bounce 1s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-5px)} }

/* HTML de Claude */
.ia-html h2     { font-size: 1rem; font-weight: 700; color: var(--text); margin: 1rem 0 .4rem; }
.ia-html h2:first-child { margin-top: 0; }
.ia-html p      { color: var(--text-muted); line-height: 1.75; margin-bottom: .5rem; }
.ia-html ul     { padding-left: 1.3rem; margin-bottom: .6rem; }
.ia-html li     { color: var(--text-muted); line-height: 1.75; margin-bottom: .25rem; }
.ia-html strong { color: var(--text); font-weight: 600; }
.ia-html em     { color: var(--text-dim); font-size: .85rem; }
.msg-error .msg-bubble { background: #fff1f1; border-color: #ffc5c5; color: #c0392b; }

/* Input */
.input-area { border-top: 1px solid var(--border); padding: 1rem 1.5rem; flex-shrink: 0; background: var(--white); }
.input-box  {
    display: flex; align-items: flex-end; gap: .65rem;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 16px; padding: .75rem 1rem;
    transition: border-color .2s, box-shadow .2s;
}
.input-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(42,124,255,.1); }
.input-box textarea { flex: 1; background: transparent; border: none; color: var(--text); font-size: .88rem; resize: none; outline: none; line-height: 1.5; max-height: 160px; font-family: inherit; }
.input-box textarea::placeholder { color: var(--text-dim); }
.btn-send { background: var(--blue); color: #fff; border: none; border-radius: 10px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: background .2s; font-size: .9rem; box-shadow: 0 2px 8px rgba(42,124,255,.3); }
.btn-send:hover    { background: var(--blue-hover); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.input-disclaimer  { font-size: .72rem; color: var(--text-dim); text-align: center; margin-top: .5rem; }

/* ══════════════════════════════════
   PDF PREVIEW BAR
══════════════════════════════════ */
.pdf-preview-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    background: var(--blue-l);
    border: 1px solid #c8d9ff;
    border-radius: 10px;
    padding: .6rem .9rem;
    margin-bottom: .5rem;
    animation: slideDown .2s ease;
}
@keyframes slideDown { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }
.pdf-preview-icon  { font-size: 1.4rem; flex-shrink: 0; }
.pdf-preview-info  { flex: 1; min-width: 0; }
.pdf-preview-nombre { font-size: .85rem; font-weight: 600; color: var(--blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-preview-hint   { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.pdf-preview-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: .2rem; border-radius: 4px; transition: all .15s; flex-shrink: 0; }
.pdf-preview-remove:hover { background: #fce8e8; color: #c0392b; }

.pdf-attach-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: .3rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .15s;
}
.pdf-attach-btn:hover { color: var(--blue); background: var(--blue-l); }
.pdf-attach-btn.active { color: var(--blue); }

/* ══════════════════════════════════
   RESPONSIVE MÓVIL
══════════════════════════════════ */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: .2rem .4rem;
    border-radius: 6px;
    margin-right: .25rem;
    transition: all .15s;
}
.sidebar-toggle:hover { background: var(--bg3); color: var(--text); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
}

@media (max-width: 768px) {

    .app-screen { position: relative; }

    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform .25s ease;
        width: 280px;
    }

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

    .sidebar-overlay.open {
        display: block;
    }

    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .main { width: 100%; }

    .msg-bubble { max-width: 88%; }

    .input-area { padding: .75rem; }

    .main-header { padding: .65rem 1rem; }

    .header-actions { display: none; }

    .messages { padding: 1rem .75rem; }
}

/* ── BOTÓN GUARDAR RESPUESTA ─────────────────────────────── */
.btn-guardar-respuesta {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    margin-top: .75rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 6px;
    padding: .3rem .75rem;
    font-size: .75rem;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.btn-guardar-respuesta:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: var(--blue-l);
}

/* ── TOAST ANIMACIÓN ─────────────────────────────────────── */
@keyframes slideUp {
    from { opacity:0; transform:translateY(8px); }
    to   { opacity:1; transform:translateY(0); }
}

/* ── BOTÓN GENERAR INFORME ───────────────────────────────── */
.btn-generar-informe {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: .35rem .85rem;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .15s, box-shadow .15s;
    box-shadow: 0 2px 6px rgba(42,124,255,.3);
    font-family: inherit;
}
.btn-generar-informe:hover {
    background: var(--blue-hover);
    box-shadow: 0 3px 10px rgba(42,124,255,.4);
}

/* ══════════════════════════════════
   MODO SELECCIÓN Y EXPORTAR
══════════════════════════════════ */
.btn-exportar-activo {
    background: var(--blue) !important;
    color: #fff !important;
    border-color: var(--blue) !important;
    font-weight: 600;
}
.btn-exportar-activo:hover {
    background: var(--blue-hover) !important;
}

/* Checkbox en mensajes */
.msg-checkbox-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    margin-right: .4rem;
    margin-top: .3rem;
}

.msg-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--blue);
    flex-shrink: 0;
}

/* Mensaje seleccionado */
.msg-seleccionado .msg-bubble {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
    border-radius: 16px;
}

/* En modo selección, los mensajes muestran cursor pointer */
.modo-seleccion .msg {
    cursor: pointer;
}
.modo-seleccion .msg:hover .msg-bubble {
    box-shadow: 0 0 0 2px rgba(42,124,255,.3);
}

/* ── DROPDOWN ITEMS ──────────────────────────────────────── */
.dropdown-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    padding: .7rem 1rem;
    background: none;
    border: none;
    font-size: .85rem;
    color: var(--text);
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
    text-align: left;
}
.dropdown-item:hover { background: var(--bg3); }
.dropdown-item span  { font-size: 1.1rem; flex-shrink: 0; }

.dropdown-item-primary { color: var(--blue); font-weight: 500; }
.dropdown-item-primary:hover { background: var(--blue-l); }
/* ══ BÚSQUEDAS EN TIEMPO REAL (estilo Maite.ai) ══ */
.buscando-widget {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .75rem 1rem;
    margin-bottom: .85rem;
    max-width: 72%;
    animation: fadeInUp .2s ease;
}
@keyframes fadeInUp {
    from { opacity:0; transform:translateY(4px); }
    to   { opacity:1; transform:translateY(0); }
}
.buscando-titulo {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .74rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .5rem;
}
.buscando-spinner {
    width: 10px;
    height: 10px;
    border: 2px solid var(--blue-l);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.buscando-paso {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .74rem;
    color: var(--text-dim);
    padding: .25rem 0;
    transition: color .2s;
}
.buscando-paso-icon { font-size: .85rem; flex-shrink: 0; }
.buscando-paso-texto { flex: 1; }
.buscando-paso-estado { flex-shrink: 0; min-width: 16px; text-align: center; }
.buscando-hecho { color: var(--text-muted); }
.buscando-hecho .buscando-paso-texto { text-decoration: none; }
.buscando-activo { color: var(--text); }
.buscando-pendiente { opacity: .45; }
.buscando-dot-anim {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--blue);
    animation: pulseDot .9s infinite;
}
@keyframes pulseDot {
    0%,100% { opacity:1; transform:scale(1); }
    50%      { opacity:.3; transform:scale(.7); }
}
