/* ─── Reset & base ────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --rojo: #dc0c1d;
    --rojo-oscuro: #b00918;
    --texto: #333333;
    --texto-suave: #6b7280;
    --borde: #e2e2e2;
    --fondo: #f6f7f9;
    --fondo-card: #ffffff;
    --exito: #10b981;
    --alerta: #f59e0b;
    --error: #ef4444;
    --sombra: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--texto);
    background: var(--fondo);
    line-height: 1.5;
    min-height: 100vh;
}

/* ─── Topbar ──────────────────────────────────────────────────────── */
.topbar {
    background: var(--fondo-card);
    border-bottom: 1px solid var(--borde);
    padding: 14px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 1.05rem; }
.logo { font-size: 1.4rem; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.whoami { color: var(--texto-suave); font-size: 0.9rem; }

/* ─── Layout ──────────────────────────────────────────────────────── */
main {
    max-width: 820px;
    margin: 0 auto;
    padding: 32px 20px 60px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s ease; }

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

/* ─── Card ────────────────────────────────────────────────────────── */
.card {
    background: var(--fondo-card);
    border: 1px solid var(--borde);
    border-radius: 12px;
    padding: 32px;
    box-shadow: var(--sombra);
}

.card h1 { font-size: 1.5rem; margin-bottom: 6px; font-weight: 600; }
.card h2 { font-size: 1.2rem; margin-bottom: 8px; font-weight: 600; }
.subtitle { color: var(--texto-suave); margin-bottom: 24px; font-size: 0.95rem; }
.text-center { text-align: center; }
.muted { color: var(--texto-suave); }
.small { font-size: 0.85rem; }
.required { color: var(--rojo); }

/* ─── Dropzone ────────────────────────────────────────────────────── */
.dropzone {
    border: 2px dashed var(--borde);
    border-radius: 10px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--rojo);
    background: #fff5f6;
}

.dropzone-icon { font-size: 3rem; margin-bottom: 12px; }
.dropzone-text { font-size: 1rem; margin-bottom: 6px; }
.dropzone-hint { color: var(--texto-suave); font-size: 0.85rem; }

/* ─── File info ───────────────────────────────────────────────────── */
.file-info {
    margin-top: 16px;
    padding: 12px 16px;
    background: #f0f9ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-icon { font-size: 1.4rem; }
.hidden { display: none !important; }

.btn-icon {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--texto-suave);
    cursor: pointer;
    padding: 0 6px;
    margin-left: auto;
}

.btn-icon:hover { color: var(--rojo); }

/* ─── Fields ──────────────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.92rem;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s;
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--rojo);
    box-shadow: 0 0 0 3px rgba(220,12,29,0.1);
}

.field textarea { resize: vertical; min-height: 100px; }

/* ─── Fieldset ────────────────────────────────────────────────────── */
fieldset {
    border: none;
    border-top: 1px solid var(--borde);
    padding-top: 20px;
    margin-top: 20px;
}

fieldset:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

legend {
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 16px;
    color: var(--texto);
}

/* ─── Tag lists (autores, keywords, aat) ─────────────────────────── */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    min-height: 34px;
}

.tag-list:empty::before {
    content: "(ninguno)";
    color: var(--texto-suave);
    font-style: italic;
    font-size: 0.85rem;
    align-self: center;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px 5px 12px;
    background: #eef2ff;
    color: #3730a3;
    border-radius: 20px;
    font-size: 0.88rem;
    line-height: 1.2;
}

.tag-aat {
    background: #ecfdf5;
    color: #065f46;
}

.tag-remove {
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.5;
    line-height: 1;
}

.tag-remove:hover { opacity: 1; }

.tag-input { display: flex; gap: 8px; }
.tag-input-field {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
}

.tag-input-field:focus {
    outline: none;
    border-color: var(--rojo);
}

.btn-small {
    padding: 8px 14px;
    background: var(--fondo);
    border: 1px solid var(--borde);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    white-space: nowrap;
}

.btn-small:hover { background: #ebedf0; }

/* ─── Tesauro search ──────────────────────────────────────────────── */
.tesauro-search { position: relative; margin-bottom: 12px; }

#tesauro-query {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
}

#tesauro-query:focus {
    outline: none;
    border-color: #065f46;
    box-shadow: 0 0 0 3px rgba(6,95,70,0.1);
}

.tesauro-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--borde);
    border-radius: 8px;
    box-shadow: var(--sombra);
    max-height: 280px;
    overflow-y: auto;
    z-index: 50;
    display: none;
}

