:root {
  color-scheme: light;
  font: 16px/1.6 "Noto Sans JP", system-ui, sans-serif;
  color: #18181b;
  background: #fafafa;
  --surface: #fff;
  --field: #f4f4f5;
  --line: #e4e4e7;
  --muted: #52525b;
  --primary: #0064d8;
  --primary-hover: #0053b6;
  --primary-soft: #e6f1fe;
  --radius: 12px;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.09), 0 1px 2px rgb(0 0 0 / 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 25rem;
}
h1, h2, h3, p { margin: 0; }
h1, h2 { line-height: 1.35; }
h1 { font-size: clamp(1rem, 3vw, 1.125rem); }
h2 { font-size: 1.125rem; }
h3 { font-size: 0.9375rem; }
button, input, textarea { font: inherit; }
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover:enabled { background: #e4e4e7; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { border-color: transparent; background: var(--primary); color: #fff; }
button.primary:hover:enabled { background: var(--primary-hover); }
button.soft-button { border-color: transparent; background: var(--primary-soft); color: #004b9e; }
button.soft-button:hover:enabled { background: #d1e6fc; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
a { color: #0055b8; text-underline-offset: 0.2em; }
svg { width: 1.25rem; height: 1.25rem; flex: none; }
.shell {
  width: min(92%, 60rem);
  margin-inline: auto;
}
.app-header {
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 4rem;
  padding-block: 0.5rem;
}
.menu-button { flex-shrink: 0; }
.badge { display: inline-flex; align-items: center; gap: 0.375rem; color: var(--muted); font-size: 0.75rem; }
.badge::before { content: ""; width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: #71717a; }
.badge.connected { color: #17623a; }
.badge.connected::before { background: #178448; }

#workspace { min-width: 0; overflow: auto; }
.workspace-inner { padding-block: clamp(1.25rem, 4vw, 2rem); }
.workspace-heading { margin-bottom: 1rem; }
.workspace-heading p { margin-top: 0.375rem; color: var(--muted); font-size: 0.875rem; }
.surface {
  padding-inline: clamp(0.875rem, 3vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.empty-state {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: clamp(1.5rem, 6vw, 3rem) 0.25rem;
  text-align: center;
}
.empty-state > p:first-of-type { font-weight: 600; }
.empty-state button { margin-top: 0.25rem; }
.empty-icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.25rem;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: #004b9e;
}
.muted, .evidence-meta { color: var(--muted); font-size: 0.8125rem; }
.notice { margin-bottom: 0.875rem; color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.notice:empty { margin: 0; }
.notice.error, .notice.loading {
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius);
}
.notice.error { background: #fee7ef; color: #931443; }
.notice.loading { background: var(--primary-soft); color: #004b9e; }
#results[aria-busy="true"] { display: none; }
#result-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 0.75rem;
  padding-block: 0.875rem;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 0.5rem;
}
.result-pagination {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  margin-block: 0.875rem;
}
.page-position { color: var(--muted); font-size: 0.75rem; text-align: center; overflow-wrap: anywhere; }
.evidence-card {
  padding-block: 1rem;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  scroll-margin-top: 0.5rem;
}
.evidence-card:target { background: #eef5fe; }
.evidence-card h3 { margin: 0.375rem 0 0.25rem; }
.evidence-top { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.75rem; }
.citation, .evidence-kind { padding: 0.125rem 0.5rem; border-radius: 6px; }
.citation { background: var(--primary-soft); color: #004b9e; font-family: ui-monospace, monospace; }
.evidence-kind { background: var(--field); color: var(--muted); }
.evidence-text {
  max-height: 20rem;
  overflow: auto;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: #fafafa;
  font-size: 0.875rem;
}
#evidence-list > p { padding-block: 1rem; }
.evidence-card:last-child { border-bottom: 0; }
.answer-panel {
  margin-top: 0.875rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: #eef5fe;
  overflow-wrap: anywhere;
}
.answer-panel h3 { margin-bottom: 0.5rem; }
.markdown-body { line-height: 1.8; overflow-wrap: anywhere; }
.plain-text { white-space: pre-wrap; }
.markdown-body :is(h1, h2, h3, h4, h5, h6) { font-size: 0.9375rem; line-height: 1.6; margin: 1em 0 0.4em; }
.markdown-body p { margin: 0 0 0.8em; }
.markdown-body ul, .markdown-body ol { margin: 0.6em 0; padding-left: 1.6em; }
.markdown-body blockquote { margin: 0.8em 0; padding-left: 0.75rem; border-left: 3px solid #d4d4d8; color: var(--muted); }
.markdown-body code { font-family: ui-monospace, monospace; font-size: 0.9em; background: var(--field); padding: 2px 4px; border-radius: 3px; }
.markdown-body pre { max-width: 100%; overflow-x: auto; padding: 0.75rem; background: var(--field); border-radius: 8px; white-space: pre; }
.markdown-body pre code { padding: 0; background: none; }
.markdown-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0.8em 0; }
.markdown-body th, .markdown-body td { border: 1px solid #d4d4d8; padding: 0.375rem 0.625rem; }
.markdown-body .contains-task-list { list-style: none; padding-left: 0.4em; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
#trace-panel { padding-block: 0.875rem; }
summary { cursor: pointer; font-weight: 600; }
.trace-row, .sync-error-row { padding-block: 0.625rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.trace-row span { display: block; color: var(--muted); }

.search-dock {
  padding-top: 0.625rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -2px 8px rgb(0 0 0 / 0.04);
}
.query-tools, .query-row { display: flex; align-items: center; gap: 0.5rem; }
.query-tools { justify-content: space-between; flex-wrap: wrap; margin-bottom: 0.5rem; }
.query-row { align-items: stretch; }
#search-button { min-width: 4.5rem; }
.mode-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-inline-size: 0;
  margin: 0;
  padding: 0.25rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--field);
}
.mode-selector span {
  display: block;
  border-radius: 8px;
  padding: 0.375rem 0.625rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.mode-selector input:checked + span { background: var(--surface); color: #004b9e; box-shadow: var(--shadow); }
.mode-selector input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
.query-field {
  flex: 1;
  min-width: 0;
  padding: 0.375rem 0.75rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
}
.query-field:focus-within { border-color: #71717a; }
.query-field label, .connection label { display: block; font-size: 0.8125rem; font-weight: 600; }
textarea {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  resize: none;
  line-height: 1.45;
}
textarea:focus { outline: none; }
textarea::placeholder { color: #60606a; }

dialog {
  width: min(92%, 32rem);
  max-height: 90dvh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.18);
}
dialog::backdrop { background: rgb(24 24 27 / 0.46); }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.icon-button { width: 2.75rem; padding: 0; border-color: transparent; background: transparent; }
.dialog-content { padding: 1.25rem; }
.connection code { margin-left: 0.375rem; color: var(--muted); }
.connection-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; margin-top: 0.375rem; }
.connection-row input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 0.75rem; background: var(--field); color: inherit; }
.connection p, .actions + p { margin-top: 0.5rem; }
#settings-notice:not(:empty) { margin-block: 0.75rem 0; }
.sync-settings { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.sync-counts, .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sync-counts { margin: 0.5rem 0; }
.sync-counts div { flex: 1 1 8rem; border-radius: 8px; padding: 0.5rem 0.75rem; background: var(--field); }
.sync-counts dt { color: var(--muted); font-size: 0.75rem; }
.sync-counts dd { margin: 0; font-weight: 600; }
.actions { margin-top: 0.75rem; }
#sync-errors { margin-top: 0.75rem; }
.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; }

@media (min-width: 64rem) {
  .header-inner { min-height: 4.5rem; }
}

@media (max-height: 28rem) {
  .header-inner { min-height: 3.25rem; padding-block: 0.25rem; }
  .workspace-inner { padding-block: 0.75rem; }
}
