:root {
  color-scheme: light dark;
  --border: #d0d0d0;
  --muted: #666;
  --accent: #2b5fb8;
  --bg-card: #f7f7f9;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --surface: #ffffff;
  --shadow: rgba(0, 0, 0, 0.08);
  --hairline: rgba(0, 0, 0, 0.05);
  --hairline-strong: rgba(0, 0, 0, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --border: #3a3d42;
    --muted: #9a9fa6;
    --accent: #5b8def;
    --bg-card: #1d2024;
    --bg: #121417;
    --fg: #e7e9ec;
    --surface: #1a1d21;
    --shadow: rgba(0, 0, 0, 0.5);
    --hairline: rgba(255, 255, 255, 0.08);
    --hairline-strong: rgba(255, 255, 255, 0.12);
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
}

.subtitle { color: var(--muted); margin-top: 0; }

.lang-switch {
  align-self: flex-end;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.lang-switch a { color: var(--accent); }

body:lang(ja) {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, Roboto, sans-serif;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: 4.25rem;
}

/* Sticky app bar: logo + query input + query/clear/copy buttons.
 * Fixed to the viewport so it stays visible no matter how the chat
 * transcript below is scrolled. */
.app-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
}

.app-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-bar-logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
}

.app-bar-form {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.status {
  min-height: 1.5em;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

select, button, input[type="text"] {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: not-allowed; }

#chat-input { flex: 1; min-width: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 0.75rem;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.icon-btn-primary {
  background: var(--accent);
  color: white;
}

@media (max-width: 640px) {
  .app-bar-inner {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }

  .icon-btn span {
    display: none;
  }

  .icon-btn {
    padding: 0.5rem;
  }
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 20rem;
  max-height: 75vh;
  overflow-y: auto;
  margin-top: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.chat-message {
  max-width: 80%;
  padding: 0.55rem 0.85rem;
  border-radius: 14px;
  white-space: pre-wrap;
  line-height: 1.4;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  max-width: 96%;
}

.hits-table {
  margin-top: 0.75rem;
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  white-space: normal;
}

.hits-table th,
.hits-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.hits-table th {
  background: var(--hairline);
  font-weight: 600;
}

.hits-table .hit-ref {
  font-weight: 600;
  white-space: nowrap;
}

.hits-table .hit-versions {
  white-space: nowrap;
}

.hits-table .hit-match {
  white-space: nowrap;
  text-align: center;
}

.match-badge {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
  white-space: nowrap;
}

.match-badge.exact {
  background: var(--accent);
  color: white;
}

.match-badge.high {
  background: #1e7e34;
  color: white;
}

.match-badge.medium {
  background: #b8860b;
  color: white;
}

.match-badge.low {
  background: var(--hairline-strong);
  color: var(--muted);
}


.chat-message a { color: inherit; }

.chat-message code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--hairline-strong);
  padding: 0.1em 0.3em;
  border-radius: 4px;
  font-size: 0.9em;
}

.chat-message.user code {
  background: rgba(255, 255, 255, 0.2);
}

.chat-message .citation {
  font-weight: 600;
  color: var(--accent);
}

.chat-message.user .citation {
  color: white;
}

/* Collapsible "reasoning" block for engines (e.g. LFM2.5-Thinking) that
 * emit a <think>...</think> block ahead of their final answer. */
.reasoning {
  margin-bottom: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--hairline);
}

.reasoning summary {
  cursor: pointer;
  font-weight: 600;
}

.reasoning-body {
  margin-top: 0.5rem;
  white-space: normal;
}

.chat-note {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Animated "query in progress" indicator: three pulsing dots, shown while
 * retrieval and/or the chat engine are working, replacing static
 * "Searching…"/"Thinking…" text so it's obvious the app is still busy. */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
  40% { transform: translateY(-4px); opacity: 1; }
}

footer {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}
