/* =========================================================================
   Email Logs page — mobile makeover.
   Same pattern:
     - Title hidden
     - Filter card + logs card wrapped as clean cards
     - Table → cards with a 3-dot ⋯ button opening a bottom sheet
     - View Email Log detail modal full-viewport with sticky footer
   ========================================================================= */

/* Mobile-only chrome hidden by default so it can't leak into desktop. */
#elMobileHeader { display: none; }

/* Right-side filter drawer (matches Bookings / Mailbox pattern) — kept
   outside the media query so the slide animation plays at the boundary. */
.el-drawer-wrap { position: fixed; inset: 0; z-index: 10000; }
.el-drawer-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s;
}
.el-drawer-wrap.is-open .el-drawer-backdrop { background: rgba(0, 0, 0, 0.35); }
.el-drawer {
    position: absolute; right: 0; top: 0; bottom: 0;
    width: 88%; max-width: 380px;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.22s ease-out;
    display: flex; flex-direction: column;
}
.el-drawer-wrap.is-open .el-drawer { transform: translateX(0); }
.el-drawer-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 700; font-size: 1.05rem;
    color: #111827;
}
.el-drawer-close {
    border: none; background: transparent; font-size: 1.5rem;
    color: #6b7280; cursor: pointer; line-height: 1;
}
.el-drawer-body {
    padding: 1rem 1.15rem;
    overflow-y: auto; flex: 1;
    display: flex; flex-direction: column;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.el-drawer-body > .form-group {
    display: block !important;
    width: 100% !important;
    margin: 0 0 14px 0 !important;
}
.el-drawer-body > .form-group > label {
    font-size: 0.85rem !important;
    font-weight: 700 !important;
    color: #111827 !important;
    margin-bottom: 6px !important;
    display: block !important;
}
.el-drawer-body select,
.el-drawer-body input {
    width: 100% !important;
    min-height: 42px !important;
    padding: 8px 12px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    background: #fff !important;
    font-size: 0.95rem !important;
    box-sizing: border-box !important;
}
.el-drawer-body .form-group > div[style*="display: flex"] {
    display: flex !important;
    gap: 8px !important;
}
/* Buttons row at the bottom (Refresh + Clear) — sticky, full-width */
.el-drawer-body > .form-group:last-child {
    margin-top: auto !important;
    padding-top: 12px !important;
    border-top: 1px solid #f3f4f6;
    margin-bottom: 0 !important;
}
.el-drawer-body > .form-group:last-child > label {
    display: none !important;
}
.el-drawer-body > .form-group:last-child button {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    height: 42px !important;
    border-radius: 10px !important;
    background: #f3f4f6 !important;
    color: #374151 !important;
    border: 1px solid #e5e7eb !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    padding: 0 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    white-space: nowrap !important;
}

/* Bottom action sheet */
.el-sheet-wrap { position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: none; }
.el-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background 0.2s; pointer-events: auto; }
.el-sheet-wrap.is-open .el-sheet-backdrop { background: rgba(0,0,0,0.4); }
.el-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; }
.el-sheet-wrap.is-open .el-sheet { transform: translateY(0); }
.el-sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #e5e7eb; margin: 4px auto 12px; }
.el-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; }
.el-sheet-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.el-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; }
.el-sheet-item:active { background: #f3f4f6; }
.el-sheet-icon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.el-sheet-label { flex: 0 0 auto; }
.el-sheet-divider { height: 1px; background: #f3f4f6; margin: 6px 8px; }
.el-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 — leave room for the fixed top search bar.
       Matches Bookings/Mailbox: 56px app header + 56px search bar.
       ----------------------------------------------------------------- */
    #email-logs {
        padding-top: 56px !important;
        padding-bottom: 90px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    /* Hide the whole desktop filter card. Contents are relocated into
       the drawer on demand by email-logs-mobile.js. */
    #email-logs > .modern-content-card.u-mb-4 {
        display: none !important;
    }

    /* -----------------------------------------------------------------
       Fixed mobile search + funnel bar
       ----------------------------------------------------------------- */
    #elMobileHeader {
        display: flex !important;
        gap: 8px;
        position: fixed !important;
        top: 56px; left: 0; right: 0;
        z-index: 990;
        padding: 8px 12px;
        background: #fff;
        border-bottom: 1px solid #e5e7eb;
    }
    #elMobileHeader #elMobileSearch {
        flex: 1;
        height: 40px;
        padding: 8px 12px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        font-size: 0.9rem;
        background: #fff;
        color: #111827;
        outline: none;
    }
    #elMobileHeader #elMobileSearch:focus { border-color: #6366f1; }
    #elMobileHeader .el-filter-btn {
        flex-shrink: 0;
        width: 40px; height: 40px;
        border-radius: 8px;
        border: 1px solid #d1d5db;
        background: #fff;
        color: #4b5563;
        display: inline-flex;
        align-items: center; justify-content: center;
        cursor: pointer;
        position: relative;
    }
    #elMobileHeader .el-filter-btn[data-has-filters="1"]::after {
        content: "";
        position: absolute; top: 6px; right: 6px;
        width: 8px; height: 8px;
        border-radius: 50%;
        background: #6366f1;
    }

    /* -----------------------------------------------------------------
       Logs card — flat wrapper, section title compact
       ----------------------------------------------------------------- */
    #email-logs > .modern-content-card:last-of-type {
        padding: 12px !important;
    }
    #email-logs .modern-section-header {
        display: block !important;
        padding: 0 !important;
        margin: 0 0 10px 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #email-logs .modern-section-title {
        font-size: 1rem !important;
        font-weight: 700 !important;
        color: #111827 !important;
        margin: 0 !important;
    }
    /* Customer filter chip — keep visible + tight */
    #email-logs #emailLogsCustomerFilterChip {
        margin-bottom: 10px !important;
    }
    #email-logs #logsLoadingState {
        padding: 24px 12px !important;
        font-size: 0.85rem !important;
    }

    /* -----------------------------------------------------------------
       Logs table → cards
       Columns: Date | Template | Recipient | Subject | Status | Booking | Actions
       ----------------------------------------------------------------- */
    #email-logs .table-container {
        overflow-x: visible !important;
        padding: 0 !important;
        border: none !important;
    }
    #email-logs #logsTable {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #email-logs #logsTable thead { display: none !important; }
    #email-logs #logsTable tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    #email-logs #logsTable 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;
    }
    #email-logs #logsTable tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: 0.85rem !important;
        color: #4b5563 !important;
    }
    /* Subject (col 4) — bold title, row 1 col 1 */
    #email-logs #logsTable tbody td:nth-child(4) {
        grid-row: 1 !important;
        grid-column: 1 !important;
        font-weight: 700 !important;
        color: #111827 !important;
        font-size: 0.9rem !important;
        overflow-wrap: anywhere !important;
        white-space: normal !important;
    }
    /* Actions (col 7) — 3-dot in row 1 col 2 */
    #email-logs #logsTable tbody td:nth-child(7) {
        grid-row: 1 !important;
        grid-column: 2 !important;
        justify-self: end !important;
        align-self: start !important;
        display: block !important;
    }
    /* Recipient (col 3) — muted, full width */
    #email-logs #logsTable tbody td:nth-child(3) {
        grid-column: 1 / -1 !important;
        color: #6b7280 !important;
        overflow-wrap: anywhere !important;
    }
    /* Date (col 1) — small footer */
    #email-logs #logsTable tbody td:nth-child(1) {
        grid-column: 1 !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    /* Booking (col 6) — small right side */
    #email-logs #logsTable tbody td:nth-child(6) {
        grid-column: 2 !important;
        justify-self: end !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    /* Template (col 2) — inline pill */
    #email-logs #logsTable tbody td:nth-child(2) {
        grid-column: 1 !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    /* Status (col 5) — inline pill */
    #email-logs #logsTable tbody td:nth-child(5) {
        grid-column: 2 !important;
        justify-self: end !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    /* Badges compact */
    #email-logs .template-badge,
    #email-logs .status-badge {
        font-size: 0.7rem !important;
        padding: 2px 8px !important;
        border-radius: 999px !important;
    }

    #email-logs .el-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;
    }
    #email-logs .el-more-btn:active { background: #e5e7eb; }

    /* Pagination — stack */
    #email-logs .email-logs-pagination {
        flex-direction: column !important;
        gap: 8px !important;
        padding: 12px 0 0 !important;
        font-size: 0.8rem !important;
        border-top: 1px solid #f3f4f6 !important;
        margin-top: 10px !important;
    }
    #email-logs .pagination-controls {
        justify-content: center !important;
    }

    /* -----------------------------------------------------------------
       Email Log Details modal — full-viewport
       ----------------------------------------------------------------- */
    #emailLogModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #emailLogModal .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;
    }
    #emailLogModal .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;
    }
    #emailLogModal .modal-header h3,
    #emailLogModal .modal-title {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #emailLogModal .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;
    }
    #emailLogModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    #emailLogModal .modal-body pre,
    #emailLogModal .modal-body code {
        white-space: pre-wrap !important;
        word-break: break-word !important;
    }
    #emailLogModal .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;
    }
    #emailLogModal .modal-footer .btn,
    #emailLogModal .modal-footer #emailLogDownloadSlot > .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;
    }
    #emailLogModal .modal-footer #emailLogDownloadSlot {
        flex: 1 1 0 !important;
        display: flex !important;
        min-width: 0 !important;
    }
    #emailLogModal .modal-footer .btn-secondary {
        background: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #e5e7eb !important;
    }
}
