:root {
  --ink: #12263f;
  --muted: #4a5d73;
  --rule: #c9d4e1;
  --blue: #1659c6;
  --navy: #0d2c55;
  --paper: #f5f7fa;
}

* {
  box-sizing: border-box;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.top :focus-visible,
.ask-head :focus-visible,
.viewer-bar :focus-visible {
  outline-color: #fff;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 30;
  padding: 0.4rem 0.7rem;
  background: #fff;
  color: var(--navy);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.55rem 6vw;
  background: var(--navy);
  color: #fff;
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.7rem;
}

.brand > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand-logo {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: #0d2c55;
}

.brand strong {
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

.brand span {
  color: #c5d4e8;
  font-size: 0.82rem;
}

.app-version {
  color: #c5d4e8;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

main {
  padding: 1rem 6vw 1.5rem;
  max-width: 58rem;
}

.landing {
  padding: 0 0 0.85rem;
}

.landing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h1,
h2,
h3 {
  font-weight: 650;
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.2;
}

.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.info-i {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.08rem;
  border: 1.5px solid var(--blue);
  border-radius: 50%;
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 700;
  font-style: italic;
  line-height: 1.05rem;
  text-align: center;
}

.ask-btn,
.send {
  border: 0;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.ask-btn {
  padding: 0.45rem 1.15rem;
  min-height: 2.4rem;
  font-size: 1rem;
}

.ask-btn:hover,
.send:hover {
  background: #124aa8;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.85rem;
  margin: 0.45rem 0 0;
}

.examples span {
  color: var(--muted);
  font-size: 0.88rem;
}

.examples button {
  min-height: 1.5rem;
  margin: 0;
  padding: 0.15rem 0;
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  cursor: pointer;
}

.examples button:hover,
.examples button:focus-visible {
  text-decoration: underline;
}

.ghost,
.send,
.cite a {
  font: inherit;
}

.ghost {
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  min-height: 1.5rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.ask-window {
  position: fixed;
  z-index: 15;
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 360px;
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 1.5rem);
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(13, 44, 85, 0.28);
  overflow: hidden;
}

.ask-window.hidden {
  display: none;
}

.ask-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  background: var(--navy);
  color: #fff;
  cursor: move;
  user-select: none;
}

.ask-head h2 {
  font-size: 1rem;
}

.ask-head-actions {
  display: flex;
  gap: 0.4rem;
}

.ask-head .ghost {
  color: #fff;
  border-color: #6d86a8;
  background: transparent;
  padding: 0.25rem 0.55rem;
}

.ask-head .ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  background: var(--paper);
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid #c9d4e1;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--blue);
  }
}

.ask-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 0 55%, #8aa0b8 55% 62%, transparent 62% 75%, #8aa0b8 75% 82%, transparent 82%);
}

.bubble {
  max-width: 90%;
  padding: 0.8rem 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  border: 1px solid var(--rule);
  background: #fff;
}

.bubble.user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.cites {
  display: grid;
  gap: 0.55rem;
}

.cite {
  background: #fff;
  border: 1px solid var(--rule);
  padding: 0.75rem 0.85rem;
}

.cite strong {
  display: block;
}

.cite p {
  margin: 0.25rem 0 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.cite blockquote {
  margin: 0.35rem 0 0.55rem;
  padding: 0.45rem 0.6rem;
  border-left: 3px solid var(--navy);
  background: #f3f6fa;
  color: var(--ink);
  font-size: 0.92rem;
}

.cite.is-active {
  outline: 2px solid var(--blue);
  background: #eef4fb;
}

.cite a,
.source-open {
  color: var(--blue);
}

.source-open {
  display: inline-flex;
  align-items: center;
  min-height: 1.5rem;
  margin: 0;
  padding: 0.15rem 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  min-height: 1.5rem;
  margin: 0 0.05rem;
  padding: 0 0.2rem;
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ref:hover,
.ref:focus-visible {
  text-decoration: underline;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  margin: 0;
  background: #fff;
  border: 0;
  border-top: 1px solid var(--rule);
  padding: 0.55rem;
}

textarea {
  resize: none;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
}

.send {
  padding: 0 1rem;
}

.send:disabled {
  opacity: 0.55;
  cursor: wait;
}

.library {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
}

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--navy);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  min-height: 2.4rem;
  min-width: 2.4rem;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

.faq-count {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.faq-toolbar {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.faq-section {
  margin: 0 0 1rem;
}

.faq-section h3 {
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
  border-bottom: 2px solid var(--navy);
  padding-bottom: 0.25rem;
  margin: 0 0 0.35rem;
}

.faq-item {
  border-bottom: 1px solid var(--rule);
  background: #fff;
}

.faq-item:nth-child(even) {
  background: #e8eef6;
}

.faq-item summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.55rem;
  font-weight: 650;
  min-height: 2.4rem;
}

.faq-item.faq-flash {
  outline: 2px solid var(--blue);
  background: #dce8f8;
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::before {
  content: "+";
  display: inline-block;
  width: 1.1rem;
  color: var(--blue);
}

.faq-item[open] summary::before {
  content: "−";
}

.faq-answer {
  padding: 0 0.55rem 0.7rem 1.65rem;
  color: var(--ink);
}

.faq-answer p {
  margin: 0 0 0.6rem;
}

.faq-ask {
  color: var(--blue);
  background: none;
  border: 0;
  padding: 0.2rem 0;
  min-height: 1.5rem;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.library-head {
  margin-bottom: 0.85rem;
}

.library-head h2 {
  font-size: 1.25rem;
}

.library-head p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.library-head a {
  color: var(--blue);
}

.catalog-section {
  margin: 0 0 1.05rem;
}

.catalog-section h3 {
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
  border-bottom: 2px solid var(--navy);
  padding-bottom: 0.25rem;
  margin-bottom: 0;
}

.catalog-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.catalog-section li:nth-child(odd) a {
  background: #fff;
}

.catalog-section li:nth-child(even) a {
  background: #e8eef6;
}

.catalog-section li a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  min-height: 1.5rem;
  padding: 0.35rem 0.5rem;
  color: var(--blue);
  text-decoration: none;
}

.catalog-section li a:hover,
.catalog-section li a:focus-visible {
  background: #d7e4f4;
}

.catalog-section .title {
  color: var(--blue);
}

.catalog-section li a:hover .title {
  text-decoration: underline;
}

.catalog-section .meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--navy);
  color: #fff;
  padding: 0.7rem 0.9rem;
  max-width: 22rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 44, 85, 0.45);
}

