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

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }

/* === LOGIN === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}
.login-container { width: 100%; max-width: 420px; }
.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.login-header { padding: 40px 30px 20px; text-align: center; }
.login-logo { font-size: 50px; margin-bottom: 10px; }
.login-header h1 { margin-bottom: 5px; }
.login-header p { color: var(--gray-500); }
.login-form { padding: 20px 30px 30px; }
.login-footer {
    text-align: center;
    padding: 15px;
    background: var(--gray-50);
    color: var(--gray-500);
}

/* === HEADER === */
.header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.header-left h1 { font-size: 18px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
.user-details { display: flex; flex-direction: column; line-height: 1.2; }
.user-details strong { font-size: 13px; }
.user-details span { font-size: 11px; color: var(--gray-500); }

/* === DASHBOARD === */
.dashboard-content { padding: 24px; max-width: 1600px; margin: 0 auto; }

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--gray-200);
    flex-wrap: wrap;
}
.tab {
    padding: 10px 18px;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--gray-500);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.2s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

h2 { margin-bottom: 15px; color: var(--gray-900); }

/* === STATS === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}
.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray-500);
    font-weight: 600;
    letter-spacing: 0.5px;
}
.stat-value {
    font-size: 20px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--gray-900);
}
.stat-pago .stat-value { color: var(--success); }
.stat-danger .stat-value { color: var(--danger); }
.stat-warning .stat-value { color: var(--warning); }
.stat-info .stat-value { color: var(--primary); }
.stat-aviso .stat-value { color: #d97706; }

/* === ACTIONS GRID === */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.action-card {
    background: white;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    text-align: center;
    transition: all 0.2s;
    color: var(--gray-900);
    box-shadow: var(--shadow);
}
.action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}
.action-icon { font-size: 40px; margin-bottom: 10px; }
.action-card h3 { margin-bottom: 5px; }
.action-card p { color: var(--gray-500); font-size: 13px; }

/* === BUTTONS === */
.btn {
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-ghost { background: transparent; color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-full { width: 100%; justify-content: center; padding: 12px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-icon {
    background: transparent;
    border: none;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    text-decoration: none;
    display: inline-block;
}
.btn-icon:hover { background: var(--gray-100); }
.btn-danger-icon:hover { background: #fee2e2; }
.btn-camera {
    background: var(--primary);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
}

/* === FORMS === */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}
.form-group-full { flex-basis: 100%; }
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-row { display: flex; gap: 16px; margin-bottom: 12px; }
.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}
.input-with-actions { display: flex; gap: 8px; align-items: center; }
.input-with-actions input { flex: 1; }

/* === ALERTS === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* === MODAL === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
    background: white;
    border-radius: 16px;
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-large {
    max-width: 900px;
    width: 95%;
}
.modal-fullscreen { padding: 0; }
.modal-fullscreen-content {
    max-width: 95vw;
    width: 95vw;
    max-height: 95vh;
}
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}
.modal-header h2 { font-size: 18px; }
.btn-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--gray-500);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
}
.btn-close:hover { background: var(--gray-100); }
.modal-body { padding: 24px; }

/* === TOOLBAR === */
.list-toolbar {
    background: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--radius) var(--radius) 0 0;
    border: 1px solid var(--gray-200);
    margin-bottom: 0;
    flex-wrap: wrap;
    gap: 10px;
}
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }

/* === FILTROS === */
.filtros-panel {
    background: white;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s;
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-bottom: 16px;
}
.filtros-panel.open {
    max-height: 500px;
    padding: 20px;
}
.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.filtros-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* === TABLE === */
.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    border: 1px solid var(--gray-200);
}
.boleto-table {
    width: 100%;
    border-collapse: collapse;
}
.boleto-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--gray-50);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--gray-500);
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
}
.boleto-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}
.boleto-table tr { cursor: pointer; transition: filter 0.15s; }
.boleto-table tr:hover { filter: brightness(0.95); }

