/* Reset e Variáveis */
:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
    color: white;
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: white;
    transform: translateY(-2px);
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    background: var(--card-bg);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.nav-tab {
    flex: 1;
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.nav-tab:hover {
    background: var(--bg-color);
}

.nav-tab.active {
    background: var(--primary-color);
    color: white;
}

/* Main Content */
.main-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow-md);
    min-height: 500px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.section-header h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.section-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

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

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Faturas Grid */
.faturas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.fatura-card {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.fatura-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.fatura-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.fatura-mes-ano {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.fatura-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-aberta {
    background: #fef3c7;
    color: #92400e;
}

.status-fechada {
    background: #d1fae5;
    color: #065f46;
}

.fatura-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fatura-valor {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

.fatura-meta {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Fatura Detalhes */
.fatura-detalhes {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fatura-resumo {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.resumo-card {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.resumo-card h4 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.resumo-valor {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Transações Table */
.transacoes-container {
    overflow-x: auto;
}

.transacoes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.transacoes-table thead {
    background: var(--bg-color);
}

.transacoes-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.transacoes-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.transacoes-table tbody tr:hover {
    background: var(--bg-color);
}

.categoria-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}

.recibo-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 12px;
}

.recibo-link:hover {
    text-decoration: underline;
}

.checkbox-conciliado {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Upload Area */
.upload-area {
    max-width: 800px;
    margin: 0 auto;
}

.upload-box {
    border: 3px dashed var(--border-color);
    border-radius: 12px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-box:hover {
    border-color: var(--primary-color);
    background: var(--bg-color);
}

.upload-content svg {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.upload-content h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.upload-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

.upload-status {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    background: var(--bg-color);
}

.ocr-resultado {
    margin-top: 30px;
}

.info-text {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* Stats */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-color);
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
}

.stat-card h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.categorias-lista {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.categoria-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 8px;
}

.categoria-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.categoria-cor {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.categoria-nome {
    font-weight: 500;
}

.categoria-quantidade {
    font-size: 13px;
    color: var(--text-secondary);
}

.categoria-valor {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

/* 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);
    animation: fadeIn 0.2s;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.close {
    font-size: 28px;
    font-weight: 300;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 25px;
}

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

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

/* Utility Classes */
.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

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

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        padding: 20px;
    }

    .header-content h1 {
        font-size: 22px;
    }

    .main-content {
        padding: 20px;
    }

    .nav-tabs {
        flex-direction: column;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .faturas-grid {
        grid-template-columns: 1fr;
    }

    .transacoes-table {
        font-size: 12px;
    }

    .transacoes-table th,
    .transacoes-table td {
        padding: 8px;
    }
}

/* Novos estilos para upload de recibos */
.upload-step {
    background: var(--bg-color);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px dashed var(--border-color);
}

.upload-step h3 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.form-row {
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
}

.info-box {
    background: #dbeafe;
    border-left: 4px solid var(--primary-color);
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
}

.info-box p {
    margin: 0;
    color: var(--text-primary);
}

.recibos-preview {
    margin-top: 20px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.recibos-preview h4 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

.recibos-preview ul {
    list-style: none;
    margin-bottom: 20px;
}

.recibos-preview li {
    padding: 8px 12px;
    background: var(--bg-color);
    margin-bottom: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.recibos-preview li::before {
    content: "📄";
    font-size: 18px;
}

.hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Modal largo para revisão */
.modal-large .modal-content {
    max-width: 1200px;
    width: 95%;
}

.revisao-container {
    max-height: 500px;
    overflow-y: auto;
}

.revisao-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.revisao-table th,
.revisao-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.revisao-table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
}

.revisao-table input,
.revisao-table select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

.revisao-table input:focus,
.revisao-table select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.recibo-nome {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-remove-item {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.btn-remove-item:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

/* Feedback visual - Loading, Success, Error */
.upload-status {
    margin-top: 20px;
    padding: 20px;
    border-radius: 12px;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.loading {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-left: 4px solid var(--primary-color);
    padding: 25px;
    text-align: center;
}

.loading p {
    margin: 10px 0;
    color: var(--text-primary);
    font-weight: 500;
}

.loading p:first-child {
    font-size: 18px;
    font-weight: 600;
}

.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 15px auto;
}

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

.success {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-left: 4px solid var(--success-color);
    padding: 25px;
}

.success p {
    margin: 8px 0;
    color: #166534;
}

.success p:first-child {
    font-size: 18px;
    font-weight: 600;
}

.success::before {
    content: "✓";
    display: inline-block;
    width: 30px;
    height: 30px;
    background: var(--success-color);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    font-size: 20px;
    margin-right: 10px;
    vertical-align: middle;
}

.error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-left: 4px solid var(--danger-color);
    padding: 25px;
}

.error p {
    margin: 8px 0;
    color: #991b1b;
}

.error p:first-child {
    font-size: 18px;
    font-weight: 600;
}

.error::before {
    content: "✕";
    display: inline-block;
    width: 30px;
    height: 30px;
    background: var(--danger-color);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    font-size: 20px;
    margin-right: 10px;
    vertical-align: middle;
}

/* ==================== RESPONSIVIDADE ==================== */

/* Tablets e telas menores */
@media (max-width: 1024px) {
    .modal-content.modal-large {
        width: 98%;
        max-width: none;
        max-height: 90vh;
    }
    
    .revisao-container {
        max-height: 60vh;
        overflow-x: auto;
    }
    
    .revisao-table {
        font-size: 13px;
    }
    
    .revisao-table th,
    .revisao-table td {
        padding: 8px;
    }
}

/* Telas HD 720p e menores (1280x720 ou menor) */
@media (max-height: 800px) {
    .modal-content.modal-large {
        max-height: 95vh;
    }
    
    .revisao-container {
        max-height: 50vh;
    }
    
    .modal-header {
        padding: 15px 20px;
    }
    
    .modal-header h3 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px 20px;
    }
    
    .modal-footer {
        padding: 15px 20px;
    }
}

/* Mobile e telas muito pequenas */
@media (max-width: 768px) {
    .modal-content.modal-large {
        width: 100%;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .revisao-container {
        max-height: calc(100vh - 200px);
    }
    
    .revisao-table {
        font-size: 12px;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .revisao-table th,
    .revisao-table td {
        padding: 6px;
        min-width: 100px;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}

/* Correção do seletor modal-large - IMPORTANTE */
.modal-content.modal-large {
    max-width: 1200px !important;
    width: 95% !important;
    max-height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
}

.modal-large .modal-content {
    max-width: 1200px;
    width: 95%;
}

/* Garantir que modal-body seja scrollável */
.modal-content.modal-large .modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    max-height: calc(90vh - 160px) !important;
}

/* Garantir que footer sempre apareça */
.modal-content.modal-large .modal-footer {
    flex-shrink: 0 !important;
    position: sticky !important;
    bottom: 0 !important;
    background: white !important;
    border-top: 1px solid var(--border-color) !important;
    z-index: 10 !important;
}

/* ==================== RELATÓRIO FINANCEIRO ==================== */

/* Botão de relatório no card de fatura */
.fatura-card {
    display: flex !important;
    flex-direction: column !important;
    gap: 15px;
}

.fatura-card-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.btn-relatorio {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(30, 64, 175, 0.2);
}

.btn-relatorio:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(30, 64, 175, 0.3);
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}

/* Modal de relatório */
.relatorio-header {
    margin-bottom: 25px;
    padding: 20px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
}

.relatorio-info-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.info-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.info-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.info-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Status badges na tabela */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.conciliado {
    background: #dcfce7;
    color: #166534;
}

.status-badge.pendente {
    background: #fee2e2;
    color: #991b1b;
}

/* Link de recibo */
.recibo-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.recibo-link:hover {
    color: #1e3a8a;
    text-decoration: underline;
}

/* Responsividade para relatório */
@media (max-width: 768px) {
    .relatorio-info-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .info-value {
        font-size: 18px;
    }

    .btn-relatorio {
        width: 100%;
        padding: 12px;
    }
}

/* ==================== MODAL DE EDIÇÃO RESPONSIVO ==================== */

/* Garantir que modal de transação seja responsivo */
#modal-transacao .modal-content {
    max-height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
}

#modal-transacao .modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    max-height: calc(90vh - 140px) !important;
}

#modal-transacao .modal-footer {
    flex-shrink: 0 !important;
    position: sticky !important;
    bottom: 0 !important;
    background: white !important;
    border-top: 1px solid var(--border-color) !important;
}

/* Responsividade para telas menores */
@media (max-height: 800px) {
    #modal-transacao .modal-content {
        max-height: 95vh !important;
    }
    
    #modal-transacao .modal-body {
        max-height: calc(95vh - 140px) !important;
    }
}
