/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html {
    font-size: 16px;
}

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

/* ===== Header ===== */
.header {
    background: var(--text);
    color: #fff;
    padding: 0.75rem 1rem;
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-sub {
    font-weight: 400;
    opacity: 0.7;
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

/* ===== Container ===== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

/* ===== Upload Section ===== */
.upload-section {
    margin-bottom: 1.5rem;
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: var(--surface);
}

.dropzone:hover,
.dropzone.drag-over {
    border-color: var(--primary);
    background: #eff6ff;
}

.dropzone-icon {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.dropzone.drag-over .dropzone-icon {
    color: var(--primary);
}

.dropzone-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.dropzone-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.dropzone-formats {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.75rem;
    opacity: 0.8;
}

/* Upload options */
.upload-options {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    align-items: flex-end;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.option-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.option-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.875rem;
    color: var(--text);
    cursor: pointer;
}

/* ===== File List ===== */
.file-list {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.file-preview {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
    background: #f1f5f9;
    flex-shrink: 0;
}

.file-preview-pdf {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    background: #dc2626;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    flex-shrink: 0;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.2rem;
    line-height: 1;
    transition: color 0.2s;
}

.file-remove:hover {
    color: var(--danger);
}

.file-error {
    font-size: 0.75rem;
    color: var(--danger);
    font-weight: 500;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    margin-top: 1rem;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover:not(:disabled) {
    background: #f1f5f9;
}

/* ===== Loading ===== */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 0.75rem;
}

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

.loading p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== Review Section ===== */
.review-section {
    margin-bottom: 1.5rem;
}

.review-header {
    margin-bottom: 1rem;
}

.review-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.review-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.review-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.review-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.review-card-error {
    border-color: var(--danger);
}

.review-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.review-filename {
    font-weight: 600;
    font-size: 0.9rem;
    margin-right: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.review-card-body {
    padding: 0.75rem 1rem;
}

.review-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.review-motor-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.review-select-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.review-select {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s;
}

.review-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.review-error-msg {
    color: var(--danger);
    font-size: 0.85rem;
}

.review-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.review-actions .btn-outline {
    flex: 0 0 auto;
}

.review-actions .btn-confirm {
    flex: 1;
    margin-top: 0;
}

.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

/* ===== Results ===== */
.results-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.result-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.result-filename {
    font-weight: 600;
    font-size: 0.9rem;
    margin-right: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

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

.badge-motor.mistral {
    background: #fef3c7;
    color: #92400e;
}

.badge-motor.pdfplumber {
    background: #dcfce7;
    color: #166534;
}

.badge-confianza {
    background: #f1f5f9;
    color: var(--text-secondary);
}

.badge-confianza.high {
    background: #dcfce7;
    color: #166534;
}

.badge-confianza.medium {
    background: #fef3c7;
    color: #92400e;
}

.badge-confianza.low {
    background: #fee2e2;
    color: #991b1b;
}

.badge-fallback {
    background: #fef3c7;
    color: #92400e;
}

.badge-coste {
    background: #dcfce7;
    color: #166534;
}

.badge-coste.paid {
    background: #fef3c7;
    color: #92400e;
}

/* Result meta row */
.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.meta-label {
    font-weight: 600;
}

/* Result text area */
.result-body {
    padding: 0;
}

.result-textarea {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: none;
    resize: vertical;
    font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--surface);
}

.result-textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

/* Result actions */
.result-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

/* Result error */
.result-error {
    padding: 1rem;
    color: var(--danger);
    font-size: 0.875rem;
}

/* Copy feedback */
.btn.copied {
    color: var(--success);
    border-color: var(--success);
}

/* ===== Login ===== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-logo {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.03em;
}

.login-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.login-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.login-field input {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.login-field input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.login-btn {
    margin-top: 0.5rem;
}

.login-error {
    background: #fee2e2;
    color: #991b1b;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    text-align: center;
}

/* ===== Header logout ===== */
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-logout {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-exit {
    background: rgba(220, 38, 38, 0.15);
    border: 1px solid rgba(220, 38, 38, 0.5);
    color: #fca5a5;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-exit:hover {
    background: rgba(220, 38, 38, 0.3);
    color: #fff;
}

/* ===== Exit dialog ===== */
.exit-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.exit-overlay[hidden] {
    display: none;
}

.exit-dialog {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 380px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.exit-dialog h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: var(--text);
}

.exit-dialog p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.exit-dialog-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-danger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .header {
        padding: 0.6rem 0.75rem;
    }

    .container {
        padding: 1rem 0.75rem 2rem;
    }

    .dropzone {
        padding: 2rem 1rem;
    }

    .result-header {
        padding: 0.6rem 0.75rem;
    }

    .result-textarea {
        padding: 0.75rem;
        font-size: 0.8rem;
        min-height: 150px;
    }

    .result-actions {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
    }

    .result-meta {
        padding: 0.4rem 0.75rem;
    }

    .upload-options {
        flex-direction: column;
        align-items: stretch;
    }

    .review-card-header {
        padding: 0.5rem 0.75rem;
    }

    .review-card-body {
        padding: 0.6rem 0.75rem;
    }

    .review-motor-select {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
    }

    .review-actions {
        flex-direction: column;
    }

    .review-actions .btn-outline {
        width: 100%;
    }
}
