/* ================================================
   3. COMPONENTS - Componentes Reutilizables
   ================================================
   Todos los componentes reutilizables del sistema:
   botones, cards, forms, modals, toast, badges, etc.
   ================================================ */

/* ========== FALLBACK FONT AWESOME ========== */
/* Forzar contenido de iconos Font Awesome */
.fa-trash::before,
.fas.fa-trash::before {
    content: "\f1f8" !important;
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
}

.fa-eye::before,
.fas.fa-eye::before {
    content: "\f06e" !important;
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
}

.fa-edit::before,
.fas.fa-edit::before {
    content: "\f044" !important;
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
}

/* ========== BOTONES ========== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8) var(--space-16);
    border-radius: var(--radius-base);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 1.5;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-standard);
    border: none;
    text-decoration: none;
    position: relative;
}

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

.btn--primary {
    background: var(--color-primary);
    color: var(--color-btn-primary-text);
}

.btn--primary:hover {
    background: var(--color-primary-hover);
}

.btn--primary:active {
    background: var(--color-primary-active);
}

.btn--secondary {
    background: var(--color-secondary);
    color: var(--color-text);
}

.btn--secondary:hover {
    background: var(--color-secondary-hover);
}

.btn--secondary:active {
    background: var(--color-secondary-active);
}

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

.btn--outline:hover {
    background: var(--color-secondary);
}

.btn--sm {
    padding: var(--space-4) var(--space-12);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

.btn--lg {
    padding: var(--space-10) var(--space-20);
    font-size: var(--font-size-lg);
    border-radius: var(--radius-md);
}

.btn--full-width {
    width: 100%;
}

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

.action-btn {
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-sm);
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.action-btn:hover {
    background: var(--color-secondary);
}

.action-btn.danger {
    color: var(--color-error);
}

.action-btn.disabled {
    opacity: .45;
    cursor: not-allowed !important;
    pointer-events: auto;
}

.action-btn.disabled i {
    color: #888;
}

/* ========== CARDS ========== */

.card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-card-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--duration-normal) var(--ease-standard);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card__body {
    padding: var(--space-24);
}

.card__header {
    padding: var(--space-24);
    border-bottom: 1px solid var(--color-card-border-inner);
}

.card__header h3 {
    margin: 0;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.card__footer {
    padding: var(--space-24);
    border-top: 1px solid var(--color-card-border-inner);
}

/* ========== FORMULARIOS ========== */

.form-control {
    display: block;
    width: 100%;
    padding: var(--space-10) var(--space-12);
    font-size: var(--font-size-md);
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    transition: border-color var(--duration-fast) var(--ease-standard),
        box-shadow var(--duration-fast) var(--ease-standard);
}

textarea.form-control {
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    padding: var(--space-10) var(--space-12);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: var(--select-caret-light);
    background-repeat: no-repeat;
    background-position: right var(--space-12) center;
    background-size: 16px;
    padding-right: var(--space-32);
}

.form-control:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.form-control:disabled {
    background-color: var(--color-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.form-label {
    display: block;
    margin-bottom: var(--space-8);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.form-group {
    margin-bottom: var(--space-20);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-16);
    margin-bottom: var(--space-20);
}

.form-actions {
    display: flex;
    gap: var(--space-12);
    justify-content: flex-end;
    margin-top: var(--space-24);
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-top: var(--space-4);
    display: block;
}

.field-error {
    border-color: var(--color-error) !important;
}

.error-message {
    color: var(--color-error);
    font-size: var(--font-size-xs);
    margin-top: var(--space-4);
}

.read-only {
    background: #f4f4f4;
    cursor: not-allowed;
    opacity: .9;
}

.password-toggle {
    position: absolute;
    right: var(--space-12);
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-4);
}

/* ========== MODALES ========== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: var(--space-24);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--color-text);
    font-size: var(--font-size-xl);
}

.modal-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: var(--font-size-2xl);
    cursor: pointer;
    padding: var(--space-8);
    border-radius: var(--radius-sm);
    transition: background-color var(--duration-fast) var(--ease-standard);
    line-height: 1;
}

.modal-close:hover {
    background: var(--color-secondary);
    color: var(--color-text);
}

.modal-body {
    padding: var(--space-24);
}

.modal-footer {
    padding: var(--space-24);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-12);
    justify-content: flex-end;
}

/* ========== TOAST NOTIFICATIONS ========== */

.toast {
    position: fixed;
    bottom: var(--space-24);
    right: var(--space-24);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-16) var(--space-20);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    min-width: 300px;
    max-width: 500px;
    transition: all var(--duration-normal) var(--ease-standard);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.hidden {
    display: none;
}

.toast.success {
    border-left: 4px solid var(--color-success);
}

.toast.error {
    border-left: 4px solid var(--color-error);
}

.toast.warning {
    border-left: 4px solid var(--color-warning);
}

.toast.info {
    border-left: 4px solid var(--color-info);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: var(--space-12);
}

.toast-icon {
    font-size: var(--font-size-xl);
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: var(--color-success);
}

.toast.error .toast-icon {
    color: var(--color-error);
}

.toast.warning .toast-icon {
    color: var(--color-warning);
}

.toast.info .toast-icon {
    color: var(--color-info);
}

.toast-message {
    flex: 1;
    font-size: var(--font-size-sm);
    line-height: 1.4;
}

/* ========== LOADING SPINNER ========== */

.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.loading-spinner.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-16);
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-spinner p {
    color: var(--color-white);
    font-size: var(--font-size-lg);
    margin: 0;
    font-weight: var(--font-weight-medium);
}

/* ========== BADGES / STATUS INDICATORS ========== */

.status {
    display: inline-flex;
    align-items: center;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

.status--success,
.status.pagada {
    background: var(--color-bg-3);
    color: #22c55e;
}

.status--error {
    background-color: rgba(var(--color-error-rgb), 0.15);
    color: var(--color-error);
    border: 1px solid rgba(var(--color-error-rgb), 0.25);
}

.status--warning,
.status.pendiente {
    background: var(--color-bg-2);
    color: #f59e0b;
}

.status--info {
    background-color: rgba(var(--color-info-rgb), 0.15);
    color: var(--color-info);
    border: 1px solid rgba(var(--color-info-rgb), 0.25);
}

.status.vencida {
    background: var(--color-bg-4);
    color: #ef4444;
}

.estado-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .3px;
    border-radius: 12px;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}

.estado-pendiente {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
    border-color: rgba(245, 158, 11, 0.4);
}

.estado-vencida {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.45);
}

