* {
    box-sizing: border-box;
}

/* ───────── Tokens (mismos colores de marca que la versión anterior) ───────── */
:root {
    color-scheme: light;

    --bg-1: #f6f3ec;
    --bg-2: #efeae0;
    --bg-overlay-1: rgba(246, 243, 236, 0.80);
    --bg-overlay-2: rgba(239, 234, 224, 0.90);

    --card: rgba(255, 253, 249, 0.96);
    --card-strong: #ffffff;
    --card-hero-1: #0b2149;
    --card-hero-2: #18366d;

    --text: #0b2149;
    --text-strong: #071535;
    --muted: #5f6d86;

    --line: #e1e7f0;
    --line-strong: #c9d4e4;

    --primary: #0b2149;
    --primary-2: #18366d;
    --primary-contrast: #ffffff;

    --accent: #d83a34;
    --accent-soft: rgba(216, 58, 52, 0.10);

    --warning: #9a6700;
    --warning-fg: #6c4a00;
    --warning-soft: rgba(154, 103, 0, 0.09);
    --warning-border: rgba(154, 103, 0, 0.22);

    --success: #198754;
    --success-soft: rgba(25, 135, 84, 0.12);

    --error: #b42318;
    --error-soft: rgba(180, 35, 24, 0.10);

    --surface-soft: #f6f8fb;
    --icon-bg: #eef3fb;

    --overlay: rgba(7, 21, 53, 0.55);

    --shadow-soft: 0 10px 30px rgba(11, 33, 73, 0.07);
    --shadow-lift: 0 24px 60px rgba(11, 33, 73, 0.22);
    --shadow-ring: 0 0 0 4px rgba(11, 33, 73, 0.10);

    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --bg-1: #0b1018;
        --bg-2: #0f1522;
        --bg-overlay-1: rgba(11, 16, 24, 0.86);
        --bg-overlay-2: rgba(15, 21, 34, 0.94);

        --card: rgba(21, 28, 41, 0.94);
        --card-strong: #171f2e;
        --card-hero-1: #10224a;
        --card-hero-2: #1d3a74;

        --text: #e8edf7;
        --text-strong: #f5f7fb;
        --muted: #9aa7bd;

        --line: rgba(255, 255, 255, 0.09);
        --line-strong: rgba(255, 255, 255, 0.16);

        --primary: #6ea0ff;
        --primary-2: #8ab4ff;
        --primary-contrast: #07122a;

        --accent: #ff6b61;
        --accent-soft: rgba(255, 107, 97, 0.14);

        --warning: #f5c26b;
        --warning-fg: #f5d293;
        --warning-soft: rgba(245, 194, 107, 0.12);
        --warning-border: rgba(245, 194, 107, 0.28);

        --success: #4ade80;
        --success-soft: rgba(74, 222, 128, 0.14);

        --error: #ff7a70;
        --error-soft: rgba(255, 122, 112, 0.14);

        --surface-soft: rgba(255, 255, 255, 0.04);
        --icon-bg: rgba(110, 160, 255, 0.14);

        --overlay: rgba(0, 0, 0, 0.66);

        --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.40);
        --shadow-lift: 0 24px 60px rgba(0, 0, 0, 0.60);
        --shadow-ring: 0 0 0 4px rgba(110, 160, 255, 0.24);
    }
}

/* ───────── Base ───────── */
html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
    -webkit-font-smoothing: antialiased;
}

body {
    position: relative;
}

.page-bg {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(var(--bg-overlay-1), var(--bg-overlay-2)),
        url("/FondoClaro.png");
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    z-index: 0;
    pointer-events: none;
}

@media (prefers-color-scheme: dark) {
    .page-bg {
        opacity: 0.35;
    }
}

.shell {
    position: relative;
    z-index: 1;
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px 20px calc(40px + env(safe-area-inset-bottom));
}

.hidden {
    display: none !important;
}

