/* ============================================================================
   compelec_styles.css - Sistema de Temas para FacturaCEL comprobantes electrónicos
   ============================================================================
   TEMA ACTUAL: Claro (Light Theme)
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* ================================================================
       Colores Base del Tema
       ================================================================ */
    --color-primary: #2c5282;
    --color-primary-dark: #1a365d;
    --color-secondary: #4a5568;
    --color-success: #2f855a;
    --color-danger: #c53030;
    --color-warning: #d69e2e;
    
    /* Fondos generales */
    --bg-main: #f7fafc;
    --bg-header: #ffffff;
    --bg-table-header: #edf2f7;
    --bg-table-row: #ffffff;
    --bg-table-row-alt: #f7fafc;
    --bg-footer: #ffffff;
    
    /* Fondos de contenedores específicos */
    --bg-cliente-area: #ffffff;          /* Fondo del área de datos del cliente */
    --bg-detalles-area: #f7fafc;         /* Fondo del área de detalles de factura */
    --bg-detalles-table: #ffffff;        /* Fondo de la tabla de detalles */
    
    /* Variables de DFORM.fieldSet - Sobrescribir para tema */
    --fs-label-bg: #ffffff;              /* Fondo de etiquetas flotantes */
    --fs-icon-color: #718096;            /* Color de iconos en campos */
    --fs-border-color: #cbd5e0;          /* Color de bordes de campos */
    
    /* Campos readonly/disabled - Estados especiales */
    --input-readonly-bg: #f7fafc;        /* Fondo de campos readonly en tablas */
    --input-readonly-text: #2c5282;      /* Texto de campos readonly */
    --input-readonly-border: #e2e8f0;    /* Borde de campos readonly */
    --modal-readonly-bg: #e2e8f0;        /* Fondo de campos readonly en modal */
    
    /* Bordes y textos generales */
    --border-color: #cbd5e0;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-md: 0 2px 4px 0 rgba(0,0,0,0.1);
    
    /* ================================================================
       Colores de Componentes Específicos (Tema Claro)
       ================================================================ */
    
    /* ENCABEZADO SUPERIOR (header-emisor) - Barra azul con fecha y número */
    --header-emisor-bg: linear-gradient(135deg, #2c5282 0%, #1a365d 100%);
    --header-emisor-text: #ffffff;
    
    /* ENCABEZADOS DE COLUMNAS (table headers) */
    --table-header-bg: linear-gradient(180deg, #e2e8f0 0%, #cbd5e0 100%);
    --table-header-text: #1a365d;
    --table-header-border: #2c5282;
    
    /* BOTONES PRIMARIOS (Guardar) */
    --btn-primary-bg: #2c5282;
    --btn-primary-bg-hover: #1a365d;
    --btn-primary-text: #ffffff;
    
    /* BOTONES SECUNDARIOS (Cancelar) */
    --btn-secondary-bg: #4a5568;
    --btn-secondary-bg-hover: #2d3748;
    --btn-secondary-text: #ffffff;
    
    /* BOTONES DE ACCIÓN (Ver/Editar) */
    --btn-action-bg: #3182ce;
    --btn-action-bg-hover: #2f855a;
    --btn-action-text: #ffffff;
    
    /* ICONOS DE BOTONES */
    --icon-edit-color: #ffffff;
    --icon-delete-color: #e53e3e;
    --icon-move-up-color: #805ad5;
    --icon-move-down-color: #d69e2e;
    
    /* ================================================================
       Variables de Layout (valores por defecto, sobrescritos por PHP)
       ================================================================ */
    
    /* ========== ENCABEZADO (HEADER) ========== */
    --layout-header-total-height: 105px;
    --layout-header-emisor-height: 60px;
    --layout-header-cliente-max-height: 200px;
    
    /* ========== PIE DE PÁGINA (FOOTER) ========== */
    --layout-footer-total-height: 240px;
    --layout-footer-section-formas-pago-height: calc(50% - 5px);
    --layout-footer-section-info-adicional-height: calc(50% - 5px);
    --layout-footer-totales-height: auto;
    --layout-footer-botones-height: 50px;
    
    /* ================================================================
       Tamaños de Fuente (Typography)
       ================================================================ */
    
    /* Títulos de secciones (ej: "Detalles de la Factura") */
    --font-size-section-title: 12px;
    
    /* Encabezados de columnas en tablas */
    --font-size-table-header: 11px;
    
    /* Contenido de campos y celdas de tablas */
    --font-size-table-content: 12px;
    
    /* Campos de formulario (inputs, selects) */
    --font-size-form-field: 13px;
}

/* Mobile: Aumentar tamaños de fuente 75% para mejor legibilidad */
@media (max-width: 768px) {
    :root {
        --font-size-section-title: 16px;      /* 12px * 1.75 ≈ 21px, ajustado a 16px */
        --font-size-table-header: 14px;       /* 11px * 1.75 ≈ 19px, ajustado a 14px */
        --font-size-table-content: 15px;      /* 12px * 1.75 = 21px, ajustado a 15px */
        --font-size-form-field: 16px;         /* 13px * 1.75 ≈ 23px, ajustado a 16px */
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-main);
    /* Mobile-first: permitir scroll natural */
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
}

.container {
    display: flex;
    flex-direction: column;
    /* Mobile-first: altura mínima, no fija */
    min-height: 100vh;
    width: 100%;
}

/* Desktop: layout fijo con 100vh */
@media (min-width: 769px) {
    body {
        overflow: hidden;
    }
    
    .container {
        height: 100vh;
        overflow: hidden;
    }
}

/* ===== ENCABEZADO ===== */
.header {
    background: var(--bg-header);
    border-bottom: 2px solid var(--border-color);
    /* Mobile-first: altura automática */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

/* Desktop: altura mínima fija */
@media (min-width: 769px) {
    .header {
        min-height: var(--layout-header-total-height);
    }
}

.header-emisor {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 6px;
    background: var(--header-emisor-bg);
    color: var(--header-emisor-text);
    height: var(--layout-header-emisor-height);
    gap: 5px;
}

.fecha-emisor {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.fecha-emisor .fecha-label {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.fecha-emisor input[type="date"] {
    padding: 3px 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    width: 130px;
    font-family: inherit;
}

.fecha-emisor input[type="date"]:focus {
    outline: none;
    border-color: white;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.emisor-info {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 12px;
    flex-wrap: nowrap;
    overflow: hidden;
    flex: 1;
}

.emisor-info strong {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emisor-info span {
    white-space: nowrap;
}

.doc-info {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 12px;
    flex-shrink: 0;
}

.doc-info .doc-type-full {
    font-weight: bold;
    font-size: 14px;
}

.doc-info .doc-type-short {
    display: none;
    font-weight: bold;
    font-size: 14px;
}

/* Botón de cambio de tema */
.btn-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    text-decoration: none;
    transition: all 0.3s ease;
    margin-left: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.btn-theme-toggle i {
    font-size: 16px;
}

/* Icono de sol en tema oscuro */
.btn-theme-toggle .fa-sun {
    color: #fbbf24;
}

/* Icono de luna en tema claro */
.btn-theme-toggle .fa-moon {
    color: #e2e8f0;
}

.header-cliente {
    padding: 4px 12px 6px 12px;
    background: var(--bg-cliente-area);
    flex: 1;
    min-height: 0;
    max-height: var(--layout-header-cliente-max-height);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Fieldset del cliente */
.cliente-fieldset {
    margin: 0;
    padding: 0.5rem 0.3rem 0.2rem 0.3rem;
    border: none;
    background: transparent;
}

.cliente-fieldset .fs-legend {
    font-size: 0.85rem;
    padding: 0 0.3rem;
    margin-bottom: 0.3rem;
}

/* Grid responsive del cliente */
.cliente-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--fs-gap);
    align-items: flex-start;
}

.cliente-grid-full {
    margin-top: var(--fs-gap);
}

.cliente-grid .fs-field {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: auto;
}

/* Respetar max-width de campos */
.cliente-grid .fs-field[style*="max-width: none"] {
    flex-grow: 2;
}

/* Asegurar que el atributo size no rompa el layout */
.cliente-grid .fs-field__control[size] {
    width: 100%;
    min-width: 0;
}

/* Responsive: mantener max-width en todas las pantallas */
/* Los campos .fs-field usan flex-wrap para manejar el layout automáticamente */

/* En pantallas pequeñas, permitir que campos con max-width compartan fila */
@media (max-width: 768px) {
    .header-cliente {
        max-height: var(--layout-header-cliente-max-height);
    }
    
    .cliente-grid .fs-field {
        /* Remover restricciones de ancho fijo */
        flex-basis: auto !important;
    }
    
    /* Campos sin max-width (none) ocupan fila completa en mobile */
    .cliente-grid .fs-field[style*="max-width: none"] {
        flex-basis: 100% !important;
        max-width: 100% !important;
    }
    
    .cliente-fieldset {
        padding: 0.4rem 0.2rem 0.2rem 0.2rem;
    }
    
    .cliente-fieldset .fs-legend {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .header-cliente {
        max-height: var(--layout-header-cliente-max-height);
    }
    
    /* En pantallas muy pequeñas, ajustar gaps */
    .cliente-grid {
        gap: 0.15rem;
    }
    
    /* Forzar agrupación de campos emparejados */
    .cliente-grid .fs-field.field-group-start {
        flex: 0 0 auto !important;
        max-width: none !important;
    }
    
    /* El siguiente campo después de un group-start también debe estar en la misma fila */
    .cliente-grid .fs-field.field-group-start + .fs-field {
        flex: 1 1 auto !important;
        max-width: none !important;
    }
    
    /* Campos sin grupo ocupan fila completa */
    .cliente-grid .fs-field:not(.field-group-start):not(.field-group-start + .fs-field)[style*="max-width: none"] {
        flex-basis: 100% !important;
    }
}

/* Scrollbar para el área de cliente */
.header-cliente::-webkit-scrollbar {
    width: 6px;
}

.header-cliente::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.header-cliente::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.header-cliente::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.form-row {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-group {
    flex: 1;
    position: relative;
}

.form-group.flex-2 {
    flex: 2;
}

.form-group.flex-3 {
    flex: 3;
}

.form-group.flex-4 {
    flex: 4;
}

.form-group.flex-full {
    flex: 1;
    width: 100%;
}

/* Floating Label Styles */
.form-group.floating-label {
    position: relative;
}

.form-group.floating-label .form-control {
    width: 100%;
    height: 32px;
    padding: 14px 10px 2px 10px;
    border: 1px solid #cbd5e0;
    border-left: none;
    border-right: none;
    border-top: none;
    border-radius: 0;
    font-size: 13px;
    font-family: inherit;
    background: white;
    transition: all 0.15s ease;
    box-sizing: border-box;
    line-height: 1;
}

.form-group.floating-label select.form-control {
    padding: 14px 28px 2px 10px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%234a5568' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.form-group.floating-label textarea.form-control {
    height: auto;
    min-height: 60px;
    padding: 14px 10px 2px 10px;
    resize: vertical;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
}

.form-group.floating-label label {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #718096;
    background: white;
    padding: 0 2px;
    pointer-events: none;
    transition: all 0.15s ease;
    font-weight: 400;
    line-height: 1;
}

/* Label flotante cuando hay contenido o focus */
.form-group.floating-label .form-control:focus + label,
.form-group.floating-label .form-control:not(:placeholder-shown) + label,
.form-group.floating-label select.form-control + label,
.form-group.floating-label .form-control.has-value + label {
    top: 0;
    transform: translateY(0);
    font-size: 9px;
    color: var(--color-primary);
    font-weight: 600;
    letter-spacing: 0.2px;
}

/* Focus state */
.form-group.floating-label .form-control:focus {
    outline: none;
    border-bottom-color: var(--color-primary);
    border-bottom-width: 2px;
    padding-bottom: 1px;
}

/* Hover state */
.form-group.floating-label .form-control:hover {
    border-bottom-color: #718096;
}

/* ===== ÁREA DE DETALLES ===== */
.details-area {
    /* Mobile-first: altura fija para que no desplace otros contenedores */
    min-height: 180px;
    max-height: 250px;
    height: 250px;
    display: flex;
    flex-direction: column;
    background: var(--bg-detalles-area);
    overflow: hidden;
}

/* Tablet: altura un poco mayor */
@media (min-width: 481px) and (max-width: 768px) {
    .details-area {
        height: 300px;
        max-height: 300px;
    }
}

/* Desktop: ocupar espacio restante con flex */
@media (min-width: 769px) {
    .details-area {
        flex: 1;
        height: auto;
        max-height: none;
        min-height: 0;
    }
}

.details-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-table-header);
    border-bottom: 1px solid var(--border-color);
    height: 36px;
}

.details-title {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: var(--font-size-section-title);
    letter-spacing: 0.5px;
}

.details-scroll {
    /* Mobile-first: scroll vertical para que no desplace otros contenedores */
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 0;
}

/* Desktop: mismo comportamiento */
@media (min-width: 769px) {
    .details-scroll {
        flex: 1;
        overflow-y: auto;
    }
}

.details-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-detalles-table);
}

.details-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--table-header-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.details-table th {
    padding: 8px 6px;
    text-align: left;
    font-size: var(--font-size-table-header);
    font-weight: 700;
    color: var(--table-header-text);
    border-bottom: 3px solid var(--table-header-border);
    border-right: 1px solid rgba(203, 213, 224, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    background: linear-gradient(180deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 100%);
}

.details-table th:last-child {
    border-right: none;
}

.details-table td {
    padding: 4px;
    border-bottom: 1px solid var(--border-color);
    font-size: var(--font-size-table-content);
    vertical-align: middle;
}

.details-table tbody tr {
    transition: background-color 0.15s ease;
}

.details-table tbody tr:nth-child(even) {
    background: var(--bg-table-row-alt);
}

.details-table tbody tr:hover {
    background: #e6f2ff;
    box-shadow: inset 0 0 0 1px rgba(49, 130, 206, 0.2);
}

.details-table input,
.details-table select {
    width: 100%;
    padding: 3px 4px;
    border: 1px solid var(--border-color);
    border-radius: 2px;
    font-size: var(--font-size-form-field);
    font-family: inherit;
}

.details-table input:focus,
.details-table select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.details-table input[type="number"] {
    text-align: right;
}

.details-table input[readonly] {
    background: var(--input-readonly-bg) !important;
    color: var(--input-readonly-text);
    font-weight: 600;
    cursor: not-allowed;
    border-color: var(--input-readonly-border);
}

.item-actions {
    display: flex;
    gap: 3px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Colores específicos para iconos de acciones */
.btn-icon i.fa-plus {
    color: white;
}

.btn-icon i.fa-arrow-up {
    color: var(--icon-move-up-color);
}

.btn-icon i.fa-arrow-down {
    color: var(--icon-move-down-color);
}

.btn-icon i.fa-trash {
    color: var(--icon-delete-color);
}

.btn-icon:hover i.fa-arrow-up {
    color: white;
}

.btn-icon:hover i.fa-arrow-down {
    color: white;
}

.btn-icon:hover i.fa-trash {
    color: white;
}

/* ===== PIE ===== */
.footer {
    background: var(--bg-footer);
    border-top: 2px solid var(--border-color);
    /* Mobile-first: altura automática, layout vertical */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
}

/* Desktop: altura fija, layout horizontal */
@media (min-width: 769px) {
    .footer {
        height: var(--layout-footer-total-height);
        flex-direction: row;
        padding: 10px 12px;
        gap: 12px;
    }
}

.footer-left {
    /* Mobile-first: sin restricciones de altura */
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Desktop: con overflow */
@media (min-width: 769px) {
    .footer-left {
        flex: 1;
        gap: 8px;
        overflow: hidden;
    }
}

.footer-section {
    /* Mobile-first: altura muy reducida para que los botones sean visibles */
    height: var(--layout-footer-section-formas-pago-height);
    min-height: 60px;
    max-height: 80px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    overflow: hidden;
}

/* Sección de información adicional usa su propia variable */
.footer-section:nth-child(2) {
    height: var(--layout-footer-section-info-adicional-height);
}

/* Desktop: altura desde configuración, sin restricciones */
@media (min-width: 769px) {
    .footer-section {
        height: var(--layout-footer-section-formas-pago-height);
        min-height: 0;
        max-height: none;
    }
    
    .footer-section:nth-child(2) {
        height: var(--layout-footer-section-info-adicional-height);
    }
}

/* Encabezados de sección eliminados para ahorrar espacio vertical */
.footer-section-header {
    display: none;
}

.footer-section-title {
    display: none;
}

.footer-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    min-height: 0;
    height: 100%;
}

.footer-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    table-layout: auto;
}

.footer-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--table-header-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.footer-table th {
    padding: 6px 4px;
    text-align: left;
    font-size: var(--font-size-table-header);
    font-weight: 700;
    color: var(--table-header-text);
    border-bottom: 2px solid var(--table-header-border);
    border-right: 1px solid rgba(203, 213, 224, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    background: linear-gradient(180deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 100%);
}

.footer-table th:last-child {
    border-right: none;
}

.footer-table td {
    padding: 3px 4px;
    border-bottom: 1px solid var(--border-color);
    font-size: var(--font-size-table-content);
    vertical-align: middle;
    white-space: nowrap;
}

.footer-table tbody tr {
    transition: background-color 0.15s ease;
}

.footer-table tbody tr:nth-child(even) {
    background: var(--bg-table-row-alt);
}

.footer-table tbody tr:hover {
    background: #e6f2ff;
    box-shadow: inset 0 0 0 1px rgba(49, 130, 206, 0.2);
}

.footer-table input,
.footer-table select {
    width: 100%;
    min-width: 0;
    padding: 3px 4px;
    border: 1px solid var(--border-color);
    border-radius: 2px;
    font-size: var(--font-size-form-field);
    font-family: inherit;
    box-sizing: border-box;
}

.footer-table input:focus,
.footer-table select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(44, 82, 130, 0.1);
}

.footer-table input[type="number"] {
    text-align: right;
}

/* Anchos específicos para tabla de pagos */
.footer-table-pagos td:nth-child(1) {
    width: 50px;
}

.footer-table-pagos td:nth-child(2) {
    width: 180px;
    min-width: 150px;
}

.footer-table-pagos td:nth-child(3) {
    width: 110px;
    min-width: 90px;
}

.footer-table-pagos td:nth-child(4) {
    width: 80px;
    min-width: 70px;
}

.footer-table-pagos td:nth-child(5) {
    width: 120px;
    min-width: 100px;
}

/* Anchos específicos para tabla de info adicional */
.footer-table-info td:nth-child(1) {
    width: 50px;
}

.footer-table-info td:nth-child(2) {
    width: 180px;
    min-width: 120px;
}

.footer-table-info td:nth-child(3) {
    min-width: 150px;
}

.footer-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.footer-scroll::-webkit-scrollbar-track {
    background: var(--bg-table-row-alt);
}

.footer-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.footer-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.footer-right {
    /* Mobile-first: ancho completo */
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Desktop: ancho fijo */
@media (min-width: 769px) {
    .footer-right {
        width: 400px;
        gap: 10px;
    }
}

.totals-grid {
    background: var(--bg-table-row-alt);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 12px;
    height: var(--layout-footer-totales-height);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 13px;
}

.total-row span:last-child {
    font-family: 'Courier New', monospace;
    text-align: right;
    min-width: 100px;
}

.total-final {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 2px solid var(--border-color);
    font-size: 15px;
    color: var(--color-primary);
}

.footer-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    height: var(--layout-footer-botones-height);
    align-items: center;
}

/* ===== BOTONES ===== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
}

.btn-primary:hover {
    background: var(--btn-primary-bg-hover);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
}

.btn-secondary:hover {
    background: var(--btn-secondary-bg-hover);
}

.btn-icon {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    font-size: 11px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-icon:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.btn-icon:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Botón agregar (verde) */
.btn-icon.btn-success {
    background: var(--color-success) !important;
    color: white !important;
    border-color: var(--color-success) !important;
}

.btn-icon.btn-success i {
    color: white !important;
}

.btn-icon.btn-success:hover {
    background: #276749 !important;
    border-color: #276749 !important;
}

.btn-icon.btn-success:hover i {
    color: white !important;
}

/* Botón subir (morado) */
.btn-icon:hover:has(i.fa-arrow-up) {
    background: #805ad5;
    border-color: #805ad5;
}

/* Botón bajar (naranja) */
.btn-icon:hover:has(i.fa-arrow-down) {
    background: #d69e2e;
    border-color: #d69e2e;
}

/* Botón eliminar (rojo) */
.btn-icon.btn-danger:hover,
.btn-icon:hover:has(i.fa-trash) {
    background: var(--color-danger);
    border-color: var(--color-danger);
}

/* ===== SCROLLBAR ===== */
.details-scroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.details-scroll::-webkit-scrollbar-track {
    background: var(--bg-table-row-alt);
}

.details-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

.details-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
/* Las variables de layout se sobrescriben desde index.php en cada media query */

@media (max-width: 768px) {
    /* Tablas del footer más compactas en tablet */
    .footer-table th {
        padding: 5px 3px;
    }
    
    .footer-table td {
        padding: 2px 3px;
    }
    
    .footer-table input,
    .footer-table select {
        padding: 2px 3px;
    }
    
    .footer-table-pagos td:nth-child(2) {
        min-width: 130px;
    }
    
    .footer-table-info td:nth-child(2) {
        min-width: 100px;
    }
    
    .header {
        min-height: auto;
        height: auto;
    }
    
    .header-emisor {
        height: var(--layout-header-emisor-height);
        padding: 8px 10px;
        gap: 8px;
        flex-shrink: 0;
    }
    
    .fecha-emisor .fecha-label {
        display: none;
    }
    
    .fecha-emisor input[type="date"] {
        width: 120px;
        font-size: 11px;
        padding: 2px 4px;
    }
    
    .emisor-info {
        gap: 10px;
        font-size: 11px;
    }
    
    .emisor-info strong {
        font-size: 12px;
        max-width: 150px;
    }
    
    .doc-info {
        gap: 8px;
        font-size: 11px;
    }
    
    .doc-info .doc-type-full {
        display: none;
    }
    
    .doc-info .doc-type-short {
        display: inline;
    }
    
    /* Botón de tema más pequeño en tablet */
    .btn-theme-toggle {
        width: 28px;
        height: 28px;
        margin-left: 8px;
    }
    
    .btn-theme-toggle i {
        font-size: 14px;
    }
    
    .header-cliente {
        padding: 4px 10px 6px 10px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 6px;
        margin-bottom: 4px;
    }
    
    .form-group.floating-label .form-control {
        height: 30px;
        font-size: 12px;
        padding: 13px 8px 2px 8px;
    }
    
    .form-group.floating-label select.form-control {
        padding-right: 26px;
        background-position: right 6px center;
    }
    
    .form-group.floating-label label {
        font-size: 11px;
        left: 8px;
    }
    
    .form-group.floating-label .form-control:focus + label,
    .form-group.floating-label .form-control:not(:placeholder-shown) + label,
    .form-group.floating-label select.form-control + label,
    .form-group.floating-label .form-control.has-value + label {
        font-size: 8px;
        top: 0;
    }
    
    /* Totales más compactos en tablet */
    .totals-grid {
        padding: 6px 10px;
    }
    
    .total-row {
        padding: 2px 0;
        font-size: 12px;
    }
    
    .total-row span:last-child {
        min-width: 80px;
    }
    
    .total-final {
        font-size: 14px;
    }
    
    /* Botones en tablet */
    .footer-actions {
        gap: 6px;
    }
    
    .btn {
        padding: 7px 14px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .header {
        min-height: auto;
    }
    
    .header-emisor {
        padding: 6px 8px;
        gap: 6px;
    }
    
    .fecha-emisor input[type="date"] {
        width: 110px;
        font-size: 10px;
    }
    
    .emisor-info {
        gap: 8px;
        font-size: 10px;
    }
    
    .emisor-info strong {
        font-size: 11px;
        max-width: 100px;
    }
    
    .doc-info {
        gap: 6px;
        font-size: 10px;
    }
    
    .doc-info .doc-type-short {
        font-size: 12px;
    }
    
    /* Botón de tema compacto en mobile */
    .btn-theme-toggle {
        width: 26px;
        height: 26px;
        margin-left: 6px;
    }
    
    .btn-theme-toggle i {
        font-size: 13px;
    }
    
    .header-cliente {
        padding: 4px 8px 6px 8px;
    }
    
    .form-group.floating-label .form-control {
        height: 28px;
        font-size: 11px;
        padding: 12px 6px 2px 6px;
    }
    
    .form-group.floating-label select.form-control {
        padding-right: 24px;
        background-position: right 4px center;
    }
    
    .form-group.floating-label label {
        font-size: 10px;
        left: 6px;
    }
    
    .form-group.floating-label .form-control:focus + label,
    .form-group.floating-label .form-control:not(:placeholder-shown) + label,
    .form-group.floating-label select.form-control + label,
    .form-group.floating-label .form-control.has-value + label {
        font-size: 8px;
        top: 0;
    }
    
    /* Footer más compacto en mobile - altura controlada desde index.php */
    
    /* Totales muy compactos en mobile - grid de 2 columnas */
    .totals-grid {
        padding: 4px 6px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2px 8px;
    }
    
    .total-row {
        padding: 1px 0;
        font-size: 10px;
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    
    .total-row span:first-child {
        font-size: 8px;
        color: var(--text-muted);
        line-height: 1.1;
    }
    
    .total-row span:last-child {
        min-width: auto;
        font-size: 11px;
        font-weight: 600;
        text-align: left;
    }
    
    .total-final {
        grid-column: 1 / -1;
        margin-top: 4px;
        padding-top: 4px;
        font-size: 12px;
        flex-direction: row;
        justify-content: space-between;
        border-top: 2px solid var(--border-color);
    }
    
    .total-final span:first-child {
        font-size: 12px;
        color: var(--text-primary);
    }
    
    .total-final span:last-child {
        font-size: 14px;
        text-align: right;
    }
    
    /* Botones en mobile - compactos pero táctiles */
    .footer-actions {
        gap: 6px;
        height: auto;
        padding: 6px 0 4px 0;
        flex-shrink: 0;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 13px;
        gap: 4px;
        flex: 1;
        justify-content: center;
    }
    
    .btn i {
        font-size: 12px;
    }
    
    .footer-table th {
        padding: 4px 2px;
    }
    
    .footer-table td {
        padding: 2px;
    }
    
    .footer-table input,
    .footer-table select {
        padding: 2px 3px;
    }
    
    .footer-table-pagos td:nth-child(2) {
        min-width: 110px;
    }
    
    .footer-table-pagos td:nth-child(3),
    .footer-table-pagos td:nth-child(4) {
        min-width: 60px;
    }
    
    .footer-table-pagos td:nth-child(5) {
        min-width: 80px;
    }
    
    .footer-table-info td:nth-child(2) {
        min-width: 90px;
    }
    
    .footer-table-info td:nth-child(3) {
        min-width: 120px;
    }
}

@media (min-width: 1920px) {
    body {
        font-size: 14px;
    }
    
    .details-table th,
    .details-table td {
        padding: 8px 6px;
    }
}


/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 80vw;
    max-width: 1200px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid var(--border-color);
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.btn-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

/* Estilos específicos para modal con DFORM.fieldSet */
.modal-body .fs-fieldset {
    margin-bottom: 0;
    background: var(--bg-table-row-alt);
}

.modal-body .fs-legend {
    color: var(--color-primary);
    font-size: 0.85rem;
}

.modal-body .fs-field {
    margin-bottom: 0.3rem;
}

.modal-body .fs-field:last-child {
    margin-bottom: 0;
}

.modal-body .fs-field__control[readonly] {
    background: var(--modal-readonly-bg) !important;
    color: var(--input-readonly-text);
    font-weight: 600;
    cursor: not-allowed;
    border-color: var(--input-readonly-border);
}

.modal-body .fs-field__control[readonly]:focus {
    border-color: var(--input-readonly-border);
    box-shadow: none;
}

.modal-body textarea.fs-field__control {
    min-height: 70px;
    resize: vertical;
    padding-top: 1.2rem;
}

/* Layout flexible para campos del modal */
.modal-flex-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--fs-gap);
    align-items: flex-start;
}

/* Tamaños específicos de campos en modal */
.modal-field-code {
    /* Códigos: máximo 30 caracteres visibles */
    min-width: 200px;
    max-width: 280px;
    flex: 1 1 auto;
}

.modal-field-number {
    /* Números: máximo 14 caracteres visibles */
    min-width: 140px;
    max-width: 180px;
    flex: 0 1 auto;
}

.modal-field-percent {
    /* Porcentajes: máximo 6 caracteres visibles */
    min-width: 90px;
    max-width: 110px;
    flex: 0 0 auto;
}

.modal-field-full {
    /* Campo completo (descripción) */
    width: 100%;
    flex: 1 1 100%;
}

/* Asegurar que size no rompa el layout */
.modal-body .fs-field__control[size] {
    width: 100%;
    min-width: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 2px solid var(--border-color);
    background: var(--bg-table-row-alt);
    border-radius: 0 0 8px 8px;
}

/* ===== DROPDOWN ===== */
.dropdown {
    position: relative;
    display: inline-block;
}

.btn-dropdown {
    background: white;
    border: 1px solid var(--border-color);
}

.btn-dropdown:hover {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: white;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    z-index: 100;
    margin-top: 4px;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
    animation: dropdownSlide 0.2s ease;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-primary);
    transition: background 0.15s;
}

.dropdown-menu button:hover {
    background: var(--bg-table-row-alt);
}

.dropdown-menu button.danger {
    color: var(--color-danger);
}

.dropdown-menu button.danger:hover {
    background: #fff5f5;
}

.dropdown-menu button i {
    width: 14px;
    text-align: center;
}

.dropdown-menu button i.fa-plus {
    color: var(--color-success);
}

.dropdown-menu button i.fa-arrow-up {
    color: #805ad5;
}

.dropdown-menu button i.fa-arrow-down {
    color: #d69e2e;
}

.dropdown-menu button i.fa-trash {
    color: var(--color-danger);
}

/* Botón editar destacado */
.btn-icon.btn-edit {
    background: var(--btn-action-bg);
    color: var(--btn-action-text);
    border-color: var(--btn-action-bg);
}

.btn-icon.btn-edit i {
    color: var(--icon-edit-color);
}

.btn-icon.btn-edit:hover {
    background: var(--btn-action-bg-hover);
    border-color: var(--btn-action-bg-hover);
}

.btn-icon.btn-edit:hover i {
    color: var(--icon-edit-color);
}

/* ===== RESPONSIVE MODAL ===== */
@media (max-width: 1024px) {
    .modal-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 90vw;
        max-height: 85vh;
    }
    
    /* En tablets, permitir que algunos campos se apilen */
    .modal-field-code {
        min-width: 180px;
    }
    
    .modal-field-number {
        min-width: 120px;
    }
}

@media (max-width: 768px) {
    .modal-content {
        width: 95vw;
        max-height: 90vh;
    }
    
    .modal-header {
        padding: 16px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .modal-body .fs-fieldset {
        padding: 0.6rem 0.2rem 0.2rem 0.2rem;
    }
    
    .modal-body .fs-legend {
        font-size: 0.8rem;
    }
    
    /* En mobile, campos más compactos */
    .modal-field-code {
        min-width: 150px;
        flex: 1 1 calc(50% - var(--fs-gap));
    }
    
    .modal-field-number {
        min-width: 110px;
        flex: 1 1 calc(50% - var(--fs-gap));
    }
    
    .modal-field-percent {
        min-width: 80px;
        flex: 0 1 auto;
    }
}

@media (max-width: 480px) {
    /* En pantallas muy pequeñas, algunos campos ocupan fila completa */
    .modal-field-code {
        flex: 1 1 100%;
    }
    
    .modal-field-number {
        flex: 1 1 calc(50% - var(--fs-gap));
    }
}
