/* =====================================================================
   css/ux-polish.css — Global UX Polish (Owner: UX Polish worker)
   1) Horizontal scrollers (mask-image fades + desktop circular arrows)
   2) App-wide text selection / copy protection (inputs & .ds-allow-select exempt)
   3) Floating Drawer Account Switcher dropdown (#drawerAccountTray)
   4) World-class Sheets & Dialogs (grabber, 92vh, velocity drag, kb-aware)
   5) Add Payment Card Showcase (3D flip preview, brand gradients, validation)
   ===================================================================== */

/* =====================================================================
   1. APP-WIDE TEXT COPY & LONG-PRESS SELECTION PROTECTION
   ===================================================================== */
html,
body,
body * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

img:not([draggable="true"]) {
  -webkit-user-drag: none;
}

input,
textarea,
select,
[contenteditable=""],
[contenteditable="true"],
[contenteditable="plaintext-only"],
.ds-allow-select,
.ds-allow-select * {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

/* =====================================================================
   2. UNIVERSAL HORIZONTAL SCROLLERS (Edge Fades + Desktop Arrows)
   ===================================================================== */
.ux-hs-wrap {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.ds-rail {
  scroll-padding-inline: 16px;
}

/* Soft edge fades on BOTH mobile & desktop via CSS mask-image */
[data-ux-hs="1"][data-hs-left="1"][data-hs-right="1"] {
  -webkit-mask-image: linear-gradient(to right, transparent 0%, #000 28px, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0%, #000 28px, #000 calc(100% - 28px), transparent 100%);
}

[data-ux-hs="1"][data-hs-left="0"][data-hs-right="1"] {
  -webkit-mask-image: linear-gradient(to right, #000 0%, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, #000 0%, #000 calc(100% - 28px), transparent 100%);
}

[data-ux-hs="1"][data-hs-left="1"][data-hs-right="0"] {
  -webkit-mask-image: linear-gradient(to right, transparent 0%, #000 28px, #000 100%);
  mask-image: linear-gradient(to right, transparent 0%, #000 28px, #000 100%);
}

[data-ux-hs="1"][data-hs-left="0"][data-hs-right="0"] {
  -webkit-mask-image: none;
  mask-image: none;
}

.ux-hs-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 16;
  width: 30px;
  height: 30px;
  border-radius: 9999px;
  margin: 0 !important;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--background) 92%, transparent);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  border: 1px solid var(--card-border);
  color: var(--foreground);
  box-shadow: 0 4px 14px rgba(15, 20, 25, .14), 0 1px 3px rgba(15, 20, 25, .08);
  opacity: .88;
  cursor: pointer;
  transition: opacity 160ms ease, transform 160ms var(--ds-ease), border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}

html.dark .ux-hs-btn {
  background: color-mix(in srgb, var(--card) 94%, transparent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .52), 0 0 0 1px rgba(255, 255, 255, .06);
}

.ux-hs-wrap:hover .ux-hs-btn {
  opacity: 1;
}

.ux-hs-btn:hover {
  opacity: 1;
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-50%) scale(1.07);
}

.ux-hs-btn:active {
  transform: translateY(-50%) scale(.93);
}

.ux-hs-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}

.ux-hs-btn--left {
  left: 6px;
}

.ux-hs-btn--right {
  right: 6px;
}

.ux-hs-btn[data-hs-hidden="1"] {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-50%) scale(.82) !important;
}

@media (max-width: 767px), (pointer: coarse) {
  .ux-hs-btn {
    display: none !important;
  }
}

body.mobile-sim .ux-hs-btn {
  display: none !important;
}

/* Retire any legacy horizontal scroll button artifacts just in case */
.hscroll-btn,
.hscroll-fade-l,
.hscroll-fade-r {
  display: none !important;
}

/* =====================================================================
   3. FLOATING DRAWER ACCOUNT SWITCHER DROPDOWN (#drawerAccountTray)
   ===================================================================== */
