/* ==========================================================================
   AI Chatbot — Portfolio Demo
   Vanilla CSS. Dark futuristic theme: cyan (#00d4ff) + violet (#7c3aed)
   on dark bg (#050810). Glassmorphism bubbles, smooth animations.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg:            #050810;
  --bg-soft:       #0a0f1f;
  --surface:       rgba(18, 24, 44, 0.55);
  --surface-strong:rgba(22, 30, 54, 0.85);
  --border:        rgba(0, 212, 255, 0.18);
  --border-soft:   rgba(255, 255, 255, 0.06);

  --cyan:          #00d4ff;
  --violet:        #7c3aed;
  --violet-soft:   #a78bfa;
  --text:          #e6edf7;
  --text-dim:      #9aa6bd;
  --text-faint:    #647089;

  --radius-lg:     22px;
  --radius-md:     14px;
  --radius-sm:     10px;

  --shadow-glow:   0 0 0 1px rgba(0, 212, 255, 0.06), 0 18px 60px rgba(0, 0, 0, 0.55);
  --shadow-bubble: 0 6px 22px rgba(0, 0, 0, 0.35);

  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Space Grotesk', var(--font-body);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Ambient background ---------- */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Soft glowing orbs that drift slowly */
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}
.orb--cyan {
  width: 460px; height: 460px;
  top: -120px; left: -120px;
  background: radial-gradient(circle at 30% 30%, #00d4ff, transparent 70%);
}
.orb--violet {
  width: 520px; height: 520px;
  bottom: -160px; right: -140px;
  background: radial-gradient(circle at 70% 70%, #7c3aed, transparent 70%);
  animation-delay: -6s;
}

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, -30px) scale(1.12); }
}

/* Faint tech grid overlay */
.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 58, 237, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, #000 35%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 35%, transparent 78%);
}

/* ---------- App shell ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 860px;
  height: min(92vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  overflow: hidden;
}

/* ---------- Header ---------- */
.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.05), transparent);
}

.app__title-wrap { display: flex; align-items: center; gap: 12px; }

/* Glowing avatar orb */
.app__avatar {
  position: relative;
  width: 42px; height: 42px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.app__avatar-core {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 0 18px rgba(0, 212, 255, 0.55);
}
.app__avatar-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 212, 255, 0.35);
  animation: pulse-ring 2.4s ease-out infinite;
}
@keyframes pulse-ring {
  0%   { transform: scale(0.85); opacity: 0.9; }
  100% { transform: scale(1.25); opacity: 0; }
}

.app__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  background: linear-gradient(90deg, #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.app__subtitle {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #34f5c5;
  box-shadow: 0 0 8px #34f5c5;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.app__header-actions { display: flex; align-items: center; gap: 10px; }

/* Demo badge */
.badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.35);
}

/* Icon button (clear) */
.icon-btn {
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  transition: all 0.18s ease;
}
.icon-btn:hover {
  color: var(--cyan);
  border-color: var(--border);
  background: rgba(0, 212, 255, 0.08);
  transform: translateY(-1px);
}
.icon-btn:active { transform: translateY(0); }
.icon-btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.18);
  border-radius: 8px;
}
.messages::-webkit-scrollbar-thumb:hover { background: rgba(0, 212, 255, 0.3); }

/* Single message row */
.msg {
  display: flex;
  max-width: 100%;
  opacity: 0;
  transform: translateY(8px);
  animation: msg-in 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
@keyframes msg-in {
  to { opacity: 1; transform: translateY(0); }
}

.msg--user { justify-content: flex-end; }
.msg--bot  { justify-content: flex-start; }

.msg__bubble {
  max-width: min(78%, 560px);
  padding: 11px 15px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-bubble);
}

/* Bot bubble: glass with cyan tint */
.msg--bot .msg__bubble {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* User bubble: violet/cyan gradient */
.msg--user .msg__bubble {
  background: linear-gradient(135deg, var(--violet), #4f46e5 60%, var(--cyan));
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg__meta {
  font-size: 0.66rem;
  color: var(--text-faint);
  margin: 5px 4px 0;
  letter-spacing: 0.3px;
}
.msg--user .msg__meta { text-align: right; }

/* Inline code blocks for math/tech answers */
.msg__bubble code {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 0.86em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 212, 255, 0.12);
  color: var(--cyan);
}
.msg--user .msg__bubble code {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* ---------- Typing indicator ---------- */
.typing {
  padding: 0 20px 6px;
  display: flex;
  justify-content: flex-start;
}
.typing.hidden { display: none; }

.typing__bubble {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  padding: 13px 16px;
  display: inline-flex;
  gap: 5px;
  box-shadow: var(--shadow-bubble);
}
.typing__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  opacity: 0.5;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing__dot:nth-child(2) { animation-delay: 0.18s; }
.typing__dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Quick reply chips ---------- */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 20px 8px;
  border-top: 1px solid var(--border-soft);
}

.chip {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0, 212, 255, 0.05);
  color: var(--text);
  transition: all 0.18s ease;
  white-space: nowrap;
}
.chip:hover {
  background: rgba(0, 212, 255, 0.14);
  border-color: var(--cyan);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 212, 255, 0.2);
}
.chip:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.25), transparent);
}

.composer__input {
  flex: 1;
  height: 46px;
  padding: 0 16px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  transition: all 0.18s ease;
}
.composer__input::placeholder { color: var(--text-faint); }
.composer__input:focus {
  outline: none;
  border-color: var(--cyan);
  background: rgba(0, 212, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}

.composer__send {
  width: 46px; height: 46px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 6px 18px rgba(0, 212, 255, 0.35);
  transition: all 0.18s ease;
}
.composer__send:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(124, 58, 237, 0.45);
}
.composer__send:active { transform: translateY(0); }
.composer__send:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { padding: 0; }
  .app {
    height: 100vh;
    max-width: 100%;
    border-radius: 0;
  }
  .app__header { padding: 12px 14px; }
  .messages { padding: 16px 14px 8px; }
  .quick-replies { padding: 8px 14px; }
  .composer { padding: 10px 14px 14px; }
  .msg__bubble { max-width: 86%; font-size: 0.92rem; }
  .app__title { font-size: 1.05rem; }
  .badge { display: none; } /* keep header compact on mobile */
}

/* Reduced-motion accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
