/* =============================================================================
   SEEKAR — Chat UI Styles
   ============================================================================= */

/* ---- Layout ---- */

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

#chat-app {
  display: flex;
  height: 100dvh;
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  position: relative;
}

/* ---- Sidebar ---- */

.chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
              width 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  overflow: hidden;
  z-index: 20;
}

.chat-sidebar.collapsed {
  width: 0;
  border-right-color: transparent;
}

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

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.sidebar-logo svg {
  flex-shrink: 0;
  color: var(--accent-primary);
}

.new-chat-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.new-chat-btn:hover {
  background: var(--bg-surface-3);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 10px 6px;
  padding: 8px 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-tertiary);
}

.sidebar-search svg {
  flex-shrink: 0;
}

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

.sidebar-search input::placeholder {
  color: var(--text-tertiary);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.conv-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 14px 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 8px;
  margin: 1px 6px;
  transition: background 0.12s;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.conv-item:hover {
  background: var(--bg-surface-2);
}

.conv-item.active {
  background: var(--bg-surface-3);
}

.conv-item-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item.active .conv-item-text {
  color: var(--text-primary);
}

.conv-item-delete {
  opacity: 0;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 4px;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
}

.conv-item:hover .conv-item-delete {
  opacity: 1;
}

.conv-item-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.sidebar-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 1.5;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  width: 100%;
}

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

/* ---- Main chat area ---- */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
  min-height: 56px;
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.chat-title-display {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-badge-sm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.model-dot {
  width: 6px;
  height: 6px;
  background: #22c55e;
  border-radius: 50%;
  animation: modelPulse 2.5s ease-in-out infinite;
}

@keyframes modelPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---- Messages ---- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* ---- Welcome screen ---- */

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 48px 24px;
  text-align: center;
  animation: fadeInUp 0.5s cubic-bezier(0.23, 1, 0.32, 1) both;
}

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

.welcome-logo {
  color: var(--accent-primary);
  margin-bottom: 20px;
}

.welcome-title {
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 460px;
  line-height: 1.6;
  margin-bottom: 32px;
}

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 640px;
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.suggestion-chip:hover {
  background: var(--bg-surface-2);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ---- Message bubbles ---- */

.message {
  max-width: 760px;
  margin: 0 auto;
  padding: 4px 24px;
  animation: messageIn 0.25s cubic-bezier(0.23, 1, 0.32, 1) both;
}

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

.message-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.message-user-bubble {
  max-width: 80%;
  padding: 10px 16px;
  background: var(--accent-primary);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-ai {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.message-ai-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  color: var(--accent-primary);
}

.message-ai-content {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
}

/* ---- Thinking block ---- */

.thinking-block {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-surface);
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}

.thinking-header:hover {
  background: var(--bg-surface-2);
}

.thinking-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.thinking-spinner.done {
  border: 2px solid var(--border);
  border-top-color: #22c55e;
  animation: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.thinking-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.thinking-chevron {
  margin-left: auto;
  color: var(--text-tertiary);
  transition: transform 0.2s;
}

.thinking-block.open .thinking-chevron {
  transform: rotate(180deg);
}

.thinking-body {
  display: none;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
}

.thinking-block.open .thinking-body {
  display: block;
}

.thinking-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thinking-shimmer {
  height: 12px;
  background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-surface-3) 50%, var(--bg-surface-2) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.thinking-line {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
  font-style: italic;
}

/* ---- Tool call cards ---- */

.tool-calls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.tool-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-surface);
  animation: toolCardIn 0.3s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes toolCardIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}

.tool-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  font-size: 14px;
}

.tool-icon-search { background: rgba(124, 109, 250, 0.15); color: var(--accent-primary); }
.tool-icon-read   { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.tool-icon-code   { background: rgba(251, 191, 36, 0.12); color: #fbbf24; }
.tool-icon-info   { background: rgba(56, 189, 248, 0.12); color: #38bdf8; }

.tool-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.tool-query {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 2px;
}

.tool-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.tool-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.tool-status-dot.running {
  background: var(--accent-primary);
  animation: dotPulse 1s ease-in-out infinite;
}

.tool-status-dot.done {
  background: #22c55e;
  animation: none;
}

@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.6); }
}