@keyframes uxDrawerPopIn {
  from {
    opacity: 0;
    transform: scale(.92) translateY(-6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.sh-drawer-head {
  position: relative !important;
  z-index: 25 !important;
}

#drawerAccountTray:not(.hidden) {
  position: absolute !important;
  z-index: 45 !important;
  inset-inline-end: 12px !important;
  left: auto !important;
  top: 58px;
  width: min(278px, calc(100% - 24px)) !important;
  margin-top: 0 !important;
  padding: 6px !important;
  border-top: 1px solid var(--card-border) !important;
  border: 1px solid var(--card-border) !important;
  border-radius: 18px !important;
  background: var(--background) !important;
  box-shadow: var(--ds-shadow-pop) !important;
  max-height: min(320px, calc(100vh - 136px)) !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  transform-origin: top right;
  animation: uxDrawerPopIn 220ms var(--ds-ease) forwards;
}

html[dir="rtl"] #drawerAccountTray:not(.hidden) {
  transform-origin: top left;
}

html.dark #drawerAccountTray:not(.hidden) {
  background: var(--card) !important;
}

#drawerAccountTray::-webkit-scrollbar {
  display: none;
}

.ux-acc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 4px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.ux-acc-divider {
  height: 1px;
  margin: 4px 8px;
  background: var(--border);
  flex-shrink: 0;
}

.ux-acc-action-ico {
  width: 34px;
  height: 34px;
  border-radius: 9999px;
  background: var(--content);
  color: var(--foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ux-acc-action-ico svg {
  width: 17px;
  height: 17px;
}

.ux-acc-action-ico.is-accent {
  background: color-mix(in srgb, var(--primary) 13%, transparent);
  color: var(--primary);
}

/* =====================================================================
   4. WORLD-CLASS SHEETS & DIALOGS (Mobile Bottom Sheet / Desktop Dialog)
   ===================================================================== */
@keyframes uxSheetSpringUp {
  from {
    opacity: .65;
    transform: translate3d(0, 100%, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes uxDialogPopIn {
  from {
    opacity: 0;
    transform: scale(.94) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

#frameActionModal:not(.hidden),
#siteThemeModal:not(.hidden),
#expressionModal:not(.hidden),
#checkoutModal:not(.hidden) {
  background: rgba(8, 11, 20, .54) !important;
  backdrop-filter: blur(10px) saturate(145%) !important;
  -webkit-backdrop-filter: blur(10px) saturate(145%) !important;
}

#frameActionBody {
  transition: none;
}

#frameActionBody:focus,
#siteThemeBody:focus,
#expressionBody:focus,
#checkoutBody:focus {
  outline: none;
}

.vp-sheet.ux-sheet-spring {
  animation: none !important;
  transition: transform 280ms var(--ds-ease), max-height 280ms var(--ds-ease) !important;
}

.vp-sheet.ux-sheet-dismissing {
  animation: none !important;
  transition: transform 180ms cubic-bezier(.32, 0, .67, 0), opacity 160ms ease !important;
}

/* Desktop & Tablet (>=768px and not mobile-sim): centered dialog (max 480 / 600) */
@media (min-width: 768px) {
  body:not(.mobile-sim) #frameActionBody,
  body:not(.mobile-sim) #siteThemeBody {
    max-width: 480px !important;
    border-radius: 24px !important;
    max-height: min(86vh, 700px) !important;
    animation: uxDialogPopIn 240ms var(--ds-ease) forwards !important;
  }

  body:not(.mobile-sim) #frameActionBody.vp-fullpage,
  body:not(.mobile-sim) #frameActionBody.sx-full {
    max-width: 600px !important;
    max-height: min(88vh, 760px) !important;
  }

  body:not(.mobile-sim) .sheet-grabber,
  body:not(.mobile-sim) .ov-grabber-wrap {
    display: none !important;
  }
}

/* Mobile (<768px) & ?sim=1: stylish centered floating modals (no bottom-edge sheets) */
@media (max-width: 767px) {
  #frameActionModal:not(.vp-fullpage-wrap),
  #siteThemeModal,
  #expressionModal {
    top: var(--vvt, 0px) !important;
    bottom: auto !important;
    height: var(--vvh, 100dvh) !important;
    max-height: var(--vvh, 100dvh) !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 16px !important;
  }

  #frameActionModal:not(.vp-fullpage-wrap) #frameActionBody,
  #siteThemeBody {
    max-width: 460px !important;
    width: 100% !important;
    height: auto !important;
    border-radius: 24px !important;
    border: 1px solid var(--card-border) !important;
    max-height: min(84dvh, calc(var(--vvh, 100dvh) - 32px)) !important;
    padding-bottom: 0 !important;
    box-shadow: 0 24px 64px -12px rgba(8, 11, 20, .42), 0 0 0 1px rgba(255, 255, 255, .06) !important;
    animation: uxDialogPopIn 240ms var(--ds-ease) forwards !important;
  }

  #frameActionModal:not(.vp-fullpage-wrap) #frameActionBody.vp-flex-shell,
  #siteThemeBody {
    padding-bottom: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  #frameActionModal:not(.vp-fullpage-wrap) #frameActionBody[data-snap-state="half"] {
    max-height: min(76dvh, calc(var(--vvh, 100dvh) - 32px)) !important;
  }

  #frameActionModal.vp-fullpage-wrap {
    top: var(--vvt, 0px) !important;
    bottom: auto !important;
    height: var(--vvh, 100dvh) !important;
    max-height: var(--vvh, 100dvh) !important;
  }

  #frameActionBody:not(.vp-fullpage) .sheet-grabber,
  .ov-grabber-wrap {
    display: none !important;
  }
}

