/* === Base === */
* { box-sizing: border-box; }
::selection { background: rgba(139, 92, 246, 0.3); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.08) transparent; }

/* === Sidebar === */
.sidebar-closed { transform: translateX(-100%); }
.sidebar-open { transform: translateX(0); }
@media (min-width: 1024px) {
  .sidebar-closed { transform: translateX(0); }
}

.chat-history-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-history-item:hover { background: rgba(255,255,255,0.05); }
.chat-history-item.active {
  background: rgba(255,255,255,0.08);
  color: #e5e7eb;
}

/* === Avatars === */
.avatar-user {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 12px; font-weight: 600; color: white;
}
.avatar-assistant {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #8b5cf6, #a78bfa);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 12px; font-weight: 600; color: white;
}

/* === Typing Indicator === */
.typing-dots { display: flex; align-items: center; gap: 4px; }
.typing-dots .dot {
  width: 7px; height: 7px;
  background: #6b7280;
  border-radius: 50%;
  display: inline-block;
  animation: dotPulse 1.4s ease-in-out infinite both;
}
.typing-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dots .dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0s; }
@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* === Message Animation === */
.msg-animate { animation: msgIn 0.3s ease-out; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Message Action Buttons === */
.msg-actions {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.message-row:hover .msg-actions { opacity: 1; }

/* === Status Dot === */
.status-connecting { animation: statusPulse 1.5s ease-in-out infinite; }
@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === Markdown in Messages === */
.msg-content h1, .msg-content h2, .msg-content h3 {
  font-weight: 600; margin: 12px 0 6px 0;
}
.msg-content h1 { font-size: 1.25em; }
.msg-content h2 { font-size: 1.1em; }
.msg-content h3 { font-size: 1em; }
.msg-content p { margin: 6px 0; }
.msg-content ul, .msg-content ol { margin: 6px 0; padding-left: 20px; }
.msg-content li { margin: 2px 0; }
.msg-content strong { font-weight: 600; color: #e5e7eb; }
.msg-content em { font-style: italic; }

.msg-content pre {
  background: #0d0d1a;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.6;
  position: relative;
}
.msg-content code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: rgba(255,255,255,0.05);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}
.msg-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.msg-content blockquote {
  border-left: 3px solid rgba(139, 92, 246, 0.4);
  padding-left: 12px;
  color: #9ca3af;
  margin: 8px 0;
}
.msg-content a {
  color: #a78bfa;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg-content hr { border-color: rgba(255,255,255,0.06); margin: 12px 0; }
.msg-content table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.msg-content th, .msg-content td { border: 1px solid rgba(255,255,255,0.08); padding: 6px 10px; text-align: left; }
.msg-content th { background: rgba(255,255,255,0.03); font-weight: 600; }

/* === Code Block Copy Button === */
.code-copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px 8px;
  font-size: 11px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #9ca3af;
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0;
}
.msg-content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: rgba(255,255,255,0.12); color: #e5e7eb; }

/* === Textarea === */
#message-input { line-height: 1.55; font-family: inherit; }

/* === Smooth scroll for chat === */
#chat-container { scroll-behavior: smooth; }

/* === Mobile responsive === */
@media (max-width: 640px) {
  .msg-content { font-size: 14px; }
  .msg-actions { opacity: 1; }
}

/* === Prompt suggestions hover === */
.prompt-suggestion:hover {
  border-color: rgba(139, 92, 246, 0.2);
}

/* === Network Status Panel === */
.block-bar {
  display: flex;
  gap: 2px;
  padding: 4px 0;
}
.block-cell {
  flex: 1;
  height: 28px;
  border-radius: 3px;
  transition: all 0.2s;
  cursor: default;
  position: relative;
}
.block-cell:hover {
  opacity: 0.8;
  transform: scaleY(1.15);
}
.block-covered {
  background: linear-gradient(to bottom, #22c55e, #16a34a);
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.3);
}
.block-missing {
  background: linear-gradient(to bottom, #ef4444, #dc2626);
  box-shadow: 0 0 4px rgba(239, 68, 68, 0.3);
}

.peer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
  font-size: 12px;
  gap: 8px;
}
.peer-item:hover {
  background: rgba(255,255,255,0.04);
}
.peer-id {
  color: #9ca3af;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  flex-shrink: 0;
}
.peer-blocks {
  color: #a78bfa;
  font-size: 11px;
}
.peer-throughput {
  color: #22c55e;
  font-size: 11px;
  flex-shrink: 0;
}

/* === RAG Source Citations === */
.rag-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 0 2px;
}
.rag-sources-label {
  font-size: 10px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-right: 2px;
}
.rag-source-link {
  display: inline-grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 6px;
  row-gap: 1px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  text-decoration: none;
  transition: all 0.15s ease;
  max-width: 280px;
}
.rag-source-link:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(139, 92, 246, 0.25);
}
.rag-source-index {
  grid-row: 1 / span 2;
  font-size: 10px;
  font-weight: 600;
  color: #a78bfa;
  background: rgba(139, 92, 246, 0.12);
  border-radius: 4px;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.rag-source-title {
  font-size: 12px;
  font-weight: 500;
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.rag-source-domain {
  font-size: 9px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

/* === Inline Citation Links === */
.rag-inline-cite {
  color: #a78bfa;
  text-decoration: none;
  font-size: 0.8em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  padding: 0 1px;
  border-radius: 2px;
  transition: all 0.15s ease;
}
.rag-inline-cite:hover {
  color: #c4b5fd;
  background: rgba(167, 139, 250, 0.15);
  text-decoration: none;
}

/* === Network Node Cards === */
.node-card {
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(30, 30, 50, 0.8);
  border: 1px solid rgba(255,255,255,0.05);
  transition: all 0.2s ease;
}
.node-card:hover {
  background: rgba(37, 37, 64, 0.9);
  border-color: rgba(255,255,255,0.08);
}
.node-card.offline {
  opacity: 0.5;
  border-color: rgba(239, 68, 68, 0.2);
  background: rgba(30, 30, 50, 0.4);
}

/* Node status dots */
.node-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.node-status-dot.up {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}
.node-status-dot.down {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
  animation: statusPulse 1.5s ease-in-out infinite;
}

/* Offline badge */
.node-offline-badge {
  font-size: 10px;
  padding: 1px 8px;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Node info row */
.node-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: #9ca3af;
  margin-top: 6px;
}
.node-info span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* VRAM progress bar */
.vram-bar-track {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(45, 45, 74, 0.8);
  overflow: hidden;
}
.vram-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease, background 0.3s ease;
}
.vram-bar-fill.low { background: linear-gradient(90deg, #22c55e, #4ade80); }
.vram-bar-fill.medium { background: linear-gradient(90deg, #eab308, #facc15); }
.vram-bar-fill.high { background: linear-gradient(90deg, #ef4444, #f87171); }

.vram-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.vram-label span {
  font-size: 10px;
}
.vram-section {
  margin-top: 8px;
}

/* Privacy notice in chat footer */
.privacy-notice {
  opacity: 0.65;
  letter-spacing: 0.01em;
  line-height: 1.35;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}
.privacy-notice:hover {
  opacity: 0.9;
  transition: opacity 0.2s ease;
}

/* === Curated Sources Panel === */
.source-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.source-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(167, 139, 250, 0.2);
}
.src-main {
  flex: 1 1 auto;
  min-width: 0;
}
.src-title {
  display: block;
  color: #e5e7eb;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.src-title:hover {
  color: #a78bfa;
}
.src-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.src-domain {
  color: #9ca3af;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}
.src-cat {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(167, 139, 250, 0.12);
  color: #c4b5fd;
  font-size: 10px;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.src-votes {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.src-vote {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}
.src-vote.up { color: #4ade80; }
.src-vote.down { color: #f87171; }
.src-net {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.src-net.positive {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}
.src-net.negative {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}
.src-net.neutral {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
}

/* === Small phones (under 480px) === */
@media (max-width: 480px) {
  /* Use dynamic viewport height so iOS Safari URL bar collapse doesn't cut off the input */
  body.h-screen { height: 100dvh; }

  /* Slightly smaller body text on small screens */
  body { font-size: 13.5px; }
  .msg-content { font-size: 13.5px; line-height: 1.55; }
  .msg-content pre { font-size: 11.5px; padding: 10px 12px; }
  .msg-content table { font-size: 12px; }
  .msg-content th, .msg-content td { padding: 4px 6px; }

  /* Tighter chat scroll area: kill the px-4 py-6 outer padding so chat goes full-width */
  #chat-container > div.max-w-3xl { padding-left: 0.5rem; padding-right: 0.5rem; padding-top: 0.75rem; padding-bottom: 0.75rem; }

  /* Tighter header padding */
  body > div > header.flex { padding-left: 0.5rem; padding-right: 0.5rem; }

  /* Tighter input footer with iOS safe-area for home-indicator devices */
  body > div > footer.flex-shrink-0 {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    padding-top: 0.5rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }
  body > div > footer.flex-shrink-0 > div.max-w-3xl { padding: 0; }

  /* Smaller avatars to give content more room */
  .avatar-user, .avatar-assistant { width: 28px; height: 28px; border-radius: 8px; font-size: 11px; }

  /* Welcome screen vertical breathing room reduced */
  #welcome-screen { padding-top: 2.5rem !important; padding-bottom: 2.5rem !important; }
  #welcome-screen h2 { font-size: 1.05rem; }

  /* Modals: full-screen on mobile (network status + sources + settings) */
  #network-status-modal > div:nth-child(2),
  #sources-modal > div:nth-child(2),
  #settings-modal > div:nth-child(2),
  #image-modal > div:nth-child(2) {
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    transform: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 0.875rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #ns-nodes-list { max-height: calc(100dvh - 360px); }
  #src-list { max-height: calc(100dvh - 220px); }

  /* RAG source pills: wrap properly, no fixed max-width */
  .rag-sources { gap: 5px; }
  .rag-source-link {
    max-width: 100%;
    flex: 0 1 auto;
    min-width: 0;
    padding: 4px 8px;
  }
  .rag-source-title { font-size: 11.5px; }
  .rag-source-domain { font-size: 9px; }

  /* Source cards (curated panel) shrink */
  .source-card { padding: 8px 10px; gap: 8px; }
  .src-title { font-size: 12.5px; }

  /* iOS auto-zoom prevention: input must be 16px+ */
  #message-input { font-size: 16px !important; }
  #image-prompt { font-size: 16px !important; }

  /* Privacy notice less prominent */
  .privacy-notice { font-size: 9px; line-height: 1.3; }

  /* Hide Shift+Enter for new line hint - mobile users don't need it */
  body > div > footer.flex-shrink-0 > div > div.flex.items-center.justify-between > span:first-child { display: none; }

  /* Image panel input */
  #image-panel .flex.items-end { gap: 0.375rem; }
  #image-panel input[type=text] { font-size: 16px; }

  /* Code blocks: enable smooth horizontal scroll on touch */
  .msg-content pre { -webkit-overflow-scrolling: touch; }

  /* Network status grid: stack to single column on very small screens */
  #ns-content .grid.grid-cols-2 { grid-template-columns: 1fr; gap: 0.5rem; }
}

.node-hub-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: 4px;
  line-height: 1.4;
}

/* === Curated Sources: category groups === */
.src-group {
  margin-bottom: 14px;
}
.src-group:last-child {
  margin-bottom: 0;
}
.src-group-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 2px 6px 2px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.src-group-name {
  color: #d1d5db;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.src-group-count {
  color: #6b7280;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.src-group .source-card,
.src-subgroup .source-card {
  margin-bottom: 4px;
}
.src-subgroup {
  margin-top: 6px;
  margin-left: 10px;
  padding-left: 8px;
  border-left: 2px solid rgba(167, 139, 250, 0.18);
}
.src-subgroup-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 2px 4px 2px;
  margin-bottom: 4px;
}
.src-subgroup-name {
  color: #c4b5fd;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}
.src-subgroup-count {
  color: #6b7280;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