/* ───────── Marca ───────── */
.brand-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.brand-left {
    display: flex;
    gap: 14px;
    align-items: center;
    min-width: 0;
}

.brand-logo {
    width: 52px;
    height: 52px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 14px;
    background: #fff;
    padding: 6px;
    box-shadow: var(--shadow-soft);
}

.brand-eyebrow {
    margin: 0 0 4px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand-title {
    margin: 0;
    font-size: 26px;
    line-height: 1.15;
    color: var(--text-strong);
    letter-spacing: -0.4px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.status-pill.is-signed {
    background: var(--success-soft);
    color: var(--success);
}

/* ───────── Estados ───────── */
.state-panel {
    max-width: 560px;
    margin: 48px auto;
    padding: 36px 24px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.state-panel h2 {
    margin: 0;
    font-size: 22px;
    color: var(--text-strong);
}

.state-panel p {
    margin: 10px auto 0;
    color: var(--muted);
    line-height: 1.65;
}

.state-hint {
    font-size: 13px;
}

.state-error h2 {
    color: var(--error);
}

.state-success h2 {
    color: var(--success);
}

.state-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 26px;
}

.state-icon-loading {
    border: 4px solid var(--line);
    border-top-color: var(--primary);
    animation: spin 0.9s linear infinite;
}

.state-icon-error {
    background: var(--error-soft);
    color: var(--error);
}

.state-icon-success {
    background: var(--success-soft);
    color: var(--success);
    animation: pop 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ───────── Stepper ───────── */
.stepper {
    list-style: none;
    display: flex;
    gap: 8px;
    padding: 0;
    margin: 0 0 18px;
}

.step {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background: var(--icon-bg);
    color: var(--primary);
    flex-shrink: 0;
}

.step.is-active {
    color: var(--text-strong);
    border-color: var(--line-strong);
    box-shadow: var(--shadow-soft);
}

.step.is-active .step-num {
    background: var(--primary);
    color: var(--primary-contrast);
}

.step.is-done .step-num {
    background: var(--success);
    color: #fff;
}

.step.is-done {
    color: var(--success);
}

/* ───────── Layout 2 columnas ───────── */
.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.col-main,
.col-side {
    display: grid;
    gap: 18px;
    min-width: 0;
}

.col-side {
    position: sticky;
    top: 16px;
}

/* ───────── Hero ───────── */
.hero-card {
    padding: 24px;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--card-hero-1) 0%, var(--card-hero-2) 100%);
    color: #fff;
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-end;
    box-shadow: 0 16px 40px rgba(11, 33, 73, 0.25);
    position: relative;
    overflow: hidden;
}

.hero-card::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -60px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(216, 58, 52, 0.35), transparent 70%);
    pointer-events: none;
}

.hero-copy {
    min-width: 0;
    position: relative;
    z-index: 1;
}

.hero-kicker {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.70);
}

.hero-title {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
    color: #fff;
    letter-spacing: -0.3px;
    overflow-wrap: anywhere;
}

.hero-period {
    margin: 10px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: rgba(255, 255, 255, 0.80);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.hero-arrow {
    opacity: 0.6;
}

.hero-amount {
    position: relative;
    z-index: 1;
    text-align: right;
    flex-shrink: 0;
}

.hero-amount-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.70);
}

.hero-amount-value {
    display: block;
    margin-top: 6px;
    font-size: 34px;
    font-weight: 800;
    line-height: 1;
    color: #fff;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}

/* ───────── Tarjetas ───────── */
.notice-card {
    display: flex;
    gap: 14px;
    padding: 16px 18px;
    border-radius: var(--radius-lg);
    border: 1px solid;
    line-height: 1.6;
}

.notice-card p {
    margin: 2px 0 0;
}

.notice-icon {
    font-size: 20px;
    line-height: 1.4;
}

.notice-warning {
    background: var(--warning-soft);
    border-color: var(--warning-border);
    color: var(--warning-fg);
}

.notice-title {
    font-weight: 800;
}

.section-card {
    padding: 22px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--shadow-soft);
}

