/* ===== SPACE AI v2 - Black/Gray Theme ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg-primary: #050508;
  --bg-secondary: #0a0a0f;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --text-primary: #e8e8f0;
  --text-secondary: #6b6b80;
  --text-muted: #3a3a4a;
  --accent: #7c7cff;
  --accent-dim: rgba(124,124,255,0.15);
  --accent-glow: rgba(124,124,255,0.3);
  --error: #ff4d4d;
  --success: #4dff9b;
  --user-bubble: rgba(255,255,255,0.06);
  --glass: rgba(10,10,18,0.85);
  --glass-border: rgba(255,255,255,0.07);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
  --shadow: 0 8px 32px rgba(0,0,0,0.6);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.8);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  font-family: var(--font);
  color: var(--text-primary);
}

/* ===== STARS ===== */
#stars-container {
  position: fixed; inset: 0;
  overflow: hidden; pointer-events: none; z-index: 0;
}
.star {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,0.7);
  animation: starTwinkle var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
}
@keyframes starTwinkle {
  0%, 100% { opacity: 0.1; transform: scale(1); }
  50%       { opacity: 0.8; transform: scale(1.3); }
}

/* App shell */
#app {
  position: relative; height: 100vh;
  display: flex; flex-direction: column; z-index: 1;
  background:
    radial-gradient(ellipse 60% 50% at 80% 50%, rgba(80,80,160,0.07) 0%, transparent 70%),
    radial-gradient(ellipse 40% 60% at 10% 80%, rgba(40,40,100,0.05) 0%, transparent 60%);
}

/* ===== HEADER ===== */
#main-header {
  position: relative; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 20px;
  animation: slideDown 0.5s cubic-bezier(0.4,0,0.2,1);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.header-pill {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 50px;
  padding: 8px 16px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  transition: var(--transition);
  animation: fadeIn 0.6s ease;
}
.header-pill:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }

.conv-title {
  font-size: 13px; font-weight: 400; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px; cursor: text; transition: color 0.2s;
}
.conv-title:hover { color: var(--text-primary); }

.conv-meta { display: flex; align-items: center; gap: 8px; }
.msg-count { font-size: 11px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.5px; min-width: 36px; }
.count-bar { width: 60px; height: 3px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; }
.count-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #a0a0ff); border-radius: 2px; width: 0%; transition: width 0.4s cubic-bezier(0.4,0,0.2,1); }

.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px;
  padding: 4px 6px; border-radius: var(--radius-xs);
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--error); background: rgba(255,77,77,0.1); transform: scale(1.1); }

.header-actions {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 8px; align-items: center;
}

/* ===== POLLINATIONS BADGE ===== */
.pollinations-badge {
  display: flex; align-items: center; gap: 6px;
  background: rgba(77,255,155,0.06);
  border: 1px solid rgba(77,255,155,0.2);
  border-radius: 50px; padding: 5px 12px;
  cursor: default; transition: var(--transition);
  animation: fadeIn 0.8s ease;
}
.pollinations-badge:hover { background: rgba(77,255,155,0.1); border-color: rgba(77,255,155,0.35); }

.badge-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.4s, box-shadow 0.4s;
}
.badge-dot.online  { background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulseDot 2s ease infinite; }
.badge-dot.offline { background: var(--error);   box-shadow: 0 0 6px var(--error); }

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 6px var(--success); }
  50%       { box-shadow: 0 0 14px var(--success), 0 0 24px rgba(77,255,155,0.3); }
}

.badge-text { font-size: 10px; font-weight: 700; letter-spacing: 1.5px; color: var(--success); }

/* ===== CHAT AREA ===== */
#chat-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 20px 0; position: relative; scroll-behavior: smooth;
}
#chat-area::-webkit-scrollbar { width: 4px; }
#chat-area::-webkit-scrollbar-track { background: transparent; }
#chat-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

#chat-messages {
  max-width: 680px; margin: 0 auto; padding: 0 20px;
  display: flex; flex-direction: column; gap: 20px;
}

