/* =====================================================
   GenPulse Web LLM — Stylesheet
   Dark-mode first, fully responsive, RTL-aware
   ===================================================== */

:root {
  --bg-0: #0d0d14;
  --bg-1: #13131f;
  --bg-2: #1b1b2e;
  --bg-3: #22223b;
  --border: #2e2e4a;
  --accent: #7c6df0;
  --accent-2: #22d3ee;
  --accent-glow: rgba(124, 109, 240, 0.25);
  --text-primary: #f0f0f8;
  --text-secondary: #9898b8;
  --text-muted: #55556e;
  --user-bubble: #2a2050;
  --user-border: #5a4fc8;
  --ai-bubble: #131a2e;
  --ai-border: #1e3a5f;
  --success: #22d3ee;
  --warning: #f59e0b;
  --error: #ef4444;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* ── Animated gradient bg ──────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(124,109,240,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 50% at 80% 85%, rgba(34,211,238,0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── App shell ─────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 820px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}

/* ── Header ────────────────────────────────────────── */
header {
  padding: 24px 0 16px;
  text-align: center;
  flex-shrink: 0;
}

.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo-icon {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px var(--accent));
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #a78bfa, var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Status bar ────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  transition: border-color 0.3s;
}

#status-bar.ready   { border-color: var(--success); }
#status-bar.loading { border-color: var(--accent); }
#status-bar.error   { border-color: var(--error); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

#status-bar.ready   .status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
#status-bar.loading .status-dot { background: var(--accent);  box-shadow: 0 0 8px var(--accent); animation: pulse 1.2s infinite; }
#status-bar.error   .status-dot { background: var(--error);   box-shadow: 0 0 8px var(--error); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

#status-text { flex: 1; color: var(--text-secondary); }

/* ── Progress bar ──────────────────────────────────── */
#progress-wrap {
  height: 3px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
  opacity: 0;
  transition: opacity 0.3s;
}
#progress-wrap.visible { opacity: 1; }

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--accent);
}

/* ── Chat window ───────────────────────────────────── */
#chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 300px;
  scroll-behavior: smooth;
}

#chat-window::-webkit-scrollbar { width: 4px; }
#chat-window::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Message bubbles ───────────────────────────────── */
.msg {
  display: flex;
  gap: 10px;
  animation: fadeUp 0.25s ease;
}

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

.msg.user  { flex-direction: row-reverse; }
.msg.user[dir="rtl"]  { flex-direction: row; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.user .avatar  { background: linear-gradient(135deg, var(--accent), #a78bfa); }
.msg.ai   .avatar  { background: linear-gradient(135deg, #1e3a5f, #164e63); border: 1px solid var(--ai-border); }

.bubble {
  max-width: 76%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.93rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--user-border);
  border-top-right-radius: var(--radius-sm);
  color: #d4d0ff;
}

.msg.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--ai-border);
  border-top-left-radius: var(--radius-sm);
  color: var(--text-primary);
}

/* Blinking cursor during streaming */
.bubble.streaming::after {
  content: "▍";
  display: inline-block;
  color: var(--accent);
  animation: blink .7s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Welcome / empty state ─────────────────────────── */
#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 0;
  text-align: center;
  color: var(--text-secondary);
}

#welcome h2 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
#welcome p  { font-size: 0.85rem; max-width: 360px; }

.example-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.example-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: border-color .2s, background .2s, color .2s;
  line-height: 1.4;
}

.example-btn:hover {
  border-color: var(--accent);
  background: var(--bg-3);
  color: var(--text-primary);
}

/* ── Controls panel ────────────────────────────────── */
#controls {
  display: flex;
  gap: 16px;
  padding: 10px 0 6px;
  flex-wrap: wrap;
  align-items: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 140px;
}

.control-group label {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-3);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
}

.range-val {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Input area ────────────────────────────────────── */
#input-area {
  display: flex;
  gap: 8px;
  padding: 12px 0 20px;
  flex-shrink: 0;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 0.93rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color .2s, box-shadow .2s;
}

#user-input::placeholder { color: var(--text-muted); }

#user-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#send-btn, #clear-btn {
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .1s, box-shadow .2s;
}

#send-btn {
  width: 46px; height: 46px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

#send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

#send-btn:active:not(:disabled) { transform: translateY(0); }

#send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

#clear-btn {
  width: 38px; height: 38px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

#clear-btn:hover { border-color: var(--error); color: var(--error); }

/* ── Footer ────────────────────────────────────────── */
footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding-bottom: 12px;
  flex-shrink: 0;
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 540px) {
  h1 { font-size: 1.35rem; }
  .example-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 90%; }
  #controls { gap: 10px; }
}
