/**
 * Components CSS
 * 
 * Estilos específicos para componentes JavaScript.
 * Complementa o main.css com estilos dinâmicos.
 */

/* ============================================================================
   EXPENSE CARD COMPONENT
   ============================================================================ */

.expense-card-wrapper {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    transition: all 0.2s ease;
    position: relative;
}

.expense-card-wrapper:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-color: #2563eb;
}

.expense-card-wrapper.paid {
    background-color: #f0fdf4;
    border-left-color: #10b981;
    border-left-width: 4px;
}

.expense-card-wrapper.overdue {
    border-left-color: #ef4444;
    border-left-width: 4px;
    background-color: #fef2f2;
}

.expense-card-wrapper.virtual {
    border-style: dashed;
    opacity: 0.9;
}

/* Card Layout */
.expense-card-content {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.expense-card-checkbox {
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.expense-card-main {
    flex-grow: 1;
    min-width: 0; /* Para permitir text-overflow */
}

.expense-card-actions {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
}

/* Card Header */
.expense-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.expense-card-description {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-card-description.paid {
    text-decoration: line-through;
    opacity: 0.7;
}

.expense-card-amount {
    font-size: 1.125rem;
    font-weight: 700;
    color: #111827;
    white-space: nowrap;
}

.expense-card-amount.paid {
    color: #10b981;
}

/* Card Meta */
.expense-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.875rem;
    color: #6b7280;
    min-height: 1.5rem;  /* Garante altura mínima para evitar sobreposição */
}

.expense-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;  /* Impede que o badge encolha e sobreponha outros elementos */
    position: static;  /* Garante que não fique fixo na tela */
}

.expense-card-badge.fixed {
    background-color: #f5f3ff;
    color: #8b5cf6;
    position: static;  /* Força posicionamento estático para evitar conflito com CSS fixed */
}

.expense-card-badge.variable {
    background-color: #f9fafb;
    color: #6b7280;
}

.expense-card-due-date {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;  /* Impede que o texto de vencimento encolha */
    white-space: nowrap;  /* Evita quebra de linha no meio do texto */
}

.expense-card-due-date.overdue {
    color: #ef4444;
    font-weight: 600;
}

.expense-card-due-date.soon {
    color: #f59e0b;
    font-weight: 600;
    background-color: #fef3c7;  /* Fundo amarelo claro */
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

.expense-card-due-date.urgent {
    color: #ffffff;  /* Branco para contrastar com fundo vermelho */
    background-color: #ef4444;  /* Fundo vermelho */
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 700;
    animation: pulse 1.5s ease-in-out infinite;
}

.expense-card-status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;  /* Impede que o status encolha */
    white-space: nowrap;  /* Evita quebra de linha */
}

.expense-card-status.pending {
    color: #f97316;
}

.expense-card-status.scheduled {
    color: #3b82f6;
}

.expense-card-status.paid {
    color: #10b981;
}

/* Card Actions */
.expense-card-button {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.expense-card-button.edit {
    color: #2563eb;
    border-color: #2563eb;
    background: white;
}

.expense-card-button.edit:hover {
    background: #eff6ff;
}

.expense-card-button.delete {
    color: #ef4444;
    border-color: #ef4444;
    background: white;
}

.expense-card-button.delete:hover {
    background: #fef2f2;
}

.expense-card-button.cancel-recurrence {
    color: #f59e0b;
    border-color: #f59e0b;
    background: white;
}

.expense-card-button.cancel-recurrence:hover {
    background: #fff7ed;
}

.expense-card-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.expense-card-button svg {
    width: 1rem;
    height: 1rem;
}

/* Checkbox Custom */
.expense-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #d1d5db;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.15s ease;
    appearance: none;
    background: white;
    position: relative;
}

.expense-checkbox:checked {
    background-color: #10b981;
    border-color: #10b981;
}

.expense-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.875rem;
    font-weight: bold;
}

.expense-checkbox:hover:not(:checked) {
    border-color: #2563eb;
}

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

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ============================================================================
   CATEGORY DISPLAY
   ============================================================================ */

.expense-category {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.5rem;
    padding: 0.25rem 0.5rem;
    background-color: #f0f0f0;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.expense-category .category-icon {
    font-size: 1rem;
    line-height: 1;
}

.expense-category.no-category {
    color: #999;
    font-style: italic;
    background-color: transparent;
}

/* ============================================================================
   CATEGORY SELECTOR
   ============================================================================ */

.form-select optgroup {
    font-weight: bold;
    font-style: normal;
}

.form-select option {
    font-weight: normal;
    padding-left: 1rem;
}

/* ============================================================================
   RESPONSIVE - MOBILE
   ============================================================================ */

