/* ═══════════════════════════════════════════
   VARIÁVEIS & RESET
   ═══════════════════════════════════════════ */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --success: #22c55e;
    --success-bg: #dcfce7;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
    --sidebar-w: 240px;
    --topbar-h: 60px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════ */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

.login-header p {
    color: var(--gray-500);
    font-size: .9rem;
    margin-top: 4px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

/* ═══════════════════════════════════════════
   FORM ELEMENTS
   ═══════════════════════════════════════════ */
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    transition: border-color .2s, box-shadow .2s;
    background: #fff;
    color: var(--gray-800);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: .9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
}

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

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--gray-300);
    color: var(--gray-600);
}
.btn-outline:hover {
    border-color: var(--gray-400);
    background: var(--gray-50);
}

.btn-sm {
    padding: 6px 14px;
    font-size: .8rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}
.btn-warning:hover {
    background: #d97706;
}

/* ═══════════════════════════════════════════
   ALERT
   ═══════════════════════════════════════════ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    margin-bottom: 20px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fca5a5;
}

/* ═══════════════════════════════════════════
   TOPBAR
   ═══════════════════════════════════════════ */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gray-900);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-600);
    padding: 4px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-size: .85rem;
    color: var(--gray-500);
    font-weight: 500;
}

/* ═══════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════ */
.sidebar-content {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid var(--gray-200);
    padding-top: 16px;
    z-index: 90;
    overflow-y: auto;
}

.sidebar-header {
    display: none;
}

.sidebar-nav {
    list-style: none;
    padding: 0 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--gray-600);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: .9rem;
    transition: all .15s;
    margin-bottom: 2px;
}

.nav-link:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.nav-link.active {
    background: rgba(99,102,241,.1);
    color: var(--primary);
}

.sidebar-overlay {
    display: none;
}

.sidebar-close {
    display: none;
}

/* ═══════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-w);
    margin-top: var(--topbar-h);
    padding: 24px;
    min-height: calc(100vh - var(--topbar-h));
}

.section {
    display: none;
}
.section.active {
    display: block;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 16px;
}

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

/* ═══════════════════════════════════════════
   STATS CARDS
   ═══════════════════════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid transparent;
}

.stat-total { border-left-color: var(--primary); }
.stat-pagos { border-left-color: var(--success); }
.stat-abertos { border-left-color: var(--warning); }
.stat-valor { border-left-color: #8b5cf6; }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-total .stat-icon { background: rgba(99,102,241,.1); color: var(--primary); }
.stat-pagos .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-abertos .stat-icon { background: var(--warning-bg); color: var(--warning); }
.stat-valor .stat-icon { background: rgba(139,92,246,.1); color: #8b5cf6; }

.stat-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-label {
    font-size: .8rem;
    color: var(--gray-500);
    font-weight: 500;
}

/* ═══════════════════════════════════════════
   CHART
   ═══════════════════════════════════════════ */
.chart-container {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.chart-container canvas {
    width: 100% !important;
    max-height: 350px;
}

/* ═══════════════════════════════════════════
   FILTERS
   ═══════════════════════════════════════════ */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 20px;
    background: #fff;
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.filter-group label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.filter-group select,
.filter-group input {
    padding: 8px 12px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    background: #fff;
    color: var(--gray-700);
    min-width: 130px;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

/* ═══════════════════════════════════════════
   TABLE
   ═══════════════════════════════════════════ */
.table-wrapper {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}

.data-table thead {
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.badge-pago {
    background: var(--success-bg);
    color: #15803d;
}

.badge-aberto {
    background: var(--warning-bg);
    color: #92400e;
}

.badge-desconsiderado {
    background: var(--gray-100);
    color: var(--gray-500);
    text-decoration: line-through;
}

.codigo-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'Courier New', monospace;
    font-size: .8rem;
}

.codigo-cell-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.codigo-copiavel {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-copiar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--gray-50);
    color: var(--gray-500);
    cursor: pointer;
    transition: all .15s;
    flex-shrink: 0;
    padding: 0;
}

.btn-copiar:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.acoes-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    background: #fff;
    color: var(--gray-500);
    cursor: pointer;
    transition: all .15s;
    padding: 0;
}

.btn-icon:hover {
    background: var(--gray-50);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

.btn-icon.danger:hover {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #fca5a5;
}

/* ═══════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state svg {
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 20px;
}

/* ═══════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    backdrop-filter: blur(2px);
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-400);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-100);
    margin-top: 8px;
}

/* ═══════════════════════════════════════════
   DETALHES MODAL
   ═══════════════════════════════════════════ */
.detalhe-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
}

.detalhe-row:last-child {
    border-bottom: none;
}

.detalhe-label {
    font-weight: 600;
    color: var(--gray-600);
    font-size: .85rem;
}

.detalhe-valor {
    color: var(--gray-800);
    font-size: .9rem;
    text-align: right;
    max-width: 60%;
    word-break: break-all;
}

.status-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

.status-action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.status-action-row span {
    font-weight: 600;
    font-size: .9rem;
    color: var(--gray-700);
}

/* ═══════════════════════════════════════════
   MOBILE CARDS (hidden by default, shown on mobile)
   ═══════════════════════════════════════════ */
.mobile-cards {
    display: none;
}

.mobile-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-300);
}

.mobile-card.card-pago {
    border-left-color: var(--success);
}

.mobile-card.card-aberto {
    border-left-color: var(--warning);
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.mobile-card-title {
    font-weight: 700;
    font-size: .95rem;
    color: var(--gray-800);
}

.mobile-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: .85rem;
    margin-bottom: 12px;
}

.mobile-card-field {
    display: flex;
    flex-direction: column;
}

.mobile-card-field .label {
    font-size: .7rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .3px;
}

.mobile-card-field .value {
    color: var(--gray-700);
    font-weight: 500;
}

.mobile-card-field.full-width {
    grid-column: 1 / -1;
}

.mobile-card-field .value.mono {
    font-family: 'Courier New', monospace;
    font-size: .75rem;
    word-break: break-all;
}

.mobile-card-actions {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-100);
    flex-wrap: wrap;
}

.mobile-card-actions .btn {
    font-size: .78rem;
    padding: 6px 12px;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

    .sidebar-content {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100%;
        z-index: 300;
        transition: left .3s ease;
        padding-top: 0;
    }

    .sidebar.open .sidebar-content {
        left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 299;
        opacity: 0;
        pointer-events: none;
        transition: opacity .3s;
    }

    .sidebar.open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid var(--gray-200);
        font-weight: 700;
        font-size: 1rem;
    }

    .sidebar-close {
        display: block;
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--gray-500);
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
        gap: 10px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
    }

    .stat-icon svg {
        width: 20px;
        height: 20px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group select,
    .filter-group input {
        min-width: 0;
        width: 100%;
    }

    .table-wrapper {
        display: none;
    }

    .mobile-cards {
        display: block;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .section-header .btn {
        justify-content: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .chart-container {
        padding: 16px;
    }

    .topbar-title {
        font-size: 1rem;
    }
}

@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 28px 20px;
    }

    .mobile-card-body {
        grid-template-columns: 1fr;
    }

    .mobile-card-actions .btn {
        flex: none;
        width: 100%;
    }
}

/* ═══════════════════════════════════════════
   TOAST / NOTIFICAÇÃO
   ═══════════════════════════════════════════ */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 500;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: .88rem;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-md);
    animation: toastIn .3s ease-out;
    max-width: 340px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

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

@media (max-width: 768px) {
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .toast {
        max-width: 100%;
    }
}
