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

:root {
    --accent: #ff4200;
    --accent-hover: #e03a00;
    --accent-disabled: rgba(255, 66, 0, 0.44);
    --text: #000000;
    --text-muted: #707070;
    --text-cite: #a7a7a7;
    --border: #999;
    --border-light: #dfdfdf;
    --border-card: #e3e3e3;
    --card-bg: #fafafa;
    --bg: #ffffff;
    --error-bg: #fef2f2;
    --error-border: #fca5a5;
    --error-text: #991b1b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    margin: 0;
}

/* Page shell */

.page {
    width: 100%;
    max-width: 1440px;
    min-height: 100vh;
    margin: 0 auto;
    background: var(--bg);
}

.page-inner {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    height: 100%;
    padding: 50px 96px;
}

/* Header */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    width: 100%;
}

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

.back-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.2s;
}

.back-arrow:hover {
    opacity: 0.8;
}

.page-title {
    font-family: "American Typewriter", serif;
    font-size: 48px;
    font-weight: normal;
    font-style: normal;
    line-height: 60px;
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--accent);
}

.page-subtitle {
    font-size: 18px;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 28px;
    letter-spacing: -0.44px;
}

.btn-about {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 0 25px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--bg);
    color: var(--accent);
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-about:hover {
    background: #fff5f2;
}

/* Cards */

.card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
    min-height: 0;
}

.card-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    line-height: 28px;
    color: var(--text);
    letter-spacing: -0.44px;
}

.card-subtitle {
    font-size: 12px;
    font-weight: 400;
    line-height: 20px;
    color: var(--text-muted);
    letter-spacing: -0.15px;
}

/* Upload grid (two columns) */

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* Upload area */

.upload-area {
    flex: 1;
    border: 2px solid var(--border-light);
    border-radius: 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
    min-height: 200px;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--text-muted);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.upload-placeholder p {
    font-size: 14px;
    font-weight: 400;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.6;
}

#preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* Form fields */

.fields-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    overflow-y: auto;
}

.field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 20px;
    margin-bottom: 8px;
}

.label-hint {
    font-weight: 400;
    opacity: 0.7;
}

.field input {
    width: 100%;
    height: 50px;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.2s;
}

.field input::placeholder {
    color: rgba(112, 112, 112, 0.6);
}

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

/* Form footer + buttons */

.form-footer {
    flex-shrink: 0;
    padding-top: 18px;
    border-top: 1px solid var(--border-card);
    margin-top: auto;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 48px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    letter-spacing: -0.31px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-primary:disabled {
    background: var(--accent-disabled);
    cursor: not-allowed;
}

/* Loading */

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 2rem;
}

.loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 40px 48px;
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid var(--border-light);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    text-align: center;
    min-width: 280px;
}

.loading-card p {
    color: var(--text-muted);
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.loading-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}

.loading-error p {
    color: var(--text-muted);
    max-width: 280px;
    line-height: 1.5;
    margin: 0;
}

.progress-bar-track {
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    margin: 1rem auto 0;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.timer {
    font-size: 1.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

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

/* Error */

#error-box {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--error-border);
    border-radius: 10px;
    background: var(--error-bg);
    color: var(--error-text);
}

/* ==================== RESULTS VIEW ==================== */

#results-view > .page-inner {
    max-height: 100vh;
    overflow: hidden;
}

.results-grid {
    display: grid;
    grid-template-columns: 274px 1fr 1fr;
    gap: 17px;
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* Sidebar (reference image + metadata) */

.results-sidebar {
    gap: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    border-color: #757575;
}

.ref-image-wrap {
    border-radius: 10px;
    background: var(--bg);
    flex-shrink: 0;
}

.ref-image-wrap img {
    width: 100%;
    height: auto;
    border-radius: 10px;
}

.metadatos {
    display: flex;
    flex-direction: column;
    gap: 5px;
    border: 2px solid var(--border-light);
    border-radius: 10px;
    padding: 17px;
    background: var(--bg);
    flex-shrink: 0;
}

.metadatos-title {
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    letter-spacing: 0.05px;
    text-transform: uppercase;
    color: var(--text-muted);
    flex-shrink: 0;
}

.metadatos-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    padding-right: 8px;
    font-size: 10px;
    letter-spacing: -0.15px;
    color: var(--text-muted);
}

.metadatos-list::-webkit-scrollbar {
    width: 4px;
}

.metadatos-list::-webkit-scrollbar-track {
    background: transparent;
}

.metadatos-list::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 2px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 3px 0;
}

.meta-item .meta-label {
    font-weight: 500;
    line-height: 20px;
    text-transform: uppercase;
}

.meta-item .meta-value {
    font-weight: 400;
    line-height: 22.75px;
}

/* Fixed header inside scrollable columns */