.tesauro-results.visible { display: block; }

.tesauro-result {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
}

.tesauro-result:last-child { border-bottom: none; }
.tesauro-result:hover { background: #f9fafb; }
.tesauro-result strong { display: block; font-size: 0.92rem; }
.tesauro-result small { color: var(--texto-suave); font-size: 0.8rem; }

/* ─── Buttons ─────────────────────────────────────────────────────── */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: var(--rojo);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

.btn-primary:hover:not(:disabled) { background: var(--rojo-oscuro); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.btn-ghost {
    padding: 10px 18px;
    background: transparent;
    border: 1px solid var(--borde);
    border-radius: 8px;
    color: var(--texto);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
}

.btn-ghost:hover { background: var(--fondo); }

.actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--borde);
}

.actions-center {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

.actions .btn-primary { width: auto; padding: 12px 28px; }

/* ─── Spinner ─────────────────────────────────────────────────────── */
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--borde);
    border-top-color: var(--rojo);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

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

/* ─── Success ─────────────────────────────────────────────────────── */
.success-icon { font-size: 4rem; margin-bottom: 12px; }
.success-details {
    background: var(--fondo);
    border-radius: 8px;
    padding: 16px;
    margin: 20px 0;
    text-align: left;
    font-size: 0.9rem;
}

.success-details a { color: var(--rojo); text-decoration: none; word-break: break-all; }
.success-details a:hover { text-decoration: underline; }

/* ─── Badges ──────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--fondo);
    font-size: 0.82rem;
    color: var(--texto-suave);
    margin-left: 8px;
}

.badge-info { background: #eff6ff; color: #1e40af; }
.badge-success { background: #ecfdf5; color: #065f46; }

.review-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

/* ─── Toast ───────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: #1f2937;
    color: white;
    border-radius: 10px;
    font-size: 0.9rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    max-width: 400px;
    z-index: 1000;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.toast.error { background: var(--error); }
.toast.success { background: var(--exito); }

/* ─── History ─────────────────────────────────────────────────────── */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--borde);
    border-radius: 10px;
    margin-bottom: 10px;
}

.history-item-info { flex: 1; min-width: 0; }
.history-item-title { font-weight: 500; margin-bottom: 4px; }
.history-item-meta { font-size: 0.82rem; color: var(--texto-suave); }
.history-item-actions { display: flex; gap: 8px; }

