/* =========================
   FLOATING PANELS (shared)
========================= */

.ai-panel,
#masivoPanel,
#unificadoPanel,
#noticiasPanel,
#liqPanel {
    position: fixed;
    z-index: var(--z-panel);
    display: none;
    flex-direction: column;
    width: min(920px, 95vw);
    height: min(90vh, 900px);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    overflow: hidden;
    opacity: 0;
    transition: all var(--transition);
}

body.light .ai-panel,
body.light #masivoPanel,
body.light #unificadoPanel,
body.light #noticiasPanel,
body.light #liqPanel {
    background: rgba(255, 255, 255, 0.95);
}

.ai-panel.active,
#masivoPanel.active,
#unificadoPanel.active,
#noticiasPanel.active,
#liqPanel.active {
    display: flex;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

@media (max-width: 700px) {
    .ai-panel,
    #masivoPanel,
    #unificadoPanel,
    #noticiasPanel,
    #liqPanel {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        top: 0;
        left: 0;
        border-radius: 0;
        transform: translate(0, 100%);
    }

    .ai-panel.active,
    #masivoPanel.active,
    #unificadoPanel.active,
    #noticiasPanel.active,
    #liqPanel.active {
        transform: translate(0, 0);
    }
}

/* =========================
   AI PANEL FIXED INPUT
========================= */
.ai-panel {
    min-height: 0;
}

.ai-panel.active {
    display: flex;
}

.ai-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 24px 0;
}

.ai-input {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 24px;
    border-top: 1px solid var(--border);
    background: var(--card-soft);
    position: sticky;
    bottom: 0;
    z-index: 10;
    flex-shrink: 0;
}

.ai-input input {
    min-width: 0;
}

/* =========================
   PANEL HEADER
========================= */

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    background: var(--card-soft);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.3px;
    color: var(--text);
    flex-shrink: 0;
}

body.light .ai-header {
    background: rgba(235, 241, 255, 0.5);
}

.ai-header button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.ai-header button:hover {
    background: var(--danger);
    color: white;
    transform: scale(1.05);
}

.ai-header button:active {
    transform: scale(0.95);
}

@media (max-width: 640px) {
    .ai-header { padding: 12px 16px; }
}

/* =========================
   PANEL BODY
========================= */

.panel-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.carta-body     { gap: 20px; }
.noticias-body  { gap: 18px; }
.liquidador-body { gap: 20px; }

/* carta-body dentro de gestion-content no necesita padding adicional */
.gestion-content.carta-body {
    padding: 32px;
    gap: 24px;
}

@media (max-width: 768px) {
    .panel-body { padding: 18px; }
    .gestion-content.carta-body { padding: 20px; }
}

/* =========================
   NOTES PANEL
========================= */

.notes-panel {
    position: fixed;
    z-index: var(--z-panel);
    display: none;
    flex-direction: column;
    width: min(700px, 92vw);
    height: min(72vh, 650px);
    top: 120px;
    left: 120px;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    overflow: hidden;
    opacity: 0;
    transition: all var(--transition);
}

body.light .notes-panel {
    background: rgba(255, 255, 255, 0.95);
}

.notes-panel.active {
    display: flex;
    opacity: 1;
}

.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background: var(--card-soft);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text);
    flex-shrink: 0;
}

body.light .notes-header {
    background: rgba(235, 241, 255, 0.5);
}

.notes-header button {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.notes-header button:hover {
    background: var(--danger);
    color: white;
}

#notesArea {
    flex: 1;
    width: 100%;
    padding: 16px;
    border: none;
    resize: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

#notesArea::placeholder {
    color: var(--text-dim);
}

@media (max-width: 768px) {
    .notes-panel {
        width: 90vw;
        height: 70vh;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

/* =========================
   AI CHAT — Burbujas estilo mensajería
========================= */

/* Contenedor de mensajes */
#aiMessages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 2px;
}

/* Fila de mensaje — envuelve avatar + burbuja */
.ai-message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: fadeIn 0.2s ease;
}

/* Filas del usuario van a la derecha */
.ai-message-row.user {
    flex-direction: row-reverse;
}

/* Avatar circular */
.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    line-height: 1;
}

.ai-message-row.user .ai-avatar {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}

.ai-message-row.model .ai-avatar,
.ai-message-row.error .ai-avatar {
    background: var(--card-soft);
    border: 1px solid var(--border);
}

/* Columna con label + burbuja */
.ai-bubble-col {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 76%;
}

.ai-message-row.user .ai-bubble-col {
    align-items: flex-end;
}

.ai-message-row.model .ai-bubble-col,
.ai-message-row.error .ai-bubble-col {
    align-items: flex-start;
}

/* Etiqueta "Tú" / "Asistente IA" */
.ai-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    padding: 0 4px;
}

.ai-message-row.user  .ai-label { color: var(--accent-light); }
.ai-message-row.model .ai-label { color: var(--text-muted); }
.ai-message-row.error .ai-label { color: var(--danger); }

body.light .ai-message-row.user  .ai-label { color: var(--accent-dark); }
body.light .ai-message-row.model .ai-label { color: var(--text-muted); }

/* Burbuja */
.ai-bubble {
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.ai-bubble p {
    margin: 0 0 6px;
}

.ai-bubble p:last-child {
    margin: 0;
}

/* TÚ — azul, esquina inferior derecha recta */
.ai-message-row.user .ai-bubble {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

/* IA — fondo suave, esquina inferior izquierda recta */
.ai-message-row.model .ai-bubble {
    background: var(--card-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

body.light .ai-message-row.model .ai-bubble {
    background: rgba(235, 241, 255, 0.75);
    border-color: var(--border);
}

/* ERROR */
.ai-message-row.error .ai-bubble {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-bottom-left-radius: 4px;
}

/* INDICADOR TYPING */
.ai-message-row.typing .ai-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    min-width: 60px;
}

.ai-message-row.typing .ai-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.ai-message-row.typing .ai-bubble span:nth-child(1) { animation-delay: 0s; }
.ai-message-row.typing .ai-bubble span:nth-child(2) { animation-delay: 0.18s; }
.ai-message-row.typing .ai-bubble span:nth-child(3) { animation-delay: 0.36s; }

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

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

/* =========================
   LIQUIDADOR PANEL
========================= */

.liq-top {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.liq-tipo {
    font-size: 13px;
    color: var(--text-muted);
}

.liq-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.liq-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-radius: var(--radius);
    background: var(--card-soft);
    border: 1px solid var(--border);
    transition: background var(--transition);
}

.liq-result.total {
    background: var(--accent-glow);
    border-color: var(--card-border);
    font-weight: 600;
}

.liq-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
}