.signature-priority-card {
    border-color: var(--line-strong);
}

.section-head {
    margin-bottom: 16px;
}

.section-head-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}

.section-head h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-strong);
    letter-spacing: -0.2px;
}

.section-head p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.55;
    font-size: 14px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.field-hint {
    margin-left: 4px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.75;
}

.info-value {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--text-strong);
    font-weight: 600;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

/* ───────── PDF ───────── */
.pdf-preview-button {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #fff;
    cursor: pointer;
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.pdf-preview-button:hover {
    box-shadow: var(--shadow-lift);
}

.pdf-preview-button:focus-visible {
    outline: none;
    box-shadow: var(--shadow-ring);
}

.pdf-preview-frame {
    display: block;
    width: 100%;
    height: 340px;
    border: none;
    background: #fff;
    pointer-events: none;
    color-scheme: light;
}

.pdf-preview-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 28px 16px 14px;
    background: linear-gradient(180deg, rgba(11, 33, 73, 0), rgba(11, 33, 73, 0.82));
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    text-align: center;
}

.pdf-preview-fallback {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    color: var(--muted);
    line-height: 1.55;
    font-size: 14px;
}

/* ───────── Revisión + bloqueo ───────── */
.review-checks {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.check-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--surface-soft);
    cursor: pointer;
    line-height: 1.5;
    font-size: 14px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.check-card:hover {
    border-color: var(--line-strong);
}

.check-card:has(input:checked) {
    border-color: var(--success);
    background: var(--success-soft);
}

.check-card input {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--success);
    flex-shrink: 0;
}

.lock-banner {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
}

.signature-area {
    transition: opacity 0.25s ease, filter 0.25s ease;
}

.signature-area-locked {
    opacity: 0.45;
    filter: grayscale(0.3);
    pointer-events: none;
}

/* Área de firma: SIEMPRE clara (los píxeles blancos se pintan en JS para el PNG) */
.signature-box {
    position: relative;
    overflow: hidden;
    border: 2px dashed #b9c8dc;
    border-radius: var(--radius-lg);
    background: #ffffff;
    color-scheme: light only;
    forced-color-adjust: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.signature-area:not(.signature-area-locked) .signature-box {
    border-color: #0b2149;
    box-shadow: 0 0 0 4px rgba(11, 33, 73, 0.08);
}

.signature-box::before {
    content: "";
    position: absolute;
    left: 22px;
    right: 22px;
    bottom: 44px;
    height: 1px;
    background: repeating-linear-gradient(to right,
            rgba(11, 33, 73, 0.20) 0,
            rgba(11, 33, 73, 0.20) 6px,
            transparent 6px,
            transparent 12px);
    pointer-events: none;
    z-index: 2;
}

.signature-box::after {
    content: "✕";
    position: absolute;
    left: 22px;
    bottom: 50px;
    font-size: 14px;
    font-weight: 700;
    color: rgba(11, 33, 73, 0.30);
    pointer-events: none;
    z-index: 2;
}

.signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: rgba(11, 33, 73, 0.30);
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.2s ease;
}

.signature-placeholder.is-hidden {
    opacity: 0;
}

canvas#signatureCanvas {
    display: block;
    width: 100%;
    height: 220px;
    background: #ffffff;
    touch-action: none;
    position: relative;
    z-index: 1;
    cursor: crosshair;
    color-scheme: light only;
    forced-color-adjust: none;
}

.signature-note {
    margin: 12px 0 14px;
    color: var(--muted);
    line-height: 1.55;
    font-size: 13px;
}

.action-row {
    display: flex;
    gap: 10px;
}

.action-row .btn-primary {
    flex: 1;
}

.disagree-row {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--muted);
}

/* ───────── Botones ───────── */
.btn {
    border: none;
    border-radius: var(--radius-md);
    padding: 13px 18px;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    white-space: nowrap;
}

