/* ============================================
   Qrite AI – Main Stylesheet
   Claude-inspired dark UI
   ============================================ */

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

:root {
  --bg-base:       #1a1a1a;
  --bg-sidebar:    #141414;
  --bg-surface:    #212121;
  --bg-hover:      #2a2a2a;
  --bg-active:     #2f2f2f;
  --bg-input:      #2a2a2a;
  --bg-user-msg:   #2f2f2f;
  
  --border:        rgba(255,255,255,0.08);
  --border-light:  rgba(255,255,255,0.05);
  
  --text-primary:  #ececec;
  --text-secondary:#a8a8a8;
  --text-muted:    #6a6a6a;
  
  --accent:        #c0a06e;
  --accent-hover:  #d4b47e;
  --accent-glow:   rgba(192,160,110,0.15);
  
  --green:  #4caf82;
  --red:    #e05252;
  --blue:   #5ba3e0;
  
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  
  --sidebar-w: 260px;
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ════════════════════════════════
   SIDEBAR
   ════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

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

.logo-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--accent), #e8c887);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #1a1a1a;
  flex-shrink: 0;
}

.logo-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.logo-accent { color: var(--accent); }

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: all var(--transition);
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
}

/* ── MODEL SECTION ── */
.model-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  position: relative;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.optional-tag {
  font-size: 9px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.model-selector:hover { background: var(--bg-hover); border-color: rgba(255,255,255,0.12); }

.model-sel-icon { font-size: 14px; flex-shrink: 0; }

.model-sel-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.model-sel-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-sel-provider {
  font-size: 10px;
  color: var(--text-muted);
}

.chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.model-selector.open .chevron { transform: rotate(180deg); }

/* ── MODEL DROPDOWN ── */
.model-dropdown {
  display: none;
  position: absolute;
  left: 14px; right: 14px;
  top: calc(100% + 4px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  z-index: 200;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}

.model-dropdown.open { display: block; }

.dropdown-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.dropdown-search svg { color: var(--text-muted); flex-shrink: 0; }

.dropdown-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
}

.dropdown-search input::placeholder { color: var(--text-muted); }

.model-list {
  max-height: 280px;
  overflow-y: auto;
  padding: 4px;
}

.model-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.model-item:hover { background: var(--bg-hover); }
.model-item.active { background: var(--accent-glow); }
.model-item.hidden { display: none; }

.mi-icon { font-size: 14px; flex-shrink: 0; width: 20px; text-align: center; }

.mi-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mi-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mi-desc {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mi-ctx {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

.mi-check {
  color: var(--accent);
  flex-shrink: 0;
  opacity: 0;
}

.model-item.active .mi-check { opacity: 1; }

/* ── SYSTEM PROMPT ── */
.system-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.system-prompt-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font);
  padding: 8px 10px;
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.5;
}

.system-prompt-input::placeholder { color: var(--text-muted); }
.system-prompt-input:focus { border-color: var(--accent); }

.system-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.preset-btn {
  padding: 4px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 10px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.preset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
}

/* ── CHAT HISTORY ── */
.history-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 8px;
  min-height: 0;
  overflow: hidden;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  group: true;
}

.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: var(--bg-active); }

.history-item svg { color: var(--text-muted); flex-shrink: 0; }

.history-title {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover .history-title { color: var(--text-primary); }

.history-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: none;
  transition: color var(--transition);
}

.history-item:hover .history-del { display: flex; }
.history-del:hover { color: var(--red); }

/* ── SIDEBAR FOOTER ── */
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.footer-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--text-muted);
}

/* ════════════════════════════════
   MAIN AREA
   ════════════════════════════════ */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  transition: margin-left var(--transition);
}

/* ── TOPBAR ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  background: var(--bg-base);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all var(--transition);
}

.menu-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.topbar-model {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.free-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--green);
  background: rgba(76,175,130,0.12);
  border: 1px solid rgba(76,175,130,0.25);
  padding: 1px 6px;
  border-radius: 20px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  transition: all var(--transition);
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: rgba(255,255,255,0.12); }

/* ── CHAT CONTAINER ── */
.chat-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

/* ── WELCOME SCREEN ── */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.welcome-logo-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--accent), #e8c887);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 28px;
  color: #1a1a1a;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px var(--accent-glow);
}