/* Welcome */
.welcome-prompt {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center; pointer-events: none;
  animation: fadeIn 1s ease;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.welcome-logo {
  font-size: 36px; color: var(--accent);
  animation: glowPulse 3s ease infinite;
  line-height: 1;
}
@keyframes glowPulse {
  0%, 100% { text-shadow: 0 0 10px var(--accent-glow); }
  50%       { text-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(124,124,255,0.2); }
}
.try-asking { font-size: 12px; color: var(--text-muted); letter-spacing: 0.8px; font-weight: 400; }
.prompt-suggestion {
  font-size: 15px; color: var(--text-secondary); font-weight: 400;
  max-width: 380px; line-height: 1.5; transition: opacity 0.4s ease;
  pointer-events: all !important; cursor: pointer !important;
}
.prompt-suggestion:hover { color: var(--text-primary); }

/* Messages */
.message {
  display: flex; flex-direction: column; gap: 6px;
  animation: messageIn 0.4s cubic-bezier(0.4,0,0.2,1);
  transform-origin: bottom center;
}
@keyframes messageIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.message.user      { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.msg-bubble {
  padding: 12px 16px; border-radius: 18px;
  font-size: 14px; line-height: 1.6; max-width: 88%;
  word-wrap: break-word; white-space: pre-wrap;
}
.message.user .msg-bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom-right-radius: 6px;
  color: var(--text-primary); backdrop-filter: blur(10px);
}
.message.assistant .msg-bubble {
  background: transparent; color: var(--text-primary);
  padding: 4px 0; border-radius: 0; font-size: 14px;
}
.message.error .msg-bubble {
  color: var(--error); font-size: 13px; padding: 4px 0;
}

/* Image */
.msg-image {
  max-width: 260px; max-height: 200px; border-radius: 12px;
  object-fit: cover; border: 1px solid var(--border); margin-bottom: 6px;
  animation: fadeIn 0.4s ease;
}

/* Message actions */
.msg-actions {
  display: flex; gap: 6px; opacity: 0;
  transition: opacity 0.2s ease; padding: 0 4px;
}
.message:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 12px;
  padding: 4px 6px; border-radius: var(--radius-xs);
  transition: var(--transition);
}
.msg-action-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); transform: scale(1.15); }

/* Loading */
.loading-indicator {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px; padding: 4px 0;
  animation: fadeIn 0.3s ease;
}
.loading-dots { display: flex; gap: 4px; }
.loading-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.2s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