body.mobile-sim #frameActionModal:not(.vp-fullpage-wrap),
body.mobile-sim #siteThemeModal,
body.mobile-sim #expressionModal {
  inset: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 14px !important;
}

body.mobile-sim #frameActionModal:not(.vp-fullpage-wrap) #frameActionBody,
body.mobile-sim #siteThemeBody {
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
  border-radius: 24px !important;
  border: 1px solid var(--card-border) !important;
  max-height: calc(100% - 36px) !important;
  padding-bottom: 0 !important;
  box-shadow: 0 24px 64px -12px rgba(8, 11, 20, .42) !important;
  animation: uxDialogPopIn 240ms var(--ds-ease) forwards !important;
}

body.mobile-sim #frameActionModal:not(.vp-fullpage-wrap) #frameActionBody.vp-flex-shell,
body.mobile-sim #siteThemeBody {
  padding-bottom: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

body.mobile-sim #frameActionBody:not(.vp-fullpage) .sheet-grabber,
body.mobile-sim .ov-grabber-wrap {
  display: none !important;
}

body.mobile-sim #frameActionBody:not(.vp-fullpage) .sheet-grabber > div {
  width: 36px;
  height: 4px;
  border-radius: 9999px;
  background: var(--card-border);
}

/* Sticky header & safe-area footer polish inside flex sheets */
.ov-bar {
  position: sticky;
  top: 0;
  z-index: 10;
}

.ov-dock {
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
}

/* =====================================================================
   5. ADD PAYMENT CARD SHOWCASE (.ux-cc-*)
   ===================================================================== */
.ux-cc-brands {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ux-cc-brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: 9999px;
  border: 1px solid var(--card-border);
  background: var(--content);
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 120ms ease;
}

.ux-cc-brand-pill.is-detected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 13%, var(--background));
  color: var(--primary);
}

.ux-cc-brand-pill.is-tab {
  cursor: pointer;
}

.ux-cc-brand-pill.is-tab:active {
  transform: scale(.96);
}

.ux-cc-stage {
  perspective: 1200px;
  width: 100%;
  max-width: 316px;
  margin: 0 auto;
}

.ux-cc-card {
  position: relative;
  width: 100%;
  height: 168px;
  cursor: default;
}

.ux-cc-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(.22, 1, .36, 1);
}

.ux-cc-card.is-flipped .ux-cc-inner {
  transform: rotateY(180deg);
}

.ux-cc-face {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  padding: 15px 18px;
  color: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 18px 42px -18px rgba(8, 12, 26, .62), inset 0 0 0 1px rgba(255, 255, 255, .16);
  transition: background 320ms ease;
}

.ux-cc-face::before {
  content: "";
  position: absolute;
  inset: -45% -25% auto auto;
  width: 240px;
  height: 240px;
  border-radius: 9999px;
  background: radial-gradient(circle, rgba(255, 255, 255, .24) 0%, transparent 68%);
  pointer-events: none;
}

.ux-cc-face::after {
  content: "";
  position: absolute;
  inset: auto auto -55% -30%;
  width: 220px;
  height: 220px;
  border-radius: 9999px;
  background: radial-gradient(circle, rgba(255, 255, 255, .12) 0%, transparent 70%);
  pointer-events: none;
}

