:root {
  --bg-primary:    #F9F7F3;
  --bg-secondary:  #FFFFFF;
  --bg-panel:      #FFFFFF;
  --bg-hover:      #F0F0F0;
  --border:        #e0e0e0;
  --border-glow:   rgba(26,115,232,0.3);
  --accent:        #1a73e8;
  --accent-dim:    rgba(26,115,232,0.1);
  --accent2:       #673ab7;
  --accent2-dim:   rgba(103,58,183,0.1);
  --green:         #1aa53c;
  --green-dim:     rgba(26,165,60,0.1);
  --red:           #d93025;
  --red-dim:       rgba(217,48,37,0.1);
  --amber:         #f59e0b;
  --text-primary:  #333333;
  --text-secondary:#666666;
  --text-muted:    #888888;
  --radius:        8px;
  --radius-sm:     6px;
  --shadow:        0 1px 2px rgba(0,0,0,0.05);
  --transition:    0.2s cubic-bezier(0.4,0,0.2,1);
}

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

html {
  height: 100%;
  scroll-behavior: smooth;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  /* Desktop: locked viewport (no page scroll, panels scroll internally) */
  overflow: hidden;
}
/* Mobile: page scrolls naturally — applied via JS device detection */
body.is-mobile {
  display: block;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
}

/* ── Accessibility: Skip Link ───────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--bg-primary);
  padding: 8px 16px;
  text-decoration: none;
  z-index: 100;
  border-radius: var(--radius);
  font-weight: 600;
}
.skip-link:focus {
  top: 10px;
  left: 10px;
}

/* ── Accessibility: Focus indicators ────────────────────────────────────────── */
:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus, input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Scrollbars ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 20px rgba(26,115,232,0.2);
  color: white;
}
.logo-text h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
.logo-text span { font-size: 11px; color: var(--text-secondary); }

#status-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  min-width: 0;
  flex-shrink: 1;
  overflow-x: auto;
}
.status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  transition: var(--transition);
  min-width: 0;
  flex-shrink: 1;
  white-space: nowrap;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}
.status-pill.ok   .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-pill.warn .status-dot { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.status-pill.err  .status-dot { background: var(--red);   box-shadow: 0 0 6px var(--red); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
#workspace {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  gap: 0;
}
/* When auto-ingest banner is visible it adds 38px — JS adds this class to body */
body.ingest-banner-visible #workspace {
  /* Flex layout automatically handles this size adjustment */
}

/* ── Mobile Responsiveness ───────────────────────────────────────────────────── */

/* ── Tablet (≤1200px): Flex column override ───────────────────────────────── */
@media (max-width: 1200px) {
  #workspace {
    flex-direction: column;
  }
  #chat-panel {
    resize: none !important;
    max-width: none !important;
  }
}

/* ── Mobile (≤768px): Full single-column, long scrollable page ──────────────── */
/* Applied via both CSS media query AND body.is-mobile class (set by JS) */
body.is-mobile #workspace,
@media (max-width: 768px) {
  #workspace {
    /* Override the fixed desktop height — let content expand naturally */
    height: auto !important;
    min-height: 0 !important;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: visible;
  }
}

body.is-mobile #chat-panel,
body.is-mobile #output-panel {
  flex: none;
  width: 100% !important;
  resize: none !important;
  /* Allow each panel to be as tall as its content, min 400px for usability */
  height: auto;
  min-height: 400px;
  overflow: visible;
}

body.is-mobile .panel-body {
  overflow-y: visible;
  max-height: none;
  /* Give the chat panel body enough room to show full history */
  flex: none;
}

/* For the chat panel specifically, keep a natural min-height */
body.is-mobile #chat-panel {
  min-height: 520px;
}

