/* =========================================
   FitGen AI • Chat UI Styles
   -----------------------------------------
   - Modern glass header
   - Cozy chat bubbles (bot + user)
   - Quick action chips (responsive grid)
   - Sticky input bar with clear focus states
   - Dark mode + reduced motion
   ========================================= */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #0b1020;
  --bg-accent: #0f1630;
  --text: #0f172a;        /* slate-900 */
  --muted: #475569;       /* slate-600 */
  --card: #ffffff;
  --soft: rgba(255, 255, 255, 0.6);

  --brand-1: #6ee7f3;     /* cyan-300 */
  --brand-2: #a78bfa;     /* violet-400 */
  --brand-3: #22d3ee;     /* cyan-400 */

  --bot-bubble: #f1f5f9;  /* slate-100 */
  --user-bubble: #0ea5e9; /* sky-500 */
  --user-text: #ffffff;

  --ring: #60a5fa;        /* blue-400 */
  --danger: #ef4444;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow-lg: 0 20px 45px rgba(2, 6, 23, 0.18);
  --shadow-md: 0 10px 25px rgba(2, 6, 23, 0.12);
  --border: 1px solid rgba(15, 23, 42, 0.06);
}

/* ---------- Base / Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  line-height: 1.55;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(102,126,234,.25), transparent 60%),
    radial-gradient(800px 400px at 90% 0%, rgba(118,75,162,.25), transparent 60%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-accent) 100%);
  overflow-y: auto;
}

/* Container constrains everything */
.container {
  max-width: 1120px;
  margin: 24px auto;
  padding: 0 20px 24px;
  display: grid;
  gap: 18px;
}

/* ---------- Header ---------- */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 18px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(180deg, rgba(255,255,255,.75), rgba(255,255,255,.6));
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  backdrop-filter: saturate(140%) blur(14px);
  border: var(--border);
  box-shadow: var(--shadow-md);
}

.header-content {
  display: grid;
  gap: 8px;
}

.chat-header h1 {
  margin: 0;
  font-size: clamp(20px, 2vw, 26px);
  font-weight: 700;
  letter-spacing: -0.015em;
  background: linear-gradient(90deg, var(--brand-1), var(--brand-2), var(--brand-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chat-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.18);
  font-size: 12px;
  color: #4338ca;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9ca3af;
  position: relative;
}

.status-dot.online { background: #22c55e; }
.status-dot.online::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  border: 2px solid rgba(34, 197, 94, .35);
  animation: ping 1.8s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes ping {
  0% { transform: scale(0.8); opacity: .9; }
  80%, 100% { transform: scale(1.6); opacity: 0; }
}

/* ---------- Chat Area ---------- */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  border: var(--border);
  box-shadow: var(--shadow-lg);
  min-height: min(62vh, 760px);
  max-height: 68vh;
  overflow-y: auto;
  scroll-padding-bottom: 120px;
}

/* Single message row */
.message {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: start;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #f1f5f9;
  border: 1px solid rgba(15, 23, 42, 0.06);
}

/* Bubble base */
.message-content {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: var(--bot-bubble);
  box-shadow: 0 6px 20px rgba(2, 6, 23, 0.06);
  font-size: 15px;
}

.message-content p { margin: 0 0 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul { margin: 6px 0 0 18px; }

/* Bot vs User variations */
.bot-message .message-content {
  border-top-left-radius: 6px;
}

.user-message {
  grid-template-columns: 1fr 36px;
}

.user-message .message-avatar {
  order: 2;
  background: rgba(14, 165, 233, .08);
  border-color: rgba(14, 165, 233, .25);
}

.user-message .message-content {
  order: 1;
  justify-self: end;
  background: linear-gradient(180deg, var(--user-bubble), #0284c7);
  color: var(--user-text);
  border-color: rgba(2, 132, 199, .5);
  border-top-right-radius: 6px;
}

.user-message .message-content a { color: #e0f2fe; text-decoration: underline; }

/* ---------- Quick Responses ---------- */
.quick-responses {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .quick-responses { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .quick-responses { grid-template-columns: repeat(2, 1fr); }
}

.quick-btn {
  appearance: none;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background:
    linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.85));
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.06);
  color: #0f172a;
  padding: 10px 12px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.quick-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.10);
  border-color: rgba(99, 102, 241, 0.35);
}

.quick-btn:active { transform: translateY(0); }

.quick-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, .35);
}

/* ---------- Input Section ---------- */
.input-section {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: grid;
  gap: 8px;
  padding: 10px 0 0;
}

.input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.86));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.10);
}

#userInput {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 15px;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}

#userInput::placeholder { color: #94a3b8; }

#sendButton {
  appearance: none;
  border: none;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: radial-gradient(120% 100% at 30% 0%, var(--brand-2), var(--brand-3));
  color: white;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.18);
  transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}

#sendButton:hover { transform: translateY(-1px) scale(1.02); }
#sendButton:active { transform: translateY(0) scale(.98); }

#sendButton:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

.send-icon { font-size: 18px; line-height: 1; }

.input-footer {
  text-align: center;
  color: #64748b;
  font-size: 12px;
}

/* ---------- Scrollbar (WebKit) ---------- */
.chat-container::-webkit-scrollbar { width: 10px; }
.chat-container::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.18);
  border-radius: 999px;
}
.chat-container::-webkit-scrollbar-track { background: transparent; }

/* ---------- Accessibility / States ---------- */
:focus-visible {
  outline: 3px solid transparent;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, .45);
  border-radius: 12px;
}

[aria-busy="true"] { cursor: progress; }

/* ---------- Dark Mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --text: #e5e7eb;
    --muted: #9aa3b2;
    --card: rgba(17, 24, 39, 0.75);
    --bot-bubble: rgba(30, 41, 59, 0.9);
    --border: 1px solid rgba(255, 255, 255, 0.06);
    --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.28);
  }

  .chat-header {
    background: linear-gradient(180deg, rgba(30,41,59,.75), rgba(30,41,59,.6));
    border: var(--border);
  }

  .chat-container {
    background: rgba(17, 24, 39, 0.7);
    border: var(--border);
  }

  .message-avatar { background: rgba(148, 163, 184, .12); border-color: rgba(255,255,255,.06); }

  .quick-btn {
    background: linear-gradient(180deg, rgba(31,41,55,.9), rgba(31,41,55,.8));
    color: #e5e7eb;
    border-color: rgba(255,255,255,.06);
  }

  .input-container {
    background: linear-gradient(180deg, rgba(31,41,55,.9), rgba(31,41,55,.82));
    border-color: rgba(255,255,255,.06);
  }

  #userInput { color: #e5e7eb; }
  #userInput::placeholder { color: #94a3b8; }
}

/* ---------- Motion Reduction ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