/* Parallel read grid */
.parallel-read-grid {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
}

.pr-item {
  padding: 8px 10px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 11px;
  transition: border-color 0.3s;
  min-width: 0;
}

.pr-item.analyzing {
  border-color: rgba(124, 109, 250, 0.4);
}

.pr-item.done {
  border-color: rgba(34, 197, 94, 0.4);
}

.pr-item-url {
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.pr-item-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.pr-item-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 2px;
  width: 0%;
  transition: width 1.5s ease-out;
}

.pr-item.analyzing .pr-item-fill {
  width: 60%;
  background: linear-gradient(90deg, var(--accent-primary), rgba(124,109,250,0.3));
  animation: prShimmer 1.5s ease-in-out infinite alternate;
}

.pr-item.done .pr-item-fill {
  width: 100%;
  background: #22c55e;
  animation: none;
}

@keyframes prShimmer {
  from { opacity: 1; }
  to   { opacity: 0.5; }
}

.pr-item-status {
  margin-top: 4px;
  color: var(--text-tertiary);
  font-size: 10px;
}

.pr-item.analyzing .pr-item-status { color: var(--accent-primary); }
.pr-item.done .pr-item-status { color: #22c55e; }

/* Search results preview */
.search-results-preview {
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.search-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeInUp 0.3s cubic-bezier(0.23, 1, 0.32, 1) both;
}

.search-result-row:nth-child(1) { animation-delay: 0.05s; }
.search-result-row:nth-child(2) { animation-delay: 0.12s; }
.search-result-row:nth-child(3) { animation-delay: 0.19s; }
.search-result-row:nth-child(4) { animation-delay: 0.26s; }

.search-result-num {
  font-size: 10px;
  color: var(--text-tertiary);
  width: 14px;
  flex-shrink: 0;
}

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

.search-result-source {
  font-size: 11px;
  color: var(--accent-primary);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

/* ---- AI response text ---- */

.ai-response-text {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-primary);
}

.ai-response-text h1,
.ai-response-text h2,
.ai-response-text h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 16px 0 6px;
  color: var(--text-primary);
}

.ai-response-text h1 { font-size: 18px; }
.ai-response-text h2 { font-size: 16px; }
.ai-response-text h3 { font-size: 14px; }

.ai-response-text p { margin-bottom: 10px; }

.ai-response-text ul,
.ai-response-text ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.ai-response-text li { margin-bottom: 4px; }

.ai-response-text code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--accent-primary);
}

.ai-response-text pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin-bottom: 12px;
}

.ai-response-text pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
}

.ai-response-text strong { font-weight: 600; }
.ai-response-text em { font-style: italic; color: var(--text-secondary); }

.ai-response-text a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Citations */
.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.citation-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.citation-chip:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.citation-num {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary);
  color: #fff;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent-primary);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 0.9s step-end infinite;
}

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

/* ---- Input area ---- */

.chat-input-area {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
  max-width: 760px;
  margin: 0 auto;
}

.chat-input-wrap:focus-within {
  border-color: var(--border-strong);
}

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

.chat-input::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.send-btn:not(:disabled):hover {
  opacity: 0.85;
  transform: scale(1.05);
}

.chat-input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

/* ---- Sidebar toggle ---- */

.sidebar-toggle {
  display: none; /* handled by JS positioning */
}

/* ---- Message spacing ---- */

.message + .message {
  margin-top: 2px;
}

.message-user + .message-ai,
.message-ai + .message-user {
  margin-top: 12px;
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    width: 280px;
  }

  .chat-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  .chat-sidebar.collapsed {
    transform: translateX(-100%);
    width: 280px;
  }

  .parallel-read-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 769px) {
  .chat-sidebar.collapsed {
    width: 0;
  }
}

/* ---- Loading state ---- */

.generating-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 4px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.gen-dots {
  display: flex;
  gap: 4px;
}

.gen-dot {
  width: 4px;
  height: 4px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: genBounce 1.2s ease-in-out infinite;
}

.gen-dot:nth-child(2) { animation-delay: 0.15s; }
.gen-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes genBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1); opacity: 1; }
}

/* ---- Sidebar overlay (mobile) ---- */

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
  animation: fadeIn 0.2s ease;
}

#sidebar-overlay.visible {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
