/* ============================================================
   Swimtraxx Support Chat — chat.css
   Mobile-first, dark-mode, Swimtraxx branded
   ============================================================ */

:root {
  --st-navy: #0f223b;
  --st-navy-secondary: #1E4565;
  --st-turquoise: #46bfe0;
  --st-white: #ffffff;
  --st-grey: #9d9c9c;
  --st-grey-light: #dadada;
  --st-gradient: linear-gradient(135deg, #46bfe0, #0f223b);
  --st-gradient-dark: linear-gradient(135deg, #1a4f6e 0%, #0f223b 50%, #0f223b 100%);
  --st-radius: 10px;
  --st-radius-lg: 20px;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Montserrat", sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--st-gradient-dark);
  color: var(--st-white);
  display: flex;
  flex-direction: column;
}

/* ---- Layout Shell ---- */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Header ---- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 34, 59, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-header__logo {
  height: 20px;
  width: auto;
}

.chat-header__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--st-white);
  flex: 1;
}

.chat-header__new-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--st-grey-light);
  font-family: "Montserrat", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}

.chat-header__new-btn:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.25);
  color: var(--st-white);
}

.chat-header__new-btn:active {
  transform: scale(0.96);
}

.chat-header__new-btn svg {
  flex-shrink: 0;
}

/* ---- Messages Area ---- */
.chat-app > main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  /* Subtle scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

/* ---- Message Bubbles ---- */
.message {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--st-radius-lg);
  line-height: 1.55;
  font-size: 0.925rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: msgFadeIn 0.3s ease forwards;
  opacity: 0;
}

@keyframes msgFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Bot messages — left */
.message--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--st-grey-light);
  border-bottom-left-radius: 6px;
}

/* User messages — right */
.message--user {
  align-self: flex-end;
  background: var(--st-turquoise);
  color: var(--st-navy);
  border-bottom-right-radius: 6px;
  font-weight: 500;
}

/* Operator messages — left, accented */
.message--operator {
  align-self: flex-start;
  background: rgba(70, 191, 224, 0.12);
  border: 1px solid rgba(70, 191, 224, 0.35);
  color: var(--st-grey-light);
  border-bottom-left-radius: 6px;
}

.message--operator::before {
  content: "Support Agent";
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--st-turquoise);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* System / info messages */
.message--system {
  align-self: center;
  max-width: 90%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--st-grey);
  font-size: 0.84rem;
  text-align: center;
  border-radius: var(--st-radius);
}

/* ---- Typing Indicator ---- */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--st-radius-lg);
  border-bottom-left-radius: 6px;
  animation: msgFadeIn 0.2s ease forwards;
  opacity: 0;
}

.typing-indicator__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--st-grey);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-indicator__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ---- Escalation Countdown ---- */
.escalation-countdown {
  align-self: flex-start;
  max-width: 82%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(70, 191, 224, 0.08);
  border: 1px solid rgba(70, 191, 224, 0.25);
  border-radius: var(--st-radius-lg);
  border-bottom-left-radius: 6px;
  animation: msgFadeIn 0.3s ease forwards;
  opacity: 0;
}

.escalation-countdown__icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.escalation-countdown__text {
  font-size: 0.88rem;
  color: var(--st-grey-light);
  line-height: 1.45;
}

.escalation-countdown__timer {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--st-turquoise);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 3.2em;
  text-align: right;
}

/* ---- Email Prompt ---- */
.email-prompt {
  align-self: flex-start;
  max-width: 82%;
  padding: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(70, 191, 224, 0.3);
  border-radius: var(--st-radius-lg);
  border-bottom-left-radius: 6px;
  animation: msgFadeIn 0.3s ease forwards;
  opacity: 0;
}

.email-prompt__text {
  font-size: 0.92rem;
  color: var(--st-grey-light);
  line-height: 1.5;
  margin-bottom: 12px;
}

.email-prompt__form {
  display: flex;
  gap: 8px;
}

.email-prompt__input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--st-radius);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--st-white);
  font-family: "Montserrat", sans-serif;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.email-prompt__input:focus {
  border-color: var(--st-turquoise);
}

.email-prompt__input::placeholder {
  color: var(--st-grey);
}

.email-prompt__submit {
  padding: 10px 18px;
  border-radius: var(--st-radius);
  border: none;
  background: var(--st-turquoise);
  color: var(--st-white);
  font-family: "Montserrat", sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.email-prompt__submit:hover {
  background: #3aacc9;
}

.email-prompt__submit:active {
  transform: scale(0.97);
}

.email-prompt__submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Input Area ---- */
.chat-input-area {
  flex-shrink: 0;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(15, 34, 59, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 820px;
  margin: 0 auto;
}

.chat-input-container {
  flex: 1;
  position: relative;
}

.chat-input {
  width: 100%;
  padding: 12px 16px;
  padding-right: 52px;
  border-radius: var(--st-radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--st-white);
  font-family: "Montserrat", sans-serif;
  font-size: 0.925rem;
  line-height: 1.45;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: none;
}

.chat-input::-webkit-scrollbar {
  display: none;
}

.chat-input:focus {
  border-color: rgba(70, 191, 224, 0.5);
  box-shadow: 0 0 0 2px rgba(70, 191, 224, 0.1);
}

.chat-input::placeholder {
  color: var(--st-grey);
  font-weight: 300;
}

.char-counter {
  position: absolute;
  bottom: -18px;
  right: 4px;
  font-size: 0.7rem;
  color: var(--st-grey);
  opacity: 0;
  transition: opacity 0.2s;
}

.char-counter--visible {
  opacity: 1;
}

.char-counter--warning {
  color: #f59e0b;
}

.char-counter--limit {
  color: #ef4444;
}

/* Send button */
.chat-send-btn {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--st-turquoise);
  color: var(--st-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
  background: #3aacc9;
  transform: scale(1.06);
}

.chat-send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-send-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Footer ---- */
.chat-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 16px;
  background: rgba(15, 34, 59, 0.85);
}

.chat-footer__text {
  color: var(--st-grey);
  font-size: 0.72rem;
  opacity: 0.6;
}

/* ---- Desktop Adjustments ---- */
@media (min-width: 600px) {
  .chat-header {
    padding: 18px 28px;
  }

  .chat-messages {
    padding: 28px 24px;
  }

  .message {
    max-width: 70%;
    font-size: 0.94rem;
  }

  .chat-input-area {
    padding: 16px 24px;
  }

  .email-prompt {
    max-width: 70%;
  }

  .escalation-countdown {
    max-width: 70%;
  }
}

@media (min-width: 960px) {
  .chat-app {
    margin-top: 20px;
    margin-bottom: 20px;
    height: calc(100% - 40px);
    border-radius: var(--st-radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  }

  .message {
    max-width: 65%;
  }
}
