/* ============================================================
   CFDI 4.0 Visualizador - Hoja de Estilos
   Diseño moderno con soporte completo para impresión
   ============================================================ */

/* === Google Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* === CSS Custom Properties === */
:root {
    --color-bg: #0f1117;
    --color-surface: #1a1d27;
    --color-surface-2: #232736;
    --color-surface-3: #2c3044;
    --color-border: #353a50;
    --color-border-light: #434968;
    --color-text: #e8eaf0;
    --color-text-secondary: #9ca3b8;
    --color-text-muted: #6b7394;
    --color-primary: #6366f1;
    --color-primary-light: #818cf8;
    --color-primary-dark: #4f46e5;
    --color-accent: #22d3ee;
    --color-success: #34d399;
    --color-warning: #fbbf24;
    --color-danger: #f87171;
    --color-white: #ffffff;
    --color-black: #000000;

    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* === UPLOAD PAGE === */
.upload-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(34, 211, 238, 0.06) 0%, transparent 50%),
        var(--color-bg);
    padding: 2rem;
}

.upload-container {
    width: 100%;
    max-width: 560px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 3rem 2.5rem;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    position: relative;
    overflow: hidden;
}

.upload-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
}

.upload-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.upload-header .icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.2rem;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.upload-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-white);
    margin-bottom: 0.4rem;
}

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

/* Form styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}

.form-group label .required {
    color: var(--color-danger);
    margin-left: 2px;
}

.form-group label .optional {
    color: var(--color-text-muted);
    font-weight: 400;
    font-size: 0.8rem;
}

/* File drop zone */
.file-drop-zone {
    position: relative;
    border: 2px dashed var(--color-border-light);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--color-surface-2);
}

.file-drop-zone:hover,
.file-drop-zone.dragover {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.05);
}

.file-drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-drop-zone .drop-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.7;
}

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

.file-drop-zone .drop-text strong {
    color: var(--color-primary-light);
}

.file-drop-zone .file-name {
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: var(--color-success);
    font-weight: 500;
    display: none;
}

.file-drop-zone .file-name.show {
    display: block;
}

/* Submit button */
.btn-submit {
    width: 100%;
    padding: 0.9rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.02em;
    margin-top: 0.5rem;
}

.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}

.btn-submit:active {
    transform: translateY(0);
}

/* Alert messages */
.alert {
    padding: 1rem 1.2rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    line-height: 1.5;
}

.alert-error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--color-danger);
}

.alert-success {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.3);
    color: var(--color-success);
}

.alert-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

/* ============================================================
   FACTURA VIEW PAGE
   ============================================================ */
.factura-page {
    background:
        radial-gradient(ellipse at 30% 0%, rgba(99, 102, 241, 0.05) 0%, transparent 50%),
        var(--color-bg);
    min-height: 100vh;
    padding: 0 2rem 2rem;
}

.factura-wrapper {
    max-width: 900px;
    margin: 0 auto;
}

/* Action bar */
.action-bar {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    padding-top: 1rem;
    justify-content: flex-end;
}

.btn {
    padding: 0.6rem 1.3rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-print {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--color-white);
}

.btn-print:hover {
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: var(--color-surface-3);
    border-color: var(--color-border-light);
}

/* Factura container */
.factura {
    background: var(--color-white);
    color: #1e293b;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

/* Encabezado Unificado - B&N */
.factura-header {
    background: #ffffff;
    color: #1e293b;
    border-bottom: 3px solid #1e293b;
}

/* -- Fila superior: Logo + Info -- */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.5rem 2rem;
    gap: 1.5rem;
}

.factura-logo {
    flex-shrink: 0;
    align-self: flex-start;
}

.factura-logo img {
    max-width: 180px;
    max-height: 180px;
    object-fit: contain;
    display: block;
}

.factura-logo .logo-placeholder {
    width: 120px;
    height: 120px;
    background: #f1f5f9;
    border: 1px dashed #94a3b8;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #94a3b8;
}

.factura-info {
    text-align: right;
    flex-shrink: 0;
}

.factura-info .tipo-badge {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    background: #1e293b;
    color: #ffffff;
}

.tipo-I {
    color: #000000 !important;
}

.tipo-E {
    background: #dc2626 !important;
    color: #fff !important;
}

.tipo-P {
    background: #059669 !important;
    color: #fff !important;
}

.tipo-N {
    background: #d97706 !important;
    color: #fff !important;
}

.tipo-T {
    background: #0891b2 !important;
    color: #fff !important;
}

.factura-info h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.1rem;
}

.factura-info .folio {
    font-size: 1.05rem;
    font-weight: 600;
    color: #334155;
}