.status-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.status-review    { background: #eff6ff; color: #1e40af; }
.status-sent      { background: #ecfdf5; color: #065f46; }
.status-failed    { background: #fef2f2; color: #991b1b; }
.status-deleted   { background: #f3f4f6; color: #6b7280; }

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .topbar { padding: 12px 16px; }
    .brand span:not(.logo) { font-size: 0.9rem; }
    .whoami { display: none; }
    .card { padding: 20px; }
    .field-row { grid-template-columns: 1fr; }
    .review-header { flex-direction: column; }
    .actions { flex-direction: column-reverse; }
    .actions .btn-primary, .actions .btn-ghost { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════════
   INTEGRIA · BRANDING INFOTEGRA
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Logo en topbar ──────────────────────────────────────────────── */
.brand-logo {
    height: 42px;
    width: auto;
    border-radius: 4px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--texto);
}

.brand-sub {
    font-size: 0.72rem;
    color: var(--texto-suave);
    font-weight: 400;
}

.stats-badge {
    font-size: 0.8rem;
    color: var(--texto-suave);
    padding: 4px 10px;
    background: var(--fondo);
    border-radius: 20px;
}

/* ─── Footer ──────────────────────────────────────────────────────── */
.footer {
    background: var(--fondo-card);
    border-top: 1px solid var(--borde);
    padding: 24px 32px;
    margin-top: 40px;
}

.footer-inner {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.footer-logo img {
    height: 48px;
    width: auto;
    border-radius: 4px;
}

.footer-text {
    font-size: 0.85rem;
    color: var(--texto-suave);
    line-height: 1.5;
}

.footer-text strong {
    color: var(--texto);
}

/* ─── Botón de éxito (verde) ──────────────────────────────────────── */
.btn-success {
    padding: 14px 24px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
    width: 100%;
}

.btn-success:hover:not(:disabled) {
    background: #059669;
}

.btn-success:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.actions .btn-success {
    width: auto;
    padding: 12px 28px;
}

/* ─── Layout de revisión (2 columnas) ─────────────────────────────── */
.review-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    align-items: start;
}

.review-form-col {
    min-width: 0;
}

.review-preview-col {
    position: sticky;
    top: 80px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--texto-suave);
    margin-bottom: 8px;
    padding: 8px 12px;
    background: var(--fondo);
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--borde);
    border-bottom: none;
}

.pdf-preview-container {
    border: 1px solid var(--borde);
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    height: 600px;
    background: #f0f0f0;
}

.pdf-preview-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.pdf-preview-container.collapsed {
    height: 40px;
}

.pdf-preview-container.collapsed iframe {
    display: none;
}

/* ─── Vista de éxito animada ──────────────────────────────────────── */
.success-card {
    animation: successPulse 0.6s ease;
}

@keyframes successPulse {
    0% { transform: scale(0.95); opacity: 0; }
    60% { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}

.success-icon-animated {
    font-size: 5rem;
    margin-bottom: 16px;
    animation: bounceIn 0.8s ease;
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.15); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

/* ─── Validación en vivo ──────────────────────────────────────────── */
.field input.invalid,
.field textarea.invalid,
.field select.invalid {
    border-color: var(--error);
    background: #fef2f2;
}

.field .field-error {
    color: var(--error);
    font-size: 0.78rem;
    margin-top: 4px;
    display: none;
}

.field.has-error .field-error {
    display: block;
}

/* ─── Borrador ────────────────────────────────────────────────────── */
.draft-banner {
    margin-top: 16px;
    padding: 12px 16px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.draft-banner span {
    flex: 1;
}

/* ─── Responsive ajustes ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .review-layout {
        grid-template-columns: 1fr;
    }
    .review-preview-col {
        position: static;
        order: -1;
    }
    .pdf-preview-container {
        height: 400px;
    }
}

@media (max-width: 640px) {
    .brand-logo {
        height: 32px;
    }
    .brand-sub {
        display: none;
    }
    .stats-badge {
        display: none;
    }
    .footer-inner {
        flex-direction: column;
        text-align: center;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   FIX · Layout ancho en vista de revisión
   ═══════════════════════════════════════════════════════════════════ */

main.wide {
    max-width: 1300px;
}

main.wide .card {
    padding: 32px 40px;
}

.review-layout {
    grid-template-columns: 1fr 520px;
}

.pdf-preview-container {
    height: 700px;
}

@media (max-width: 1100px) {
    .review-layout {
        grid-template-columns: 1fr;
    }
    .pdf-preview-container {
        height: 500px;
    }
}


.actions-center .btn-success {
    width: auto;
    padding: 12px 28px;
}

/* ─── Logo como link al inicio ────────────────────────────────────── */
a.brand {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.brand:hover .brand-title {
    color: var(--rojo);
}


/* ─── Botón Procesar con IntegrIA (no rojo, más pequeño) ──────────── */
#btn-process {
    width: auto;
    min-width: 220px;
    padding: 12px 28px;
    background: #1e40af;      /* azul oscuro */
    font-size: 0.95rem;
    margin-top: 8px;
}

#btn-process:hover:not(:disabled) {
    background: #1e3a8a;
}

#btn-process:disabled {
    background: #cbd5e1;
}


/* ─── Barra de progreso ───────────────────────────────────────────── */
.progress-bar-container {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    margin: 24px auto 12px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #1e40af, #3b82f6);
    border-radius: 4px;
    width: 0%;
    transition: width 0.4s ease;
}

#progress-text {
    font-size: 0.85rem;
}


/* ─── Historial: header + botón borrar ────────────────────────────── */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.history-header h1 {
    margin-bottom: 0;
}

.btn-danger-ghost {
    color: var(--error);
    border-color: #fecaca;
}

.btn-danger-ghost:hover {
    background: #fef2f2;
    border-color: var(--error);
}

/* ─── Badge de idioma ────────────────────────────────────────────── */
.lang-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
    vertical-align: middle;
}

.lang-badge-en {
    background: #dbeafe;
    color: #1e40af;
}

/* Keywords en inglés: borde azulado sutil */
.tag-list-en .tag {
    background: #dbeafe;
    color: #1e40af;
}

.tag-list-en .tag-remove {
    color: #1e40af;
}


/* ─── Dropzone de licencia (más pequeño) ──────────────────────────── */
.dropzone-license {
    border-color: #d1d5db;
    background: #f9fafb;
    padding: 24px 20px;
}

.dropzone-license:hover, .dropzone-license.dragover {
    border-color: #1e40af;
    background: #eff6ff;
}

.dropzone-license .dropzone-icon {
    margin-bottom: 6px;
}
