/*
 * ACCESS.AL — Unified Popup System v2
 * Standardizes ALL manager popups (grabber-sheet, modal-overlay, hk-modal)
 * Desktop: identical centered dialogs with close button, no grabber
 * Mobile: beautiful bottom-sheet with 32×4 px grabber (navbar-matching), no X close
 */

/* ══════════════════════════════════════════════
   0.  DESIGN TOKENS
   ══════════════════════════════════════════════ */
:root {
    --popup-overlay:    rgba(15, 23, 42, 0.56);
    --popup-surface:    #ffffff;
    --popup-border:     rgba(148, 163, 184, 0.15);
    --popup-grabber:    #94a3b8;
    --popup-shadow-m:   0 -8px 32px rgba(15, 23, 42, 0.22);
    --popup-shadow-d:   0 16px 48px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(255,255,255,0.06);
    --popup-radius-m:   32px;
    --popup-radius-d:   20px;
    --popup-ease:       cubic-bezier(0.22, 1, 0.36, 1);
}

/* ══════════════════════════════════════════════
   1.  SCROLL LOCK
   ══════════════════════════════════════════════ */
html.popup-lock,
html.popup-lock body {
    overflow: hidden !important;
    overscroll-behavior: none !important;
    touch-action: none;
}

/* ══════════════════════════════════════════════
   2.  OVERLAY — unified backdrop
   ══════════════════════════════════════════════ */
.sheet-overlay,
.modal-overlay,
.hk-modal-overlay,
.modal-backdrop,
.al-modal-backdrop,
.bottom-sheet-overlay,
.pay-modal-overlay,
.res-detail-overlay,
.tr-modal {
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
}

/* ══════════════════════════════════════════════
   3.  GRABBER BAR — 48×6 px pill, Figma-matching
       Overrides all per-page variants
   ══════════════════════════════════════════════ */
