/*
 * Rhetor8 UI tokens — see docs/rhetor8-color-palette.html for full palette.
 * Steel Blue #366492 (structure), Kinetic Orange #F08D23 (highlights / primary CTA).
 */
:root {
  color-scheme: light dark;
  --r8-steel: #366492;
  --r8-steel-muted: #5c88b0;
  --r8-orange: #f08d23;
  --r8-orange-hover: #d97a1a;
  --r8-cyan: #00bcd4;
  --r8-gray: #9e9e9e;
  --bg: #f0f2f5;
  --fg: #333333;
  --muted: #9e9e9e;
  --border: #d0d5dd;
  --card: #ffffff;
  --accent: #366492;
  --accent-muted: #5c88b0;
  --forensics-bg: #e8eef4;
  --focus: #f08d23;
  accent-color: var(--r8-steel);
}

@media (prefers-color-scheme: dark) {
  :root {
    --r8-steel: #93c5fd;
    --r8-steel-muted: #7dd3fc;
    --r8-orange: #f5a84d;
    --r8-orange-hover: #ffb86b;
    --bg: #1e293b;
    --fg: #f8fafc;
    --muted: #94a3b8;
    --border: #334155;
    --card: #0f172a;
    --accent: #5b9bd4;
    --accent-muted: #7eb3e0;
    --forensics-bg: #1e293b;
    --focus: #f5a84d;
    accent-color: var(--r8-steel);
  }
}

::selection {
  background: rgba(54, 100, 146, 0.35);
  color: var(--fg);
}

@media (prefers-color-scheme: dark) {
  ::selection {
    background: rgba(147, 197, 253, 0.35);
    color: var(--fg);
  }
}

a:any-link {
  color: var(--accent);
}

a:visited {
  color: var(--r8-steel-muted);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Serif 4", "Georgia", "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  min-height: 100vh;
}

.app-header,
.app-main,
.app-footer {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.app-header {
  border-bottom: 1px solid var(--border);
  padding-top: 1.5rem;
}

.app-header-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 0.5rem;
}

.pre-approved-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  padding: 0.35rem 0.5rem 0.35rem 0.45rem;
  max-width: fit-content;
  border-radius: 6px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--r8-orange);
  background: linear-gradient(
    90deg,
    rgba(240, 141, 35, 0.12) 0%,
    var(--forensics-bg) 48%
  );
}

.pre-approved-badge-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  max-height: 28px;
}

.pre-approved-badge-text {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--r8-steel);
  line-height: 1.3;
}

.brand-mark-icon {
  flex-shrink: 0;
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 3px solid var(--r8-orange);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.4) inset,
    0 2px 8px rgba(240, 141, 35, 0.35),
    0 4px 14px rgba(15, 23, 42, 0.12);
  object-fit: cover;
}

.app-header-brand-text {
  flex: 1;
  min-width: 0;
}

.brand-wordmark {
  margin: 0 0 0.35rem;
  font-family: system-ui, "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 1.65rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.brand-rhetor {
  color: var(--r8-steel);
}

.brand-eight {
  color: var(--r8-orange);
}

.app-header h1 {
  margin: 0;
  padding: 0;
  border: none;
  font: inherit;
}

.app-header-brand-text .product-tagline {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  font-family: system-ui, sans-serif;
  color: var(--fg);
  line-height: 1.35;
}

.app-header > .tagline {
  margin: 0;
  padding-top: 0.15rem;
  font-size: 0.95rem;
  color: var(--muted);
  font-family: system-ui, sans-serif;
}

.app-main {
  padding-bottom: 3rem;
}

.query-form label {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.query-form textarea {
  width: 100%;
  min-height: 5rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  resize: vertical;
}

.query-form textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

button,
.query-form button[type="submit"] {
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent-muted);
  color: var(--accent);
}

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

button.primary {
  background: var(--r8-orange);
  color: #fff;
  border-color: var(--r8-orange-hover);
}

button.primary:hover {
  background: var(--r8-orange-hover);
  border-color: var(--r8-orange-hover);
  filter: none;
  color: #fff;
}

button.ghost {
  background: transparent;
}

.htmx-indicator {
  display: none;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
}

.htmx-request .htmx-indicator {
  display: inline;
}

#results {
  margin-top: 2rem;
}

.query-echo {
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--forensics-bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.query-echo strong {
  color: var(--fg);
}

.pipeline-note {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 1.25rem;
  padding: 0.65rem 0.85rem;
  border-left: 4px solid var(--r8-orange);
  background: var(--forensics-bg);
  border-radius: 0 6px 6px 0;
}

.pipeline-note strong {
  color: var(--fg);
}

.pipeline-note code {
  font-size: 0.88em;
  padding: 0.1em 0.25em;
  border-radius: 3px;
  background: var(--card);
  border: 1px solid var(--border);
}

.verbatim-label {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--r8-orange);
  margin: 0 0 0.35rem;
}

.verbatim-block {
  margin-bottom: 0.5rem;
}

.verbatim-block blockquote {
  margin-top: 0;
}

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

.receipt-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