.ux-cc-face[data-brand="generic"] {
  background: linear-gradient(135deg, #1b1f34 0%, #101321 55%, #23284a 100%);
}

.ux-cc-face[data-brand="visa"] {
  background: linear-gradient(135deg, #0d235c 0%, #1a52db 58%, #0ea5e9 100%);
}

.ux-cc-face[data-brand="mastercard"] {
  background: linear-gradient(135deg, #17171f 0%, #9f1239 58%, #ea580c 100%);
}

.ux-cc-face[data-brand="amex"] {
  background: linear-gradient(135deg, #064e3b 0%, #0284c7 56%, #1e293b 100%);
}

.ux-cc-face[data-brand="discover"] {
  background: linear-gradient(135deg, #1e293b 0%, #c2410c 60%, #f59e0b 100%);
}

.ux-cc-face[data-brand="telebirr"] {
  background: linear-gradient(135deg, #064e3b 0%, #00a651 56%, #0d9488 100%);
}

.ux-cc-back {
  transform: rotateY(180deg);
  padding: 18px 0;
}

.ux-cc-front-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ux-cc-chip-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ux-cc-chip {
  width: 36px;
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(253, 230, 138, .92), rgba(217, 119, 6, .85));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .32);
  position: relative;
  overflow: hidden;
}

.ux-cc-chip::after {
  content: "";
  position: absolute;
  inset: 5px 7px;
  border-radius: 3px;
  border: 1px solid rgba(120, 53, 15, .42);
}

.ux-cc-wave {
  width: 18px;
  height: 18px;
  opacity: .78;
}

.ux-cc-logo {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--ds-font-display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.ux-cc-num {
  position: relative;
  z-index: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .28);
}

.ux-cc-front-bot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.ux-cc-lbl {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .64);
}

.ux-cc-val {
  font-family: var(--ds-font-display);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: .03em;
  color: #fff;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ux-cc-stripe {
  width: 100%;
  height: 40px;
  background: rgba(6, 8, 16, .84);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.ux-cc-sig-wrap {
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.ux-cc-sig-band {
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  gap: 8px;
}

.ux-cc-sig-lines {
  flex: 1;
  height: 18px;
  border-radius: 4px;
  background: repeating-linear-gradient(-45deg, rgba(15, 20, 25, .07), rgba(15, 20, 25, .07) 4px, transparent 4px, transparent 8px);
}

.ux-cc-cvc-box {
  min-width: 54px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #fff;
  border: 2px solid var(--primary);
  color: #0f1419;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .12em;
  text-align: center;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 26%, transparent);
}

.ux-cc-back-note {
  padding: 0 20px;
  font-size: 11px;
  color: rgba(255, 255, 255, .7);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.ux-cc-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ux-cc-in-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.ux-cc-in-wrap .ds-input {
  padding-right: 40px;
}

.ux-cc-in-wrap.has-err .ds-input {
  border-color: var(--error);
}

.ux-cc-in-wrap.has-err .ds-input:focus {
  border-color: var(--error);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 18%, transparent);
}

.ux-cc-in-wrap.is-ok .ds-input {
  border-color: color-mix(in srgb, var(--success) 65%, var(--card-border));
}

.ux-cc-badge-in {
  position: absolute;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--muted-foreground);
  pointer-events: none;
}

.ux-cc-badge-in.is-ok {
  color: var(--success);
}

.ux-cc-badge-in.is-err {
  color: var(--error);
}

.ux-cc-badge-in svg {
  width: 16px;
  height: 16px;
}

.ux-cc-err {
  font-size: 12px;
  font-weight: 600;
  color: var(--error);
  min-height: 16px;
  line-height: 1.3;
}

.ux-cc-err:empty {
  display: none;
}

.ux-cc-def-row {
  border: 1px solid var(--card-border);
  border-radius: var(--ds-radius-m);
  background: var(--card);
  overflow: hidden;
}

.ux-cc-def-row .ds-row {
  padding: 9px 13px;
  min-height: 44px;
}

.ux-cc-secure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  padding-top: 8px;
  text-align: center;
}

.ux-cc-secure svg {
  width: 14px;
  height: 14px;
  color: var(--success);
  flex-shrink: 0;
}

/* Compact preview when virtual keyboard is open on mobile */
body.kb-open .ux-cc-card {
  height: 152px;
}
body.kb-open .ux-cc-face {
  padding: 14px 16px;
}
body.kb-open .ux-cc-num {
  font-size: 16px;
}

@media (prefers-reduced-motion: reduce) {
  .ux-hs-btn,
  .ux-cc-inner,
  #drawerAccountTray:not(.hidden) {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