@media (max-width: 768px) {
  /* Stack all columns vertically */
  #workspace {
    height: auto !important;
    min-height: 0 !important;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: visible;
  }

  #chat-panel,
  #output-panel {
    flex: none;
    width: 100% !important;
    resize: none !important;
    height: auto;
    min-height: 400px;
    overflow: visible;
  }

  #chat-panel { min-height: 520px; }

  .panel-body {
    overflow-y: visible;
    max-height: none;
    flex: none;
  }

  /* Reduce panel header for mobile */
  .panel-header {
    padding: 12px 14px 10px;
  }
  .panel-title   { font-size: 11px; }
  .panel-subtitle { font-size: 10px; }

  /* Status bar */
  #status-bar {
    gap: 8px;
    flex-wrap: wrap;
  }
  .status-pill {
    padding: 3px 8px;
    font-size: 10px;
  }

  /* Header becomes 2-row on mobile */
  #app-header {
    padding: 0 12px;
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .logo {
    gap: 8px;
    flex: 1 1 auto;
  }
  .logo-icon {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .logo-text h1  { font-size: 13px; }
  .logo-text span { font-size: 9px; }

  /* Resource banner */
  #resource-banner-inner {
    flex-wrap: nowrap;
    overflow-x: auto;
    font-size: 10px !important;
    gap: 8px;
  }
  .res-item { font-size: 10px !important; }
}

/* ── Panel base ─────────────────────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.panel:last-child { border-right: none; }

.panel-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.panel-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.panel-body { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }

/* ── Drop Zone ──────────────────────────────────────────────────────────────── */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-panel);
  position: relative;
  overflow: hidden;
}
#drop-zone::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(0,212,255,0.05), transparent 70%);
  opacity: 0;
  transition: var(--transition);
}
#drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
#drop-zone.drag-over::before { opacity: 1; }
#drop-zone:hover { border-color: rgba(0,212,255,0.4); }

.drop-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }
.drop-text { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.drop-text strong { color: var(--accent); }

.file-types {
  display: flex; flex-wrap: wrap; gap: 4px;
  justify-content: center;
  margin-top: 12px;
}
.ft-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px; font-weight: 600;
  border: 1px solid;
}
.ft-pdf  { color: #f87171; border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.08); }
.ft-docx { color: #60a5fa; border-color: rgba(96,165,250,0.3); background: rgba(96,165,250,0.08); }
.ft-txt  { color: #a78bfa; border-color: rgba(167,139,250,0.3); background: rgba(167,139,250,0.08); }
.ft-xlsx { color: #34d399; border-color: rgba(52,211,153,0.3); background: rgba(52,211,153,0.08); }
.ft-csv  { color: #fbbf24; border-color: rgba(251,191,36,0.3); background: rgba(251,191,36,0.08); }
.ft-img  { color: #f472b6; border-color: rgba(244,114,182,0.3); background: rgba(244,114,182,0.08); }

#file-input { display: none; }

/* ── Ingest Progress ────────────────────────────────────────────────────────── */
#ingest-progress {
  margin-top: 14px;
  display: none;
}
.progress-bar-wrap {
  background: var(--bg-secondary);
  border-radius: 99px;
  height: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s ease;
  animation: progress-shimmer 1.5s infinite;
}
@keyframes progress-shimmer {
  0%   { opacity: 1; }
  50%  { opacity: 0.6; }
  100% { opacity: 1; }
}
#ingest-status-text { font-size: 11px; color: var(--text-secondary); margin-top: 6px; }

/* ── Document List ──────────────────────────────────────────────────────────── */
#doc-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }

.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.doc-item:hover { background: var(--bg-hover); border-color: rgba(0,212,255,0.2); }
.doc-icon { font-size: 18px; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-type { font-size: 10px; color: var(--text-muted); }
.doc-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; padding: 2px 6px;
  border-radius: 4px; transition: var(--transition);
  flex-shrink: 0;
}
.doc-delete:hover { color: var(--red); background: var(--red-dim); }

.empty-state {
  text-align: center; padding: 24px 12px;
  color: var(--text-muted); font-size: 12px; line-height: 1.6;
}

/* ── Center: Chat Panel ─────────────────────────────────────────────────────── */
#chat-panel {
  background: var(--bg-secondary);
  flex: 1 1 50%;
  overflow: hidden; /* Keep to prevent content overflow */
  min-width: 320px;
  max-width: 80vw;
}

#chat-history {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-msg {
  display: flex;
  gap: 12px;
  animation: fadeSlideUp 0.3s ease;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.chat-msg.user .chat-avatar { background: var(--accent-dim); border: 1px solid var(--border-glow); }
.chat-msg.assistant .chat-avatar { background: var(--accent2-dim); border: 1px solid rgba(124,58,237,0.3); }

.chat-bubble {
  flex: 1;
  padding: 12px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
}
.chat-msg.user .chat-bubble { background: var(--accent-dim); border-color: var(--border-glow); }
.chat-time { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* Thinking animation (legacy) */
.thinking-dots span {
  display: inline-block;
  animation: bounce 1.2s infinite;
  font-size: 20px;
  color: var(--accent);
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-8px); }
}

/* Milestone Graph */
.milestone-graph {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 8px 0;
}
.milestone {
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}
.milestone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  transition: var(--transition);
  box-shadow: 0 0 4px var(--red);
}
.milestone-dot.executing {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: blink 1s infinite alternate;
}
.milestone-dot.complete {
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
}
.milestone-dot.failed {
  background: #ff4444;
  box-shadow: 0 0 8px #ff4444;
}
.milestone-timer {
  font-family: monospace;
  font-size: 10px;
  opacity: 0.7;
}
.milestone-line {
  height: 2px;
  width: 24px;
  background: var(--border);
  transition: var(--transition);
}
@keyframes blink {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.4; transform: scale(0.85); }
}

/* ── Query Input ────────────────────────────────────────────────────────────── */
#query-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#query-form { display: flex; gap: 10px; align-items: flex-end; }

#query-input {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  transition: var(--transition);
  outline: none;
}
#query-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,212,255,0.1);
}
#query-input::placeholder { color: var(--text-muted); }

