/* ==========================================================================
   Chat screens (customer chat.php + admin/chat.php): clean "native app" look with frosted glass.
   Scoped under .cx-scope so it never touches the rest of the site.
   Dark by default; follows the eye-button theme (html[data-theme]); the admin screen adds .cx-light.
   ========================================================================== */
.cx-scope {
    --cx-ink: #eceef6; --cx-ink2: #a3a9c0; --cx-ink3: #737a94;
    --cx-bar: rgba(14, 15, 26, .72); --cx-glass: rgba(255, 255, 255, .075); --cx-glass2: rgba(255, 255, 255, .12);
    --cx-line: rgba(255, 255, 255, .13); --cx-input: rgba(255, 255, 255, .09);
    --cx-me1: #6d6cf7; --cx-me2: #3bb4c9; --cx-green: #34d399; --cx-red: #fb7185;
    --cx-shadow: 0 18px 40px -16px rgba(0, 0, 0, .6);
    color: var(--cx-ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html[data-theme="light"] .cx-scope, .cx-scope.cx-light {
    --cx-ink: #14162b; --cx-ink2: #4b516f; --cx-ink3: #7d8399;
    --cx-bar: rgba(255, 255, 255, .72); --cx-glass: rgba(255, 255, 255, .62); --cx-glass2: rgba(255, 255, 255, .85);
    --cx-line: rgba(80, 90, 160, .16); --cx-input: rgba(255, 255, 255, .8);
    --cx-shadow: 0 18px 40px -18px rgba(70, 80, 170, .35);
}
.cx-scope *, .cx-scope *::before, .cx-scope *::after { box-sizing: border-box; }
.cx-scope button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- Frame ---------- */
.cx {
    display: flex; flex-direction: column; width: 100%; max-width: 760px; margin: 0 auto;
    height: 100vh; height: 100dvh; position: relative;
}
body.cx-body { padding-bottom: 0 !important; overflow: hidden; }
body.cx-body .cx { height: calc(100vh - 72px - env(safe-area-inset-bottom, 0px)); height: calc(100dvh - 72px - env(safe-area-inset-bottom, 0px)); }
body.cx-body.kbd .cx { height: 100vh; height: 100dvh; }
body.kbd .unav { display: none; }

/* ---------- Top bar ---------- */
.cx-bar {
    flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    background: var(--cx-bar); border-bottom: 1px solid var(--cx-line);
    -webkit-backdrop-filter: blur(20px) saturate(170%); backdrop-filter: blur(20px) saturate(170%);
    z-index: 5;
}
.cx-back { width: 38px; height: 38px; border-radius: 999px; display: grid; place-items: center; color: var(--cx-ink); text-decoration: none; background: var(--cx-glass); border: 1px solid var(--cx-line); }
.cx-back svg { width: 20px; height: 20px; }
.cx-avatar {
    width: 42px; height: 42px; border-radius: 999px; flex: 0 0 auto; display: grid; place-items: center; color: #fff; font-weight: 700;
    background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); box-shadow: 0 8px 20px -8px rgba(99, 102, 241, .8);
}
.cx-avatar svg { width: 22px; height: 22px; }
.cx-title { min-width: 0; flex: 1 1 auto; }
.cx-title strong { display: block; font-size: 16px; line-height: 1.2; color: var(--cx-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-title span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--cx-ink2); }
.cx-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--cx-green); box-shadow: 0 0 0 3px rgba(52, 211, 153, .2); }
.cx-icon-btn {
    width: 38px; height: 38px; border-radius: 999px; display: grid; place-items: center; color: var(--cx-ink);
    background: var(--cx-glass); border: 1px solid var(--cx-line); flex: 0 0 auto;
}
.cx-icon-btn svg { width: 19px; height: 19px; }
.cx-icon-btn.on { color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); border-color: transparent; }

/* ---------- Messages ---------- */
.cx-list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 6px; }
.cx-card {
    margin: 4px 0 10px; padding: 16px; border-radius: 22px; background: var(--cx-glass); border: 1px solid var(--cx-line);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: var(--cx-shadow);
}
.cx-card h2 { margin: 0 0 6px; font-size: 16px; font-weight: 700; color: var(--cx-ink); }
.cx-card p, .cx-card li { margin: 0; font-size: 13px; line-height: 1.5; color: var(--cx-ink2); }
.cx-card ol { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.cx-card li { display: flex; gap: 10px; align-items: flex-start; }
.cx-card li b { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 999px; display: grid; place-items: center; font-size: 12px; color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); }
.cx-warn { margin-top: 10px !important; font-size: 12px !important; color: var(--cx-ink3) !important; }

