/* ==========================================================================
   TGSIMS  -  Support Ticket System & Floating Messenger Widget
   ========================================================================== */

/* ---- Floating Action Button (FAB) ---- */
.support-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.38), 0 2px 6px rgba(0, 0, 0, 0.12);
  z-index: 998;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  outline: none;
}

.support-fab:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.48), 0 4px 8px rgba(0, 0, 0, 0.14);
}

.support-fab:active {
  transform: translateY(0) scale(0.96);
}

.support-fab svg {
  width: 26px;
  height: 26px;
  stroke-width: 2.1;
  transition: transform 0.2s ease;
}

.support-fab.is-active svg {
  transform: rotate(90deg);
}

.support-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--hue-danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 5px rgba(239, 68, 68, 0.4);
  animation: pulse-fab 2s infinite;
}

@keyframes pulse-fab {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ---- Messenger Chat Widget Shell ---- */
.support-widget {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18), 0 0 0 1px var(--border);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.95);
  transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
}

.support-widget.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Widget Header */
.widget-header {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  color: #ffffff;
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.widget-header-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.widget-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.widget-title-text {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.widget-sub-text {
  font-size: 0.72rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.widget-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  display: inline-block;
}

.widget-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

.widget-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Widget Views */
.widget-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* View 1: Home / List */
.widget-hero-card {
  margin: 1rem;
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}

.widget-hero-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.widget-hero-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 0.85rem;
}

.widget-section-header {
  padding: 0 1rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.widget-ticket-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.widget-ticket-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: block;
  text-decoration: none;
  color: inherit;
}

.widget-ticket-item:hover {
  border-color: var(--brand-300);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

/* View 2: Form */
.widget-form-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.widget-category-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.widget-chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.widget-chip.is-active, .widget-chip:hover {
  border-color: var(--brand);
  background: var(--brand-50);
  color: var(--brand-600);
}

/* View 3: Chat Thread */
.widget-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.chat-bubble-wrap.is-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-bubble-wrap.is-support {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.chat-bubble {
  padding: 0.65rem 0.95rem;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-xs);
}

.chat-bubble-wrap.is-user .chat-bubble {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
}

.chat-bubble-wrap.is-support .chat-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
}

.chat-bubble-time {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.chat-system-pill {
  align-self: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  margin: 0.35rem 0;
}

.chat-resolved-alert {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--hue-success);
  padding: 0.6rem 0.85rem;
  font-size: 0.78rem;
  border-radius: var(--r-md);
  margin: 0 1rem 0.5rem;
  text-align: center;
}

/* Chat Input Composer */
.widget-chat-input-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.widget-chat-textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.55rem 0.8rem;
  font-size: 0.88rem;
  color: var(--text);
  resize: none;
  max-height: 100px;
  min-height: 38px;
  line-height: 1.35;
  outline: none;
  font-family: inherit;
}

.widget-chat-textarea:focus {
  border-color: var(--brand);
}

.widget-chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--brand);
  color: #ffffff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.widget-chat-send-btn:hover {
  background: var(--brand-600);
  transform: scale(1.05);
}

.widget-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Notification Item in Topbar Dropdown */
.notif-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  display: block;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
  cursor: pointer;
}

.notif-item:hover {
  background: var(--surface-2);
}

.notif-item.is-unread {
  background: var(--brand-50);
}

.notif-item-title {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.notif-item-msg {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-item-time {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* ---- Backdrop for overlay and outside clicks ---- */
.support-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 996;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  cursor: pointer;
}

.support-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

/* Mobile responsive (bottom sheet with tap-outside-to-close) */
@media (max-width: 600px) {
  .support-widget {
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 86vh;
    height: 86dvh;
    max-height: 86vh;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, visibility 0.2s;
  }

  .support-widget.is-open {
    transform: translateY(0);
  }

  .support-fab {
    bottom: 18px;
    right: 18px;
    width: 52px;
    height: 52px;
  }
}