#send-btn {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #0099cc);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 4px 15px rgba(0,212,255,0.3);
}
#send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,212,255,0.4); }
#send-btn:active { transform: translateY(0); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Output Panel ───────────────────────────────────────────────────────────── */
#output-panel {
  flex: 1 1 50%;
  min-width: 320px;
}
#output-panel .panel-body {
  display: flex;
  flex-direction: column;
}

#output-container {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 200px;
  flex: 1;
  padding: 16px;
  font-size: 13px;
  line-height: 1.7;
  overflow-y: auto;
}

/* Markdown rendering */
#output-container h1 { font-size: 18px; color: var(--accent); margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
#output-container h2 { font-size: 15px; color: var(--text-primary); margin: 16px 0 8px; }
#output-container h3 { font-size: 13px; color: var(--text-secondary); margin: 12px 0 6px; }
#output-container p  { margin-bottom: 10px; color: var(--text-secondary); }
#output-container ul, #output-container ol { margin: 8px 0 8px 20px; }
#output-container li { margin-bottom: 4px; color: var(--text-secondary); }
#output-container strong { color: var(--text-primary); font-weight: 600; }
#output-container em { color: var(--accent); font-style: normal; }
#output-container code {
  background: rgba(0,212,255,0.1);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Fira Code', monospace;
}
#output-container pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
#output-container pre code { background: none; padding: 0; color: var(--text-primary); }
#output-container blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 10px 0;
}

.output-placeholder {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}
.output-placeholder .ph-icon { font-size: 36px; margin-bottom: 10px; opacity: 0.4; }

/* ── Inference Metrics Banner (pinned at top of output panel) ───────────────── */
#metrics-banner {
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(0,212,255,0.08), rgba(124,58,237,0.08));
  border: 1px solid rgba(0,212,255,0.2);
  padding: 10px 14px;
  animation: fadeSlideUp 0.3s ease;
}
.metrics-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.metrics-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-right: 4px;
  white-space: nowrap;
}
.metrics-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.metrics-pill strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Citations */
#citations-block { margin-top: 16px; }
.citation-tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  background: var(--accent-dim);
  border: 1px solid var(--border-glow);
  border-radius: 99px;
  font-size: 10px;
  color: var(--accent);
  margin: 3px;
}

