/* =========================================================================
   Service Extras page — mobile makeover.
   Same pattern as Service Categories / User Management: title hidden,
   wrapper stripped, Add button → purple FAB, table → cards with a
   3-dot ⋯ button opening a bottom sheet.
   ========================================================================= */

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

/* Search bar + filter drawer (declared outside media query for consistent
   specificity with base rules). */
#seMobileSearchBar { display: none; }

.se-drawer-wrap { position: fixed; inset: 0; z-index: 10000; }
.se-drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background 0.2s; }
.se-drawer-wrap.is-open .se-drawer-backdrop { background: rgba(0,0,0,0.35); }
.se-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;
}
.se-drawer-wrap.is-open .se-drawer { transform: translateX(0); }
.se-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;
}
.se-drawer-close {
    border: none; background: transparent; font-size: 1.5rem;
    color: #6b7280; cursor: pointer; line-height: 1;
}
.se-drawer-body {
    padding: 1rem 1.15rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.se-drawer-body .form-group > label {
    display: block;
    font-size: 0.85rem; font-weight: 600; color: #374151;
    margin-bottom: 4px;
}
.se-drawer-body .form-group > select {
    width: 100%; min-height: 42px;
    padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 8px;
    background: #fff; font-size: 0.95rem; box-sizing: border-box;
}
.se-drawer-body .form-group.u-flex {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
    display: flex;
}
.se-drawer-body .form-group.u-flex > .btn {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 600;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #e5e7eb;
    cursor: pointer;
}

@media (max-width: 767px) {

    #service-extras {
        padding: 8px !important;
        padding-bottom: 100px !important;
        /* .main-content already has margin-top: 56px for the fixed mobile
           header (mobile-optimized.css). Only reserve space for the fixed
           search bar (~56px) that sits below it. */
        padding-top: 64px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    #service-extras > .page-header { display: none !important; }

    /* Fixed search + filter bar — pinned right below the 56px mobile header. */
    #seMobileSearchBar {
        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;
    }
    #seMobileSearchBar input {
        flex: 1; padding: 0.55rem 0.75rem; border: 1px solid #d1d5db;
        border-radius: 8px; font-size: 0.9rem; background: #fff;
    }
    #seMobileSearchBar .se-filter-btn {
        width: 40px; height: 40px; border-radius: 8px;
        border: 1px solid #d1d5db; background: #fff;
        display: inline-flex; align-items: center; justify-content: center;
        cursor: pointer;
    }

    #service-extras > .content-section {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
    #service-extras > .content-section > .section-header,
    #service-extras > .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-extras > .content-section > .section-header > .section-title { display: none !important; }

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

    /* Table → cards. Columns:
       Name | Category | Price | Max Qty | Available Services | Status | Actions */
    #service-extras .table-container { overflow-x: visible !important; padding: 0 !important; margin: 0 !important; border: none !important; }
    #service-extras .data-table { display: block !important; width: 100% !important; min-width: 0 !important; background: transparent !important; border: none !important; }
    #service-extras .data-table thead { display: none !important; }
    #service-extras .data-table tbody { display: flex !important; flex-direction: column !important; gap: 8px !important; }
    #service-extras .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-extras .data-table tbody tr:has(td[colspan]) {
        display: block !important;
        text-align: center !important;
        padding: 24px 12px !important;
        color: #9ca3af !important;
    }
    #service-extras .data-table tbody tr:has(td[colspan]) td { display: block !important; padding: 0 !important; border: none !important; text-align: center !important; }
    #service-extras .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 — row 1 col 1, bold */
    #service-extras .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;
    }
    /* Actions — row 1 col 2 (3-dot in top-right) */
    #service-extras .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;
    }
    /* Category | Price | Max Qty — inline pills */
    #service-extras .data-table tbody td:nth-child(2)::before {
        content: "Categoria: "; font-weight: 600 !important; color: #6b7280 !important;
    }
    #service-extras .data-table tbody td:nth-child(2),
    #service-extras .data-table tbody td:nth-child(3),
    #service-extras .data-table tbody td:nth-child(4) {
        grid-column: 1 / -1 !important;
        font-size: 0.8rem !important;
    }
    #service-extras .data-table tbody td:nth-child(3)::before {
        content: "Preço: "; font-weight: 600 !important; color: #6b7280 !important;
    }
    #service-extras .data-table tbody td:nth-child(3) { color: #111827 !important; font-weight: 600 !important; }
    #service-extras .data-table tbody td:nth-child(4)::before {
        content: "Qtd. máx.: "; font-weight: 600 !important; color: #6b7280 !important;
    }
    /* Linked services (col 5) — pills */
    #service-extras .data-table tbody td:nth-child(5) { grid-column: 1 / -1 !important; }
    /* Status (col 6) — inline badge */
    #service-extras .data-table tbody td:nth-child(6) {
        grid-column: 1 / -1 !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    #service-extras .se-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-extras .se-more-btn:active { background: #e5e7eb; }

    /* -----------------------------------------------------------------
       Add/Edit Service Extra modal — full-viewport frame with sticky
       bottom action row. Same pattern as the Categories modal.
       ----------------------------------------------------------------- */
    #serviceExtraModal.modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }
    #serviceExtraModal .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;
    }
    /* Kill the purple gradient header, white bg + dark title */
    #serviceExtraModal .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;
    }
    #serviceExtraModal .modal-header h3,
    #serviceExtraModal .modal-title {
        color: #111827 !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    #serviceExtraModal .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;
    }

    /* Body — grey scrolling surface, form fills */
    #serviceExtraModal .modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        overflow-y: auto !important;
        flex: 1 !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    #serviceExtraModal #serviceExtraForm {
        display: flex !important;
        flex-direction: column !important;
        min-height: 100% !important;
    }

    /* Stack the 3-col grid (Price / Qty / Category) into 1 col */
    #serviceExtraModal .form-grid[style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    #serviceExtraModal .form-grid {
        display: block !important;
        margin-bottom: 12px !important;
    }
    #serviceExtraModal .form-grid[style*="grid-template-columns: repeat(3"] {
        display: grid !important;
    }
    /* Form fields — normalize */
    #serviceExtraModal .form-group {
        margin-bottom: 12px !important;
    }
    #serviceExtraModal .form-group > label {
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        color: #374151 !important;
        display: block !important;
        margin-bottom: 4px !important;
    }
    #serviceExtraModal .form-group input:not([type="checkbox"]):not([type="radio"]),
    #serviceExtraModal .form-group select,
    #serviceExtraModal .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;
    }
    #serviceExtraModal .form-group textarea {
        min-height: 70px !important;
        resize: vertical !important;
    }
    #serviceExtraModal .form-group input:focus,
    #serviceExtraModal .form-group select:focus,
    #serviceExtraModal .form-group textarea:focus {
        outline: none !important;
        border-color: #6366f1 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    }
    /* "Service Extra is active" checkbox — keep native size */
    #serviceExtraModal .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;
    }
    /* Tour checkbox list — cleaner box + purple-accent checkboxes */
    #serviceExtraModal #tourCheckboxList {
        background: #fff !important;
        border: 1px solid #d1d5db !important;
        border-radius: 8px !important;
        padding: 10px !important;
        max-height: 260px !important;
    }
    #serviceExtraModal #tourCheckboxList label {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        font-size: 0.9rem !important;
        padding: 6px 4px !important;
    }
    /* Sticky bottom actions (Cancel + Save) */
    #serviceExtraModal #serviceExtraForm > 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;
    }
    #serviceExtraModal #serviceExtraForm > 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;
    }
    #serviceExtraModal .btn-secondary {
        background: #f3f4f6 !important;
        color: #374151 !important;
        border: 1px solid #e5e7eb !important;
    }
    #serviceExtraModal .btn-secondary span {
        color: #374151 !important;
    }
    #serviceExtraModal .btn-success {
        background: linear-gradient(135deg, #667eea, #764ba2) !important;
        color: #fff !important;
        border: none !important;
    }

    /* -----------------------------------------------------------------
       Delete Service Extra confirm modal — full-viewport frame.
       ----------------------------------------------------------------- */
    #deleteServiceExtraModal.modal,
    #deleteServiceExtraModal.status-confirm-modal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
        backdrop-filter: none !important;
    }
    #deleteServiceExtraModal .modal-content,
    #deleteServiceExtraModal .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;
        background: #fff !important;
        box-shadow: none !important;
        animation: none !important;
    }
    #deleteServiceExtraModal .modal-header,
    #deleteServiceExtraModal .status-confirm-modal-header {
        padding: 14px 20px !important;
        background: #fff !important;
        border-bottom: 1px solid #f3f4f6 !important;
        flex-shrink: 0 !important;
    }
    #deleteServiceExtraModal .modal-body,
    #deleteServiceExtraModal .status-confirm-modal-body {
        padding: 14px !important;
        background: #f9fafb !important;
        flex: 1 !important;
        overflow-y: auto !important;
    }
    #deleteServiceExtraModal .modal-footer,
    #deleteServiceExtraModal .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;
    }
    #deleteServiceExtraModal .modal-footer .btn,
    #deleteServiceExtraModal .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;
    }
}