@media (max-width: 640px) {
    .expense-card-wrapper {
        padding: 0.75rem;
    }

    .expense-card-content {
        flex-direction: column;
        gap: 0.5rem;
    }

    .expense-card-header {
        flex-direction: column;
        gap: 0.25rem;
    }

    .expense-card-description {
        white-space: normal;
    }

    .expense-card-actions {
        width: 100%;
        justify-content: space-between;
    }

    .expense-card-button {
        flex: 1;
        justify-content: center;
        /* CORREÇÃO MOBILE: Garantir área de toque adequada */
        min-height: 44px;
        padding: 0.625rem 0.75rem;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }

    .expense-card-button span {
        display: none; /* Mostrar apenas ícones em mobile */
    }

    .expense-card-button svg {
        width: 1.25rem;
        height: 1.25rem;
    }

    /* CORREÇÃO MOBILE: Feedback visual ao tocar */
    .expense-card-button:active:not(:disabled) {
        transform: scale(0.95);
        opacity: 0.8;
    }

    /* CORREÇÃO MOBILE: Remover hover em dispositivos touch */
    @media (hover: none) {
        .expense-card-button.edit:hover {
            background: white;
        }

        .expense-card-button.delete:hover {
            background: white;
        }

        .expense-card-button.cancel-recurrence:hover {
            background: white;
        }

        .expense-card-wrapper:hover {
            box-shadow: none;
            border-color: #e5e7eb;
        }
    }

    /* CORREÇÃO MOBILE: Aumentar área de toque do checkbox */
    .expense-checkbox {
        width: 1.5rem;
        height: 1.5rem;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }

    .expense-checkbox:hover:not(:checked) {
        border-color: #d1d5db; /* Remover hover em mobile */
    }
}

/* ============================================================================
   LOADING SKELETON
   ============================================================================ */

.expense-card-skeleton {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-line {
    height: 1rem;
    background: linear-gradient(
        90deg,
        #f3f4f6 0%,
        #e5e7eb 50%,
        #f3f4f6 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .expense-card-checkbox,
    .expense-card-actions {
        display: none;
    }

    .expense-card-wrapper {
        border: 1px solid black;
        page-break-inside: avoid;
    }
}


/* ========== Sub-Expense Modal Styles ========== */

.sub-expense-modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.sub-expense-modal .modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9998;
}

.sub-expense-modal .modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 10000;
}

.sub-expense-modal-content {
    max-width: 900px;
}

.sub-expense-modal .modal-header {
    padding: 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.sub-expense-modal .modal-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #111827;
}

.modal-header .parent-info {
    margin: 4px 0 0 0;
    font-size: 14px;
    color: #6b7280;
}

.modal-header .parent-amount-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.modal-header .parent-amount-info .label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-header .parent-amount-info .amount {
    font-size: 20px;
    font-weight: 700;
    color: #059669;
}

.modal-header .close-btn {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-header .close-btn:hover {
    background-color: #f3f4f6;
    color: #374151;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Children List */

.children-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #6b7280;
}

.empty-state p {
    margin: 8px 0;
}

.empty-state .hint {
    font-size: 14px;
    color: #9ca3af;
}

.child-expense-row {
    display: grid;
    grid-template-columns: 1fr 120px 1fr 50px;
    gap: 12px;
    align-items: end;
    padding: 16px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    transition: all 0.2s;
}

.child-expense-row:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.child-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0; /* Permite que o campo encolha */
}

.child-field-actions {
    display: flex;
    align-items: flex-end;
}

.child-field label {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.child-field input,
.child-field select,
.child-category {
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.child-field input:focus,
.child-field select:focus,
.child-category:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.delete-child-btn {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    height: 42px;
    width: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.delete-child-btn:hover {
    background: #fecaca;
    border-color: #fca5a5;
}

/* Sum Validation */

.sum-validation {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
}

.sum-validation.valid {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.sum-validation.invalid {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.sum-validation .label {
    font-size: 14px;
}

.sum-validation .sum-amount {
    font-size: 18px;
    font-weight: 700;
}

.sum-validation .validation-icon {
    font-size: 20px;
    margin-left: auto;
}

.sum-validation .difference {
    font-size: 13px;
    margin-left: 8px;
    opacity: 0.8;
}

/* Add Child Button */

.btn-add-child {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    font-size: 14px;
    font-weight: 500;
}

.btn-add-child span {
    font-size: 20px;
}

/* Parent Badge */

.parent-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

/* Responsive */

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .sub-expense-modal-content {
        max-width: 100%;
    }

    .modal-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-header .close-btn {
        position: absolute;
        top: 16px;
        right: 16px;
    }

    .child-expense-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .delete-child-btn {
        width: 100%;
    }

    .sum-validation {
        flex-wrap: wrap;
    }

    .sum-validation .validation-icon {
        margin-left: 0;
    }
}


.sum-validation.invalid {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.sum-validation .label {
    font-size: 14px;
}

.sum-validation .sum-amount {
    font-size: 18px;
    font-weight: 700;
}

.sum-validation .validation-icon {
    font-size: 20px;
    margin-left: auto;
}

.sum-validation .difference {
    font-size: 13px;
    opacity: 0.8;
}

/* Add Child Button */

.btn-add-child {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: #f3f4f6;
    border: 2px dashed #d1d5db;
    color: #6b7280;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-add-child:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
    color: #374151;
}

.btn-add-child span {
    font-size: 20px;
    font-weight: 700;
}

/* Modal Buttons */

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

/* Responsive */

@media (max-width: 768px) {
    .sub-expense-modal .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .sub-expense-modal .modal-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sub-expense-modal .modal-header .close-btn {
        position: absolute;
        top: 16px;
        right: 16px;
    }

    .child-expense-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .delete-child-btn {
        width: 100%;
    }
}