.day-sep { align-self: center; margin: 10px 0 4px; padding: 3px 12px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--cx-ink2); background: var(--cx-glass); border: 1px solid var(--cx-line); }
.bub-row { display: flex; }
.bub-row.me { justify-content: flex-end; }
.bub {
    max-width: min(82%, 520px); padding: 9px 13px 6px; font-size: 15px; line-height: 1.4; word-wrap: break-word; overflow-wrap: anywhere;
    border-radius: 20px; position: relative;
}
.bub.them { color: var(--cx-ink); background: var(--cx-glass2); border: 1px solid var(--cx-line); border-bottom-left-radius: 6px; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.bub.me { color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); border-bottom-right-radius: 6px; box-shadow: 0 10px 22px -10px rgba(99, 102, 241, .8); }
.bub.pending { opacity: .6; }
.bub.failed { background: linear-gradient(135deg, #e11d48, #fb7185); }
.bub-text { white-space: pre-wrap; }
.bub-time { display: block; margin-top: 2px; text-align: right; font-size: 10.5px; opacity: .72; }
.bub img { display: block; max-width: 100%; width: 240px; max-height: 300px; object-fit: cover; border-radius: 14px; margin: 0 0 5px; cursor: zoom-in; background: rgba(255, 255, 255, .08); }
.cx-empty { margin: auto; text-align: center; color: var(--cx-ink3); font-size: 13px; padding: 20px; }

/* ---------- Composer ---------- */
.cx-compose { flex: 0 0 auto; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--cx-bar); border-top: 1px solid var(--cx-line); -webkit-backdrop-filter: blur(20px) saturate(170%); backdrop-filter: blur(20px) saturate(170%); }
body.cx-body:not(.kbd) .cx-compose { padding-bottom: 10px; }
.cx-chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 8px; scrollbar-width: none; }
.cx-chips::-webkit-scrollbar { display: none; }
.cx-chip { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--cx-ink); background: var(--cx-glass); border: 1px solid var(--cx-line); white-space: nowrap; }
.cx-preview { display: none; align-items: center; gap: 10px; margin-bottom: 8px; padding: 6px; border-radius: 16px; background: var(--cx-glass); border: 1px solid var(--cx-line); }
.cx-preview.show { display: flex; }
.cx-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 10px; }
.cx-preview span { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--cx-ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-preview button { width: 30px; height: 30px; border-radius: 999px; border: 0; color: var(--cx-ink); background: var(--cx-glass2); font-size: 16px; line-height: 1; }
.cx-row { display: flex; align-items: flex-end; gap: 8px; }
.cx-field {
    flex: 1 1 auto; min-width: 0; display: flex; align-items: flex-end; border-radius: 24px; background: var(--cx-input); border: 1px solid var(--cx-line);
    padding: 4px 6px 4px 14px;
}
.cx-field textarea {
    flex: 1 1 auto; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--cx-ink);
    font: inherit; font-size: 16px; line-height: 1.35; padding: 8px 0; max-height: 120px; box-shadow: none !important;
}
.cx-field textarea::placeholder { color: var(--cx-ink3); }
.cx-attach { width: 36px; height: 36px; border-radius: 999px; border: 0; background: transparent; color: var(--cx-ink2); display: grid; place-items: center; flex: 0 0 auto; }
.cx-attach svg { width: 21px; height: 21px; }
.cx-send {
    width: 46px; height: 46px; border-radius: 999px; border: 0; flex: 0 0 auto; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); box-shadow: 0 10px 22px -8px rgba(99, 102, 241, .85); transition: transform .12s ease, opacity .12s ease;
}
.cx-send:active { transform: scale(.92); }
.cx-send:disabled { opacity: .45; }
.cx-send svg { width: 21px; height: 21px; }

/* ---------- Toast + lightbox ---------- */
.cx-toast { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%) translateY(10px); z-index: 120; max-width: 90vw; padding: 10px 16px; border-radius: 16px; font-size: 13px; font-weight: 600; color: #fff; background: rgba(20, 22, 43, .92); border: 1px solid var(--cx-line); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.cx-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.cx-lightbox { position: fixed; inset: 0; z-index: 130; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 6, 12, .88); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.cx-lightbox.show { display: flex; }
.cx-lightbox img { max-width: 100%; max-height: 100%; border-radius: 16px; }

