:root {
  color-scheme: light;
  --ink: #162723;
  --muted: #55625d;
  --border: #d7e1dc;
  --surface: #f5f8f6;
  --accent: #13634f;
  --accent-hover: #0d4a3c;
  --accent-soft: #eaf4ee;
  --danger: #97382e;
  --sidebar-width: 290px;
  font-family: system-ui, "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: #fff;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent); }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid #26826a;
  outline-offset: 3px;
}
.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(18px, 4vw, 62px);
  border-bottom: 1px solid #eaf0ed;
}
.secure-label {
  color: var(--muted);
  font-weight: 650;
  font-size: .9rem;
  letter-spacing: .025em;
}
.primary-button, .secondary-button, .plain-button, .danger-button {
  min-height: 42px;
  border-radius: 9px;
  padding: 8px 16px;
  border: 1px solid transparent;
  font-weight: 650;
  white-space: nowrap;
}
.primary-button {
  color: #fff;
  background: var(--accent);
}
.primary-button:hover:not(:disabled) { background: var(--accent-hover); }
.secondary-button {
  color: var(--accent);
  border-color: var(--border);
  background: #fff;
}
.secondary-button:hover:not(:disabled), .plain-button:hover:not(:disabled) { background: var(--accent-soft); }
.plain-button { color: var(--accent); background: transparent; }
.danger-button { color: #fff; background: var(--danger); }
.danger-button:hover:not(:disabled) { background: #792c24; }
.history-toggle { display: inline-flex; align-items: center; gap: 9px; }
.history-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  position: relative;
}
.history-icon::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 6px;
  width: 4px;
  height: 6px;
  border: solid currentColor;
  border-width: 0 0 1.5px 1.5px;
  border-radius: 0 0 0 2px;
}

.workspace {
  min-width: 0;
  padding: 0 clamp(18px, 4vw, 56px) 68px;
}
.workspace.history-open { margin-left: var(--sidebar-width); }
.search-layout { max-width: 690px; margin: 0 auto; }
.search-layout.initial { padding-top: clamp(72px, 15vh, 160px); }
.search-layout.has-results { padding-top: clamp(32px, 7vh, 76px); }
.wordmark {
  margin: 0 0 26px;
  text-align: center;
  font-size: clamp(2.5rem, 6.7vw, 4.8rem);
  line-height: 1.03;
  font-weight: 760;
  letter-spacing: -.065em;
}
.admin-wordmark { font-size: clamp(2rem, 5vw, 3.25rem); letter-spacing: -.03em; }
.search-box {
  min-height: 61px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  padding: 8px 9px 8px 20px;
  border: 1px solid var(--border);
  border-radius: 36px;
  box-shadow: 0 3px 12px #12281a0a;
}
.search-box:focus-within { border-color: #589783; box-shadow: 0 3px 17px #12281a16; }
.search-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid #587067;
  border-radius: 50%;
  position: relative;
}
.search-icon::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 2px;
  right: -5px;
  bottom: -3px;
  background: #587067;
  transform: rotate(45deg);
}
.search-input {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 0;
  padding: 0 2px;
  border-radius: 4px;
  color: var(--ink);
  background: transparent;
  font-size: 1.06rem;
}
.search-input::placeholder { color: #687570; }
.search-button { border-radius: 26px; padding-inline: 24px; }
.search-settings { margin: 5px 5px 0; }
.search-settings-bar { display: flex; justify-content: flex-end; }
.search-settings-toggle { padding-inline: 10px; font-size: .86rem; }
.search-settings-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px 15px;
}
.search-settings-fields { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.search-settings-field { display: grid; gap: 4px; min-width: min(100%, 200px); }
.search-settings-field label { color: var(--muted); font-size: .84rem; font-weight: 650; }
.search-settings-field select {
  border: 1px solid var(--border);
  border-radius: 7px;
  min-height: 38px;
  padding: 5px 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.search-settings-field select:focus-visible { outline: 3px solid #26826a; outline-offset: 3px; }
.settings-message { color: var(--muted); margin: 0; line-height: 1.6; }
.auth-label { color: var(--muted); text-align: center; line-height: 1.7; }
.login-panel { text-align: center; }
.login-panel .primary-button { min-height: 47px; }
.boot-message { margin: 24vh auto 0; text-align: center; }
.selected-thread { color: var(--muted); margin: 14px 3px 0; line-height: 1.4; overflow-wrap: anywhere; }

.history-panel {
  position: absolute;
  inset: 70px auto auto 0;
  width: var(--sidebar-width);
  padding: 20px 16px 26px;
  min-height: calc(100dvh - 70px);
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.history-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.history-header h2 { margin: 0 0 0 4px; font-size: 1.16rem; }
.new-search { width: 100%; margin: 8px 0 14px; text-align: left; }
.history-message { padding: 0 4px; color: var(--muted); line-height: 1.6; }
.thread-list { margin: 0; padding: 0; list-style: none; }
.thread-row { display: flex; align-items: center; gap: 3px; border-radius: 8px; }
.thread-row.active { background: var(--accent-soft); }
.thread-title {
  flex: 1;
  min-width: 0;
  min-height: 43px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
  padding: 7px 8px;
}
.thread-title:hover:not(:disabled) { border-color: var(--border); }
.delete-entry { padding: 8px; color: var(--danger); }
.load-more { justify-content: center; display: flex; margin-top: 10px; }

.results { display: grid; gap: 15px; margin-top: 22px; }
.result-card { border: 1px solid var(--border); border-radius: 16px; padding: 21px 23px; }
.result-label { color: var(--accent); font-size: .86rem; font-weight: 720; margin: 0 0 4px; }
.result-text { font-size: 1rem; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.72; margin: 0; }
.result-question .result-text { font-weight: 650; }
.result-answer, .result-question + .result-question { margin-top: 17px; }
.turn-status { color: var(--muted); font-size: .84rem; margin: 12px 0 0; }
.notice, .recovery, .delete-confirmation {
  margin: 16px 0 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.delete-confirmation { border-color: #e7c2bd; background: #fff9f8; }
.delete-confirmation h2 { font-size: 1.05rem; margin: 0 0 6px; }
.delete-confirmation p, .recovery p { margin: 0 0 10px; }
.action-row, .progress-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.progress-row { justify-content: space-between; margin: 14px 2px 0; color: var(--muted); }
.admin-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 22px auto;
  max-width: 520px;
}
.admin-form label { grid-column: 1 / -1; font-weight: 650; }
.admin-token {
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 42px;
  padding: 8px 11px;
  color: var(--ink);
  background: #fff;
}
.back-link { display: block; text-align: center; margin-top: 24px; }

.visually-hidden, .skip-link:not(:focus) {
  position: absolute;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link:focus {
  position: absolute;
  top: 8px;
  left: 12px;
  padding: 10px 16px;
  background: #fff;
  z-index: 1;
}

@media (max-width: 680px) {
  .topbar { min-height: 60px; padding: 8px 12px; }
  .history-panel { position: static; width: 100%; min-height: unset; border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace.history-open { margin-left: 0; }
  .search-layout.initial { padding-top: clamp(46px, 11vh, 90px); }
  .search-box { gap: 9px; padding-left: 14px; }
  .search-button { padding-inline: 14px; }
  .search-input { font-size: 1rem; }
  .result-card { padding: 15px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto; }
}
