/* =====================================================
   NovelMind AI — style.css
   Dark, Premium, Literary Design
   ===================================================== */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-card: #16161f;
  --bg-sidebar: #0d0d14;
  --accent-gold: #c9a227;
  --accent-gold-light: #e8c456;
  --accent-purple: #7c3aed;
  --accent-purple-light: #a855f7;
  --accent-rose: #e11d48;
  --text-primary: #f0ece4;
  --text-secondary: #9d9ba6;
  --text-muted: #4d4b59;
  --border-color: #2a2738;
  --border-glow: rgba(201, 162, 39, 0.3);
  --user-bubble: linear-gradient(135deg, #7c3aed, #6d28d9);
  --ai-bubble: #1a1a26;
  --input-bg: #13131c;
  --scrollbar: #2a2738;
  --scrollbar-thumb: #4a4860;
  --shadow-gold: 0 0 30px rgba(201, 162, 39, 0.15);
  --sidebar-width: 300px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  position: relative;
}

/* ===================== BACKGROUND ===================== */
.bg-particles {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--accent-gold);
  border-radius: 50%;
  opacity: 0;
  animation: float-particle linear infinite;
}

@keyframes float-particle {
  0% { transform: translateY(100vh) scale(0); opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.3; }
  100% { transform: translateY(-20px) scale(1); opacity: 0; }
}

.bg-overlay {
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(124, 58, 237, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(201, 162, 39, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(225, 29, 72, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  overflow: hidden;
  flex-shrink: 0;
  transition: width var(--transition), transform var(--transition);
}

.sidebar.collapsed {
  width: 0;
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.05) 0%, transparent 100%);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px rgba(201, 162, 39, 0.5));
}

.logo-text {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-card); }

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  overflow-y: auto;
}
.sidebar-section:last-child { border-bottom: none; flex: 1; }

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Mode Buttons */
.mode-buttons { display: flex; flex-direction: column; gap: 6px; }

.mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  text-align: left;
  transition: all var(--transition);
  width: 100%;
}

.mode-btn:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.2), rgba(201, 162, 39, 0.1));
  border-color: rgba(201, 162, 39, 0.4);
  color: var(--text-primary);
  box-shadow: 0 0 15px rgba(124, 58, 237, 0.15);
}

.mode-icon { font-size: 20px; flex-shrink: 0; }
.mode-name { font-size: 13px; font-weight: 600; }
.mode-desc { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.mode-btn.active .mode-desc { color: var(--text-secondary); }

/* Tool Buttons */
.tool-buttons { display: flex; flex-direction: column; gap: 4px; }

.tool-btn {
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  text-align: left;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  transition: all var(--transition);
  width: 100%;
}
.tool-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  padding-left: 16px;
}

/* Settings Box */
.settings-box { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }

.input-field {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  padding: 8px 10px;
  outline: none;
  transition: border-color var(--transition);
}
.input-field:focus { border-color: var(--accent-gold); }
.input-field option { background: var(--bg-card); }
.input-field.hidden { display: none; }

.btn-connect {
  padding: 8px 12px;
  background: linear-gradient(135deg, var(--accent-purple), #5b21b6);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
  font-weight: 500;
}
.btn-connect:hover { opacity: 0.85; transform: translateY(-1px); }

.connection-status {
  font-size: 12px;
  padding: 4px 0;
  min-height: 20px;
}
.connection-status.ok { color: #22c55e; }
.connection-status.error { color: #ef4444; }
.connection-status.loading { color: var(--accent-gold); }

/* Chat History */
.btn-new-chat {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.15), rgba(201, 162, 39, 0.05));
  border: 1px dashed rgba(201, 162, 39, 0.4);
  border-radius: 8px;
  color: var(--accent-gold);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 10px;
}
.btn-new-chat:hover { background: rgba(201, 162, 39, 0.2); }

.chat-history { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 150px; }
.history-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--transition);
}
.history-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.history-item.active { background: rgba(124, 58, 237, 0.15); color: var(--text-primary); }