.codigo-cell {
    font-family: 'Courier New', monospace;
    font-size: 12px;
}
.valor-cell {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-pago { background: #dcfce7; color: #166534; }
.badge-vencido { background: #fee2e2; color: #991b1b; }
.badge-aviso { background: #fef3c7; color: #92400e; }
.badge-normal { background: #dbeafe; color: #1e40af; }

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--gray-500);
}
.empty-icon { font-size: 60px; margin-bottom: 10px; }

/* === BOLETO DETAIL === */
.boleto-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.info-card {
    background: var(--gray-50);
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
.info-label {
    display: block;
    font-size: 11px;
    color: var(--gray-500);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 4px;
}
.info-value {
    font-size: 14px;
    font-weight: 500;
    word-break: break-word;
}
.info-value.big {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}
.info-valor {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border-color: var(--primary);
}

.codigo-area {
    margin-top: 20px;
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--gray-200);
}
.codigo-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
}
.codigo-display {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 150px;
}
.barcode-container, .qr-container { text-align: center; }
.barcode-container svg { max-width: 100%; height: auto; }
.qr-container img { max-width: 250px; }
.linha-digitavel-container { text-align: center; width: 100%; }
.linha-digitavel-display {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    padding: 16px;
    background: var(--gray-50);
    border-radius: var(--radius);
    margin-bottom: 15px;
    letter-spacing: 1px;
    word-break: break-all;
}

/* === SCANNER MELHORADO === */
.scanner-box {
    margin-top: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #0ea5e9;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.scanner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.scanner-header h3 {
    margin: 0;
    color: #0369a1;
    font-size: 18px;
}

.btn-close-small {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #64748b;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close-small:hover {
    background: #e0f2fe;
    color: #0369a1;
}

.scanner-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.camera-area {
    margin-bottom: 16px;
}

.camera-container {
    position: relative;
    width: 100%;
    height: 450px;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

#cameraVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.scan-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    height: 120px;
    border: 4px solid #22c55e;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.6);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { border-color: #22c55e; opacity: 1; }
    50% { border-color: #4ade80; opacity: 0.8; }
}

.camera-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.btn-capture {
    background: #22c55e;
    color: white;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
}

.btn-capture:hover:not(:disabled) {
    background: #16a34a;
}

.btn-capture:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.scanner-hint {
    text-align: center;
    color: #64748b;
    font-size: 14px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    margin: 0;
}

.scanner-status {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    display: none;
}

.status-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
    display: block;
}

.status-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    display: block;
}

.status-info {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
    display: block;
}

.status-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
    display: block;
}

.foto-preview {
    margin-top: 20px;
    padding: 16px;
    background: white;
    border-radius: 8px;
    border: 2px solid #0ea5e9;
}

.foto-preview h4 {
    margin: 0 0 12px 0;
    color: #0369a1;
}

.foto-preview img {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--gray-200);
}

.preview-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.leitor-area {
    text-align: center;
    padding: 20px;
}

.input-leitor {
    padding: 14px;
    font-size: 16px;
    border: 2px solid #0ea5e9;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 12px;
}

/* === RELATORIO === */
.relatorio-header {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow);
}
.relatorio-header h1 { color: var(--primary); margin-bottom: 5px; }
.relatorio-header p { color: var(--gray-500); }

/* === PRINT === */
@media print {
    body { background: white !important; }
    .header, .tabs, .list-toolbar, .filtros-panel,
    .no-print, .btn { display: none !important; }
    
    .dashboard-content { padding: 0; }
    .table-container { box-shadow: none; border: none; }
    .boleto-table tr { page-break-inside: avoid; }
    .stat-card { break-inside: avoid; }
}

/* === RESPONSIVO === */
@media (max-width: 768px) {
    .header { padding: 10px 15px; flex-wrap: wrap; }
    .header-left h1 { font-size: 15px; }
    .user-details { display: none; }
    .dashboard-content { padding: 12px; }
    .form-row { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-fullscreen-content { max-width: 100vw; width: 100vw; }
    .filtros-grid { grid-template-columns: 1fr; }
    
    .camera-container {
        height: 350px;
    }
    
    .scan-guide {
        width: 90%;
        height: 100px;
    }
    
    .camera-controls {
        flex-direction: column;
    }
    
    .btn-capture {
        width: 100%;
    }
    
    .scanner-tabs {
        flex-direction: column;
    }
    
    .scanner-tabs .btn {
        width: 100%;
        justify-content: center;
    }
    
    .preview-actions {
        flex-direction: column;
    }
    
    .preview-actions .btn {
        width: 100%;
        justify-content: center;
    }
}