/* ============================================================
   PHANTXM - Stylesheet
   Aesthetic: Terminal-Cyberpunk / Dark Glass
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400&family=Syne:wght@400;600;700;800&family=JetBrains+Mono:wght@300;400;500&display=swap');

/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg-void:     #060608;
  --bg-surface:  #0d0e14;
  --bg-glass:    rgba(16,18,28,0.85);
  --bg-card:     rgba(22,25,38,0.9);
  --border:      rgba(80,90,140,0.25);
  --border-glow: rgba(100,120,255,0.4);

  --accent:      #6c63ff;
  --accent-2:    #00d4ff;
  --accent-3:    #ff2d78;
  --success:     #00e5a0;
  --warning:     #ffb020;

  --text-1:      #e8eaf0;
  --text-2:      #8890b0;
  --text-3:      #4a5070;

  --user-bubble: rgba(108, 99, 255, 0.12);
  --ai-bubble:   rgba(16, 18, 28, 0.95);

  --font-display: 'Syne', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
  --font-ui:      'Space Mono', monospace;

  --radius:      12px;
  --radius-lg:   20px;
  --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --glow:        0 0 30px rgba(108, 99, 255, 0.15);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 15px; }

body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg-void);
  color: var(--text-1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Background ─────────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 20%, rgba(108,99,255,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 40% 60% at 80% 80%, rgba(0,212,255,0.04) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,0.015) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.015) 40px);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ─────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  position: relative;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 50%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-version {
  font-size: 0.6rem;
  color: var(--text-3);
  letter-spacing: 0.15em;
  font-family: var(--font-mono);
  align-self: flex-end;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badge.active {
  border-color: var(--success);
  color: var(--success);
  background: rgba(0,229,160,0.08);
}

/* ── Mode Toggle ────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 5px 10px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--text-2);
  letter-spacing: 0.06em;
  transition: var(--transition);
  text-transform: uppercase;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.memory-indicator {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition);
}

.memory-indicator:hover { background: rgba(255,255,255,0.04); }
.memory-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Main Layout ────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */
#sidebar {
  width: 240px;
  background: var(--bg-glass);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition);
}

#sidebar.collapsed { width: 0; }

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 0.6rem;
  color: var(--text-3);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 10px;
  font-family: var(--font-mono);
}

/* Skills list */
.skill-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 3px;
  font-size: 0.75rem;
  color: var(--text-2);
  transition: var(--transition);
  cursor: default;
}

.skill-item.active { color: var(--text-1); background: rgba(108,99,255,0.08); }
.skill-item.active .skill-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.skill-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }

/* Commands reference */
.cmd-list { display: flex; flex-direction: column; gap: 6px; }
.cmd-item {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: var(--transition);
}
.cmd-item:hover { border-color: var(--accent); color: var(--accent); background: rgba(108,99,255,0.06); }
.cmd-item code { color: var(--accent-2); }

/* Model selector */
.model-select {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  outline: none;
}

/* ── Chat area ───────────────────────────────────────────── */
#chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--text-3); border-radius: 4px; }

/* ── Welcome ────────────────────────────────────────────── */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px;
  gap: 20px;
}

.welcome-logo {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 40%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.welcome-sub {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

.chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 8px 14px;
  border-radius: 30px;
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: var(--transition);
  background: rgba(255,255,255,0.02);
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(108,99,255,0.08);
}

/* ── Message bubbles ─────────────────────────────────────── */
.message {
  display: flex;
  gap: 12px;
  max-width: 820px;
  animation: msg-in 0.3s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.ai   { align-self: flex-start; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.avatar.user-av { background: rgba(108,99,255,0.2); border: 1px solid rgba(108,99,255,0.3); color: var(--accent); }
.avatar.ai-av   { background: rgba(0,212,255,0.1);  border: 1px solid rgba(0,212,255,0.2);  color: var(--accent-2); }

.bubble {
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  line-height: 1.6;
  font-size: 0.85rem;
  max-width: 680px;
}

.message.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(108,99,255,0.2);
  border-bottom-right-radius: 4px;
  color: var(--text-1);
}

.message.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-1);
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.meta-tag {
  font-size: 0.58rem;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.meta-tag.model  { background: rgba(108,99,255,0.15); color: var(--accent); border: 1px solid rgba(108,99,255,0.2); }
.meta-tag.skill  { background: rgba(0,229,160,0.1);   color: var(--success); border: 1px solid rgba(0,229,160,0.2); }
.meta-tag.reason { background: rgba(255,176,32,0.1);  color: var(--warning); border: 1px solid rgba(255,176,32,0.2); }

/* Markdown-like text formatting */
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code {
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.82em;
  color: var(--accent-2);
}
.bubble pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.bubble pre code { background: none; padding: 0; color: var(--text-1); }
.bubble strong { color: #fff; font-weight: 700; }
.bubble em { color: var(--text-2); font-style: italic; }
.bubble ul, .bubble ol { margin: 6px 0 6px 18px; }
.bubble li { margin-bottom: 3px; }
.bubble h1,.bubble h2,.bubble h3 {
  font-family: var(--font-display);
  margin: 12px 0 6px;
  color: #fff;
}
.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-2);
  margin: 8px 0;
  font-style: italic;
}

/* Image bubble */
.bubble-image img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 8px;
}

