/* ==========================================================================
   MOBILE-FIRST DESIGN SYSTEM
   ========================================================================== */
:root {
    --primary-color: #1e3a8a;
    --primary-hover: #172554;
    --accent-emerald: #059669;
    --accent-emerald-hover: #047857;
    --doc-title-color: #1a3c68;
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --border-light: #e2e8f0;
    --border-focus: #3b82f6;
    --text-title: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Header (Mobile First)
   ========================================================================== */
.app-header {
    background: #0f172a;
    color: #ffffff;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1e293b;
}

.brand-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 22px;
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    color: #f8fafc;
}

.brand-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.badge {
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
    font-size: 0.72rem;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   Contenedor Principal: Flujo Vertical en Móvil
   ========================================================================== */
.main-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
}

/* Formulario */
.form-section {
    width: 100%;
    padding: 16px;
}

.form-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-title);
    margin: 0;
}

.form-label.mb-0 {
    margin-bottom: 0;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Inputs optimizados para toque móvil (16px font para evitar zoom de iOS) */
.form-control {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-title);
    background-color: #f8fafc;
    border: 1.5px solid var(--border-light);
    border-radius: 10px;
    outline: none;
    transition: all 0.2s ease;
}

.form-control:focus {
    background-color: #ffffff;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-prefix-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-prefix-wrapper .prefix {
    position: absolute;
    left: 14px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
}

.form-control.has-prefix {
    padding-left: 32px;
    font-weight: 600;
    font-size: 18px;
}

/* Switch toggle minimalista */
.switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.switch-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.switch-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background-color: #cbd5e1;
    border-radius: 24px;
    transition: 0.25s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.25s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch-toggle input:checked + .slider {
    background-color: var(--accent-emerald);
}

.switch-toggle input:checked + .slider:before {
    transform: translateX(20px);
}

/* Acordeón secundario */
details.details-accordion {
    border-top: 1px solid var(--border-light);
    padding-top: 12px;
}

details.details-accordion summary {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-title);
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

details.details-accordion summary::-webkit-details-marker {
    display: none;
}

details.details-accordion summary::after {
    content: '▾';
    font-size: 1rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

details.details-accordion[open] summary::after {
    transform: rotate(180deg);
}

.accordion-body {
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Botón de Acción Principal Único */
.action-wrapper {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-main {
    width: 100%;
    min-height: 52px;
    background-color: var(--accent-emerald);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
    transition: all 0.2s ease;
}

.btn-main:hover {
    background-color: var(--accent-emerald-hover);
    box-shadow: 0 6px 18px rgba(5, 150, 105, 0.4);
}

.btn-main:disabled {
    background-color: #94a3b8;
    box-shadow: none;
    cursor: not-allowed;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    padding: 6px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-link:hover {
    color: var(--text-title);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* ==========================================================================
   Vista Previa del Documento
   ========================================================================== */
.preview-section {
    width: 100%;
    padding: 16px;
    background-color: #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-header {
    width: 100%;
    max-width: 800px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.live-indicator .dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-emerald);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.25);
}

.sheet-scroller {
    width: 100%;
    overflow-x: auto;
    display: flex;
    justify-content: center;
    padding-bottom: 16px;
}

/* Hoja Tamaño Carta (Ajustada exactamente a 1 página de 8.5 x 11 in sin desbordes) */
.document-sheet {
    width: 215.9mm;
    height: 279.4mm;
    max-height: 279.4mm;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    padding: 24mm 22mm 20mm 22mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: hidden;
    page-break-inside: avoid;
    page-break-after: avoid;
}

.doc-header {
    text-align: center;
    margin-bottom: 32px;
}

.doc-title {
    color: var(--doc-title-color);
    font-size: 25px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.doc-body {
    font-size: 15px;
    line-height: 1.6;
    color: #1e1e1e;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.doc-paragraph {
    text-align: justify;
    margin: 0;
}

.highlight-name {
    font-weight: 700;
    color: #000000;
}

.amount-container {
    text-align: center;
    margin: 6px 0 12px 0;
}

.amount-number {
    color: var(--doc-title-color);
    font-size: 25px;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.amount-words {
    color: #2b2b2b;
    font-size: 14.5px;
    font-weight: 500;
}

.doc-signatures-section {
    margin-top: 48px;
    display: flex;
    justify-content: space-between;
    gap: 36px;
}

.signature-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.signature-line {
    width: 100%;
    max-width: 240px;
    height: 1.5px;
    background-color: #000000;
    margin-bottom: 12px;
}

.signature-role {
    font-weight: 800;
    font-size: 14px;
    color: #000000;
    margin-bottom: 6px;
}

.signature-name {
    font-weight: 700;
    font-size: 14.5px;
    color: #111111;
    margin-bottom: 4px;
}

.signature-extra {
    font-size: 13.5px;
    color: #333333;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(30px);
    background-color: #0f172a;
    color: #ffffff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border-left: 4px solid var(--accent-emerald);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   DESKTOP / TABLET (Pantallas >= 1024px)
   ========================================================================== */
@media (min-width: 1024px) {
    .main-container {
        flex-direction: row;
        height: calc(100vh - 65px);
        overflow: hidden;
    }

    .form-section {
        width: 440px;
        padding: 24px;
        overflow-y: auto;
        border-right: 1px solid var(--border-light);
    }

    .form-card {
        padding: 24px;
    }

    .preview-section {
        flex: 1;
        overflow-y: auto;
        padding: 30px;
    }
}

/* ==========================================================================
   REGLAS DE IMPRESIÓN (@media print)
   ========================================================================== */
@media print {
    .app-header,
    .form-section,
    .preview-header,
    .toast {
        display: none !important;
    }

    body, html {
        background: #ffffff !important;
        padding: 0 !important;
        margin: 0 !important;
        height: 100% !important;
        max-height: 100% !important;
        overflow: hidden !important;
    }

    .main-container,
    .preview-section,
    .sheet-scroller {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        overflow: visible !important;
        background: #ffffff !important;
    }

    .document-sheet {
        box-shadow: none !important;
        width: 100% !important;
        height: 279.4mm !important;
        max-height: 279.4mm !important;
        padding: 24mm 22mm 20mm 22mm !important;
        margin: 0 auto !important;
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
    }

    @page {
        size: letter portrait;
        margin: 0;
    }
}
