/* Flint FOIA Search — self-contained stylesheet sharing the design language
   of networklanguagetoolkit.com (same tokens, theme behavior, and voice).
   No external stylesheet dependency. */

/* ----- Theme tokens -------------------------------------------------------
   Light is the base; dark applies via the system preference (unless the
   visitor chose Light) or an explicit data-theme choice. */
:root {
  color-scheme: light dark;
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --text: #26313B;          /* 12.7:1 on --bg */
  --heading: #1B2530;
  --text-muted: #59636E;    /* 5.9:1 on --bg */
  --accent: #2456A6;        /* links 6.8:1 on --bg */
  --accent-contrast: #FFFFFF;
  --accent-bg: #F1F5FB;
  --border: #D5D9DE;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.06);
  --badge-epa: #1d6fb8;
  --status-error-bg: #FDECEC;
  --status-error-text: #8A1F1F;
  --status-warn-bg: #FFF4CC;
  --status-warn-text: #5A4400;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14181D;
    --surface: #1C2229;
    --text: #D5DCE3;
    --heading: #EDF1F5;
    --text-muted: #98A4B0;
    --accent: #8FB8EF;
    --accent-contrast: #14181D;
    --accent-bg: #1A2130;
    --border: #333B45;
    --shadow: none;
    --badge-epa: #6DB3F2;
    --status-error-bg: #3A1D1D;
    --status-error-text: #F3B8B8;
    --status-warn-bg: #3A311A;
    --status-warn-text: #EFD48A;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14181D;
  --surface: #1C2229;
  --text: #D5DCE3;
  --heading: #EDF1F5;
  --text-muted: #98A4B0;
  --accent: #8FB8EF;
  --accent-contrast: #14181D;
  --accent-bg: #1A2130;
  --border: #333B45;
  --shadow: none;
  --badge-epa: #6DB3F2;
  --status-error-bg: #3A1D1D;
  --status-error-text: #F3B8B8;
  --status-warn-bg: #3A311A;
  --status-warn-text: #EFD48A;
}

/* ----- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-size: 1.0625rem;
  line-height: 1.65;
  display: grid;
  grid-template-columns: 1fr min(46rem, 94%) 1fr;
}
body > * { grid-column: 2; }
h1, h2, h3 { color: var(--heading); overflow-wrap: break-word; }
p { overflow-wrap: break-word; }
a { color: var(--accent); }
a:hover { text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----- Skip link ----------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.5rem 1rem;
  z-index: 10;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* ----- Header -------------------------------------------------------------- */
header {
  position: relative;
  grid-column: 1 / -1;
  background: linear-gradient(var(--accent-bg), var(--bg));
  padding: 2.75rem 1rem 1.75rem;
  text-align: center;
}
header h1 {
  font-size: 2rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 0.5rem;
}
header p {
  margin: 0.25rem auto;
  max-width: 38rem;
  color: var(--text-muted);
}
@media (max-width: 720px) {
  /* Clear the absolute-positioned theme toggle (bottom edge ~3.5rem). */
  header { padding: 4.5rem 1rem 1.25rem; }
  header h1 { font-size: 1.6rem; }
  body { font-size: 1rem; }
}

/* ----- Theme toggle (top right, cycles System -> Light -> Dark) ------------ */
.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover { color: var(--heading); border-color: var(--accent); }
.theme-toggle svg { width: 1.15rem; height: 1.15rem; display: none; }
.theme-toggle .icon-system { display: block; }
:root[data-theme="light"] .theme-toggle .icon-system,
:root[data-theme="dark"] .theme-toggle .icon-system { display: none; }
:root[data-theme="light"] .theme-toggle .icon-light { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: block; }

/* ----- About box + search form --------------------------------------------- */
main { padding-block: 0.5rem 3rem; }

main > details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  margin-block: 1rem;
  box-shadow: var(--shadow);
}
main > details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--heading);
  padding: 0.35rem 0.25rem;
}
main > details[open] summary { margin-bottom: 0.25rem; }

form { margin-block: 1.25rem; }
label {
  display: block;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 0.35rem;
}
input[type="search"],
input[type="number"] {
  font-size: inherit;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.5rem 0.75rem;
}
button {
  font-size: inherit;
  font-family: inherit;
  border-radius: 7px;
  cursor: pointer;
}
button[type="submit"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
  font-weight: 600;
  padding: 0.5rem 1.1rem;
}
button[type="submit"]:hover { filter: brightness(1.12); }

.search-bar {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.search-bar input[type="search"] {
  flex: 1;
  min-width: 0;
}

form details {
  margin-block: 0.9rem;
}
form details summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block-start: 0.6rem;
}
.suggestions button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  font-size: 0.9rem;
  margin: 0;
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }

label[for="num-results"] {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 0.9rem;
}
input[type="number"]#num-results { width: 6rem; }

.index-gate {
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-block: 1.25rem;
}
.index-gate h2 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
}
.index-gate p { margin: 0.25rem 0 0.8rem; }
.index-gate button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
  font-weight: 600;
  padding: 0.55rem 1rem;
}
.index-gate button:hover { filter: brightness(1.12); }
.index-gate button:disabled { cursor: wait; opacity: 1; }
.index-gate button.is-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.index-gate button.is-loading::after {
  content: '';
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: index-download-spin 0.8s linear infinite;
}
@keyframes index-download-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .index-gate button.is-loading::after { animation: none; }
}

/* ----- Status line --------------------------------------------------------- */
#status { margin-block: 1rem; }
#status:empty {
  min-height: 1.75rem;
  margin-block: 0.5rem;
}
#status[data-level="info"] { font-style: italic; color: var(--text-muted); }
#status[data-level="error"] {
  background-color: var(--status-error-bg);
  color: var(--status-error-text);
  padding: 0.75rem 1rem;
  border-radius: 7px;
  border: 1px solid var(--status-error-text);
}
#status[data-level="warning"] {
  background-color: var(--status-warn-bg);
  color: var(--status-warn-text);
  padding: 0.75rem 1rem;
  border-radius: 7px;
  border: 1px solid var(--status-warn-text);
}

/* ----- Result cards -------------------------------------------------------- */
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-block: 1.25rem;
  box-shadow: var(--shadow);
}
.result .meta {
  text-align: right;
  font-size: 0.85rem;
  margin: 0.15rem 0;
}
.result .meta b { color: var(--heading); }
.result details {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--accent-bg);
  padding: 0.5rem 0.85rem;
  margin-block: 0.75rem;
}
.result details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--heading);
  font-size: 0.95rem;
}
.result details pre {
  white-space: pre-wrap;
  font-size: 0.9rem;
  font-family: Consolas, Menlo, Monaco, "Ubuntu Mono", monospace;
  color: var(--text);
  max-height: 30rem;
  overflow-y: auto;
  margin-block: 0.5rem 0;
}

/* badges */
.result .source-badge {
  margin: 0 0 0.75rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--accent-bg);
  color: var(--text);
}
.badge-epa {
  border-color: var(--badge-epa);
  color: var(--badge-epa);
}
.badge-dup {
  color: var(--text-muted);
  font-style: italic;
}
.result .permalink {
  margin-left: auto;
  font-size: 0.85rem;
  align-self: center;
}

/* page-image tabs */
.result .image-tabs { margin-block: 1rem 0.5rem; }
.result .tabs-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 0.4rem;
}
.result .image-tabs .tab-buttons {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.result .image-tabs .tab-buttons button {
  font-size: 0.8rem;
  padding: 0.25rem 0.7rem;
  margin: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.result .image-tabs .tab-buttons button:hover { border-color: var(--accent); }
.result .image-tabs .tab-buttons button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}
.result .image-tabs figure {
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  margin: 0;
  background: var(--surface);
}
.result .image-tabs figure img {
  width: 100%;
  display: block;
}

/* Edge navigation over the scan (multi-page threads only) */
.result .image-frame {
  position: relative;
}
.result .edge-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  max-width: 7rem;
  border: none;
  background: transparent;
  color: transparent;
  font-size: 2.5rem;
  display: flex;
  align-items: center;
  padding: 0;
  margin: 0;
  border-radius: 0;
}
.result .edge-prev { left: 0; justify-content: flex-start; }
.result .edge-next { right: 0; justify-content: flex-end; }
.result .edge-nav span {
  padding: 0 0.5rem;
  line-height: 1;
}
.result .edge-nav:hover:not(:disabled),
.result .edge-nav:focus-visible {
  color: var(--accent-contrast);
  background: linear-gradient(to right, rgb(0 0 0 / 0.28), transparent);
  cursor: pointer;
}
.result .edge-next:hover:not(:disabled),
.result .edge-next:focus-visible {
  background: linear-gradient(to left, rgb(0 0 0 / 0.28), transparent);
}
.result .edge-nav:hover:not(:disabled) span,
.result .edge-nav:focus-visible span {
  color: #fff;
  text-shadow: 0 1px 4px rgb(0 0 0 / 0.6);
}
.result .edge-nav:disabled { display: none; }
.result .image-tabs figcaption {
  font-size: 0.8rem;
  text-align: center;
  color: var(--text-muted);
  padding: 0.35rem 0.5rem;
  border-top: 1px solid var(--border);
}
.result .archive-link {
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}