.welcome-title {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.welcome-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 32px;
  max-width: 420px;
  line-height: 1.7;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 680px;
}

.suggestion-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  font-family: var(--font);
}

.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: rgba(255,255,255,0.12);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.sc-icon { font-size: 20px; flex-shrink: 0; }

.sc-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sc-text strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.sc-text span {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── MESSAGES ── */
.messages {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.message-wrapper {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
  animation: msgIn 0.2s ease;
}

.message-wrapper:last-child { border-bottom: none; }

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

.message-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.msg-avatar.user-avatar {
  background: linear-gradient(135deg, #5b8de0, #7c6fe0);
  color: white;
  font-size: 11px;
}

.msg-avatar.ai-avatar {
  background: linear-gradient(135deg, var(--accent), #e8c887);
  color: #1a1a1a;
  font-size: 13px;
}

.msg-role {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.msg-model-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 7px;
  border-radius: 10px;
}

.msg-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.message-wrapper:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition);
}

.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.message-content {
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.75;
  padding-left: 38px;
}

/* ── MARKDOWN RENDERING ── */
.message-content p { margin-bottom: 12px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
  color: var(--text-primary);
  font-weight: 600;
  margin: 20px 0 10px;
  line-height: 1.4;
}

.message-content h1 { font-size: 20px; letter-spacing: -0.3px; }
.message-content h2 { font-size: 17px; }
.message-content h3 { font-size: 15px; }
.message-content h4, .message-content h5, .message-content h6 { font-size: 14px; }

.message-content ul, .message-content ol {
  margin: 10px 0 12px 20px;
}

.message-content li { margin-bottom: 5px; }

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 14px;
  margin: 12px 0;
  background: rgba(192,160,110,0.06);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content strong { color: var(--text-primary); font-weight: 600; }
.message-content em { color: var(--text-secondary); }

.message-content a { color: var(--accent); text-decoration: underline; }
.message-content a:hover { color: var(--accent-hover); }

.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
}

.message-content th, .message-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.message-content th {
  background: var(--bg-hover);
  font-weight: 600;
  color: var(--text-primary);
}

.message-content td { color: var(--text-secondary); }

/* Code blocks */
.message-content code {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 12px;
  color: #e89c6a;
}

.message-content pre {
  background: #111;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
  margin: 14px 0;
  position: relative;
}

.message-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: #e0e0e0;
  font-family: var(--mono);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
  margin-top: 14px;
}

.code-header + pre {
  margin-top: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.copy-code-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color var(--transition);
  padding: 2px 4px;
}

.copy-code-btn:hover { color: var(--text-primary); }

/* ── THINKING / LOADING ── */
.thinking-wrapper {
  padding: 16px 0;
}

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 38px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.thinking-dots span {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotBounce 1.2s ease infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}

.thinking-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── INPUT AREA ── */
.input-area {
  padding: 12px 24px 16px;
  flex-shrink: 0;
  background: var(--bg-base);
  border-top: 1px solid var(--border-light);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 10px 10px 16px;
  max-width: 760px;
  margin: 0 auto;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within {
  border-color: rgba(192,160,110,0.4);
  box-shadow: 0 0 0 3px rgba(192,160,110,0.06);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--text-muted); }

.input-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.char-count {
  font-size: 10px;
  color: var(--text-muted);
}

.send-btn {
  width: 34px; height: 34px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #1a1a1a;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  max-width: 760px;
  margin: 6px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  max-width: 320px;
}

.toast.success { border-color: rgba(76,175,130,0.3); }
.toast.error   { border-color: rgba(224,82,82,0.3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── SIDEBAR OVERLAY ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ════════════════════════════════
   RESPONSIVE
   ════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open { display: block; }

  .main { margin-left: 0; }

  .menu-toggle { display: flex; }

  .suggestion-grid { grid-template-columns: 1fr; }

  .welcome-screen { padding: 24px 16px; }

  .welcome-title { font-size: 20px; }

  .messages { padding: 16px 16px 8px; }

  .input-area { padding: 10px 14px 14px; }
}

@media (max-width: 480px) {
  .suggestion-grid { gap: 8px; }
  .suggestion-card { padding: 12px 12px; }
}
