/* Chat overrides for enhanced SpaceCatWeb experience */
body.chat-open-active #chat-trigger {
  transform: translate3d(0, 90px, 0) scale(0.65) rotate(14deg);
  opacity: 0;
  pointer-events: none;
  filter: blur(1px);
}
body.chat-open-active #scroll-to-top {
  opacity: 0;
  transform: translate3d(0, 60px, 0) scale(0.9);
  pointer-events: none;
}
body.chat-open-active #scroll-to-top.visible {
  opacity: 0;
}
body.chat-open-active #uwf-chat-container {
  bottom: 25px;
}

/* Hide mobile menu when chat is open */
@media (max-width: 767px) {
  body.chat-open-active .header-area .main-nav .nav {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translate3d(0, -20px, 0) !important;
  }
  
  body.chat-open-active .header-area .menu-trigger {
    opacity: 0.3 !important;
    pointer-events: none !important;
  }
}

#chat-main-area {
  grid-template-rows: auto 1fr auto auto auto;
  grid-template-areas:
    "head"
    "history"
    "typing"
    "input"
    "policy";
}
#chat-main-area .chat-policy-bubble {
  grid-area: policy;
}

.sender-chip .sender-icon {
  width: 10px;
  height: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: 50%;
  flex-shrink: 0;
}
.sender-chip .sender-icon i {
  display: none;
}
.sender-chip.sender-admin .sender-icon::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #2fae4b;
  border-radius: 50%;
  display: block;
}
.sender-chip.sender-user .sender-icon {
  display: none;
}
.msg-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}
.msg-row.msg-admin-row {
  align-items: flex-start;
}
.msg-row.msg-user-row {
  align-items: flex-end;
}
.msg-bubble {
  position: relative;
  width: fit-content;
  margin-bottom: 0;
}
.msg-row .msg-timestamp {
  font-size: 0.62rem;
  letter-spacing: 0.2px;
  opacity: 0.78;
  transition: opacity 0.18s var(--ease-smooth);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 0;
  transform: none;
  pointer-events: auto;
}
.msg-row.msg-admin-row .msg-timestamp {
  color: rgba(15, 21, 53, 0.52);
  padding: 1px 6px;
}
.msg-row.msg-user-row .msg-timestamp {
  background: rgba(230, 126, 34, 0.15);
  color: rgba(211, 84, 0, 0.9);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
}
.msg-row:hover .msg-timestamp,
.msg-row:focus-within .msg-timestamp {
  opacity: 1;
}
.sender-chip.sender-admin {
  background: linear-gradient(90deg, #2fae4b, #1f8a36);
  color: #ffffff;
}
.sender-chip.sender-admin .sender-name {
  color: #ffffff;
}
.sender-chip.sender-user {
  background: rgba(0, 0, 0, 0.08);
  color: #333;
}
.sender-chip.sender-user .sender-name {
  color: #333;
}

#chat-history {
  gap: 8px;
}

.chat-policy-bubble {
  margin: 0 20px 18px;
  padding: 16px 48px 16px 18px;
  border-radius: 14px;
  background: rgba(211, 84, 0, 0.08);
  border: 1px solid rgba(211, 84, 0, 0.15);
  border-left: 4px solid var(--accent);
  color: rgba(15, 21, 53, 0.75);
  font-size: 0.82rem;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: 0 16px 40px rgba(15, 42, 80, 0.12);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s var(--ease-smooth), box-shadow 0.2s var(--ease-smooth);
}
.chat-policy-bubble:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 46px rgba(15, 42, 80, 0.15);
}
.chat-policy-bubble:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.chat-policy-bubble i {
  font-size: 1rem;
  color: var(--accent);
  margin-top: 2px;
}
.chat-policy-bubble .policy-dismiss {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(211, 84, 0, 0.12);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s var(--ease-smooth), transform 0.2s var(--ease-smooth);
}
.chat-policy-bubble .policy-dismiss:hover {
  background: rgba(211, 84, 0, 0.22);
  transform: rotate(90deg);
}
.chat-policy-bubble .policy-dismiss:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chat-policy-bubble .policy-dismiss i {
  margin-top: 0;
  font-size: 0.85rem;
}
.chat-policy-bubble .policy-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-policy-bubble .policy-link {
  font-size: 0.75rem;
  font-weight: 600;
  color: #D35400;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chat-policy-bubble .policy-link i {
  font-size: 0.7rem;
  margin-top: 0;
}

.chat-policy-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 40, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 25;
}
.chat-policy-overlay[hidden] {
  display: none;
}
.chat-policy-dialog {
  width: min(520px, 100%);
  max-height: calc(100% - 40px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(8, 19, 38, 0.35);
  border: 1px solid rgba(211, 84, 0, 0.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-policy-dialog-header {
  padding: 18px 22px;
  background: linear-gradient(135deg, #E67E22, #D35400);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.chat-policy-dialog-header h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.chat-policy-dialog-close {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s var(--ease-smooth), transform 0.2s var(--ease-smooth);
}
.chat-policy-dialog-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}
.chat-policy-dialog-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}
.chat-policy-dialog-body {
  padding: 18px 22px;
  overflow-y: auto;
  color: #182033;
  font-size: 0.82rem;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-policy-dialog-body h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f1535;
  margin: 6px 0 4px;
}
.chat-policy-dialog-body p {
  margin: 0;
  color: rgba(15, 21, 53, 0.78);
}
.chat-policy-dialog-body ul {
  margin: 0;
  padding-left: 18px;
  list-style: disc;
}
.chat-policy-dialog-body li {
  margin-bottom: 6px;
}

.chat-empty-state {
  margin: auto;
  text-align: center;
  padding: 24px 20px;
  border-radius: 18px;
  border: 1px dashed rgba(211, 84, 0, 0.2);
  background: linear-gradient(145deg, rgba(211, 84, 0, 0.04), rgba(255, 255, 255, 0.92));
  max-width: 260px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 18px 38px rgba(15, 42, 80, 0.08);
}
.chat-empty-state .empty-icon {
  width: 50px;
  height: 50px;
  border-radius: 18px;
  background: rgba(211, 84, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: var(--accent);
  box-shadow: 0 10px 24px rgba(211, 84, 0, 0.15);
}
.chat-empty-state h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #0f1535;
  margin-bottom: 10px;
}
.chat-empty-state p {
  font-size: 0.85rem;
  color: rgba(15, 21, 53, 0.65);
}

@media (max-width: 640px) {
  .chat-policy-bubble {
    margin: 0 14px 16px;
    font-size: 0.76rem;
    padding-right: 44px;
  }
}

@media (max-width: 480px) {
  body.chat-open-active #uwf-chat-container {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .chat-policy-dialog {
    width: 100%;
    max-height: calc(100% - 24px);
  }
  .chat-policy-overlay {
    padding: 16px;
  }
}