/* Copy button */
#copy-btn {
  display: none;
  margin-top: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}
#copy-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Notifications ──────────────────────────────────────────────────────────── */
#notif-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 1000;
}
.notif {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideInRight 0.3s ease;
  max-width: 320px;
}
.notif.success { border-color: rgba(16,185,129,0.4); color: var(--green); }
.notif.error   { border-color: rgba(239,68,68,0.4);  color: var(--red); }
.notif.info    { border-color: var(--border-glow);   color: var(--accent); }
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Utility ────────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ── Docker control buttons (header) ───────────────────────────────────────── */
#docker-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: 8px;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}
.docker-btn {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.docker-btn:hover          { background: var(--green-dim);  border-color: var(--green);  color: var(--green); }
.docker-btn.warn:hover     { background: rgba(245,158,11,0.15); border-color: var(--amber); color: var(--amber); }
.docker-btn.danger:hover   { background: var(--red-dim);    border-color: var(--red);    color: var(--red); }

/* ── Diagnostic log (ingestion) ─────────────────────────────────────────────── */
.log-summary {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  padding: 4px 0;
}
.log-summary:hover { color: var(--accent); }
.ingest-log-box {
  margin-top: 6px;
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.log-line { white-space: pre-wrap; word-break: break-all; }

/* ── KB header row ──────────────────────────────────────────────────────────── */
.kb-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.kb-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 2px 7px;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── X delete button — at start of doc-item ────────────────────────────────── */
.doc-delete {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
  line-height: 1;
}
.doc-delete:hover { color: var(--red); background: var(--red-dim); border-color: rgba(239,68,68,0.3); }

/* ── Preset prompt buttons ──────────────────────────────────────────────────── */
#prompt-presets {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
  border-top: 1px solid var(--border);
}
.preset-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: normal;       /* allow wrapping on mobile */
  word-break: break-word;
  text-align: center;
  line-height: 1.4;
}
.preset-btn:hover   { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.preset-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Docker modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#tier-modal, #captcha-modal {
  z-index: 3000;
}
.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(540px, 90vw);
  box-shadow: var(--shadow);
  animation: fadeSlideUp 0.2s ease;
}
.modal-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}
.modal-body {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.modal-pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: 'Fira Code', monospace;
  font-size: 10.5px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 260px;
  overflow-y: auto;
  color: var(--text-secondary);
  margin-top: 4px;
}
.modal-close-btn {
  margin-top: 16px;
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}
.modal-close-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Warn notification type ─────────────────────────────────────────────────── */
.notif.warn { border-color: rgba(245,158,11,0.4); color: var(--amber); }

/* ── Resource Monitor Banner ────────────────────────────────────────────────── */
#resource-banner {
  height: 36px;
  background: rgba(7,11,20,0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  overflow: hidden;
  flex-shrink: 0;
}

#resource-banner-inner {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  padding: 0 20px;
  gap: 16px;
}

.res-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  margin-right: 4px;
}

.res-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.res-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.res-icon { font-size: 12px; }

.res-bar-wrap {
  width: 56px;
  height: 4px;
  background: rgba(255,255,255,0.07);
  border-radius: 99px;
  overflow: hidden;
  flex-shrink: 0;
}

.res-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--green);
  transition: width 0.6s ease, background 0.4s ease;
  width: 0%;
}

/* Color thresholds: green < 70%, amber 70-89%, red >= 90% */
.res-bar.warn  { background: var(--amber); }
.res-bar.crit  { background: var(--red); box-shadow: 0 0 6px var(--red); }

.res-pct {
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  min-width: 30px;
  color: var(--text-secondary);
}
.res-pct.warn  { color: var(--amber); }
.res-pct.crit  { color: var(--red); }