/* Generated image */
.gen-image-wrap {
  margin-top: 8px;
}
.gen-image-wrap img {
  max-width: 400px;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border-glow);
  box-shadow: 0 0 20px rgba(108,99,255,0.2);
}

/* Source links */
.source-links {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.source-link {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--accent-2);
  text-decoration: none;
  padding: 3px 7px;
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: 5px;
  transition: var(--transition);
}
.source-link:hover { background: rgba(0,212,255,0.08); }

/* ── Thinking animation ──────────────────────────────────── */
.thinking {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  font-size: 0.78rem;
  color: var(--text-2);
  font-family: var(--font-mono);
  animation: msg-in 0.3s ease;
}

.thinking-dots {
  display: flex; gap: 4px;
}
.thinking-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* Reasoning steps */
.reasoning-steps {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-2);
  border-left: 2px solid var(--warning);
  padding-left: 12px;
  margin-bottom: 12px;
  opacity: 0.8;
}

/* ── Input Area ──────────────────────────────────────────── */
#input-area {
  padding: 16px 24px 20px;
  background: var(--bg-glass);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
}

/* Upload preview */
#upload-preview {
  display: none;
  margin-bottom: 10px;
  position: relative;
  width: fit-content;
}

#upload-preview img {
  height: 60px;
  border-radius: 8px;
  border: 1px solid var(--border-glow);
}

#upload-preview .remove-img {
  position: absolute;
  top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent-3);
  border: none;
  color: #fff;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 10px 8px 16px;
  transition: var(--transition);
}
.input-row:focus-within {
  border-color: var(--border-glow);
  box-shadow: var(--glow);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  resize: none;
  min-height: 24px;
  max-height: 180px;
  line-height: 1.5;
  padding: 4px 0;
}

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

.input-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.action-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  transition: var(--transition);
}
.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(108,99,255,0.08);
}

#send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
  box-shadow: 0 2px 12px rgba(108,99,255,0.4);
}

#send-btn:hover { background: #7c74ff; transform: translateY(-1px); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hint {
  font-size: 0.62rem;
  color: var(--text-3);
  font-family: var(--font-mono);
  padding: 5px 6px 0;
  display: flex;
  gap: 12px;
}
.input-hint span { display: flex; align-items: center; gap: 4px; }

/* ── Memory Panel ────────────────────────────────────────── */
#memory-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 320px;
  background: var(--bg-glass);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(20px);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

#memory-panel.open { transform: translateX(0); }

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.panel-close {
  background: none; border: none;
  color: var(--text-2); cursor: pointer;
  font-size: 1.2rem; padding: 4px;
}

.memory-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-entry {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-2);
}
.memory-entry .mem-type {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin-bottom: 4px;
}
.memory-entry .mem-fact { color: var(--success); }

.panel-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.danger-btn {
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid rgba(255,45,120,0.3);
  background: rgba(255,45,120,0.08);
  color: var(--accent-3);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: var(--transition);
}
.danger-btn:hover { background: rgba(255,45,120,0.15); }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-1);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Hidden file input ────────────────────────────────────── */
#file-input { display: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #messages { padding: 14px; }
  #input-area { padding: 12px 14px 16px; }
  .bubble { max-width: 100%; }
  .welcome-logo { font-size: 2.5rem; }
}