.factura-info .fecha {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.2rem;
}

/* -- Barra fiscal (UUID, NoCert, FechaTimbrado) -- */
.header-fiscal-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    padding: 0.5rem 2rem;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
}

.fiscal-header-item {
    font-size: 0.73rem;
    display: flex;
    gap: 0.3rem;
    align-items: baseline;
}

.fiscal-header-label {
    color: #64748b;
    font-weight: 600;
}

.fiscal-header-value {
    color: #1e293b;
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.7rem;
}

/* -- Emisor / Receptor dentro del header -- */
.header-actores {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.actor-block {
    padding: 0.2rem 2rem;
}

.actor-block:first-child {
    border-right: 1px solid #e2e8f0;
}

.actor-block .actor-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #475569;
    margin-bottom: 0.5rem;
}

.actor-block .actor-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.3rem;
}

.actor-block .actor-detail {
    font-size: 0.78rem;
    color: #64748b;
    margin-bottom: 0.1rem;
}

.actor-block .actor-detail strong {
    color: #475569;
    font-weight: 600;
}

/* Tabla de conceptos */
.factura-conceptos {
    padding: 0 2.5rem;
    margin-top: .5rem;
}

.factura-conceptos .section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6366f1;
    margin-bottom: 0.8rem;
}

.tabla-conceptos {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.tabla-conceptos thead th {
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.7rem 0.8rem;
    text-align: left;
    border-bottom: 2px solid #e2e8f0;
}

.tabla-conceptos thead th.text-right {
    text-align: right;
}

.tabla-conceptos thead th.text-center {
    text-align: center;
}

.tabla-conceptos tbody td {
    padding: 0.65rem 0.8rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: top;
}

.tabla-conceptos tbody tr:last-child td {
    border-bottom: 2px solid #e2e8f0;
}

.tabla-conceptos tbody tr:nth-child(even) {
    background: #fafbfc;
}

.tabla-conceptos .col-clave {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: #64748b;
    white-space: nowrap;
}

.tabla-conceptos .col-cantidad,
.tabla-conceptos .col-unidad {
    text-align: center;
    white-space: nowrap;
}

.tabla-conceptos .col-precio,
.tabla-conceptos .col-importe {
    text-align: right;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-weight: 500;
}

.tabla-conceptos .col-descripcion {
    min-width: 200px;
}

/* Totales */
.factura-totales {
    padding: 0.5rem 2.5rem;
    display: flex;
    justify-content: flex-end;
}

.totales-grid {
    width: 320px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0;
    font-size: 0.85rem;
    color: #475569;
}

.total-row .label {
    font-weight: 500;
}

.total-row .value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: #1e293b;
}

.total-row.total-descuento .value {
    color: var(--color-danger);
}

.total-row.total-final {
    border-top: 2px solid #1e293b;
    margin-top: 0.3rem;
    padding-top: 0.7rem;
    font-size: 1.1rem;
}

.total-row.total-final .label {
    font-weight: 700;
    color: #1e293b;
}

.total-row.total-final .value {
    font-weight: 700;
    color: #1e293b;
    font-size: 1.15rem;
}

/* Total con letra */
.total-letra {
    padding: 0 2.5rem 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.total-letra .letra-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6366f1;
    margin-bottom: 0.3rem;
}

.total-letra .letra-text {
    font-size: 0.82rem;
    color: #334155;
    font-weight: 500;
    background: #f8fafc;
    padding: 0.2rem 0.2rem;

}

/* Método de pago info */
.factura-pago-info {
    display: flex;
    gap: 2rem;
    padding: 0.2rem 2.5rem;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
}

.pago-item {
    font-size: 0.78rem;
}

.pago-item .pago-label {
    color: #94a3b8;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.06em;
}

.pago-item .pago-value {
    color: #334155;
    font-weight: 600;
    margin-top: 0.1rem;
}

/* Pie fiscal (QR + sellos - misma fila, compacto) */
.factura-fiscal {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 1rem;
    padding: 1.2rem 2.5rem;
    align-items: start;
    border-top: 1px solid #e2e8f0;
}

.qr-container {
    flex-shrink: 0;
}

.qr-container img {
    width: 100px;
    height: 100px;
    display: block;
}

.qr-container .qr-label {
    font-size: 0.6rem;
    color: #94a3b8;
    text-align: center;
    margin-top: 0.2rem;
}

.fiscal-data {
    min-width: 0;
}

.fiscal-item {
    margin-bottom: 0.5rem;
}

.fiscal-item:last-child {
    margin-bottom: 0;
}

.fiscal-item .fiscal-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    margin-bottom: 0.1rem;
}