.res-mode-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border: 1px solid;
  white-space: nowrap;
}
.res-mode-badge.hf-mode  {
  color: #fbbf24;
  border-color: rgba(251,191,36,0.35);
  background: rgba(251,191,36,0.08);
}
.res-mode-badge.gpu-mode {
  color: var(--green);
  border-color: rgba(16,185,129,0.35);
  background: rgba(16,185,129,0.08);
}

/* ── Auto-Ingest Progress Banner ────────────────────────────────────────────── */
#auto-ingest-banner {
  height: 38px;
  background: linear-gradient(90deg, rgba(0,212,255,0.08), rgba(124,58,237,0.08), rgba(0,212,255,0.08));
  background-size: 200% 100%;
  animation: banner-shimmer 3s linear infinite;
  border-bottom: 1px solid rgba(0,212,255,0.2);
  backdrop-filter: blur(10px);
  overflow: hidden;
  flex-shrink: 0;
}

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

#auto-ingest-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  padding: 0 20px;
}

.auto-ingest-icon {
  font-size: 14px;
  animation: spin 2s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

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

.auto-ingest-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  flex-shrink: 0;
}

#auto-ingest-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.3px;
}

.auto-ingest-sub {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.auto-ingest-progress-wrap {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.07);
  border-radius: 99px;
  overflow: hidden;
  margin: 0 8px;
}

.auto-ingest-progress-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.5s ease;
  width: 0%;
  box-shadow: 0 0 8px rgba(0,212,255,0.5);
}

.auto-ingest-count {
  font-size: 10px;
  font-family: 'Fira Code', monospace;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Tooltips ───────────────────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
  cursor: pointer;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(11, 16, 33, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
}
[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-6px);
}

/* ── Mobile-Friendly Buttons & Form Elements ──────────────────────────────── */
@media (max-width: 768px) {
  /* Increase touch target size for all interactive elements */
  button {
    min-height: 44px;
    min-width: 44px;
  }

  input[type="text"],
  input[type="number"],
  input[type="email"],
  textarea,
  select {
    min-height: 44px;
    font-size: 16px; /* Prevents auto-zoom on iOS Safari */
  }

  /* Expand query input for comfortable mobile typing */
  #query-input {
    min-height: 64px !important;
    font-size: 16px;
    max-height: 120px;
  }

  #send-btn {
    width: 56px;
    height: 56px;
    font-size: 20px;
  }

  /* Stack query presets vertically on mobile */
  #query-presets {
    flex-direction: column !important;
    gap: 6px;
  }
  #query-presets button {
    width: 100%;
    min-height: 44px;
  }

  /* Prompt test presets: stacked on mobile */
  #prompt-presets {
    flex-wrap: wrap;
    gap: 6px;
  }
  #prompt-presets button {
    flex: 1 1 calc(50% - 6px);
  }

  /* Expand file drop zone for easier finger tap */
  #drop-zone {
    padding: 36px 16px;
  }

  /* Modal: full-width, comfortable padding */
  .modal-card {
    width: 95vw;
    padding: 16px;
  }
  .modal-pre {
    max-height: 200px;
    font-size: 10px;
  }

  /* Preset buttons: larger tap target on mobile */
  .preset-btn {
    min-height: 44px;
    font-size: 12px;
  }

  /* Chat message improvements */
  .chat-msg  { gap: 8px; }
  .chat-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  .chat-bubble {
    font-size: 13px;
    padding: 10px 12px;
  }

  /* Notifications: full-width on mobile */
  #notif-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }
  .notif {
    max-width: 100%;
  }

  /* Output container: allow natural height */
  #output-container {
    min-height: 200px;
    overflow-y: visible;
  }
}

/* ── Very small screens (≤480px): compact resource banner ─────────────────── */
/* NOTE: This is intentionally a TOP-LEVEL query (not nested) for broad browser support */
@media (max-width: 480px) {
  .res-icon    { display: none; }
  .res-divider { display: none; }
  .res-label   { margin-right: auto; }
  #res-cpu-label,
  #res-ram-label,
  #res-disk-label { display: none; }
  .res-bar-wrap { width: 40px; }

  /* Header: hide long subtitle on tiny screens */
  #logo-subtitle { display: none; }

  /* Status pills: show only dots on tiny screens */
  .status-label { display: none; }
  .status-pill  { padding: 3px 6px; }
}