/* ---------- Login prompt ---------- */
.cx-login { margin: auto; max-width: 340px; text-align: center; padding: 28px 20px; }
.cx-login a { display: block; margin-top: 12px; padding: 12px 16px; border-radius: 16px; font-weight: 700; color: #fff; text-decoration: none; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); }

/* ---------- Admin two-pane layout ---------- */
.ax { display: grid; grid-template-columns: 340px 1fr; gap: 14px; height: calc(100vh - 130px); height: calc(100dvh - 130px); min-height: 460px; }
.ax-side, .ax-main { min-height: 0; border-radius: 26px; overflow: hidden; display: flex; flex-direction: column; background: var(--cx-glass); border: 1px solid var(--cx-line); box-shadow: var(--cx-shadow); -webkit-backdrop-filter: blur(18px) saturate(170%); backdrop-filter: blur(18px) saturate(170%); }
.ax-side-head { padding: 14px; display: grid; gap: 10px; border-bottom: 1px solid var(--cx-line); }
.ax-side-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.ax-search { width: 100%; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--cx-line); background: var(--cx-input); color: var(--cx-ink); font-size: 14px; outline: 0; }
.ax-threads { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ax-thread { display: flex; gap: 11px; align-items: center; width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--cx-line); background: transparent; color: var(--cx-ink); text-align: left; }
.ax-thread:hover, .ax-thread.active { background: var(--cx-glass2); }
.ax-thread .cx-avatar { width: 44px; height: 44px; text-transform: uppercase; }
.ax-thread-main { flex: 1 1 auto; min-width: 0; }
.ax-thread-top { display: flex; justify-content: space-between; gap: 8px; }
.ax-thread-top b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ax-thread-top small { font-size: 11px; color: var(--cx-ink3); flex: 0 0 auto; }
.ax-thread-prev { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-top: 2px; }
.ax-thread-prev span { font-size: 13px; color: var(--cx-ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ax-badge { flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: #f43f5e; }
.ax-main .cx-list { padding-top: 16px; }
.ax-none { margin: auto; text-align: center; color: var(--cx-ink3); padding: 24px; font-size: 14px; }
.ax-notice { margin: 0 0 12px; padding: 12px 16px; border-radius: 18px; font-size: 13px; color: var(--cx-ink); background: var(--cx-glass); border: 1px solid var(--cx-line); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.ax-notice button { padding: 8px 14px; border-radius: 999px; border: 0; font-weight: 700; font-size: 13px; color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); }
.ax-back { display: none; }

@media (max-width: 899px) {
    .ax { height: calc(100vh - 190px); height: calc(100dvh - 190px); }
}
@media (max-width: 767px) {
    .ax { grid-template-columns: 1fr; }
    .ax .ax-main { display: none; }
    .ax.open .ax-side { display: none; }
    .ax.open .ax-main { display: flex; }
    .ax-back { display: grid; }
}
body.cx-body .tg { display: none !important; }

/* resets so the chat looks the same with or without Tailwind loaded */
body.cx-body { margin: 0; }
.cx-field textarea { border: 0 !important; background: transparent !important; box-shadow: none !important; border-radius: 0 !important; margin: 0; width: auto; }
.cx-scope textarea:focus { outline: 0 !important; box-shadow: none !important; }

/* bell switch states: slashed when notifications are off / not allowed */
.cx-icon-btn .slash { display: none; }
.cx-icon-btn[data-state="off"] .slash, .cx-icon-btn[data-state="blocked"] .slash, .cx-icon-btn[data-state="ask"] .slash { display: inline; }
.cx-icon-btn[data-state="on"] { color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); border-color: transparent; }

/* laptop / desktop: the menu is a rail on the left, so the chat uses the full height beside it */
@media (min-width: 900px) {
    body.cx-body { padding-left: 96px !important; }
    body.cx-body .cx, body.cx-body.kbd .cx { height: 100vh; height: 100dvh; }
    .cx-compose { padding-bottom: 12px !important; }
}

/* ---------- Ended conversations ---------- */
/* customer: notice under the old messages */
.cx-ended {
    align-self: center; margin: 14px 0 6px; padding: 12px 18px; max-width: 320px; text-align: center; display: grid; gap: 3px;
    border-radius: 18px; background: var(--cx-glass); border: 1px solid var(--cx-line);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.cx-ended strong { font-size: 14px; color: var(--cx-ink); }
.cx-ended span { font-size: 12.5px; line-height: 1.4; color: var(--cx-ink2); }

/* admin: Open / Closed tabs */
.ax-tabs { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--cx-input); border: 1px solid var(--cx-line); }
.ax-tab { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 10px; border: 0; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--cx-ink2); background: transparent; }
.ax-tab.on { color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); box-shadow: 0 8px 18px -10px rgba(99, 102, 241, .85); }
.ax-days { flex: 0 0 auto; font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: var(--cx-ink2); background: var(--cx-glass2); border: 1px solid var(--cx-line); white-space: nowrap; }

