/* WP Support Desk — front-end widget styles
   Theming: each widget's brand color comes from an inline
   --wpsd-primary / --wpsd-primary-dark / --wpsd-primary-rgb
   set per-site in Settings → Branding & Text. */

.wpsd {
  --wpsd-primary: #2563eb;
  --wpsd-primary-dark: #1d4ed8;
  --wpsd-primary-rgb: 37,99,235;
  --wpsd-border: #e5e7eb;
  --wpsd-bg: #f8fafc;
  --wpsd-surface: #ffffff;
  --wpsd-text: #0f172a;
  --wpsd-text-muted: #64748b;
  --wpsd-radius: 14px;
  --wpsd-shadow: 0 1px 2px rgba(15,23,42,0.04), 0 8px 24px rgba(15,23,42,0.06);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--wpsd-text);
  box-sizing: border-box;
}
.wpsd *, .wpsd *::before, .wpsd *::after { box-sizing: inherit; }

.wpsd-card {
  background: var(--wpsd-surface);
  border: 1px solid var(--wpsd-border);
  border-radius: var(--wpsd-radius);
  box-shadow: var(--wpsd-shadow);
  padding: 28px 28px 24px;
}

.wpsd-card__header { margin-bottom: 20px; }
.wpsd-card__title { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.wpsd-card__subtitle { margin: 0; color: var(--wpsd-text-muted); font-size: 14px; line-height: 1.5; }

/* Fields ---------------------------------------------------------------- */
.wpsd-field { margin: 0 0 18px; display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; }
.wpsd-field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.wpsd-field-row .wpsd-field { min-width: 180px; }
.wpsd-field label { font-weight: 600; font-size: 13px; color: var(--wpsd-text); }
.wpsd-req { color: #ef4444; }

.wpsd input[type="text"],
.wpsd textarea,
.wpsd select {
  border: 1.5px solid var(--wpsd-border);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  width: 100%;
  background: var(--wpsd-surface);
  color: var(--wpsd-text);
  transition: border-color .15s ease, box-shadow .15s ease;
  font-family: inherit;
}
.wpsd input[type="text"]::placeholder,
.wpsd textarea::placeholder { color: #9ca3af; }
.wpsd input[type="text"]:focus,
.wpsd textarea:focus,
.wpsd select:focus {
  outline: none;
  border-color: var(--wpsd-primary);
  box-shadow: 0 0 0 4px rgba(var(--wpsd-primary-rgb), 0.12);
}
.wpsd textarea { resize: vertical; line-height: 1.5; }

.wpsd-select-wrap { position: relative; display: block; }
.wpsd-select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
}
.wpsd-select-wrap::after {
  content: "";
  position: absolute;
  top: 50%; right: 14px;
  width: 8px; height: 8px;
  border-right: 2px solid var(--wpsd-text-muted);
  border-bottom: 2px solid var(--wpsd-text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.wpsd-hint { font-size: 12px; color: var(--wpsd-text-muted); }

/* File drop --------------------------------------------------------------*/
.wpsd-file-drop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px dashed var(--wpsd-border);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  background: var(--wpsd-bg);
  transition: border-color .15s ease, background .15s ease;
  font-size: 13px;
  color: var(--wpsd-text-muted);
}
.wpsd-file-drop::before {
  content: attr(data-label);
}
.wpsd-file-drop.has-file::before { content: "\2713 "; color: #16a34a; font-weight: 700; }
.wpsd-file-drop.is-dragover, .wpsd-file-drop:hover {
  border-color: var(--wpsd-primary);
  background: rgba(var(--wpsd-primary-rgb), 0.05);
}
.wpsd-file-drop input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.wpsd-file-drop__name { font-weight: 600; color: var(--wpsd-text); }

/* The small circular chat "attach" button reuses .wpsd-file-drop for its
   click/drag-drop JS behavior, but not its full-size dropzone look — strip
   the parts (gap, empty ::before label slot) that were pushing the icon
   off-center inside the circle. */
.wpsd-composer__attach.wpsd-file-drop { gap: 0; }
.wpsd-composer__attach.wpsd-file-drop::before,
.wpsd-composer__attach.wpsd-file-drop.has-file::before { content: none; }

/* Buttons ----------------------------------------------------------------*/
.wpsd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform .1s ease, box-shadow .15s ease, opacity .15s ease;
}
.wpsd-btn--primary {
  background: linear-gradient(135deg, var(--wpsd-primary), var(--wpsd-primary-dark));
  color: #fff !important;
  box-shadow: 0 8px 20px rgba(var(--wpsd-primary-rgb), 0.28);
}
.wpsd-btn--primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(var(--wpsd-primary-rgb), 0.34); }
.wpsd-btn--primary:disabled { opacity: 0.65; cursor: default; transform: none; }
.wpsd-btn--outline {
  background: #fff; color: var(--wpsd-primary) !important;
  border: 1.5px solid var(--wpsd-border);
}
.wpsd-btn--outline:hover { border-color: var(--wpsd-primary); }
.wpsd-btn--small { padding: 7px 14px; font-size: 13px; border-radius: 8px; }
.wpsd-field--submit { margin-top: 4px; }

/* Alerts / success ---------------------------------------------------------*/
.wpsd-alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; font-weight: 500; }
.wpsd-alert--error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.wpsd-alert--success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

.wpsd-success { text-align: center; padding: 12px 8px 4px; }
.wpsd-success__icon {
  width: 52px; height: 52px; line-height: 52px; margin: 0 auto 14px;
  background: #dcfce7; color: #16a34a; border-radius: 50%;
  font-size: 24px; font-weight: 700;
}
.wpsd-success h4 { margin: 0 0 8px; font-size: 18px; }
.wpsd-success .wpsd-token {
  display: inline-block; font-size: 22px; font-weight: 800; letter-spacing: 0.5px;
  background: var(--wpsd-bg); border: 1px solid var(--wpsd-border);
  border-radius: 8px; padding: 6px 16px; margin: 4px 0 14px; font-family: ui-monospace, monospace;
}
.wpsd-success__note { color: var(--wpsd-text-muted); font-size: 13px; max-width: 380px; margin: 0 auto; }

/* Tables (my tickets) -------------------------------------------------------*/
.wpsd-table-wrap { overflow-x: auto; }
.wpsd-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.wpsd-table th {
  text-align: left; padding: 10px 14px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--wpsd-text-muted); border-bottom: 1.5px solid var(--wpsd-border);
}
.wpsd-table td { padding: 14px; border-bottom: 1px solid var(--wpsd-border); vertical-align: middle; }
.wpsd-table tr:last-child td { border-bottom: none; }
.wpsd-token-cell { font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: 0.2px; }
.wpsd-muted { color: var(--wpsd-text-muted); }