.estado-pagada {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
    border-color: rgba(34, 197, 94, 0.45);
}

/* ========== DROPDOWNS ========== */

.cliente-search-wrapper {
    position: relative;
}

.cliente-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 4px;
}

.cliente-dropdown.hidden {
    display: none;
}

.cliente-dropdown-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    line-height: 1.4;
    transition: background-color 0.15s;
}

.cliente-dropdown-item:hover,
.cliente-dropdown-item.active {
    background-color: #f8f9fa;
}

.cliente-dropdown-item:last-child {
    border-bottom: none;
}

.cliente-dropdown-empty {
    padding: 10px 12px;
    color: #666;
    font-style: italic;
    font-size: 14px;
    text-align: center;
}

.cliente-search-wrapper input.field-error {
    border-color: #c62828;
}

/* ========== TABLAS ========== */

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chart-container canvas {
    max-width: 100%;
    height: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

table th,
table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

table th {
    background: var(--color-bg-1);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Encabezados ordenables */
table th[data-sort] {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background-color 0.15s;
}

table th[data-sort]:hover {
    background: rgba(59, 130, 246, 0.15);
}

table th[data-sort] i {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.3;
    transition: opacity 0.2s;
}

table tbody tr:hover {
    background: var(--color-secondary);
}

.actions-cell {
    display: flex;
    gap: var(--space-8);
    justify-content: flex-end;
}

/* ========== FILTROS ========== */

.filters-section {
    margin-bottom: var(--space-24);
    padding: var(--space-16);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
}

.filters-grid {
    display: grid;
    gap: var(--space-16);
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: end;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.filter-field label {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
}

.filter-field input,
.filter-field select {
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-8) var(--space-12);
    font-size: var(--font-size-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-field input:focus,
.filter-field select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(var(--color-teal-500-rgb), .15);
}

.filter-actions {
    display: flex;
    align-items: flex-end;
    gap: var(--space-8);
}

/* ========== INVOICE SUMMARY ========== */

.invoice-summary {
    background: var(--color-bg-1);
    padding: var(--space-24);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-24);
}

.invoice-summary h4 {
    margin: 0 0 var(--space-16) 0;
    color: var(--color-text);
}

.summary-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-8) 0;
    font-size: var(--font-size-sm);
}

.summary-item.total {
    border-top: 2px solid var(--color-border);
    padding-top: var(--space-12);
    margin-top: var(--space-8);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
}

/* ========== UTILIDADES ========== */

.container {
    width: 100%;
    margin-right: auto;
    margin-left: auto;
    padding-right: var(--space-16);
    padding-left: var(--space-16);
}

.flash-new {
    animation: flashRow 2s ease-in-out;
}

@keyframes flashRow {
    0% {
        background: #d1f5e5;
    }

    100% {
        background: transparent;
    }
}

.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-4 {
    gap: var(--space-4);
}

.gap-8 {
    gap: var(--space-8);
}

.gap-16 {
    gap: var(--space-16);
}

.text-center {
    text-align: center;
}

.block {
    display: block;
}