/* =========================================================================
   Activity Logs page — mobile makeover.
   Mirrors email-logs-mobile.css pattern:
     - Desktop filter card hidden; fixed top bar (search + funnel) shown
     - Funnel opens a right-side drawer that relocates the filter fields
     - Table → cards
     - Details modal → full-viewport with sticky bottom row
   ========================================================================= */

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

/* Right-side filter drawer (matches email-logs / Bookings pattern) — kept
   outside the media query so the slide animation plays at the boundary. */
.al-drawer-wrap { position: fixed; inset: 0; z-index: 10000; }
.al-drawer-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s;
}
.al-drawer-wrap.is-open .al-drawer-backdrop { background: rgba(0, 0, 0, 0.35); }
.al-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;
}
.al-drawer-wrap.is-open .al-drawer { transform: translateX(0); }
.al-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;
}
.al-drawer-close {
    border: none; background: transparent; font-size: 1.5rem;
    color: #6b7280; cursor: pointer; line-height: 1;
}
.al-drawer-body {
    padding: 1rem 1.15rem;
    overflow-y: auto; flex: 1;
    display: flex; flex-direction: column;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.al-drawer-body > .form-group {
    display: block !important;
    width: 100% !important;
    margin: 0 0 14px 0 !important;
}
.al-drawer-body > .form-group > label {
    font-size: 0.85rem !important;
    font-weight: 700 !important;
    color: #111827 !important;
    margin-bottom: 6px !important;
    display: block !important;
}
.al-drawer-body select,
.al-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;
}
.al-drawer-body .form-group > div[style*="display: flex"] {
    display: flex !important;
    gap: 8px !important;
}
/* Refresh button at bottom — sticky, full-width */
.al-drawer-body > .form-group:last-child {
    margin-top: auto !important;
    padding-top: 12px !important;
    border-top: 1px solid #f3f4f6;
    margin-bottom: 0 !important;
}
.al-drawer-body > .form-group:last-child > label {
    display: none !important;
}
.al-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;
}

@media (max-width: 767px) {

    /* ---------------------------------------------------------------
       Page shell — leave room for the fixed top search bar.
       Matches email-logs: 56px app header + 56px search bar reserved.
       --------------------------------------------------------------- */
    #activity-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 activity-logs-mobile.js. */
    #activity-logs > .modern-content-card.u-mb-4 {
        display: none !important;
    }

    /* Fixed mobile search + funnel bar (mirrors email-logs pattern). */
    #alMobileHeader {
        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;
    }
    #alMobileHeader #alMobileSearch {
        flex: 1;
        height: 40px;
        padding: 8px 12px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        font-size: 0.9rem;
        background: #fff;
        color: #111827;
        outline: none;
    }
    #alMobileHeader #alMobileSearch:focus { border-color: #6366f1; }
    #alMobileHeader .al-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;
    }
    #alMobileHeader .al-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
       --------------------------------------------------------------- */
    #activity-logs > .modern-content-card:last-of-type {
        padding: 12px !important;
    }
    #activity-logs .modern-section-header {
        display: block !important;
        padding: 0 !important;
        margin: 0 0 10px 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #activity-logs .modern-section-title {
        font-size: 1rem !important;
        font-weight: 700 !important;
        color: #111827 !important;
        margin: 0 !important;
    }
    #activity-logs #alLoadingState {
        padding: 24px 12px !important;
        font-size: 0.85rem !important;
    }

    /* ---------------------------------------------------------------
       Table → cards.
       Columns rendered by activity-logs.js:
         1) Date & Time
         2) User
         3) Action  (template-badge)
         4) Entity
         5) Description + status
         6) Actions (view details button)
       --------------------------------------------------------------- */
    #activity-logs .table-container {
        overflow-x: visible !important;
        padding: 0 !important;
        border: none !important;
    }
    #activity-logs #alTable {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #activity-logs #alTable thead { display: none !important; }
    #activity-logs #alTable tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    #activity-logs #alTable 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;
    }
    #activity-logs #alTable tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: 0.85rem !important;
        color: #4b5563 !important;
    }
    /* Description (col 5) — bold title, row 1 col 1 */
    #activity-logs #alTable tbody td:nth-child(5) {
        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 6) — view button, top-right */
    #activity-logs #alTable tbody td:nth-child(6) {
        grid-row: 1 !important;
        grid-column: 2 !important;
        justify-self: end !important;
        align-self: start !important;
        display: block !important;
    }
    /* User (col 2) — muted, full width */
    #activity-logs #alTable tbody td:nth-child(2) {
        grid-column: 1 / -1 !important;
        color: #6b7280 !important;
        overflow-wrap: anywhere !important;
        font-size: 0.85rem !important;
    }
    /* Date (col 1) — small footer */
    #activity-logs #alTable tbody td:nth-child(1) {
        grid-column: 1 !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    /* Entity (col 4) — small right side */
    #activity-logs #alTable tbody td:nth-child(4) {
        grid-column: 2 !important;
        justify-self: end !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
    }
    /* Action pill (col 3) — inline badge */
    #activity-logs #alTable tbody td:nth-child(3) {
        grid-column: 1 !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    /* Badge compact */
    #activity-logs .template-badge {
        font-size: 0.7rem !important;
        padding: 2px 8px !important;
        border-radius: 999px !important;
    }

    /* Pagination — stack */
    #activity-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;
    }
    #activity-logs .pagination-controls {
        justify-content: center !important;
    }

    /* ---------------------------------------------------------------
       Log Details modal — full-viewport, matches email-logs modal.
       --------------------------------------------------------------- */
    #activityLogDetailsModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #activityLogDetailsModal .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;
    }
    #activityLogDetailsModal .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;
    }
    #activityLogDetailsModal .modal-header h2 {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #activityLogDetailsModal .close-modal {
        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;
    }
    #activityLogDetailsModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    #activityLogDetailsModal .modal-body pre,
    #activityLogDetailsModal .modal-body code {
        white-space: pre-wrap !important;
        word-break: break-word !important;
    }
    /* Compact tables inside the modal so wide "changes" don't overflow */
    #activityLogDetailsModal .modal-body table {
        font-size: 0.8rem !important;
    }
    #activityLogDetailsModal .modal-body table td,
    #activityLogDetailsModal .modal-body table th {
        padding: 4px 6px !important;
        word-break: break-word !important;
    }
}