/* admin: End chat button in the conversation header */
.ax-endbtn { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--cx-ink); background: var(--cx-glass2); border: 1px solid var(--cx-line); white-space: nowrap; }
.ax-endbtn:hover { color: #fff; background: #e11d48; border-color: transparent; }
.ax-endbtn:disabled { opacity: .5; }

/* admin: bar shown instead of the reply box when a conversation has ended */
.ax-closedbar { display: grid; gap: 10px; padding-top: 12px; }
.ax-closedbar p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--cx-ink2); text-align: center; }
.ax-closed-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ax-btn { padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 700; border: 0; color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); }
.ax-btn.danger { color: var(--cx-red); background: var(--cx-glass2); border: 1px solid var(--cx-line); }
.ax-btn.danger:hover { color: #fff; background: #e11d48; border-color: transparent; }

/* ---------- Ended screen: notice, button, Recent messages ---------- */
.cx-endwrap { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 28px 16px 20px; display: flex; flex-direction: column; align-items: center; gap: 26px; }
.cx-endwrap[hidden], .cx-list[hidden], .cx-compose[hidden] { display: none !important; }
.cx-endpanel { display: grid; justify-items: center; gap: 18px; text-align: center; }
.cx-endtitle { margin: 0; font-size: 22px; font-weight: 500; color: var(--cx-ink2); }
.cx-newbtn {
    display: inline-flex; align-items: center; gap: 12px; padding: 16px 28px; border-radius: 20px; font-size: 18px; font-weight: 800;
    color: var(--cx-ink); background: var(--cx-glass2); border: 3px solid var(--cx-line);
}
.cx-newbtn:active { transform: scale(.97); }
.cx-newbtn svg { width: 22px; height: 22px; }
.cx-recent { width: 100%; max-width: 560px; }
.cx-recent h3 { margin: 0 0 10px; font-size: 14px; font-weight: 700; color: var(--cx-ink2); text-transform: uppercase; letter-spacing: .04em; }
.cx-ritem { margin-bottom: 8px; border-radius: 18px; overflow: hidden; background: var(--cx-glass); border: 1px solid var(--cx-line); }
.cx-rhead { display: flex; width: 100%; padding: 12px 14px; border: 0; background: transparent; color: var(--cx-ink); text-align: left; }
.cx-rmain { min-width: 0; display: grid; gap: 3px; }
.cx-rmain b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-rmain small { font-size: 12px; color: var(--cx-ink3); }
.cx-rbody { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 14px; border-top: 1px solid var(--cx-line); max-height: 60vh; overflow-y: auto; font-size: 13px; color: var(--cx-ink2); }
.cx-rbody[hidden] { display: none; }
.cx-recent-note { margin: 10px 2px 0; font-size: 12px; color: var(--cx-ink3); text-align: center; }

/* ---------- Away notice (customer chat) ---------- */
.cx-away {
    flex: 0 0 auto; display: flex; align-items: flex-start; gap: 10px; margin: 10px 14px 0; padding: 11px 14px; border-radius: 18px;
    font-size: 13px; line-height: 1.45; color: var(--cx-ink); background: rgba(251, 191, 36, .14); border: 1px solid rgba(251, 191, 36, .4);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.cx-away[hidden] { display: none; }
.cx-away svg { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; color: #f5b82e; }
.cx-dot.away { background: #f5b82e; box-shadow: 0 0 0 3px rgba(245, 184, 46, .22); }
.cx-title span em { font-style: normal; }

/* ---------- Who wrote a reply (admin + agent screens) ---------- */
.bub-by { margin: 0 0 3px; font-size: 11px; font-weight: 700; letter-spacing: .02em; opacity: .85; }

/* ---------- Admin: Away switch row ---------- */
.ax-away { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; padding: 10px 14px; border-radius: 18px; color: var(--cx-ink); background: var(--cx-glass); border: 1px solid var(--cx-line); }
.ax-away-main { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.ax-away-main b { font-size: 14px; }
.ax-away-state { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #0f766e; background: rgba(52, 211, 153, .18); border: 1px solid rgba(52, 211, 153, .45); }
.ax-away-state.away { color: #92620a; background: rgba(251, 191, 36, .2); border-color: rgba(251, 191, 36, .55); }
.ax-switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; border-radius: 999px; border: 1px solid var(--cx-line); background: var(--cx-glass2); padding: 0; }
.ax-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 999px; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform .18s ease; }
.ax-switch.on { background: linear-gradient(135deg, #f5b82e, #f59e0b); border-color: transparent; }
.ax-switch.on::after { transform: translateX(20px); }
.ax-away-note { flex: 1 1 220px; min-width: 0; padding: 9px 14px; border-radius: 14px; font-size: 14px; color: var(--cx-ink); background: var(--cx-input); border: 1px solid var(--cx-line); outline: 0; }
.ax-away-link { font-size: 13px; font-weight: 700; color: var(--cx-me2); text-decoration: none; white-space: nowrap; }

/* ---------- Agent screen (agent_chat.php): full-height glass layout ---------- */
body.ag-body { margin: 0; overflow: hidden; }
body.ag-body .tg { display: none !important; }
.ag { display: flex; flex-direction: column; width: 100%; max-width: 1180px; margin: 0 auto; height: 100vh; height: 100dvh; padding: 0 12px; }
.ag-top { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; margin: calc(10px + env(safe-area-inset-top, 0px)) 0 10px; padding: 10px 14px; border-radius: 22px; background: var(--cx-bar); border: 1px solid var(--cx-line); box-shadow: var(--cx-shadow); -webkit-backdrop-filter: blur(20px) saturate(170%); backdrop-filter: blur(20px) saturate(170%); }
.ag-top .cx-title { flex: 1 1 auto; }
.ag-out { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; text-decoration: none; color: var(--cx-ink); background: var(--cx-glass2); border: 1px solid var(--cx-line); }
.ag .ax { flex: 1 1 auto; height: auto; min-height: 0; margin-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.ag .cx-away { margin: 0 0 10px; }
@media (max-width: 767px) {
    .ag { padding: 0 8px; }
    .ag-top { margin-top: calc(6px + env(safe-area-inset-top, 0px)); padding: 8px 10px; border-radius: 18px; }
    .ag-top .cx-title span { display: none; }
    .ax-away { padding: 9px 12px; }
}

/* ---------- Agent login ---------- */
.ag-login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px 16px; }
.ag-login { width: 100%; max-width: 380px; padding: 28px 22px; border-radius: 28px; text-align: center; background: var(--cx-glass); border: 1px solid var(--cx-line); box-shadow: var(--cx-shadow); -webkit-backdrop-filter: blur(22px) saturate(170%); backdrop-filter: blur(22px) saturate(170%); }
.ag-login .cx-avatar { margin: 0 auto 12px; width: 54px; height: 54px; }
.ag-login .cx-avatar svg { width: 28px; height: 28px; }
.ag-login h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; color: var(--cx-ink); }
.ag-login p { margin: 0 0 18px; font-size: 13px; color: var(--cx-ink2); }
.ag-login label { display: block; margin: 12px 0 5px; text-align: left; font-size: 12px; font-weight: 700; color: var(--cx-ink2); }
.ag-login input { width: 100%; padding: 12px 14px; border-radius: 16px; font-size: 16px; color: var(--cx-ink); background: var(--cx-input); border: 1px solid var(--cx-line); outline: 0; }
.ag-login input:focus { border-color: var(--cx-me1); box-shadow: 0 0 0 3px rgba(109, 108, 247, .25); }
.ag-login button { width: 100%; margin-top: 18px; padding: 13px 16px; border: 0; border-radius: 16px; font-size: 16px; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); box-shadow: 0 12px 24px -10px rgba(99, 102, 241, .85); }
.ag-err { margin: 0 0 6px; padding: 10px 12px; border-radius: 14px; font-size: 13px; color: var(--cx-red); background: rgba(251, 113, 133, .12); border: 1px solid rgba(251, 113, 133, .4); text-align: left; }

/* ---------- Gift-card trades (admin + agent chat) ---------- */
.ax-tradebtn { margin-right: 8px; }
.ax-trades { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; max-height: 190px; overflow-y: auto; margin: 0 12px 8px; padding: 10px 12px; border-radius: 18px; background: var(--cx-glass); border: 1px solid var(--cx-line); }
.ax-trade { display: grid; gap: 4px; padding-bottom: 8px; border-bottom: 1px solid var(--cx-line); }
.ax-trade:last-child { padding-bottom: 0; border-bottom: 0; }
.ax-trade-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--cx-ink); }
.ax-trade-top b { min-width: 0; overflow-wrap: anywhere; }
.ax-trade small { font-size: 11px; color: var(--cx-ink3); }
.ax-pill { flex: 0 0 auto; font-style: normal; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; }
.ax-pill.submitted { color: #fcd980; background: rgba(251, 191, 36, .18); border-color: rgba(251, 191, 36, .5); }
.ax-pill.approved { color: #9cc4ff; background: rgba(96, 165, 250, .18); border-color: rgba(96, 165, 250, .5); }
.ax-pill.paid { color: #6ee7b7; background: rgba(52, 211, 153, .18); border-color: rgba(52, 211, 153, .5); }
.ax-pill.rejected { color: #fda4b4; background: rgba(251, 113, 133, .16); border-color: rgba(251, 113, 133, .5); }
.cx-light .ax-pill.submitted, html[data-theme="light"] .ax-pill.submitted { color: #92620a; }
.cx-light .ax-pill.approved, html[data-theme="light"] .ax-pill.approved { color: #1d4ed8; }
.cx-light .ax-pill.paid, html[data-theme="light"] .ax-pill.paid { color: #0f766e; }
.cx-light .ax-pill.rejected, html[data-theme="light"] .ax-pill.rejected { color: #be123c; }
.ax-trade-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.ax-trade-btn { padding: 7px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; color: var(--cx-ink); background: var(--cx-glass2); border: 1px solid var(--cx-line); }
.ax-trade-btn.paid { color: #fff; border-color: transparent; background: linear-gradient(135deg, #10b981, #0d9488); }
.ax-trade-btn.approved { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); }
.ax-trade-btn.rejected { color: var(--cx-red); }
.ax-trade-btn:disabled { opacity: .55; }

.ax-modal { position: fixed; inset: 0; z-index: 9990; display: flex; align-items: flex-end; justify-content: center; padding: 0; background: rgba(5, 6, 12, .55); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.ax-modal[hidden] { display: none; }
.ax-sheet { width: 100%; max-width: 460px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; display: grid; gap: 10px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); border-radius: 26px 26px 0 0; color: var(--cx-ink); background: var(--cx-bar); border: 1px solid var(--cx-line); box-shadow: var(--cx-shadow); -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%); }
.cx-light .ax-sheet, html[data-theme="light"] .ax-sheet { background: rgba(255, 255, 255, .92); }
.ax-sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; }
.ax-x { width: 34px; height: 34px; border-radius: 999px; font-size: 22px; line-height: 1; color: var(--cx-ink); background: var(--cx-glass2); border: 1px solid var(--cx-line); }
.ax-sheet label { display: grid; gap: 5px; font-size: 12px; font-weight: 700; color: var(--cx-ink2); }
.ax-sheet input, .ax-sheet textarea { width: 100%; padding: 11px 13px; border-radius: 14px; font-size: 16px; font-weight: 500; color: var(--cx-ink); background: var(--cx-input); border: 1px solid var(--cx-line); outline: 0; font-family: inherit; resize: none; }
.ax-sheet input:focus, .ax-sheet textarea:focus { border-color: var(--cx-me1); box-shadow: 0 0 0 3px rgba(109, 108, 247, .25); }
.ax-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ax-hint { margin: 0; font-size: 12px; color: var(--cx-ink3); }
.ax-primary { padding: 13px 16px; border: 0; border-radius: 16px; font-size: 16px; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--cx-me1), var(--cx-me2)); box-shadow: 0 12px 24px -10px rgba(99, 102, 241, .85); }
.ax-primary:disabled { opacity: .6; }
@media (min-width: 640px) { .ax-modal { align-items: center; padding: 20px; } .ax-sheet { border-radius: 26px; } }

/* ---------- Gift card WhatsApp chip (right side of the "never share a card" line) ---------- */
.cx-warnrow { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-top: 10px; }
.cx-warnrow .cx-warn { flex: 1 1 200px; margin-top: 0 !important; }
.cx-wa-chip {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 10px; border-radius: 999px;
    background: #25d366; color: #06361a; font-size: 12px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
}
.cx-wa-chip b { font-weight: 800; }
.cx-wa-chip svg { width: 16px; height: 16px; flex: 0 0 auto; }
.cx-wa-chip:active { filter: brightness(.92); }