/* =========================================================================
   Scheduled Reports page — mobile makeover.
   Same pattern:
     - Title hidden
     - Wrapper cards stripped, sections float free
     - "Novo Agendamento" → purple FAB in the bottom-right
     - Preview Report → full-width secondary in the section header
     - Table → cards with 3-dot ⋯ opening a bottom sheet
     - Test Reports section stacked with a full-width Send Test button
     - New Report + Preview modals full-viewport with sticky bottom actions
   ========================================================================= */

/* Bottom action sheet */
.sr-sheet-wrap { position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: none; }
.sr-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background 0.2s; pointer-events: auto; }
.sr-sheet-wrap.is-open .sr-sheet-backdrop { background: rgba(0,0,0,0.4); }
.sr-sheet { position: relative; background: #fff; border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform 0.22s ease-out; box-shadow: 0 -8px 24px rgba(0,0,0,0.15); pointer-events: auto; max-height: 85vh; overflow-y: auto; }
.sr-sheet-wrap.is-open .sr-sheet { transform: translateY(0); }
.sr-sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #e5e7eb; margin: 4px auto 12px; }
.sr-sheet-title { font-weight: 700; font-size: 0.95rem; color: #111827; text-align: center; margin-bottom: 8px; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sheet-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.sr-sheet-item { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px 8px; border: none; background: transparent; color: #111827; font-size: 0.95rem; font-weight: 500; text-align: left; cursor: pointer; border-radius: 10px; }
.sr-sheet-item:active { background: #f3f4f6; }
.sr-sheet-item.is-danger { color: #991b1b; }
.sr-sheet-icon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sr-sheet-label { flex: 0 0 auto; }
.sr-sheet-divider { height: 1px; background: #f3f4f6; margin: 6px 8px; }
.sr-sheet-cancel { width: 100%; margin-top: 8px; padding: 12px; background: #f3f4f6; border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 600; color: #374151; cursor: pointer; }

@media (max-width: 767px) {

    /* -----------------------------------------------------------------
       Page shell + hide title
       ----------------------------------------------------------------- */
    #scheduled-reports {
        padding: 8px !important;
        padding-bottom: 100px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    #scheduled-reports > .page-header { display: none !important; }

    /* -----------------------------------------------------------------
       Content sections — each becomes a clean rounded white card.
       ----------------------------------------------------------------- */
    #scheduled-reports > .content-section {
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px !important;
        padding: 12px !important;
        margin: 0 0 14px 0 !important;
        box-shadow: none !important;
    }
    #scheduled-reports > .content-section > .section-header {
        display: block !important;
        padding: 4px 4px 10px !important;
        background: transparent !important;
        border: none !important;
        margin: 0 !important;
    }
    #scheduled-reports > .content-section > .section-header > .section-title {
        font-size: 1rem !important;
        font-weight: 700 !important;
        color: #111827 !important;
        margin: 0 0 8px 0 !important;
    }
    /* Header button group (Preview + New Schedule) — stack full-width */
    #scheduled-reports > .content-section > .section-header > div[style*="display: flex"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        margin: 0 !important;
    }
    /* "Pré-visualizar Relatório" secondary button — full-width grey */
    #scheduled-reports .section-header > div > .btn[onclick*="openPreviewModal"] {
        width: 100% !important;
        height: 42px !important;
        border-radius: 10px !important;
        justify-content: center !important;
        font-size: 0.9rem !important;
        margin: 0 !important;
    }
    /* "Novo Agendamento" primary button → purple FAB (fixed, corner) */
    #scheduled-reports .section-header > div > .btn[onclick*="openNewReportModal"] {
        position: fixed !important;
        bottom: 90px !important; right: 16px !important;
        z-index: 900 !important;
        width: 56px !important; height: 56px !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4) !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 0 !important;
        overflow: hidden !important;
    }
    #scheduled-reports .section-header > div > .btn[onclick*="openNewReportModal"] svg {
        width: 22px !important; height: 22px !important; color: #fff !important; margin: 0 !important;
    }
    #scheduled-reports .section-header > div > .btn[onclick*="openNewReportModal"] span { display: none !important; }
    #scheduled-reports .section-header > div > .btn[onclick*="openNewReportModal"]:active { transform: scale(0.95) !important; }

    /* -----------------------------------------------------------------
       Report Schedules table → cards
       Columns: Recipients | Report Type | Schedule | Timezone |
                Last Sent | Status | Actions
       ----------------------------------------------------------------- */
    #scheduled-reports .table-container {
        overflow-x: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }
    #scheduled-reports .data-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #scheduled-reports .data-table thead { display: none !important; }
    #scheduled-reports .data-table tbody { display: flex !important; flex-direction: column !important; gap: 8px !important; }
    #scheduled-reports .data-table tbody tr {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        gap: 6px 12px !important;
        background: #f9fafb !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px !important;
        padding: 12px !important;
    }
    #scheduled-reports .data-table tbody tr:has(td[colspan]) {
        display: block !important;
        text-align: center !important;
        padding: 24px 12px !important;
        color: #9ca3af !important;
    }
    #scheduled-reports .data-table tbody tr:has(td[colspan]) td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        text-align: center !important;
    }
    #scheduled-reports .data-table tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: 0.85rem !important;
        color: #4b5563 !important;
    }
    /* Recipients (col 1) — bold title, top-left */
    #scheduled-reports .data-table tbody td:nth-child(1) {
        grid-row: 1 !important;
        grid-column: 1 !important;
        font-weight: 700 !important;
        color: #111827 !important;
        font-size: 0.9rem !important;
        text-align: left !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(1) small {
        display: block !important;
        font-weight: 500 !important;
        color: #9ca3af !important;
        font-size: 0.75rem !important;
        margin-top: 2px !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(1) br { display: none !important; }
    /* Actions (col 7) — 3-dot in row 1 col 2 */
    #scheduled-reports .data-table tbody td:nth-child(7) {
        grid-row: 1 !important;
        grid-column: 2 !important;
        justify-self: end !important;
        align-self: start !important;
        display: block !important;
    }
    /* Report Type (col 2) — bold + frequency small */
    #scheduled-reports .data-table tbody td:nth-child(2) {
        grid-column: 1 / -1 !important;
        color: #111827 !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(2) small {
        display: inline !important;
        color: #6b7280 !important;
        margin-left: 6px !important;
        font-weight: 500 !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(2) br { display: none !important; }
    /* Schedule (col 3) — muted */
    #scheduled-reports .data-table tbody td:nth-child(3) {
        grid-column: 1 / -1 !important;
        color: #6b7280 !important;
        font-size: 0.8rem !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(3)::before {
        content: "Agendamento: ";
        font-weight: 600 !important;
    }
    /* Timezone (col 4) + Last Sent (col 5) side-by-side small */
    #scheduled-reports .data-table tbody td:nth-child(4) {
        grid-column: 1 !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(4)::before {
        content: "Fuso: ";
        font-weight: 600 !important;
        color: #6b7280 !important;
    }
    #scheduled-reports .data-table tbody td:nth-child(5) {
        grid-column: 2 !important;
        justify-self: end !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    /* Status (col 6) — inline pill full width */
    #scheduled-reports .data-table tbody td:nth-child(6) {
        grid-column: 1 / -1 !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    #scheduled-reports .sr-more-btn {
        width: 36px; height: 36px;
        border: none; background: #f3f4f6; color: #4b5563;
        border-radius: 8px;
        display: inline-flex; align-items: center; justify-content: center;
        cursor: pointer; padding: 0;
    }
    #scheduled-reports .sr-more-btn:active { background: #e5e7eb; }

    /* -----------------------------------------------------------------
       Test Reports section — wrap the whole section in a white card so
       the form elements don't float loose on the grey page background.
       Uses :has(#testReportEmail) to unambiguously target the Testar
       Relatórios section (:nth-of-type(2) counts by element type, not
       class — .page-header is the 1st <div> so nth-of-type(2) matched
       the wrong .content-section).
       ----------------------------------------------------------------- */
    #scheduled-reports > .content-section:has(#testReportEmail) {
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px !important;
        padding: 12px !important;
        margin: 0 0 14px 0 !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) > .section-header {
        padding: 0 !important;
        margin: 0 0 10px 0 !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) > .section-header > .section-title {
        margin: 0 !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) > div[style*="padding"] {
        padding: 0 !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) > div > p {
        font-size: 0.85rem !important;
        margin: 0 0 12px 0 !important;
        color: #6b7280 !important;
    }
    /* The 3-column grid (Email + Type + Send Test) — force single col. */
    #scheduled-reports > .content-section:has(#testReportEmail) > div > div[style*="grid-template-columns"],
    #scheduled-reports > .content-section:has(#testReportEmail) > div > div[style*="grid"] {
        display: block !important;
        grid-template-columns: 1fr !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) .form-group {
        margin-bottom: 10px !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) .form-group:last-child {
        margin-bottom: 0 !important;
    }
    #scheduled-reports > .content-section:has(#testReportEmail) label {
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: #374151 !important;
        display: block !important;
        margin-bottom: 4px !important;
    }
    /* Hide the &nbsp; empty label above Send Test */
    #scheduled-reports > .content-section:has(#testReportEmail) .form-group:last-of-type label {
        display: none !important;
    }
    #scheduled-reports #testReportEmail,
    #scheduled-reports #testReportType {
        width: 100% !important;
        min-height: 42px !important;
        padding: 8px 12px !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        font-size: 0.95rem !important;
        background: #fff !important;
        box-sizing: border-box !important;
    }
    #scheduled-reports #testReportEmail:focus,
    #scheduled-reports #testReportType:focus {
        outline: none !important;
        border-color: #6366f1 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    }
    #scheduled-reports .btn.btn-warning {
        width: 100% !important;
        height: 44px !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        justify-content: center !important;
        background: linear-gradient(135deg, #f59e0b, #d97706) !important;
        color: #fff !important;
        border: none !important;
    }

    /* -----------------------------------------------------------------
       New Report modal + Preview modal — full-viewport frames.
       ----------------------------------------------------------------- */
    #newReportModal.modal,
    #reportPreviewModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #newReportModal .modal-content,
    #reportPreviewModal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        background: #fff !important;
    }
    #newReportModal .modal-header,
    #reportPreviewModal .modal-header {
        padding: 14px 20px !important;
        background: #fff !important;
        color: #111827 !important;
        border-bottom: 1px solid #f3f4f6 !important;
        flex-shrink: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    #newReportModal .modal-header h3,
    #newReportModal .modal-title,
    #reportPreviewModal .modal-header h3,
    #reportPreviewModal .modal-title {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #newReportModal .close,
    #reportPreviewModal .close {
        background: #f3f4f6 !important;
        color: #6b7280 !important;
        border: none !important;
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.15rem !important;
        cursor: pointer !important;
    }
    #newReportModal .modal-body,
    #reportPreviewModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    /* New Report form-grid — stack all cells */
    #newReportModal .form-grid {
        display: block !important;
    }
    /* Nested "Frequency | Time | Timezone" 3-col grid — stack */
    #newReportModal .form-grid > div[style*="grid-template-columns"] {
        display: block !important;
    }
    #newReportModal .form-grid > div[style*="grid-template-columns"] > .form-group {
        margin-bottom: 12px !important;
    }
    #newReportModal .form-group {
        margin-bottom: 12px !important;
    }
    #newReportModal .form-group > label {
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: #374151 !important;
        display: block !important;
        margin-bottom: 4px !important;
    }
    #newReportModal .form-group input:not([type="checkbox"]):not([type="radio"]),
    #newReportModal .form-group select,
    #newReportModal .form-group textarea {
        width: 100% !important;
        min-height: 42px !important;
        padding: 8px 12px !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        font-size: 0.95rem !important;
        background: #fff !important;
        box-sizing: border-box !important;
    }
    #newReportModal .form-group input:focus,
    #newReportModal .form-group select:focus {
        outline: none !important;
        border-color: #6366f1 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    }
    #newReportModal .form-group small {
        display: block !important;
        margin-top: 4px !important;
        font-size: 0.75rem !important;
        color: #6b7280 !important;
    }
    #newReportModal .form-group input[type="checkbox"] {
        width: 18px !important;
        height: 18px !important;
        min-height: 0 !important;
        padding: 0 !important;
        accent-color: #6366f1 !important;
        flex-shrink: 0 !important;
    }
    /* Attachment options — stack */
    #newReportModal .form-group > div[style*="display: flex"][style*="gap: 2rem"] {
        flex-direction: column !important;
        gap: 8px !important;
        margin-top: 6px !important;
    }
    /* Tour filter multi-select — bigger tap target */
    #newReportModal #reportTourIds {
        height: 100px !important;
    }
    /* Recipient row (email + add button) */
    #newReportModal .recipient-row {
        display: flex !important;
        gap: 6px !important;
    }
    #newReportModal .recipient-row .btn {
        width: 42px !important;
        height: 42px !important;
        padding: 0 !important;
        border-radius: 8px !important;
        flex-shrink: 0 !important;
    }

    /* Sticky bottom action row */
    #newReportModal .modal-footer,
    #reportPreviewModal .modal-footer {
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom)) !important;
        background: #fff !important;
        border-top: 1px solid #f3f4f6 !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        justify-content: stretch !important;
        flex-shrink: 0 !important;
    }
    #newReportModal .modal-footer .btn,
    #reportPreviewModal .modal-footer .btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        max-width: none !important;
        width: 50% !important;
        margin: 0 !important;
        padding: 0 8px !important;
        height: 44px !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        font-size: 0.9rem !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    #newReportModal .modal-footer .btn-secondary,
    #reportPreviewModal .modal-footer .btn-secondary {
        background: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #e5e7eb !important;
    }
    #newReportModal .modal-footer .btn-secondary span,
    #reportPreviewModal .modal-footer .btn-secondary span {
        color: #374151 !important;
    }
    #newReportModal .modal-footer .btn-primary {
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: none !important;
    }
    /* Preview modal — Close spans full width */
    #reportPreviewModal .modal-footer .btn {
        width: 100% !important;
    }
    /* Preview modal header controls — stack */
    #reportPreviewModal .modal-body > div[style*="background: #f5f5f5"] > div {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    #reportPreviewModal #previewFrequency {
        width: 100% !important;
        min-height: 42px !important;
        padding: 8px 12px !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        font-size: 0.95rem !important;
        background: #fff !important;
    }
    #reportPreviewModal .modal-body > div > div > .btn {
        width: 100% !important;
        height: 40px !important;
        border-radius: 8px !important;
        justify-content: center !important;
    }
    #reportPreviewModal #reportPreviewContent {
        max-height: none !important;
        flex: 1 !important;
    }
}