.btn:not(:disabled):hover {
    transform: translateY(-1px);
}

.btn:not(:disabled):active {
    transform: translateY(0);
}

.btn:focus-visible,
.btn-link:focus-visible {
    outline: none;
    box-shadow: var(--shadow-ring);
}

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

.btn-primary {
    background: linear-gradient(135deg, #0b2149 0%, #18366d 100%);
    color: #fff;
    box-shadow: 0 8px 22px rgba(11, 33, 73, 0.28);
}

.btn-secondary {
    background: var(--icon-bg);
    color: var(--primary);
    border: 1px solid var(--line);
    padding: 10px 14px;
    font-size: 14px;
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line-strong);
}

.btn-warning {
    background: linear-gradient(135deg, #b7791f 0%, #8f5a13 100%);
    color: #fff;
    box-shadow: 0 8px 22px rgba(183, 121, 31, 0.25);
}

.btn-link {
    border: none;
    background: none;
    padding: 4px 2px;
    font: inherit;
    font-weight: 700;
    color: var(--warning);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    border-radius: 6px;
}

/* ───────── Modales ───────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 16px;
    animation: fade 0.18s ease;
}

.modal-card {
    width: 100%;
    max-width: 560px;
    background: var(--card-strong);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 26px;
    box-shadow: var(--shadow-lift);
    animation: rise 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-card h3 {
    margin: 0 0 12px;
    font-size: 21px;
    color: var(--text-strong);
    letter-spacing: -0.2px;
}

.modal-card p {
    margin: 0 0 10px;
    color: var(--muted);
    line-height: 1.65;
    font-size: 15px;
}

.modal-check {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    line-height: 1.55;
    cursor: pointer;
}

.modal-check:has(input:checked) {
    border-color: var(--success);
    background: var(--success-soft);
}

.modal-check input {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--success);
    flex-shrink: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.textarea-input {
    width: 100%;
    resize: vertical;
    min-height: 130px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--text);
    font: inherit;
    line-height: 1.55;
    margin-top: 8px;
}

.textarea-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

.field-error {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--error-soft);
    color: var(--error);
    font-weight: 700;
    font-size: 14px;
}

/* ───────── Toast ───────── */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 40;
    max-width: min(92vw, 520px);
    padding: 13px 18px;
    border-radius: var(--radius-md);
    background: var(--text-strong);
    color: var(--card-strong);
    font-weight: 700;
    font-size: 14px;
    line-height: 1.45;
    box-shadow: var(--shadow-lift);
    animation: rise 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.is-error {
    background: var(--error);
    color: #fff;
}

.toast.is-success {
    background: var(--success);
    color: #fff;
}

/* ───────── Footer ───────── */
.page-footer {
    margin-top: 28px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
}

/* ───────── Animaciones ───────── */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fade {
    from {
        opacity: 0;
    }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translate(var(--tx, 0), 10px);
    }
}

.toast {
    --tx: -50%;
}

@keyframes pop {
    from {
        transform: scale(0.6);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ───────── Responsive ───────── */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .col-side {
        position: static;
    }
}

@media (max-width: 640px) {
    .shell {
        padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
    }

    .brand-bar {
        align-items: flex-start;
    }

    .brand-logo {
        width: 44px;
        height: 44px;
    }

    .brand-title {
        font-size: 21px;
    }

    .status-pill {
        padding: 6px 10px;
        font-size: 12px;
    }

    .step-label {
        font-size: 13px;
    }

    .step {
        padding: 8px 10px;
        gap: 8px;
    }

    .hero-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .hero-amount {
        text-align: left;
    }

    .hero-amount-value {
        font-size: 30px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .section-card,
    .hero-card {
        padding: 18px;
    }

    .section-head-row {
        flex-direction: column;
        align-items: stretch;
    }

    .pdf-preview-frame {
        height: 240px;
    }

    canvas#signatureCanvas {
        height: 200px;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn {
        width: 100%;
    }
}