/* Badges --------------------------------------------------------------------*/
.wpsd-badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.wpsd-badge--open { background: #dbeafe; color: #1e40af; }
.wpsd-badge--in_progress { background: #fef3c7; color: #92400e; }
.wpsd-badge--resolved { background: #dcfce7; color: #166534; }
.wpsd-badge--closed { background: #e2e8f0; color: #475569; }
.wpsd-badge--priority-low { background: #f1f5f9; color: #475569; }
.wpsd-badge--priority-medium { background: #e0f2fe; color: #075985; }
.wpsd-badge--priority-high { background: #ffedd5; color: #9a3412; }
.wpsd-badge--priority-urgent { background: #fee2e2; color: #991b1b; }

/* Ticket thread ------------------------------------------------------------*/
.wpsd-ticket-detail { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.wpsd-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.wpsd-token-chip {
  font-family: ui-monospace, monospace; font-weight: 700; font-size: 12px;
  background: var(--wpsd-bg); border: 1px solid var(--wpsd-border); border-radius: 999px; padding: 4px 12px;
}

/* Chat header ---------------------------------------------------------------*/
.wpsd-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--wpsd-border);
  background: var(--wpsd-surface);
}
.wpsd-chat-header__avatar {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: #fff;
  background: linear-gradient(135deg, var(--wpsd-primary), var(--wpsd-primary-dark));
}
.wpsd-chat-header__info { min-width: 0; }
.wpsd-chat-header .wpsd-card__title { font-size: 16px; margin: 0 0 4px; }

/* Scrollable message area ----------------------------------------------------*/
.wpsd-thread-scroll {
  flex: 1 1 auto;
  max-height: 460px;
  min-height: 260px;
  overflow-y: auto;
  padding: 18px 20px;
  background:
    radial-gradient(circle at 8px 8px, rgba(var(--wpsd-primary-rgb), 0.05) 1.5px, transparent 1.5px) 0 0/28px 28px,
    var(--wpsd-bg);
  scroll-behavior: smooth;
  /* Some browsers/OSes tint the default scrollbar with the system accent
     color (which can turn up bright orange, red, etc. depending on the
     visitor's settings) — pin it to a neutral gray that matches our UI
     instead of leaving it to chance. */
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}
.wpsd-thread-scroll::-webkit-scrollbar { width: 8px; }
.wpsd-thread-scroll::-webkit-scrollbar-track { background: transparent; }
.wpsd-thread-scroll::-webkit-scrollbar-thumb {
  background-color: rgba(100, 116, 139, 0.35); border-radius: 8px;
}
.wpsd-thread-scroll::-webkit-scrollbar-thumb:hover { background-color: rgba(100, 116, 139, 0.55); }
.wpsd-thread { display: flex; flex-direction: column; gap: 3px; }

.wpsd-day-divider { display: flex; justify-content: center; margin: 14px 0; }
.wpsd-day-divider span {
  font-size: 11.5px; font-weight: 700; color: var(--wpsd-text-muted);
  background: var(--wpsd-surface); border: 1px solid var(--wpsd-border);
  border-radius: 999px; padding: 4px 12px;
}

/* Message bubbles -------------------------------------------------------------*/
.wpsd-msg {
  display: flex; align-items: flex-end; gap: 8px; margin: 6px 0;
  max-width: 100%;
  animation: wpsd-msg-in .18s ease;
}
@keyframes wpsd-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wpsd-msg--own { justify-content: flex-end; }
.wpsd-msg--other { justify-content: flex-start; }

.wpsd-msg__avatar {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: #fff;
  background: linear-gradient(135deg, #334155, #0f172a);
}
.wpsd-msg__col { max-width: 76%; display: flex; flex-direction: column; }
.wpsd-msg--own .wpsd-msg__col { align-items: flex-end; }
.wpsd-msg__author { font-size: 11.5px; font-weight: 700; color: var(--wpsd-text-muted); margin: 0 0 2px 4px; }

.wpsd-msg__bubble {
  position: relative;
  padding: 8px 12px 6px;
  border-radius: 14px;
  background: var(--wpsd-surface);
  border: 1px solid var(--wpsd-border);
  box-shadow: 0 1px 1px rgba(15,23,42,0.03);
}
.wpsd-msg--other .wpsd-msg__bubble { border-bottom-left-radius: 4px; }
.wpsd-msg--own .wpsd-msg__bubble {
  background: linear-gradient(135deg, var(--wpsd-primary), var(--wpsd-primary-dark));
  border-color: transparent; color: #fff;
  border-bottom-right-radius: 4px;
}
.wpsd-msg--own .wpsd-msg__text a { color: #fff; text-decoration: underline; }

.wpsd-msg__text { font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.wpsd-msg__text p { margin: 0 0 6px; }
.wpsd-msg__text p:last-child { margin-bottom: 0; }

.wpsd-msg__attachment { display: block; margin: 6px 0; }
.wpsd-msg__attachment img {
  max-width: 220px; max-height: 200px; border-radius: 8px; display: block; border: 1px solid rgba(0,0,0,0.08);
}

.wpsd-msg__meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  margin-top: 2px; font-size: 10.5px; opacity: 0.75;
}
.wpsd-msg--other .wpsd-msg__meta { color: var(--wpsd-text-muted); }
.wpsd-msg__ticks { display: inline-flex; color: #93c5fd; }
.wpsd-msg__ticks--pending { color: rgba(255,255,255,0.65); }
.wpsd-msg__ticks--failed { color: #fecaca; }

/* Optimistic "sending" / "failed" states applied client-side */
.wpsd-msg--pending .wpsd-msg__bubble { opacity: 0.72; }
.wpsd-msg--failed .wpsd-msg__bubble { background: linear-gradient(135deg, #b91c1c, #991b1b); cursor: pointer; }
.wpsd-msg--failed .wpsd-msg__meta::before { content: "\26A0"; margin-right: 3px; }

/* Composer (sticky chat input bar) -------------------------------------------*/
.wpsd-composer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--wpsd-border);
  background: var(--wpsd-surface);
}
.wpsd-composer__input {
  flex: 1 1 auto; resize: none; max-height: 100px; border-radius: 20px !important;
  padding: 10px 16px !important; overflow-y: hidden;
  scrollbar-width: thin; scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}
.wpsd-composer__input.wpsd-is-scrollable { overflow-y: auto; }
.wpsd-composer__input::-webkit-scrollbar { width: 6px; }
.wpsd-composer__input::-webkit-scrollbar-track { background: transparent; }
.wpsd-composer__input::-webkit-scrollbar-thumb { background-color: rgba(100, 116, 139, 0.35); border-radius: 8px; }
.wpsd-composer__attach {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: none !important;
  display: flex; align-items: center; justify-content: center; padding: 0 !important;
  background: var(--wpsd-bg); color: var(--wpsd-text-muted); cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.wpsd-composer__attach svg { pointer-events: none; }
.wpsd-composer__attach:hover { background: rgba(var(--wpsd-primary-rgb), 0.12); color: var(--wpsd-primary); }
.wpsd-composer__attach.has-file { background: rgba(var(--wpsd-primary-rgb), 0.15); color: var(--wpsd-primary); }
.wpsd-composer__hint { padding: 0 20px 14px; margin: 0; }
/* Keep the front-end chat send button identical to the admin composer.
   Front-end themes often ship broad button[type=submit] rules, so this
   selector intentionally has higher specificity and resets those values. */
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send {
  flex: 0 0 42px !important;
  width: 42px !important;
  min-width: 42px !important;
  max-width: 42px !important;
  height: 42px !important;
  min-height: 42px !important;
  max-height: 42px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--wpsd-primary), var(--wpsd-primary-dark)) !important;
  color: #fff !important;
  box-shadow: 0 6px 16px rgba(var(--wpsd-primary-rgb), 0.3) !important;
}
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send svg {
  display: block !important;
  width: 20px !important;
  height: 20px !important;
  margin-left: 1px !important;
  margin-right: 0 !important;
  flex: 0 0 auto !important;
}
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(var(--wpsd-primary-rgb), 0.38) !important; }
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send:active:not(:disabled) { transform: scale(0.92); box-shadow: 0 4px 10px rgba(var(--wpsd-primary-rgb), 0.3) !important; }
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--wpsd-primary-rgb), 0.35), 0 6px 16px rgba(var(--wpsd-primary-rgb), 0.3) !important; }
.wpsd .wpsd-composer .wpsd-btn.wpsd-btn--send:disabled { opacity: 0.55; cursor: default; transform: none; }
.wpsd-card > .wpsd-alert, .wpsd-card > .wpsd-empty-state { margin: 14px 20px 0; }

/* Neutralize the browser's default "required/invalid" outline on the
   composer textarea — on Firefox in particular this draws a bright
   orange/red glow around any empty required field, which looked like a
   stray UI glitch sitting on top of our own focus ring. */
.wpsd-composer textarea:required,
.wpsd-composer textarea:invalid,
.wpsd-composer input:required,
.wpsd-composer input:invalid {
  box-shadow: none;
}
.wpsd-composer textarea:-moz-ui-invalid,
.wpsd-composer input:-moz-ui-invalid {
  box-shadow: none !important;
}

/* Notices / empty states -----------------------------------------------------*/
.wpsd-notice--login {
  background: var(--wpsd-bg); border: 1px solid var(--wpsd-border); border-radius: var(--wpsd-radius);
  padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.wpsd-empty-state { text-align: center; padding: 30px 10px; color: var(--wpsd-text-muted); }
.wpsd-empty-state__icon { font-size: 30px; margin-bottom: 8px; }

@media (max-width: 480px) {
  .wpsd-card { padding: 20px 18px; }
  .wpsd-ticket-detail { padding: 0; }
  .wpsd-field-row { flex-direction: column; gap: 0; }
  .wpsd-thread-scroll { max-height: 62vh; }
  .wpsd-msg__col { max-width: 88%; }
}
