/* Carte Facile — Mobile-first app style */

/* Override theme wrapper — hide title on all, fullwidth on mobile only */
.cf-fullwidth .mia-article-header,
.mia-article:has(.cf-app) .mia-article-header {
    display: none !important;
}

@media (max-width: 600px) {
    .cf-fullwidth .mia-article,
    .mia-article:has(.cf-app) {
        background: transparent !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        max-width: 100% !important;
    }
    .cf-fullwidth.mia-page-content,
    .mia-page-content:has(.cf-app) {
        padding: 0 !important;
    }
    .cf-fullwidth .mia-content-area,
    .mia-content-area:has(.cf-app) {
        max-width: 100% !important;
    }
}

.cf-app {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 24px;
    color: #1e293b;
    -webkit-font-smoothing: antialiased;
}

@media (max-width: 600px) {
    .cf-app {
        background: #f8fafc;
        min-height: calc(100vh - 80px);
        padding: 8px;
    }
}

/* Header */
.cf-header { text-align: center; margin-bottom: 20px; padding-top: 24px; }
.cf-title {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    font-size: 22px; font-weight: 800; color: #1B3A5C; margin: 0;
}
.cf-subtitle { font-size: 13px; color: #64748b; margin: 4px 0 0; word-wrap: break-word; }

/* Labels */
.cf-label { display: block; font-size: 12px; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }

/* Card selector — horizontal scrollable chips */
.cf-card-selector { margin-bottom: 16px; }
.cf-cards-grid {
    display: flex; gap: 10px; flex-wrap: wrap;
}

/* Mobile: horizontal scroll */
@media (max-width: 600px) {
    .cf-cards-grid {
        flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px;
        -webkit-overflow-scrolling: touch; scroll-snap-type: x mandatory;
    }
    .cf-cards-grid::-webkit-scrollbar { height: 3px; }
    .cf-cards-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
}

.cf-card-chip {
    flex-shrink: 0; scroll-snap-align: start;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 14px 20px; border-radius: 14px;
    border: 2px solid #e2e8f0; background: #fff;
    cursor: pointer; transition: all 0.2s; min-width: 130px;
    font-family: inherit;
}
.cf-card-chip:hover { border-color: #cbd5e1; background: #f8fafc; }
.cf-card-chip.active {
    border-color: #1B3A5C; background: #1B3A5C; color: #fff;
    box-shadow: 0 4px 12px rgba(27,58,92,0.25);
}
.cf-card-icon { font-size: 24px; }
.cf-card-name { font-size: 12px; font-weight: 700; text-align: center; line-height: 1.2; }
.cf-card-last4 { font-size: 11px; opacity: 0.7; font-family: monospace; }

/* Month/Year row */
.cf-month-row { display: flex; gap: 10px; margin-bottom: 16px; }
.cf-select-group { flex: 1; }
.cf-select {
    width: 100%; padding: 12px 14px; border: 2px solid #e2e8f0; border-radius: 12px;
    font-size: 15px; font-family: inherit; background: #fff; color: #1e293b;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.cf-select:focus { border-color: #1B3A5C; outline: none; box-shadow: 0 0 0 3px rgba(27,58,92,0.1); }

/* Business reason — inside preview */
.cf-reason-prompt { margin: 16px 0; text-align: left; }
.cf-reason-toggle {
    display: flex; align-items: center; gap: 10px; cursor: pointer;
    padding: 12px 16px; background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 12px; transition: all 0.2s;
}
.cf-reason-toggle:hover { border-color: #fbbf24; }
.cf-reason-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: #1B3A5C; cursor: pointer; }
.cf-reason-toggle-label { font-size: 14px; font-weight: 600; color: #92400e; }
.cf-reason-fields {
    margin-top: 10px; padding: 14px; background: #fefce8;
    border: 1px solid #fde68a; border-radius: 12px;
}
.cf-reason-fields .cf-select { width: 100%; }

@media (max-width: 600px) {
    .cf-reason-toggle { padding: 10px 12px; }
    .cf-reason-toggle-label { font-size: 13px; }
    .cf-reason-fields { padding: 10px; }
}

/* Upload zone */
.cf-upload-zone {
    border: 2px dashed #cbd5e1; border-radius: 16px;
    padding: 32px 16px; text-align: center;
    background: #fafbfc; cursor: pointer;
    transition: all 0.25s; margin-bottom: 20px;
    position: relative;
}
.cf-upload-zone:hover { border-color: #1B3A5C; background: rgba(27,58,92,0.02); }
.cf-upload-zone.dragover {
    border-color: #E8A630; background: rgba(232,166,48,0.06);
    transform: scale(1.01); box-shadow: 0 0 0 4px rgba(232,166,48,0.1);
}
.cf-upload-inner { pointer-events: none; }
.cf-upload-inner button, .cf-upload-inner label, .cf-upload-inner input { pointer-events: auto; }
.cf-upload-icon { font-size: 40px; margin-bottom: 8px; }
.cf-upload-text { font-size: 15px; font-weight: 600; color: #475569; margin: 0 0 4px; }
.cf-upload-hint { font-size: 12px; color: #94a3b8; margin: 0 0 16px; }

.cf-upload-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Buttons */
.cf-btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 12px 22px; border-radius: 12px;
    font-size: 15px; font-weight: 600; font-family: inherit;
    border: 2px solid #e2e8f0; background: #fff; color: #475569;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.cf-btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.cf-btn:active { transform: scale(0.97); }

.cf-btn-primary { background: #1B3A5C; color: #fff; border-color: #1B3A5C; }
.cf-btn-primary:hover { background: #24486E; }

.cf-btn-camera { background: #fff; color: #475569; }
.cf-btn-camera:hover { background: #f1f5f9; }

.cf-btn-danger { background: #DC2626; color: #fff; border-color: #DC2626; }
.cf-btn-danger:hover { background: #B91C1C; }

.cf-btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 8px; }

/* Progress */
.cf-progress {
    text-align: center; padding: 32px 16px; background: #fafbfc;
    border: 1px solid #e2e8f0; border-radius: 16px; margin-bottom: 20px;
}
.cf-progress-icon { font-size: 36px; margin-bottom: 8px; animation: cf-spin 2s linear infinite; }
@keyframes cf-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.cf-progress-counter { font-size: 14px; font-weight: 700; color: #1B3A5C; margin: 0 0 6px; }
.cf-progress-file { font-size: 13px; color: #475569; margin: 0 0 12px; word-break: break-all; }
.cf-progress-bar {
    height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.cf-progress-bar::after {
    content: ''; display: block; height: 100%; width: 0%;
    background: #E8A630; border-radius: 3px;
    animation: cf-pulse 1.5s ease-in-out infinite;
}
.cf-progress-bar.done::after { width: 100%; background: #22C55E; animation: none; }
@keyframes cf-pulse { 0% { width: 10%; } 50% { width: 70%; } 100% { width: 10%; } }
.cf-progress-status { font-size: 13px; color: #64748b; margin: 0; }

.cf-batch-results { margin-top: 10px; text-align: left; max-height: 180px; overflow-y: auto; }

/* Scan preview */
.cf-preview {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 16px;
    padding: 20px; margin-bottom: 20px; text-align: center;
}
.cf-preview-header h3 { font-size: 16px; font-weight: 700; color: #1B3A5C; margin: 0 0 4px; }
.cf-preview-filename { font-size: 13px; color: #64748b; margin: 0 0 16px; }
.cf-preview-frame {
    background: #f1f5f9; border-radius: 12px; padding: 12px;
    max-height: 500px; overflow-y: auto; margin-bottom: 16px;
}
.cf-preview-frame canvas { max-width: 100%; height: auto; display: block; margin: 0 auto; image-rendering: auto; }
.cf-preview-frame img { max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: 4px; }
.cf-preview-pages {
    display: flex; gap: 8px; overflow-x: auto; padding: 8px 4px;
    -webkit-overflow-scrolling: touch;
}
.cf-preview-pages:empty { display: none; }
.cf-page-thumb {
    flex-shrink: 0; width: 60px; height: 80px; border-radius: 8px;
    border: 2px solid #e2e8f0; overflow: hidden; cursor: pointer;
    position: relative; transition: border-color 0.15s;
}
.cf-page-thumb.active { border-color: #1B3A5C; box-shadow: 0 0 0 2px rgba(27,58,92,0.2); }
.cf-page-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cf-page-thumb-num {
    position: absolute; bottom: 2px; right: 2px;
    background: rgba(0,0,0,0.6); color: #fff; font-size: 10px;
    padding: 1px 5px; border-radius: 4px; font-weight: 700;
}
.cf-btn-add-page {
    background: #fffbeb !important; color: #92400e !important;
    border-color: #fde68a !important;
}
.cf-btn-add-page:hover { background: #fef3c7 !important; border-color: #fbbf24 !important; }
.cf-preview-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 600px) {
    .cf-preview { padding: 12px; }
    .cf-preview-frame { max-height: 400px; padding: 8px; }
    .cf-preview-actions .cf-btn { flex: 1; justify-content: center; }
}

/* Confirm */
.cf-confirm {
    text-align: center; padding: 32px 16px; background: #f0fdf4;
    border: 1px solid #bbf7d0; border-radius: 16px; margin-bottom: 20px;
}
.cf-confirm-icon { font-size: 40px; margin-bottom: 8px; }
.cf-confirm-msg { font-size: 15px; color: #1e293b; margin: 0 0 16px; }

/* History */
.cf-history { margin-bottom: 20px; }
.cf-history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cf-history-title { font-size: 16px; font-weight: 700; color: #1B3A5C; margin: 0; }
.cf-history-count { font-size: 12px; color: #94a3b8; background: #f1f5f9; padding: 4px 10px; border-radius: 12px; }

.cf-history-list { display: flex; flex-direction: column; gap: 8px; }

.cf-receipt-card {
    display: flex; align-items: center; gap: 12px;
    padding: 14px; background: #fff; border: 1px solid #e2e8f0;
    border-radius: 12px; transition: all 0.15s; cursor: pointer;
}
.cf-receipt-card:hover { border-color: #cbd5e1; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.cf-receipt-card:active { transform: scale(0.99); }

.cf-receipt-icon { font-size: 28px; flex-shrink: 0; }
.cf-receipt-info { flex: 1; min-width: 0; }
.cf-receipt-name { font-size: 14px; font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-receipt-meta { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.cf-receipt-actions { display: flex; gap: 6px; flex-shrink: 0; }

.cf-empty { text-align: center; color: #94a3b8; font-size: 14px; padding: 24px; }

/* Pagination */
.cf-pagination { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }
.cf-page-btn {
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    border: 1px solid #e2e8f0; border-radius: 8px; background: #fff;
    font-size: 13px; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.cf-page-btn:hover { background: #f1f5f9; }
.cf-page-btn.active { background: #1B3A5C; color: #fff; border-color: #1B3A5C; }

/* PDF Viewer — fullscreen modal */
.cf-viewer {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9); z-index: 99999;
    display: flex; flex-direction: column;
}
.cf-viewer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: #1e293b; color: #fff; flex-shrink: 0;
    padding-top: max(12px, env(safe-area-inset-top));
}
.cf-viewer-header span { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-viewer-close { background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; padding: 0 8px; }
.cf-viewer canvas { flex: 1; width: 100%; object-fit: contain; overflow-y: auto; }
.cf-viewer-nav {
    display: flex; align-items: center; justify-content: center; gap: 16px;
    padding: 14px 10px; background: #1e293b; color: #fff; flex-shrink: 0;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.cf-viewer-nav span { font-size: 14px; font-weight: 600; }
.cf-viewer-btn {
    display: flex; align-items: center; justify-content: center;
    width: 52px; height: 44px; border-radius: 10px;
    background: #334155; border: 2px solid #475569;
    cursor: pointer; transition: all 0.15s;
}
.cf-viewer-btn:hover { background: #475569; border-color: #E8A630; }
.cf-viewer-btn:active { transform: scale(0.95); }
.cf-viewer-btn svg { flex-shrink: 0; }

@media (max-width: 600px) {
    .cf-viewer-nav { padding: 12px 8px; padding-bottom: max(16px, env(safe-area-inset-bottom)); gap: 12px; }
    .cf-viewer-btn { width: 64px; height: 52px; border-radius: 12px; }
    .cf-viewer-btn svg { width: 28px; height: 28px; }
    .cf-viewer-nav span { font-size: 15px; }
    .cf-viewer-close { font-size: 32px; padding: 0 12px; }
}

/* Toast */
.cf-toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999999; display: flex; flex-direction: column; gap: 8px; }
.cf-toast {
    padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 500;
    color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: cf-fadein 0.3s;
    max-width: 320px;
}
.cf-toast-success { background: #16a34a; }
.cf-toast-error { background: #dc2626; }
.cf-toast-info { background: #1B3A5C; }
@keyframes cf-fadein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile — full screen app feel */
@media (max-width: 600px) {
    .cf-app {
        padding: 8px;
        max-width: 100%;
        margin: 0;
        min-height: 100vh;
        background: #f8fafc;
    }

    /* Compact header */
    .cf-header { margin-bottom: 12px; }
    .cf-title { font-size: 18px; gap: 6px; }
    .cf-title svg { width: 20px; height: 20px; }
    .cf-subtitle { font-size: 11px; margin-top: 2px; }

    /* Card chips — compact horizontal scroll */
    .cf-card-selector { margin-bottom: 10px; }
    .cf-label { font-size: 10px; margin-bottom: 5px; }
    .cf-card-chip { padding: 10px 14px; min-width: 100px; border-radius: 10px; }
    .cf-card-icon { font-size: 20px; }
    .cf-card-name { font-size: 11px; }
    .cf-card-last4 { font-size: 10px; }

    /* Month/Year — compact row */
    .cf-month-row { gap: 6px; margin-bottom: 10px; }
    .cf-select { font-size: 14px; padding: 10px 12px; border-radius: 10px; border-width: 1px; }

    /* Upload zone — compact */
    .cf-upload-zone { padding: 20px 10px; margin-bottom: 12px; border-radius: 12px; border-width: 1.5px; }
    .cf-upload-icon { font-size: 32px; margin-bottom: 4px; }
    .cf-upload-text { font-size: 14px; margin-bottom: 2px; }
    .cf-upload-hint { font-size: 11px; margin-bottom: 12px; }
    .cf-upload-buttons { gap: 8px; }
    .cf-upload-buttons .cf-btn { width: 100%; justify-content: center; padding: 14px 16px; font-size: 15px; border-radius: 10px; }

    /* Buttons — full width touch targets */
    .cf-btn { padding: 12px 16px; font-size: 15px; border-radius: 10px; }
    .cf-btn-sm { padding: 10px 12px; font-size: 13px; }

    /* Progress — compact */
    .cf-progress { padding: 20px 12px; border-radius: 12px; margin-bottom: 12px; }
    .cf-progress-icon { font-size: 28px; }
    .cf-progress-counter { font-size: 13px; }
    .cf-progress-file { font-size: 12px; }
    .cf-batch-results { max-height: 140px; }

    /* Confirm — compact */
    .cf-confirm { padding: 20px 12px; border-radius: 12px; margin-bottom: 12px; }
    .cf-confirm-icon { font-size: 32px; margin-bottom: 6px; }
    .cf-confirm-msg { font-size: 14px; }

    /* History — compact cards */
    .cf-history { margin-bottom: 12px; }
    .cf-history-header { margin-bottom: 8px; }
    .cf-history-title { font-size: 14px; }
    .cf-history-count { font-size: 11px; padding: 3px 8px; }
    .cf-history-list { gap: 6px; }
    .cf-receipt-card { padding: 10px; border-radius: 10px; gap: 10px; }
    .cf-receipt-icon { font-size: 22px; }
    .cf-receipt-name { font-size: 13px; }
    .cf-receipt-meta { font-size: 11px; }
    .cf-receipt-actions .cf-btn-sm { padding: 6px 10px; font-size: 12px; }

    /* Toast — edge to edge */
    .cf-toast-container { left: 8px; right: 8px; bottom: 8px; }
    .cf-toast { max-width: 100%; font-size: 13px; padding: 10px 14px; border-radius: 8px; }

    /* Pagination */
    .cf-page-btn { width: 32px; height: 32px; font-size: 12px; }
}