.modal-panel {
  position: relative;
  width: min(28rem, 100%);
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(13, 44, 85, 0.28);
  padding: 1.25rem 1.3rem 1.15rem;
}

.modal-panel h2 {
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}

.modal-panel p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.modal-panel label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 650;
}

.modal-panel input {
  width: 100%;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 0.55rem 0.65rem;
  margin-bottom: 1rem;
}

.modal-panel input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.modal-actions {
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
}

.modal-actions .send,
.modal-actions .ghost {
  min-height: 2.3rem;
}

.viewer {
  position: fixed;
  inset: 3vh 3vw;
  z-index: 18;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(13, 44, 85, 0.28);
}

.viewer.hidden {
  display: none;
}

.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  background: var(--navy);
  color: #fff;
}

.viewer-bar h2 {
  font-size: 1.05rem;
}

.viewer-bar p {
  margin: 0.2rem 0 0;
  color: #c5d4e8;
  font-size: 0.88rem;
}

.viewer-bar .ghost {
  color: #fff;
  border-color: #6d86a8;
  background: transparent;
}

.viewer-quote {
  margin: 0;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  background: #fff7cc;
  color: var(--ink);
  white-space: normal;
  overflow-wrap: anywhere;
}

.viewer-quote[hidden],
#page-cited[hidden],
#viewer-download[hidden] {
  display: none;
}

.viewer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--rule);
  background: #eef2f6;
}

.viewer-tools .ghost {
  min-width: 1.5rem;
  min-height: 1.5rem;
  padding: 0.25rem 0.5rem;
}

.bubble strong {
  font-weight: 700;
}

.bubble em {
  font-style: italic;
}

.tools-gap {
  flex: 1 1 0.5rem;
}

#zoom-label,
#page-label {
  min-width: 3.4rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}

.viewer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #d5dbe3;
  padding: 1rem;
  cursor: grab;
}

.viewer[data-mode="video"] .viewer-tools,
.viewer[data-mode="video"] .viewer-quote,
.viewer[data-mode="video"] .viewer-hint,
.viewer[data-mode="video"] #viewer-download {
  display: none;
}

.viewer[data-mode="video"] .viewer-body {
  padding: 0;
  background: #111;
  cursor: default;
}

.viewer-frame {
  width: 100%;
  height: 100%;
  min-height: 16rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
}

.viewer-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.viewer-body.is-panning {
  cursor: grabbing;
  user-select: none;
}

.viewer-page {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

.viewer-page canvas {
  display: block;
}

.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
}

.textLayer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  transform-origin: 0 0;
}

.textLayer .hl {
  background: rgba(255, 210, 0, 0.28);
}

.found-box {
  position: absolute;
  border: 3px solid #c9a000;
  background: rgba(255, 214, 0, 0.16);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
  pointer-events: none;
  z-index: 6;
}

.viewer-text {
  max-width: 46rem;
  margin: 0 auto;
  background: #fff;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  white-space: pre-wrap;
}

.viewer-text mark {
  background: #ffe066;
  color: inherit;
  padding: 0 0.1rem;
}

.viewer-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--rule);
}

.viewer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.viewer-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  padding: 0.35rem 0.85rem;
  text-decoration: none;
}

.viewer-links .send {
  color: #fff;
}

.viewer-links .ghost:hover {
  background: #e8eef6;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.site-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  padding: 0.7rem 6vw 1.1rem;
  border-top: 1px solid var(--rule);
  background: #eef2f7;
}

.site-foot .status {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 720px) {
  .landing-row {
    flex-wrap: wrap;
  }

  .site-foot {
    flex-direction: column;
    align-items: flex-start;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .send {
    min-height: 2.6rem;
  }
}
