:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #f8fbff;
  --muted: #d6e4f5;
  --accent: #238636;
  --accent-hover: #2ea043;
  --user-bg: #1f6feb22;
  --bot-bg: #21262d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  background: transparent;
  color: var(--text);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0f172ad9, #0f172a00);
}

.title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
}

.subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 1rem 1.25rem;
}

/* チャット履歴：ユーザーは右寄せ、ボットは左寄せ */
.history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(100vh - 220px);
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 85%;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sources {
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0d1117;
  font-size: 0.82rem;
  max-width: 100%;
}

.sources-title {
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}

.source-item {
  padding: 0.4rem 0;
  border-top: 1px solid #30363d66;
}

.source-item:first-of-type {
  border-top: none;
  padding-top: 0;
}

.source-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.2rem;
}

.source-link {
  color: #58a6ff;
  text-decoration: none;
  font-weight: 600;
}

.source-link:hover {
  text-decoration: underline;
}

.source-score {
  color: var(--muted);
  font-size: 0.76rem;
}

.source-snippet {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  opacity: 0.92;
}

.meta {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 0.2rem;
}

.bubble {
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

.msg-row.user .bubble {
  background: var(--user-bg);
  border-color: #388bfd66;
}

.msg-row.bot .bubble {
  background: var(--bot-bg);
}

/* FAQ 複数候補：ボタン行 */
.faq-candidate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
  max-width: 85%;
  align-self: flex-start;
}

/* 吹き出し内に収めるときは行幅を吹き出しに合わせる */
.faq-candidate-row--inbubble {
  margin-top: 0;
  max-width: 100%;
  align-self: stretch;
}

button.faq-candidate {
  font: inherit;
  cursor: pointer;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #388bfd66;
  background: #21262d;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}

button.faq-candidate:hover {
  background: #30363d;
  border-color: #58a6ff;
}

.bubble.bubble-candidates {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-bottom: 0;
  max-width: 100%;
  white-space: normal;
}

.bubble-candidate-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.bubble .bubble-link {
  color: #58a6ff;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.bubble .bubble-link:hover {
  color: #79b8ff;
}

.composer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  max-height: 160px;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.composer textarea:focus {
  outline: 2px solid #388bfd44;
  border-color: #388bfd;
}

.btn-send {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  height: fit-content;
}

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

.btn-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.nav-top {
  margin: 0.5rem 1.25rem 0;
  font-size: 0.9rem;
}

 .nav-top a {
  color: #dbeafe;
  text-decoration: none;
}

.nav-top a:hover {
  text-decoration: underline;
}

.admin-main {
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem 1.15rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

/* 管理画面：文書インデックスなどを折りたたみ（details/summary） */
.admin-collapsible {
  border: none;
}

.admin-collapsible-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.15rem 0;
  user-select: none;
}

.admin-collapsible-summary::-webkit-details-marker {
  display: none;
}

.admin-collapsible-summary::before {
  content: "";
  display: inline-block;
  width: 0.35rem;
  height: 0.35rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-top: -0.1rem;
}

.admin-collapsible[open] .admin-collapsible-summary::before {
  transform: rotate(45deg);
}

.admin-collapsible-heading {
  margin: 0;
}

.admin-collapsible-body {
  padding-top: 0.65rem;
}

.import-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.5rem;
}

.radio-inline {
  font-size: 0.9rem;
  color: var(--text);
}

.toolbar {
  margin: 0.5rem 0 0;
}

.btn-link {
  display: inline-block;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  background: #21262d;
  border: 1px solid var(--border);
  color: #58a6ff;
  text-decoration: none;
  font-size: 0.9rem;
}

.btn-link:hover {
  border-color: #58a6ff66;
}

.btn-link.danger {
  color: #f85149;
  background: transparent;
  border: none;
  padding: 0.15rem 0.35rem;
  cursor: pointer;
  font: inherit;
}

.faq-form .form-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 0.75rem;
  align-items: start;
}

.faq-form label {
  font-size: 0.88rem;
  color: var(--muted);
  padding-top: 0.35rem;
}

.faq-form input[type="text"],
.faq-form input[type="number"],
.faq-form textarea {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0d1117;
  color: var(--text);
  font: inherit;
}

.faq-form textarea {
  resize: vertical;
  min-height: 72px;
}

.req {
  color: #f85149;
}

.form-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-secondary {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  cursor: pointer;
  background: #21262d;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.data-table th {
  background: #161b22;
  color: var(--muted);
  font-weight: 600;
}

.data-table .row-actions {
  white-space: nowrap;
  width: 1%;
}

.muted {
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.error-msg {
  color: #f85149;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