.sheet-grabber {
    width: 100%;
    height: 36px !important;
    padding: 12px 0 14px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.sheet-grabber::before {
    content: '' !important;
    width: 48px !important;
    height: 6px !important;
    background: var(--border-color, var(--text-muted, var(--popup-grabber))) !important;
    opacity: 0.35 !important;
    border-radius: 99px !important;
    transition: none !important;
    transform: none !important;
    pointer-events: none;
}

/* res-detail-handle — 48×6 px pill grabber */
.res-detail-handle {
    width: 48px !important;
    height: 6px !important;
    background: var(--border-color, var(--text-muted, var(--popup-grabber))) !important;
    opacity: 0.35 !important;
    border-radius: 99px !important;
    margin: 12px auto 0 !important;
    pointer-events: none;
}

/* staff.php uses .modal-grabber instead of .sheet-grabber::before */
.modal-grabber {
    width: 48px !important;
    height: 6px !important;
    background: var(--border-color, var(--text-muted, var(--popup-grabber))) !important;
    opacity: 0.35 !important;
    border-radius: 99px !important;
    margin: 12px auto 6px !important;
    pointer-events: none;
}

/* ══════════════════════════════════════════════
   4.  CLOSE BUTTON — unified pill/circle
       Covers ALL close button variants across the app
   ══════════════════════════════════════════════ */
.sheet-close,
.modal-close,
.hk-modal-close,
.crop-modal-close,
.side-panel-close,
.glass-sheet-close,
.sm-logo-modal-close,
.res-detail-close,
.fp-modal-x,
.tr-modal-close {
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    border: none !important;
    background: var(--bg-tertiary, rgba(148,163,184,0.12)) !important;
    color: var(--text-secondary, #475569) !important;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.sheet-close:hover,
.modal-close:hover,
.hk-modal-close:hover,
.crop-modal-close:hover,
.side-panel-close:hover,
.glass-sheet-close:hover,
.res-detail-close:hover,
.fp-modal-x:hover,
.tr-modal-close:hover {
    background: var(--bg-hover, rgba(148,163,184,0.2)) !important;
    color: var(--text-primary, #0f172a) !important;
}

.sheet-close:active,
.modal-close:active,
.hk-modal-close:active,
.res-detail-close:active,
.fp-modal-x:active,
.tr-modal-close:active {
    transform: scale(0.93);
}

/* ══════════════════════════════════════════════
   5.  HEADER — consistent typography & spacing
   ══════════════════════════════════════════════ */
.sheet-header,
.modal-header,
.hk-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border-color, var(--popup-border));
}

.sheet-header h3,
.modal-header h3,
.hk-modal-title {
    font-size: 17px !important;
    font-weight: 700 !important;
    color: var(--text-primary, #0f172a);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sheet-header h3 i,
.modal-header h3 i {
    font-size: 18px;
}

/* ══════════════════════════════════════════════
   6.  FOOTER — consistent
   ══════════════════════════════════════════════ */
.sheet-footer,
.modal-footer,
.hk-modal-footer {
    border-top: 1px solid var(--border-color, var(--popup-border));
}

/* ══════════════════════════════════════════════
   7.  POPUP CONTAINER — shared base surface
   ══════════════════════════════════════════════ */
.grabber-sheet,
.modal-overlay > .modal-content,
.hk-modal,
.modal-overlay > .modal,
.modal-backdrop > .modal,
.al-modal,
.modal-overlay > .success-modal,
.pay-modal-overlay > .pay-modal-box,
.res-detail-panel,
.tr-modal-card {
    background: var(--bg-card, var(--bg-secondary, var(--popup-surface)));
    color: var(--text-primary, #0f172a);
}

/* ══════════════════════════════════════════════
   8.  MOBILE  (< 768 px)
       Bottom-sheet, grabber visible, NO close X
   ══════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    /* ── Hide ALL close buttons on mobile ── */
    .sheet-close,
    .modal-close,
    .hk-modal-close,
    .crop-modal-close,
    .side-panel-close,
    .glass-sheet-close,
    .sm-logo-modal-close,
    .res-detail-close,
    .fp-modal-x,
    .tr-modal-close {
        display: none !important;
    }

    /* ── Consistent bottom-sheet radius ── */
    .grabber-sheet,
    .modal-overlay > .modal-content,
    .hk-modal,
    .modal-overlay > .modal,
    .modal-backdrop > .modal,
    .al-modal,
    .modal-overlay > .success-modal,
    .pay-modal-overlay > .pay-modal-box,
    .res-detail-panel,
    .tr-modal-card {
        border-radius: var(--popup-radius-m) var(--popup-radius-m) 0 0 !important;
        box-shadow: var(--popup-shadow-m) !important;
    }

    /* ── Overlays align to bottom ── */
    .sheet-overlay.open,
    .modal-overlay.open,
    .modal-overlay.active,
    .hk-modal-overlay.open,
    .modal-backdrop.active,
    .al-modal-backdrop,
    .bottom-sheet-overlay.open,
    .pay-modal-overlay.open,
    .pay-modal-overlay.active,
    .res-detail-overlay.open {
        align-items: flex-end !important;
        justify-content: center;
    }

    .modal-overlay,
    .modal-backdrop,
    .hk-modal-overlay,
    .al-modal-backdrop,
    .pay-modal-overlay,
    .res-detail-overlay,
    .tr-modal {
        padding: 0 !important;
    }

    /* ── res-detail → bottom-sheet on mobile ── */
    .res-detail-overlay {
        align-items: flex-end !important;
    }
    .res-detail-panel {
        width: 100% !important;
        max-width: 100% !important;
        transform: translateY(100%);
        transition: transform 0.35s var(--popup-ease);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .res-detail-overlay.open .res-detail-panel {
        transform: translateY(0);
    }

    /* ── tr-modal → bottom-sheet on mobile ── */
    .tr-modal {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .tr-modal-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: var(--popup-radius-m) var(--popup-radius-m) 0 0 !important;
        border: none !important;
        max-height: 92vh !important;
        max-height: 92dvh !important;
        overflow-y: auto;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    /* Pseudo-grabber for tr-modal on mobile */
    .tr-modal-card::before {
        content: '' !important;
        display: block !important;
        width: 48px;
        height: 6px;
        border-radius: 99px;
        background: var(--border-color, var(--popup-grabber));
        opacity: 0.35;
        margin: 12px auto 6px;
        pointer-events: none;
    }

    /* ── HK modal → bottom-sheet on mobile ── */
    .hk-modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .hk-modal {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        max-height: 92vh !important;
        max-height: 92dvh !important;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform 0.3s var(--popup-ease);
    }
    .hk-modal-overlay.open .hk-modal {
        transform: translateY(0);
    }
    /* Pseudo-grabber for HK modals on mobile */
    .hk-modal::before {
        content: '' !important;
        display: block !important;
        width: 48px;
        height: 6px;
        border-radius: 99px;
        background: var(--border-color, var(--popup-grabber));
        opacity: 0.35;
        margin: 12px auto 6px;
        pointer-events: none;
    }
    .hk-modal-header {
        padding-top: 4px !important;
    }

    /* ── Pseudo-grabber for plain .modal/.modal-content ── */
    .modal-overlay > .modal-content::before,
    .modal-overlay > .modal::before,
    .modal-backdrop > .modal::before,
    .al-modal::before,
    .modal-overlay > .success-modal::before,
    .pay-modal-overlay > .pay-modal-box::before {
        content: '' !important;
        display: block !important;
        width: 48px;
        height: 6px;
        border-radius: 99px;
        background: var(--border-color, var(--text-muted, var(--popup-grabber)));
        opacity: 0.35;
        margin: 12px auto 6px;
        pointer-events: none;
    }

    /* ── Sheet header: remove top padding since grabber is above ── */
    .sheet-header {
        padding-top: 0 !important;
    }
    .modal-header {
        padding-top: 4px !important;
    }

    /* ── Safe-area for notched phones ── */
    .grabber-sheet,
    .modal-overlay > .modal-content,
    .hk-modal {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* ── Drag feedback: sheet follows finger ── */
    .grabber-sheet.popup-dragging,
    .modal-overlay > .modal-content.popup-dragging,
    .hk-modal.popup-dragging,
    .res-detail-panel.popup-dragging,
    .tr-modal-card.popup-dragging,
    .bottom-sheet.popup-dragging {
        transition: none !important;
    }
}

/* ══════════════════════════════════════════════
   9.  DESKTOP  (≥ 768 px)
       Centered dialog, close button, no grabber
   ══════════════════════════════════════════════ */
@media (min-width: 768px) {

    /* ── Hide grabbers on desktop ── */
    .sheet-grabber,
    .modal-grabber,
    .res-detail-handle {
        display: none !important;
    }

    /* ── HK pseudo-grabber hidden on desktop ── */
    .hk-modal::before {
        content: none !important;
        display: none !important;
    }
    /* ── Pseudo-grabber for modals hidden ── */
    .modal-overlay > .modal-content::before,
    .modal-overlay > .modal::before,
    .modal-backdrop > .modal::before,
    .al-modal::before,
    .modal-overlay > .success-modal::before,
    .pay-modal-overlay > .pay-modal-box::before {
        content: none !important;
        display: none !important;
    }
    /* ── tr-modal pseudo-grabber hidden on desktop ── */
    .tr-modal-card::before {
        content: none !important;
        display: none !important;
    }

    /* ── Show ALL close buttons on desktop ── */
    .sheet-close,
    .modal-close,
    .hk-modal-close,
    .crop-modal-close,
    .side-panel-close,
    .glass-sheet-close,
    .sm-logo-modal-close,
    .res-detail-close,
    .fp-modal-x,
    .tr-modal-close {
        display: inline-flex !important;
    }

    /* ── Consistent desktop dialog shell ── */
    .grabber-sheet,
    .modal-overlay > .modal-content,
    .hk-modal,
    .modal-overlay > .modal,
    .modal-backdrop > .modal,
    .al-modal,
    .modal-overlay > .success-modal,
    .pay-modal-overlay > .pay-modal-box,
    .res-detail-panel,
    .tr-modal-card {
        border-radius: var(--popup-radius-d) !important;
        box-shadow: var(--popup-shadow-d) !important;
    }

    /* ── Overlay padding on desktop ── */
    .modal-overlay,
    .modal-backdrop.active,
    .hk-modal-overlay,
    .al-modal-backdrop,
    .pay-modal-overlay.active,
    .pay-modal-overlay.open,
    .res-detail-overlay,
    .tr-modal {
        padding: 24px;
    }

    /* ── res-detail → centered dialog on desktop ── */
    .res-detail-overlay {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .res-detail-panel {
        max-width: 440px !important;
        width: 100% !important;
        animation: popupScaleIn 0.3s var(--popup-ease) both;
    }

    /* ── tr-modal → centered dialog on desktop ── */
    .tr-modal {
        align-items: center !important;
        justify-content: center !important;
    }
    .tr-modal-card {
        width: min(420px, 100%) !important;
        max-width: 420px !important;
        border-radius: var(--popup-radius-d) !important;
    }

    /* ── HK modal back to centered on desktop ── */
    .hk-modal-overlay {
        align-items: center !important;
        padding: 16px !important;
    }
    .hk-modal {
        max-width: 540px !important;
        width: 100%;
        transform: translateY(20px) scale(0.96);
        transition: transform 0.3s var(--popup-ease), opacity 0.25s ease;
    }
    .hk-modal-overlay.open .hk-modal {
        transform: translateY(0) scale(1);
    }

    /* ── Desktop header & body spacing ── */
    .sheet-header {
        padding: 20px 20px 14px !important;
    }
    .modal-header {
        padding: 18px 20px !important;
    }

    /* ── Desktop: center-aligned overlays ── */
    .modal-overlay.open,
    .modal-overlay.active {
        align-items: center !important;
    }
    .modal-overlay > .modal-content {
        border-radius: var(--popup-radius-d) !important;
        max-width: 480px;
        animation: popupScaleIn 0.3s var(--popup-ease) both;
    }
}

/* ══════════════════════════════════════════════
   10.  TABLES INSIDE POPUPS — clean & consistent
   ══════════════════════════════════════════════ */
.grabber-sheet table,
.modal-content table,
.hk-modal table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

.grabber-sheet table th,
.modal-content table th,
.hk-modal table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted, #64748b);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color, var(--popup-border));
    background: transparent;
    text-align: left;
}

.grabber-sheet table td,
.modal-content table td,
.hk-modal table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color, var(--popup-border));
    color: var(--text-primary, #0f172a);
    vertical-align: middle;
}

.grabber-sheet table tbody tr:last-child td,
.modal-content table tbody tr:last-child td,
.hk-modal table tbody tr:last-child td {
    border-bottom: none;
}

.grabber-sheet table tbody tr:hover td,
.modal-content table tbody tr:hover td,
.hk-modal table tbody tr:hover td {
    background: var(--bg-hover, rgba(148,163,184,0.06));
}

/* ══════════════════════════════════════════════
   11.  ANIMATION KEYFRAMES
   ══════════════════════════════════════════════ */
@keyframes popupScaleIn {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}