/* ParlayDesk site-wide support widget — floating button + panel.
   Reuses shared.css design tokens (--panel/--border/--accent/etc) so it
   inherits whichever theme the host page is in; defines nothing of its own. */

/* Defensive reset: some host pages (e.g. apps/styles.css) apply a
   page-wide `button,input,select{height:42px;padding:0 12px}` control reset.
   Without overriding it here, that leaks into every widget button — it
   squeezed icon buttons' padding (shrinking their SVGs) and clipped
   multi-line ticket rows to a fixed 42px. Own every generic box property so
   the widget renders identically regardless of what the host page resets. */
.pd-support-fab,
.pd-support-panel button {
  height: auto;
  box-sizing: border-box;
  font-family: inherit;
  line-height: normal;
}
.pd-support-panel textarea,
.pd-support-panel input {
  height: auto;
  box-sizing: border-box;
  font-family: inherit;
}

.pd-support-fab {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  transition: transform 150ms ease, box-shadow 150ms ease;
  z-index: 1900;
  padding: 0;
}
/* Only shown for an unread reply or while the panel is open (see
   updateFabVisibility() in support-widget.js) — [hidden] alone isn't enough
   here since the class above already sets `display: flex`, which otherwise
   beats the UA stylesheet's `[hidden]{display:none}` in the cascade. */
.pd-support-fab[hidden] { display: none; }
.pd-support-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(59, 130, 246, 0.45);
}
.pd-support-fab:active { transform: translateY(0); }
.pd-support-fab svg { width: 24px; height: 24px; color: #fff; }
.pd-support-fab.pd-open svg { width: 22px; height: 22px; }

.pd-support-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--missed);
  border: 2px solid #020617;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.pd-support-fab-badge[hidden] { display: none; }