/* Typing cursor */
.typing-cursor::after {
  content: '▋'; animation: blink 0.7s step-end infinite; color: var(--accent);
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Markdown */
.msg-bubble strong, .msg-bubble b { font-weight: 600; color: #c0c0e0; }
.msg-bubble code {
  background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px;
  font-family: 'Courier New', monospace; font-size: 12px; border: 1px solid rgba(255,255,255,0.08);
}
.msg-bubble pre {
  background: rgba(0,0,0,0.4); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; overflow-x: auto; margin: 8px 0;
}
.msg-bubble pre code { background: none; border: none; padding: 0; font-size: 13px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { color: #d0d0f0; margin: 10px 0 6px; }
.msg-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.msg-bubble p { margin: 4px 0; }

/* ===== IMAGE PREVIEW ===== */
.image-preview-container {
  max-width: 680px; margin: 0 auto 8px; padding: 0 20px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.image-preview-inner { position: relative; display: inline-block; }
#image-preview-img { height: 80px; width: auto; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; }
.remove-image-btn {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--error); border: none; color: white;
  font-size: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.remove-image-btn:hover { transform: scale(1.15); }

/* ===== INPUT DOCK ===== */
#input-dock {
  padding: 10px 20px 16px; position: relative; z-index: 50;
  animation: slideUp 0.6s cubic-bezier(0.4,0,0.2,1);
}
.input-row {
  max-width: 680px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 24px; padding: 8px 10px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.input-row:focus-within {
  border-color: rgba(124,124,255,0.3);
  box-shadow: 0 0 0 3px rgba(124,124,255,0.08), var(--shadow);
}
.input-wrap { flex: 1; display: flex; align-items: center; }
#chat-input {
  width: 100%; background: none; border: none; outline: none;
  color: var(--text-primary); font-family: var(--font);
  font-size: 14px; font-weight: 400; line-height: 1.5;
  resize: none; min-height: 24px; max-height: 160px; overflow-y: auto; padding: 4px 0;
}
#chat-input::placeholder { color: var(--text-muted); }
#chat-input::-webkit-scrollbar { width: 3px; }
#chat-input::-webkit-scrollbar-thumb { background: var(--border); }

/* Model label row */
.model-label-row {
  max-width: 680px; margin: 5px auto 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
}
.active-model-label {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  letter-spacing: 0.3px; transition: color 0.3s;
}
.source-label {
  font-size: 10px; color: var(--text-muted);
  transition: opacity 0.4s; letter-spacing: 0.3px;
}
.source-label.src-pollinations { color: #6060c0; }
.source-label.src-native       { color: var(--success); }

/* Dock buttons */
.dock-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px;
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition); flex-shrink: 0;
}
.dock-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); transform: scale(1.1); }

.model-btn { font-size: 18px; color: var(--accent); }
.model-btn:hover { color: #b0b0ff; background: var(--accent-dim); }

.send-btn { color: var(--accent); background: var(--accent-dim); }
.send-btn:hover { color: white; background: var(--accent); box-shadow: 0 0 16px var(--accent-glow); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.upload-btn:hover    { color: #80e0ff; background: rgba(128,224,255,0.1); }
.customize-btn:hover { color: #c0a0ff; background: rgba(192,160,255,0.1); }

/* ===== POPUPS ===== */
.popup {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.4,0,0.2,1);
}
.popup.active { opacity: 1; pointer-events: all; transform: translateX(-50%) translateY(0); }

.popup-inner {
  background: rgba(10,10,18,0.97);
  border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  box-shadow: var(--shadow-lg); overflow: hidden; min-width: 290px;
}

/* Model popup */
#model-popup { bottom: 82px; left: 240px; transform: translateX(0) translateY(10px); }
#model-popup.active { transform: translateX(0) translateY(0); }

/* Customize popup */
#customize-popup { bottom: 82px; right: 20px; left: auto; transform: translateY(10px); }
#customize-popup.active { transform: translateY(0); }

.popup-header {
  font-size: 10px; font-weight: 700; letter-spacing: 2px;
  color: var(--text-muted); padding: 12px 14px 6px;
}

/* Model groups */
.model-group-label {
  font-size: 9px; font-weight: 700; letter-spacing: 2px;
  color: var(--text-muted); padding: 8px 14px 4px;
  opacity: 0.7;
}

.model-option {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; cursor: pointer;
  transition: var(--transition); font-size: 13px;
  color: var(--text-secondary); font-weight: 400; position: relative;
}
.model-option:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.model-option.selected { color: var(--text-primary); background: rgba(124,124,255,0.08); }
.model-option.selected::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 2px; background: var(--accent); border-radius: 2px;
}

.model-icon   { font-size: 13px; width: 18px; text-align: center; color: var(--accent); }
.gpt-icon     { color: #74c69d; }
.ds-icon      { color: #56b4f8; }
.glm-icon     { color: #c792ea; }
.llm-icon     { color: #c792ea; }
.claude-icon  { color: #e0a060; }
.mist-icon    { color: #60c0e0; }

.model-name { flex: 1; }

.model-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 1px;
  padding: 2px 6px; border-radius: 4px;
}
.model-badge.free {
  background: rgba(77,255,155,0.1); color: var(--success);
  border: 1px solid rgba(77,255,155,0.2);
}

/* Key status dot */
.key-status {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted); display: inline-block; flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.key-status.valid   { background: var(--success); box-shadow: 0 0 6px var(--success); }
.key-status.invalid { background: var(--error);   box-shadow: 0 0 6px var(--error); }
.key-status.testing { background: #ffaa00;         animation: pulse 0.8s ease infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.popup-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* API key section (optional) */
.api-key-section { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.api-key-label {
  font-size: 11px; color: var(--text-secondary); font-weight: 500;
  display: flex; align-items: center; gap: 4px;
}
.api-key-label em { color: var(--accent); font-style: normal; font-weight: 600; }
.api-key-sublabel { font-size: 10px; color: var(--text-muted); line-height: 1.4; }
.api-key-input-row { display: flex; gap: 6px; }
.api-key-input {
  flex: 1; background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: var(--font);
  font-size: 12px; padding: 7px 10px; outline: none; transition: border-color 0.2s;
}
.api-key-input:focus { border-color: rgba(124,124,255,0.4); }
.api-key-input::placeholder { color: var(--text-muted); }
.save-key-btn {
  background: rgba(124,124,255,0.12); border: 1px solid rgba(124,124,255,0.25);
  border-radius: var(--radius-sm); color: #9898ff;
  font-size: 11px; font-weight: 600; padding: 7px 12px;
  cursor: pointer; font-family: var(--font); transition: var(--transition); white-space: nowrap;
}
.save-key-btn:hover { background: rgba(124,124,255,0.22); border-color: rgba(124,124,255,0.5); color: #c0c0ff; }

/* Pollinations credit */
.pollinations-credit {
  padding: 10px 14px; font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  border-top: 1px solid var(--border);
}
.pollinations-credit a { color: var(--success); text-decoration: none; }
.pollinations-credit a:hover { text-decoration: underline; }

/* Customize popup */
.customize-inner { padding: 16px; width: 320px; }
.customize-title {
  font-size: 10px; font-weight: 700; color: var(--text-secondary);
  letter-spacing: 2px; margin-bottom: 12px;
}
.system-textarea {
  width: 100%; background: rgba(255,255,255,0.03);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: var(--font);
  font-size: 13px; padding: 12px; min-height: 100px; resize: vertical;
  outline: none; transition: border-color 0.2s; line-height: 1.5;
}
.system-textarea:focus { border-color: rgba(124,124,255,0.4); }
.system-textarea::placeholder { color: var(--text-muted); font-size: 12px; }
.save-changes-btn {
  width: 100%; margin-top: 12px;
  background: rgba(124,124,255,0.12); border: 1px solid rgba(124,124,255,0.25);
  border-radius: var(--radius-sm); color: #a0a0ff;
  font-size: 11px; font-weight: 700; letter-spacing: 2px; padding: 10px;
  cursor: pointer; font-family: var(--font); transition: var(--transition);
}
.save-changes-btn:hover {
  background: rgba(124,124,255,0.22); border-color: rgba(124,124,255,0.5);
  color: #c8c8ff; box-shadow: 0 0 20px rgba(124,124,255,0.15);
}

/* ===== OVERLAY ===== */
.overlay { position: fixed; inset: 0; z-index: 150; display: none; }
.overlay.active { display: block; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 100px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(12,12,22,0.97); border: 1px solid var(--border);
  border-radius: 50px; padding: 10px 20px;
  font-size: 13px; color: var(--text-primary);
  backdrop-filter: blur(20px); z-index: 999;
  opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none; white-space: nowrap;
}
.toast.show       { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success    { border-color: rgba(77,255,155,0.3); color: var(--success); }
.toast.error      { border-color: rgba(255,77,77,0.3);  color: var(--error); }
.toast.info       { border-color: rgba(124,124,255,0.3); color: #a0a0ff; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin    { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.shimmer {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.05) 50%, transparent 100%);
  background-size: 200% 100%; animation: shimmer 1.5s ease infinite;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* Ripple */
.ripple {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,0.15); transform: scale(0);
  animation: rippleAnim 0.5s linear; pointer-events: none;
}
@keyframes rippleAnim { to { transform: scale(4); opacity: 0; } }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ===== SELECTION ===== */
::selection { background: rgba(124,124,255,0.3); color: white; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  #main-header  { padding: 12px 14px; }
  #chat-messages { padding: 0 14px; }
  #input-dock   { padding: 8px 14px 14px; }
  .customize-inner { width: 280px; }
  .header-actions  { right: 14px; }
  #model-popup  { left: 14px; right: 14px; transform: translateY(10px); bottom: 86px; }
  #model-popup.active { transform: translateY(0); }
  .popup-inner  { min-width: unset; }
}