.card-header-fixed {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

/* Questions column */

.results-questions {
    gap: 0;
    overflow: hidden;
}

.results-questions .card-header-fixed {
    margin-bottom: 20px;
}

.preguntas-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
}

.pregunta-card {
    background: var(--card-bg);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 17px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-label {
    font-size: 10px;
    font-weight: 700;
    line-height: 20px;
    letter-spacing: 0.72px;
    text-transform: uppercase;
    color: var(--accent);
}

.card-body {
    font-size: 14px;
    font-weight: 500;
    line-height: 22.75px;
    letter-spacing: -0.3px;
    color: var(--text-muted);
}

/* Sources column */

.results-sources {
    gap: 0;
    overflow: hidden;
}

.results-sources .card-header-fixed {
    margin-bottom: 20px;
}

.fuentes-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
}

.fuente-card {
    background: var(--card-bg);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 17px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.fuente-card .fuente-fragmento {
    font-size: 14px;
    font-weight: 500;
    font-style: italic;
    line-height: 22.75px;
    letter-spacing: -0.3px;
    color: var(--text-muted);
}

.fuente-card .fuente-source {
    font-size: 12px;
    line-height: 18px;
    letter-spacing: -0.15px;
    color: var(--text-cite);
}

/* Custom scrollbar for result columns */

.preguntas-list::-webkit-scrollbar,
.fuentes-list::-webkit-scrollbar,
.results-sidebar::-webkit-scrollbar {
    width: 4px;
}

.preguntas-list::-webkit-scrollbar-track,
.fuentes-list::-webkit-scrollbar-track,
.results-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.preguntas-list::-webkit-scrollbar-thumb,
.fuentes-list::-webkit-scrollbar-thumb,
.results-sidebar::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 2px;
}

/* Lightbox */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: zoom-out;
}

.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.ref-image-wrap {
    cursor: zoom-in;
}

/* Utilities */

.hidden {
    display: none !important;
}

/* Footer */

footer {
    width: 100%;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    padding-top: 24px;
}

footer p {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    text-align: center;
    line-height: 28px;
    letter-spacing: -0.88px;
}

/* Responsive — tablets and small desktops */

@media (max-width: 960px) {
    .page-inner {
        padding: 32px 24px;
    }

    #results-view > .page-inner {
        max-height: none;
        overflow: visible;
    }

    .page-title {
        font-size: 32px;
        line-height: 42px;
    }

    .back-arrow svg {
        width: 32px;
        height: 32px;
    }

    .header-left {
        gap: 10px;
    }

    .btn-about {
        height: 40px;
        padding: 0 18px;
        font-size: 14px;
    }

    .card {
        padding: 20px;
    }

    .upload-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .upload-area {
        min-height: 240px;
        position: static;
    }

    #preview {
        position: static;
        width: 100%;
        height: auto;
        max-height: 300px;
    }

    .results-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .results-sidebar {
        max-width: none;
    }

    .preguntas-list,
    .fuentes-list {
        overflow-y: visible;
        padding-right: 0;
    }
}

/* Responsive — phones */

@media (max-width: 480px) {
    .page-inner {
        padding: 24px 16px;
        gap: 12px;
    }

    .page-header {
        height: auto;
        gap: 8px;
    }

    .header-left {
        gap: 8px;
        min-width: 0;
    }

    .page-title {
        font-size: 24px;
        line-height: 32px;
    }

    .back-arrow svg {
        width: 28px;
        height: 28px;
    }

    .btn-about {
        height: 36px;
        padding: 0 14px;
        font-size: 13px;
    }

    .page-subtitle {
        font-size: 15px;
        line-height: 22px;
    }

    .card {
        padding: 16px;
        gap: 12px;
    }

    .card-title {
        font-size: 16px;
        line-height: 24px;
    }

    .card-subtitle {
        font-size: 11px;
    }

    .upload-grid {
        gap: 16px;
    }

    .upload-area {
        min-height: 180px;
    }

    .field label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .field input {
        height: 44px;
        padding: 10px 14px;
        font-size: 14px;
    }

    .fields-list {
        gap: 16px;
    }

    .form-footer {
        padding-top: 14px;
    }

    .btn-primary {
        height: 44px;
        font-size: 15px;
    }

    .results-grid {
        gap: 16px;
    }

    .pregunta-card,
    .fuente-card {
        padding: 14px;
    }

    .card-label {
        font-size: 9px;
    }

    .card-body {
        font-size: 13px;
        line-height: 20px;
    }

    .fuente-card .fuente-fragmento {
        font-size: 13px;
        line-height: 20px;
    }

    .fuente-card .fuente-source {
        font-size: 11px;
    }

    .metadatos {
        padding: 14px;
    }

    footer p {
        font-size: 11px;
    }
}