.pd-support-panel {
  position: fixed;
  right: 20px;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  width: clamp(380px, 92vw, 440px);
  height: clamp(550px, 78vh, 680px);
  max-height: calc(100vh - 108px - env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(2, 6, 23, 0.99));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2000;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.pd-support-panel.pd-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Phones: a full-screen sheet over the page (support-widget.js locks the
   page scroll while it is open). The box follows the VISUAL viewport
   (--pd-sw-vv-top/-h, set from window.visualViewport): a plain
   top:0 + height:100% is sized to iOS Safari's large layout viewport, so
   behind the toolbar/keyboard the composer was cut off and iOS panned the
   header (Back / ✕) out of view. 100dvh is the fallback before JS runs. */
@media (max-width: 640px) {
  .pd-support-panel {
    right: 0;
    left: 0;
    top: var(--pd-sw-vv-top, 0px);
    bottom: auto;
    width: 100%;
    height: 100%;
    height: var(--pd-sw-vv-h, 100dvh);
    max-height: none;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .pd-support-fab {
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* Smaller phones: keep the button clear of edge content (nav/action bars)
   without needing a page-specific offset — it's rare to be visible at all
   now (see item 7), but should stay out of the way on the rare occasions
   it is (an unread reply arriving while browsing on a small screen). */
@media (max-width: 400px) {
  .pd-support-fab {
    width: 50px;
    height: 50px;
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .pd-support-fab svg { width: 21px; height: 21px; }
  .pd-support-fab-badge {
    min-width: 18px; height: 18px; font-size: 10px;
  }
}

.pd-support-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pd-support-header-titles { flex: 1; min-width: 0; }
.pd-support-header-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pd-support-header-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
/* Back / Close: the shared dialog control language (/modal.css
   .pd-modal-close): 32px desktop, 40px touch target on phones, soft
   surface, hover/pressed/focus-visible states. Scoped under the panel so
   the defensive `.pd-support-panel button { height: auto }` reset above
   can't shrink them (it did: the old 30px buttons rendered 22px tall). */
.pd-support-panel .pd-support-icon-btn {
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
@media (hover: hover) {
  .pd-support-icon-btn:hover {
    background: rgba(255, 255, 255, .09);
    border-color: rgba(255, 255, 255, .14);
    color: var(--text);
  }
}
.pd-support-icon-btn:active { background: rgba(255, 255, 255, .12); color: var(--text); }
.pd-support-icon-btn:focus { outline: none; box-shadow: none; }
.pd-support-icon-btn:focus-visible { outline: 2px solid var(--accent2, #60a5fa); outline-offset: 2px; }
.pd-support-icon-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.pd-support-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* never hand a scroll on to the page */
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.pd-support-body::-webkit-scrollbar { width: 8px; }
.pd-support-body::-webkit-scrollbar-track { background: transparent; }
.pd-support-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 999px; }
.pd-support-body::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.25); }

/* ── Home / ticket list view ── */
.pd-support-home { padding: 16px; }
.pd-support-greeting { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 14px; }
.pd-support-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 20px;
  transition: opacity 120ms;
}
.pd-support-new-btn:hover { opacity: .92; }
.pd-support-new-btn svg { width: 16px; height: 16px; }

.pd-support-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.pd-ticket-list { display: flex; flex-direction: column; gap: 6px; }
.pd-ticket-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background 120ms, border-color 120ms;
}
.pd-ticket-row:hover { background: var(--panel); border-color: rgba(255,255,255,.16); }
.pd-ticket-row-main { flex: 1; min-width: 0; }
.pd-ticket-row-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.pd-ticket-row-msg {
  font-size: 12.5px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pd-ticket-row-meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.pd-ticket-row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.pd-ticket-row-arrow { color: var(--muted); font-size: 13px; }
.pd-unread-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent2);
  box-shadow: 0 0 5px var(--accent2); flex-shrink: 0;
}

.pd-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.pd-badge-bug { background: rgba(239,68,68,.14); color: #f87171; }
.pd-badge-feature_request { background: rgba(59,130,246,.14); color: var(--accent2); }
.pd-badge-other { background: rgba(148,163,184,.14); color: var(--muted); }
.pd-badge-new { background: rgba(250,204,21,.14); color: var(--pending); }
.pd-badge-reviewed { background: rgba(96,165,250,.14); color: var(--accent2); }
.pd-badge-resolved { background: rgba(34,197,94,.14); color: var(--hit); }

.pd-support-empty {
  text-align: center; color: var(--muted); font-size: 12.5px;
  padding: 28px 12px; border: 1px dashed var(--border); border-radius: 10px;
}
.pd-support-loading, .pd-support-error {
  text-align: center; color: var(--muted); font-size: 12.5px; padding: 20px 0;
}
.pd-support-error { color: var(--missed); }

/* ── New ticket view ── */
.pd-support-new { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.pd-field-label {
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 7px; display: block;
}
.pd-type-row { display: flex; gap: 6px; }
.pd-type-btn {
  flex: 1; background: rgba(255,255,255,.04); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 6px; color: var(--text);
  font-size: 12px; font-family: inherit; cursor: pointer; text-align: center;
  transition: background 120ms, border-color 120ms;
}
.pd-type-btn:hover { background: rgba(255,255,255,.07); }
.pd-type-btn.pd-active { border-color: var(--accent); background: rgba(59,130,246,.12); color: var(--accent2); }
.pd-support-new textarea,
.pd-support-new input[type="text"] {
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; color: var(--text); font-size: 13px;
  font-family: inherit; width: 100%; outline: none;
  transition: border-color 150ms, background 150ms;
}
.pd-support-new textarea { min-height: 140px; resize: vertical; }
.pd-support-new textarea:focus,
.pd-support-new input[type="text"]:focus { border-color: var(--accent); background: rgba(59,130,246,.06); }
.pd-support-new textarea::placeholder,
.pd-support-new input[type="text"]::placeholder { color: rgba(148,163,184,.4); }
.pd-support-new-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pd-support-status { font-size: 12px; }
.pd-support-status.pd-error { color: var(--missed); }
.pd-submit-btn {
  padding: 10px 20px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--accent), #2563eb); color: #fff;
  font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.pd-submit-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Conversation view ── */
.pd-thread { padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 12px; }
.pd-msg-row { display: flex; gap: 8px; align-items: flex-start; }
.pd-msg-row.pd-from-user { flex-direction: row-reverse; }
.pd-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; color: #fff;
}
.pd-msg-row.pd-from-admin .pd-avatar { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.pd-msg-row.pd-from-user .pd-avatar { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
.pd-msg-col { display: flex; flex-direction: column; max-width: 78%; }
.pd-msg-row.pd-from-user .pd-msg-col { align-items: flex-end; }
.pd-msg-bubble {
  padding: 8px 12px; border-radius: 12px; font-size: 12.5px;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.pd-msg-row.pd-from-admin .pd-msg-bubble { background: rgba(59,130,246,.14); border: 1px solid rgba(59,130,246,.3); border-top-left-radius: 4px; }
.pd-msg-row.pd-from-user .pd-msg-bubble { background: var(--panel2); border: 1px solid var(--border); border-top-right-radius: 4px; }
.pd-msg-meta { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 2px; }

.pd-support-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.pd-support-footer textarea {
  flex: 1; background: rgba(255,255,255,.04); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 12.5px; font-family: inherit; min-height: 40px;
  max-height: 110px; resize: none; outline: none; transition: border-color 150ms, background 150ms;
}
.pd-support-footer textarea:focus { border-color: var(--accent); background: rgba(59,130,246,.06); }
.pd-support-send-btn {
  padding: 9px 15px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--accent), #2563eb); color: #fff;
  font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; flex-shrink: 0;
}
.pd-support-send-btn:disabled { opacity: .55; cursor: not-allowed; }

.pd-closed-note {
  font-size: 12px; color: var(--muted); text-align: center; padding: 14px;
}

/* iOS focus-zoom guard (2026-09-29): WebKit zooms the page when a text
   control under 16px is focused. Phones only; desktop keeps 13/12.5px. */
@media (max-width: 560px) {
  .pd-support-new textarea,
  .pd-support-new input[type="text"],
  .pd-support-footer textarea { font-size: 16px; }
}

/* Phones: comfortable chrome inside the sheet — 40px Back/Close with room
   from the screen edges, a 44px composer + Send, and the home-indicator
   inset under the composer where the device reports one. */
@media (max-width: 640px) {
  .pd-support-header { padding: 12px 12px 12px 14px; gap: 10px; min-height: 64px; box-sizing: border-box; }
  .pd-support-panel .pd-support-icon-btn { width: 40px; height: 40px; border-radius: 12px; }
  .pd-support-icon-btn svg { width: 20px; height: 20px; }
  .pd-support-header-title { font-size: 15.5px; }
  .pd-support-footer { padding: 10px 12px max(10px, env(safe-area-inset-bottom, 0px)); gap: 10px; }
  .pd-support-footer textarea { min-height: 44px; }
  .pd-support-send-btn { min-height: 44px; padding: 0 18px; font-size: 14px; }
}