/* ── Accessibility: Reduced Motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Accessibility: High Contrast Mode ───────────────────────────────────── */
@media (prefers-contrast: more) {
  :root {
    --border: rgba(255,255,255,0.2);
    --text-secondary: #a8b4c8;
    --text-muted: #6b7684;
  }

  button,
  a,
  input,
  textarea {
    border-width: 2px;
  }
}

/* ── Landscape Mode Adjustments ────────────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  #app-header {
    height: 50px;
  }

  #resource-banner {
    height: 28px;
  }

  .panel-header {
    padding: 8px 14px 6px;
  }

  .panel-body {
    padding: 8px;
  }

  .chat-bubble {
    padding: 8px 10px;
  }

  #query-input {
    min-height: 36px;
  }

  #send-btn {
    width: 40px;
    height: 40px;
  }
}

/* ── Progress Graph Enhancements ────────────────────────────────────────────── */
.milestone.disabled {
  opacity: 0.4;
  filter: grayscale(1);
}
.milestone-chunks {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 2px;
  margin-left: 16px;
  display: block;
  opacity: 0;
  transition: opacity 0.3s;
  font-family: 'Fira Code', monospace;
  letter-spacing: 0.2px;
}
.milestone-chunks.visible {
  opacity: 1;
}
/* Ensure chunk count text is always legible when present */
.milestone-chunks:not(:empty) {
  opacity: 1 !important;
}
.milestone-tokens {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 2px;
  margin-left: 10px;
  font-family: monospace;
}
/* GPU checkbox label highlight */
#res-gpu label {
  color: var(--green);
  font-weight: 600;
}
#chk-gpu:checked + span,
#chk-gpu:checked ~ * {
  color: var(--green);
}

/* F14/F24: LLM Mode + Backend toggle pills */
.mode-btn {
  background: none;
  border: none;
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary) !important;
  transition: background 0.2s, color 0.2s;
}
.mode-btn.active {
  background: var(--accent) !important;
  color: #fff !important;   /* force white — fixes text vanishing on dark/light themes */
}
/* F24: Backend toggle — Local (green) / NVIDIA (violet) */
.backend-btn {
  background: none;
  border: none;
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary) !important;
  transition: background 0.2s, color 0.2s;
}
.backend-btn.active-local {
  background: #16a34a !important;
  color: #fff !important;
}
.backend-btn.active-nvidia {
  background: #7c3aed !important;
  color: #fff !important;
}

/* Custom resizer handle styling */
.resizer-handle {
  width: 8px;
  background: var(--border);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 20;
  user-select: none;
  transition: background-color 0.2s;
}
.resizer-handle:hover,
.resizer-handle.dragging {
  background: var(--accent);
}
.resizer-arrow {
  width: 22px;
  height: 22px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 21;
  transition: border-color 0.2s, color 0.2s;
}
.resizer-handle:hover .resizer-arrow,
.resizer-handle.dragging .resizer-arrow {
  color: var(--accent);
  border-color: var(--accent);
}

/* Hide resizer on mobile/tablet stacked layouts */
@media (max-width: 1200px) {
  .resizer-handle {
    display: none !important;
  }
}
body.is-mobile .resizer-handle {
  display: none !important;
}

/* ── Query History Blocks ────────────────────────────────────────────────── */
.response-block {
  position: relative;
  border-bottom: 1px solid var(--border);
  padding: 16px 16px 24px 16px;
  margin-bottom: 16px;
  animation: fadeSlideUp 0.3s ease;
}
.response-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.response-query {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.response-answer-text {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
}
.response-metrics {
  margin-top: 14px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.response-copy-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: var(--transition);
  padding: 4px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.response-copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(0, 212, 255, 0.08);
}