article.receipt {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  background: var(--card);
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

.receipt-synthesis-scope {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.receipt-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.65rem 0.75rem;
  padding-right: 2.85rem;
  min-width: 0;
}

.receipt-head-row .receipt-head-main {
  flex: 1 1 12rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.receipt-head-row .synthesis-include {
  flex: 0 1 auto;
  align-self: center;
  max-width: 100%;
}

details.receipt.receipt-drawer {
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
  max-width: 100%;
}

details.receipt.receipt-drawer > summary.receipt-summary {
  position: absolute;
  top: 1rem;
  right: 1.15rem;
  z-index: 2;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--forensics-bg);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

details.receipt.receipt-drawer > summary.receipt-summary::-webkit-details-marker {
  display: none;
}

details.receipt.receipt-drawer > summary.receipt-summary:hover {
  border-color: var(--r8-orange);
  box-shadow: 0 2px 8px rgba(240, 141, 35, 0.25);
}

details.receipt.receipt-drawer > summary.receipt-summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.receipt-expand-icon {
  font-size: 1.2rem;
  line-height: 1;
  opacity: 0.88;
  user-select: none;
}

details.receipt.receipt-drawer[open] > summary.receipt-summary {
  border-color: var(--r8-orange);
  background: rgba(240, 141, 35, 0.12);
}

@media (prefers-color-scheme: dark) {
  details.receipt.receipt-drawer[open] > summary.receipt-summary {
    background: rgba(245, 168, 77, 0.18);
  }

  .brand-mark-icon {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.08) inset,
      0 2px 10px rgba(245, 168, 77, 0.35),
      0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

details.receipt.receipt-drawer > .receipt-panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin-top: 0.85rem;
  padding: 1.15rem 1.2rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.receipt-panel-section {
  margin: 0;
}

.receipt-panel-heading {
  margin: 0 0 0.65rem;
  padding: 0;
  border: none;
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.receipt-pdf-line {
  margin: 0 0 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.65rem;
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--fg);
}

.receipt-pdf-label {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.82rem;
}

.receipt-pdf-name {
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: var(--forensics-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  word-break: break-all;
}

.receipt-panel .forensics {
  font-size: 0.8125rem;
  line-height: 1.55;
  padding: 0.85rem 1rem;
  margin-bottom: 0;
  border-radius: 6px;
}

.receipt-panel .forensics dl {
  display: block;
  margin: 0;
}

.receipt-panel .forensics dt {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.65rem 0 0.2rem;
  padding: 0;
  line-height: 1.35;
}

.receipt-panel .forensics dt:first-child {
  margin-top: 0;
}

.receipt-panel .forensics dd {
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0 0 0.35rem;
  padding: 0.35rem 0.5rem;
  background: rgba(54, 100, 146, 0.06);
  border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--fg);
}

@media (prefers-color-scheme: dark) {
  .receipt-panel .forensics dd {
    background: rgba(91, 155, 212, 0.08);
  }
}

.pre-approved-inline {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  max-height: 28px;
}

.receipt-head-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.receipt-head-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.receipt-excerpt {
  margin-top: 0.15rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.receipt-links {
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  border-left: 4px solid var(--r8-orange);
  min-width: 0;
  background: linear-gradient(
    90deg,
    rgba(240, 141, 35, 0.1) 0%,
    var(--card) 55%
  );
}

.receipt-links .receipt-pdf-line {
  margin-bottom: 0.65rem;
}

.receipt-links-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.receipt-links-list li {
  margin: 0;
}

.receipt-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  padding: 0.35rem 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--accent);
}

.receipt-link:visited {
  color: var(--r8-steel-muted);
}

.receipt-link:hover {
  color: var(--accent-muted);
}

.receipt-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

.receipt-link-retail,
.receipt-link-download {
  color: var(--r8-orange);
  font-weight: 700;
}

.receipt-link-retail:hover,
.receipt-link-download:hover {
  color: var(--r8-orange-hover);
}

.receipt-link-retail:visited,
.receipt-link-download:visited {
  color: var(--r8-orange-hover);
}

.source-work {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--forensics-bg);
}

.source-work-label {
  margin: 0 0 0.35rem;
  font-family: system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.source-work-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.4rem;
  line-height: 1.3;
}

.source-work-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.receipt-synthesis-scope {
  transition: opacity 0.2s ease;
}

article.receipt:has(.synthesis-include input:not(:checked)) .receipt-synthesis-scope {
  opacity: 0.52;
}

.receipt blockquote {
  margin: 0 0 1rem;
  padding: 0.65rem 0 0 1rem;
  border-left: 4px solid var(--r8-orange);
  font-style: italic;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.85rem;
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
}

.links a:any-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.links a:visited {
  color: var(--r8-steel-muted);
}

.links a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.forensics {
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  padding: 0.65rem 0.75rem;
  background: var(--forensics-bg);
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  overflow-x: auto;
}

.forensics dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 1rem;
}

.forensics dt {
  color: var(--muted);
  font-weight: 600;
}

.forensics dd {
  margin: 0;
  word-break: break-all;
}

.receipt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}

.receipt-toolbar button {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.synthesis-include {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.synthesis-include input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--r8-steel);
}

.context-snippet {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0.5rem 0;
  padding: 0.5rem 0.65rem;
  background: var(--forensics-bg);
  border-radius: 4px;
  font-style: normal;
}

.synthesis-actions {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.synthesis-actions h3 {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.65rem;
}

#synthesis-panel {
  margin-top: 1rem;
}

.synthesis-output {
  padding: 1rem 1.1rem;
  border: 1px dashed var(--accent-muted);
  border-radius: 8px;
  background: var(--card);
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
}

.synthesis-output .warning {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.follow-up {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.follow-up h3 {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.65rem;
}

.follow-up textarea {
  width: 100%;
  min-height: 4rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  resize: vertical;
}

.follow-up textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.follow-up .query-actions {
  margin-top: 0.5rem;
}

.app-footer {
  border-top: 1px solid var(--border);
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
}
