/* =========================================================================
   Service Categories page — mobile makeover.
   Scoped to #service-categories, fires under 768px. Same pattern as
   Partners / User Management / Mass Mailing:
     - Title hidden
     - Wrapper card removed, cards float free
     - "Add Category" → purple FAB in the bottom-right
     - Table → cards (Name / Description / Linked Services / Count)
     - Row actions → 3-dot ⋯ button opening a bottom sheet
     - Add/Edit modal + Delete confirmation full-viewport
   ========================================================================= */

/* Bottom action sheet — matches the other pages' sheet style. */
.sc-sheet-wrap {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; flex-direction: column; justify-content: flex-end;
    pointer-events: none;
}
.sc-sheet-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s;
    pointer-events: auto;
}
.sc-sheet-wrap.is-open .sc-sheet-backdrop { background: rgba(0, 0, 0, 0.4); }
.sc-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;
}
.sc-sheet-wrap.is-open .sc-sheet { transform: translateY(0); }
.sc-sheet-handle {
    width: 40px; height: 4px;
    border-radius: 2px;
    background: #e5e7eb;
    margin: 4px auto 12px;
}
.sc-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;
}
.sc-sheet-list {
    display: flex; flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}
.sc-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;
}
.sc-sheet-item:active { background: #f3f4f6; }
.sc-sheet-item.is-danger { color: #991b1b; }
.sc-sheet-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sc-sheet-label { flex: 0 0 auto; }
.sc-sheet-divider {
    height: 1px;
    background: #f3f4f6;
    margin: 6px 8px;
}
.sc-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;
}

/* Mobile search bar (declared outside the media query so it participates
   in specificity with base rules; hidden by default and revealed inside
   the mobile media query below). */
#scMobileSearchBar { display: none; }

@media (max-width: 767px) {

    /* -----------------------------------------------------------------
       Page shell + hide title.
       ----------------------------------------------------------------- */
    #service-categories {
        padding: 8px !important;
        padding-bottom: 100px !important;
        /* .main-content already gives 56px top margin for the fixed mobile
           header; reserve extra room for the search bar (~56px). */
        padding-top: 64px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    #service-categories > .page-header {
        display: none !important;
    }

    /* Fixed search bar — pinned right below the 56px mobile header. */
    #scMobileSearchBar {
        display: flex !important; gap: 0.5rem;
        padding: 0.55rem 0.75rem;
        position: fixed !important; top: 56px; left: 0; right: 0;
        z-index: 990;
        background: #ffffff;
        border-bottom: 1px solid #e5e7eb;
    }
    #scMobileSearchBar input {
        flex: 1; padding: 0.55rem 0.75rem; border: 1px solid #d1d5db;
        border-radius: 8px; font-size: 0.9rem; background: #fff;
    }

    /* -----------------------------------------------------------------
       Content section wrapper — kill background/border so cards float.
       Section-header collapsed (title hidden). Add Category becomes FAB.
       ----------------------------------------------------------------- */
    #service-categories > .content-section {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
    /* Collapse section header. Add-Category button lives inside — we
       reposition it as a fixed FAB, so the header can shrink to 0. */
    #service-categories > .content-section > .section-header,
    #service-categories > .content-section > div:first-of-type {
        display: block !important;
        height: 0 !important;
        min-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        background: transparent !important;
        overflow: visible !important;
    }
    #service-categories > .content-section > .section-header > .section-title {
        display: none !important;
    }

    /* "Add Category" button → purple rounded-square FAB. */
    #service-categories > .content-section > .section-header > .btn.btn-primary {
        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;
        cursor: pointer !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 0 !important;
        overflow: hidden !important;
    }
    #service-categories > .content-section > .section-header > .btn.btn-primary svg {
        width: 22px !important;
        height: 22px !important;
        color: #fff !important;
        margin: 0 !important;
    }
    #service-categories > .content-section > .section-header > .btn.btn-primary span {
        display: none !important;
    }
    #service-categories > .content-section > .section-header > .btn.btn-primary:active {
        transform: scale(0.95) !important;
    }

    /* -----------------------------------------------------------------
       Categories table → cards.
       Columns: Name | Description | Linked Services | Count | Actions
       ----------------------------------------------------------------- */
    #service-categories .table-container {
        overflow-x: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }
    #service-categories .data-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        background: transparent !important;
        border: none !important;
    }
    #service-categories .data-table thead {
        display: none !important;
    }
    #service-categories .data-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    #service-categories .data-table tbody tr {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        gap: 6px 12px !important;
        background: #fff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px !important;
        padding: 12px !important;
    }
    #service-categories .data-table tbody tr:has(td[colspan]) {
        display: block !important;
        text-align: center !important;
        padding: 24px 12px !important;
        color: #9ca3af !important;
    }
    #service-categories .data-table tbody tr:has(td[colspan]) td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        text-align: center !important;
    }
    #service-categories .data-table tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: 0.85rem !important;
        color: #4b5563 !important;
    }
    /* Name (col 1) — bold title, top row, next to actions */
    #service-categories .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.95rem !important;
        text-align: left !important;
    }
    /* Description (col 2) — full width, muted */
    #service-categories .data-table tbody td:nth-child(2) {
        grid-column: 1 / -1 !important;
        color: #6b7280 !important;
        font-size: 0.85rem !important;
    }
    /* Linked services (col 3) — pill row */
    #service-categories .data-table tbody td:nth-child(3) {
        grid-column: 1 / -1 !important;
    }
    /* Services count (col 4) — small footer */
    #service-categories .data-table tbody td:nth-child(4) {
        grid-column: 1 / -1 !important;
        font-size: 0.75rem !important;
        color: #9ca3af !important;
        font-weight: 500 !important;
    }
    /* Actions cell (col 5) — floated as a 3-dot button in the top-right
       corner of the card. JS injects <button.sc-more-btn>; the original
       Edit/Delete icons are removed from the DOM. */
    #service-categories .data-table tbody td:nth-child(5) {
        grid-row: 1 !important;
        grid-column: 2 !important;
        justify-self: end !important;
        align-self: start !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }
    #service-categories .sc-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;
    }
    #service-categories .sc-more-btn:active { background: #e5e7eb; }

    /* -----------------------------------------------------------------
       Add/Edit Category modal — full-viewport frame with sticky bottom.
       ----------------------------------------------------------------- */
    #categoryModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #categoryModal .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;
    }
    #categoryModal .modal-header {
        padding: 14px 20px !important;
        background: #fff !important;
        border-bottom: 1px solid #f3f4f6 !important;
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        border-radius: 0 !important;
    }
    #categoryModal .modal-header h2 {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #categoryModal .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;
    }
    #categoryModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    #categoryModal #categoryForm {
        display: flex !important;
        flex-direction: column !important;
        min-height: 100% !important;
    }
    #categoryModal .form-group {
        margin-bottom: 14px !important;
    }
    #categoryModal .form-group > label {
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: #374151 !important;
        display: block !important;
        margin-bottom: 4px !important;
    }
    #categoryModal .form-group input:not([type="checkbox"]):not([type="radio"]),
    #categoryModal .form-group select,
    #categoryModal .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;
    }
    #categoryModal .form-group textarea {
        min-height: 80px !important;
        resize: vertical !important;
    }
    #categoryModal .form-group input:focus,
    #categoryModal .form-group textarea:focus {
        outline: none !important;
        border-color: #6366f1 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    }
    /* Linked services checkbox list — cleaner box */
    #categoryModal #categoryLinkedServicesCheckboxes {
        background: #fff !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        padding: 10px !important;
        max-height: 250px !important;
    }
    #categoryModal #categoryLinkedServicesCheckboxes label {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        font-size: 0.9rem !important;
        padding: 6px 4px !important;
    }
    #categoryModal #categoryLinkedServicesCheckboxes input[type="checkbox"] {
        width: 18px !important;
        height: 18px !important;
        accent-color: #6366f1 !important;
        flex-shrink: 0 !important;
    }

    /* Sticky bottom action row (Cancel + Save) */
    #categoryModal #categoryForm > div[style*="justify-content: flex-end"]:last-child {
        margin: auto -14px 0 !important;
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom)) !important;
        position: sticky !important;
        bottom: 0 !important;
        background: #fff !important;
        border-top: 1px solid #f3f4f6 !important;
        display: flex !important;
        gap: 8px !important;
        justify-content: stretch !important;
        z-index: 5 !important;
    }
    #categoryModal #categoryForm > div[style*="justify-content: flex-end"]:last-child > .btn {
        flex: 1 1 calc(50% - 4px) !important;
        max-width: calc(50% - 4px) !important;
        margin: 0 !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;
    }
    #categoryModal .btn-danger {
        background: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #e5e7eb !important;
    }
    #categoryModal .btn-success {
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: none !important;
    }

    /* -----------------------------------------------------------------
       Delete Category confirm modal — full-viewport frame.
       ----------------------------------------------------------------- */
    #deleteCategoryConfirmModal.status-confirm-modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
        backdrop-filter: none !important;
    }
    #deleteCategoryConfirmModal .status-confirm-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;
        box-shadow: none !important;
        background: #fff !important;
        animation: none !important;
    }
    #deleteCategoryConfirmModal .status-confirm-modal-header {
        padding: 14px 20px !important;
        background: #fff !important;
        border-bottom: 1px solid #f3f4f6 !important;
        flex-shrink: 0 !important;
    }
    #deleteCategoryConfirmModal .status-confirm-modal-header h3 {
        font-size: 1.05rem !important;
        color: #111827 !important;
        margin: 0 !important;
    }
    #deleteCategoryConfirmModal .status-confirm-modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        flex: 1 !important;
        overflow-y: auto !important;
    }
    #deleteCategoryConfirmModal .status-confirm-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;
        gap: 8px !important;
        justify-content: stretch !important;
        flex-shrink: 0 !important;
    }
    #deleteCategoryConfirmModal .status-confirm-modal-footer .btn {
        flex: 1 1 calc(50% - 4px) !important;
        max-width: calc(50% - 4px) !important;
        height: 44px !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        font-size: 0.9rem !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}