.fiscal-item .fiscal-value {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    color: #64748b;
    word-break: break-all;
    line-height: 1.4;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    @page {
        size: letter;
        margin: 1.0cm 1.5cm 1.5cm 1.5cm;
    }

    /* Reset colors for print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    html,
    body {
        background: white !important;
        color: #000 !important;
        font-size: 11pt;
        margin: 0;
        padding: 0;
    }

    /* Hide non-print elements */
    .no-print,
    .action-bar,
    .upload-page {
        display: none !important;
    }

    /* Factura container for print */
    .factura-page {
        background: none !important;
        padding: 0 !important;
        min-height: auto;
    }

    .factura-wrapper {
        max-width: none;
        margin: 0;
    }

    .factura {
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    /* Header - B&W for print */
    .factura-header {
        background: #ffffff !important;
        color: #000000 !important;
        border-radius: 0 !important;
        border-bottom: 2px solid #000 !important;
    }

    .header-top {
        padding: 0.2rem 0.5rem !important;
    }

    .factura-info h2,
    .factura-info .folio {
        color: #000 !important;
    }

    .factura-info .fecha {
        color: #333 !important;
    }

    .factura-info .tipo-badge {

        color: #000000 !important;
    }

    .factura-logo .logo-placeholder {
        background: #f0f0f0 !important;
        border-color: #999 !important;
        color: #999 !important;
    }

    .factura-logo img {
        max-width: 200px;
        max-height: 200px;
    }

    /* Fiscal header bar */
    .header-fiscal-bar {
        background: #f5f5f5 !important;
        padding: 0.4rem 1.5rem !important;
    }

    /* Actor blocks in header */
    .header-actores .actor-block {
        padding: 0.2rem 1.5rem !important;
    }

    /* Table header backgrounds */
    .tabla-conceptos thead th {
        background: #f1f5f9 !important;
    }

    .tabla-conceptos tbody tr:nth-child(even) {
        background: #fafbfc !important;
    }

    /* Prevent row breaks */
    .tabla-conceptos tbody tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Actor blocks */
    .actor-block {
        padding: 0.2rem 1.5rem !important;
    }

    /* Conceptos */
    .factura-conceptos {
        padding: 0 0.5rem !important;
    }

    /* Totales */
    .factura-totales {
        padding: 1rem 1.5rem !important;
    }

    /* Total letra */
    .total-letra {
        padding: 0 1.5rem 1rem !important;
    }

    .total-letra .letra-text {
        background: #f8fafc !important;
    }

    /* Pago info */
    .factura-pago-info {
        padding: 0.2rem 1.5rem !important;
    }

    /* Fiscal footer - compact */
    .factura-fiscal {
        padding: 0.8rem 1.5rem !important;
        page-break-inside: avoid;
        break-inside: avoid;
        grid-template-columns: 80px 1fr !important;
        gap: 0.8rem !important;
    }

    .qr-container img {
        width: 80px !important;
        height: 80px !important;
    }

    .fiscal-item .fiscal-value {
        font-size: 5.5pt;
    }

    .fiscal-item {
        margin-bottom: 0.3rem !important;
    }

    /* Badges - B&W for print */
    .tipo-I {

        color: #000000 !important;
    }

    .tipo-E {
        background: #333 !important;
        color: #fff !important;
    }

    .tipo-P {
        background: #333 !important;
        color: #fff !important;
    }

    .tipo-N {
        background: #333 !important;
        color: #fff !important;
    }

    .tipo-T {
        background: #333 !important;
        color: #fff !important;
    }

    /* Links */
    a {
        color: inherit !important;
        text-decoration: none !important;
    }

    .btn-wa-fixed {
        display: none;
    }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .header-top {
        flex-direction: column;
        align-items: flex-start;
        padding: 1.2rem;
    }

    .factura-info {
        text-align: left;
    }

    .header-fiscal-bar {
        padding: 0.5rem 1.2rem;
    }

    .header-actores {
        grid-template-columns: 1fr;
    }

    .actor-block:first-child {
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .factura-conceptos {
        padding: 0 1rem;
        overflow-x: auto;
    }

    .factura-totales {
        padding: 1rem;
    }

    .totales-grid {
        width: 100%;
    }

    .factura-fiscal {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .qr-container {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .fiscal-data {
        text-align: left;
    }

    .total-letra {
        padding: 0 1rem 1rem;
    }

    .factura-pago-info {
        padding: 1rem;
        gap: 1rem;
    }
}

/* ============================================================
   BOTÓN WHATSAPP FLOTANTE
   ============================================================ */
.btn-whatsapp-float {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 60px;
    background-color: #25d366;
    color: white !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.4);
    z-index: 1000;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.btn-whatsapp-float:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6);
}