/* ===================== MAIN CONTENT ===================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 5;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(13, 13, 20, 0.8);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--transition);
}
.menu-btn:hover { color: var(--text-primary); background: var(--bg-card); }

.topbar-title {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.topbar-actions { display: flex; gap: 8px; }
.action-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}
.action-btn:hover { border-color: var(--accent-gold); color: var(--accent-gold); }

/* Chat Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-container::-webkit-scrollbar,
.sidebar::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
.chat-container::-webkit-scrollbar-thumb:hover { background: #6b6890; }

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  text-align: center;
  padding: 40px 20px;
  animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
  font-size: 64px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 20px rgba(201, 162, 39, 0.4));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.welcome-title {
  font-family: 'Cinzel', serif;
  font-size: 42px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-light), #fff8e7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
  letter-spacing: 0.05em;
}

.welcome-subtitle {
  font-family: 'Crimson Pro', serif;
  font-size: 18px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 40px;
}

.welcome-features {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
  flex-wrap: wrap;
  justify-content: center;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px 24px;
  width: 160px;
  transition: all var(--transition);
}
.feature-card:hover {
  border-color: rgba(201, 162, 39, 0.4);
  transform: translateY(-4px);
  box-shadow: var(--shadow-gold);
}
.feature-icon { font-size: 32px; display: block; margin-bottom: 10px; }
.feature-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.feature-card p { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.quick-prompts { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; max-width: 600px; }
.quick-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }

.quick-btn {
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  text-align: left;
}
.quick-btn:hover {
  background: rgba(124, 58, 237, 0.1);
  border-color: rgba(124, 58, 237, 0.4);
  color: var(--text-primary);
  transform: translateX(4px);
}

/* Messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.message {
  display: flex;
  gap: 14px;
  animation: messageIn 0.3s ease;
}
@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  position: relative;
}
.message.user .avatar {
  background: linear-gradient(135deg, var(--accent-purple), #5b21b6);
  box-shadow: 0 0 15px rgba(124, 58, 237, 0.4);
}
.message.ai .avatar {
  background: linear-gradient(135deg, var(--accent-gold), #a07820);
  box-shadow: 0 0 15px rgba(201, 162, 39, 0.3);
}

.message-content { flex: 1; max-width: calc(100% - 50px); }

.bubble {
  padding: 14px 18px;
  border-radius: 16px;
  line-height: 1.7;
  font-size: 14.5px;
  position: relative;
}
.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  color: white;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
  margin-left: auto;
  max-width: 80%;
}
.message.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
  font-family: 'Crimson Pro', serif;
  font-size: 16px;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}
.message.user .message-time { text-align: right; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
}
.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-gold);
  border-radius: 50%;
  animation: typing 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* AI Response Markdown Formatting */
.message.ai .bubble p { margin-bottom: 12px; }
.message.ai .bubble p:last-child { margin-bottom: 0; }
.message.ai .bubble strong { color: var(--accent-gold-light); }
.message.ai .bubble em { font-style: italic; color: #d4c5f5; }
.message.ai .bubble h1,
.message.ai .bubble h2,
.message.ai .bubble h3 {
  font-family: 'Cinzel', serif;
  color: var(--accent-gold);
  margin: 16px 0 8px;
}
.message.ai .bubble ul, .message.ai .bubble ol {
  padding-left: 20px;
  margin-bottom: 12px;
}
.message.ai .bubble li { margin-bottom: 6px; }
.message.ai .bubble blockquote {
  border-left: 3px solid var(--accent-gold);
  padding: 8px 16px;
  margin: 12px 0;
  background: rgba(201, 162, 39, 0.05);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}
.message.ai .bubble code {
  background: rgba(124, 58, 237, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}
.message.ai .bubble hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}

/* ===================== INPUT AREA ===================== */
.input-area {
  padding: 16px 20px 20px;
  background: rgba(13, 13, 20, 0.8);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.input-container { max-width: 860px; margin: 0 auto; }

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 12px 12px 12px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-wrapper:focus-within {
  border-color: rgba(201, 162, 39, 0.5);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.08);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 150px;
  overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent-gold), #a07820);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
.send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 15px rgba(201, 162, 39, 0.4); }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 17px; height: 17px; color: #0a0a0f; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hints {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px 0;
  font-size: 11px;
  color: var(--text-muted);
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5);
  transform: scale(0.9);
  transition: transform var(--transition);
}
.modal-overlay.show .modal { transform: scale(1); }
.modal-icon { font-size: 48px; margin-bottom: 16px; }
.modal h2 { font-family: 'Cinzel', serif; font-size: 22px; margin-bottom: 12px; color: var(--accent-gold); }
.modal p { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.btn-cancel, .btn-confirm {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition);
}
.btn-cancel { background: var(--bg-secondary); color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-cancel:hover { border-color: var(--text-muted); color: var(--text-primary); }
.btn-confirm { background: linear-gradient(135deg, #e11d48, #9f1239); color: white; }
.btn-confirm:hover { opacity: 0.85; transform: translateY(-1px); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar:not(.collapsed) { transform: translateX(0); }
  .welcome-title { font-size: 30px; }
  .welcome-features { gap: 12px; }
  .feature-card { width: 130px; }
}

/* Loading pulse for streaming */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.streaming { animation: pulse 1.5s ease-in-out infinite; }
