/* =========================================================================
   UAP Historical Record — stylesheet
   Aesthetic: editorial archive. Aged paper, warm ink, classified-stamp red.
   ========================================================================= */

:root {
  /* Palette */
  --paper:        #ebe4d2;
  --paper-soft:   #f1ebda;
  --paper-deep:   #ddd2b4;
  --ink:          #1a1614;
  --ink-soft:     #3d362e;
  --ink-mute:     #6b6051;
  --rule:         #b8a984;
  --rule-soft:    #cdc09e;

  --c-classified: #8c2418;   /* primary accent — classified stamp red */
  --c-archive:    #2c4a5e;   /* secondary accent — archival blue */
  --c-foia:       #c79114;   /* highlight — FOIA marker yellow */
  --c-redact:     #1a1614;

  /* Category swatches — desaturated, archival */
  --c-sighting:    #6b4730;
  --c-document:    #2c4a5e;
  --c-program:     #4f5c3a;
  --c-report:      #6e5a2a;
  --c-hearing:     #8c2418;
  --c-legislation: #4a3a5e;
  --c-media:       #3a5e58;

  /* Layout */
  --header-h: 64px;
  --footer-h: 36px;
  --rule-h: 56px;
  --minimap-h: 56px;

  /* Type */
  --f-display: "Fraunces", "Spectral", Georgia, serif;
  --f-body:    "Spectral", "Iowan Old Style", Georgia, serif;
  --f-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at top left,  rgba(255,250,235,0.6), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(120,90,60,0.06), transparent 60%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10 0 0 0 0 0.08 0 0 0 0 0.05 0 0 0 0.10 0'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(140,36,24,0.25); }

/* =========================================================================
   MASTHEAD
   ========================================================================= */
#masthead {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 0 22px;
  background: linear-gradient(to bottom, rgba(235,228,210,0.97) 0%, rgba(235,228,210,0.92) 100%);
  backdrop-filter: blur(8px) saturate(1.1);
  -webkit-backdrop-filter: blur(8px) saturate(1.1);
  border-bottom: 1px solid var(--rule);
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px;
  border: 1.5px solid var(--c-classified);
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--c-classified);
  font-size: 18px;
  position: relative;
  transform: rotate(-6deg);
  flex: 0 0 36px;
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: -3px;
  border: 1px solid var(--c-classified);
  border-radius: 50%;
  opacity: 0.4;
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.05;
  letter-spacing: -0.01em;
  font-variation-settings: "SOFT" 0, "WONK" 1;
}
.brand-sub {
  margin: 2px 0 0;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
  text-transform: uppercase;
}

.masthead-tools { display: flex; align-items: center; gap: 10px; }

.search-wrap {
  position: relative;
  display: flex; align-items: center;
}
.search-wrap::before {
  content: "";
  position: absolute;
  left: 12px; top: 50%;
  width: 14px; height: 14px;
  margin-top: -8px;
  border: 1.5px solid var(--ink-mute);
  border-radius: 50%;
  pointer-events: none;
}
.search-wrap::after {
  content: "";
  position: absolute;
  left: 22px; top: 50%;
  width: 6px; height: 1.5px;
  background: var(--ink-mute);
  transform: translateY(4px) rotate(45deg);
  pointer-events: none;
}
#search {
  width: 380px;
  max-width: 50vw;
  padding: 8px 34px 8px 34px;
  border: 1px solid var(--rule);
  background: var(--paper-soft);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 14px;
  border-radius: 2px;
  outline: none;
  transition: border-color 120ms, background 120ms;
}
#search:focus {
  border-color: var(--c-archive);
  background: #fff;
}
.search-count {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
  pointer-events: none;
}

.filter-toggle, .legend-toggle {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 7px 14px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: background 120ms, border-color 120ms;
}
.filter-toggle:hover, .legend-toggle:hover {
  background: var(--paper-soft);
  border-color: var(--ink-soft);
}
.filter-toggle[aria-expanded="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* =========================================================================
   FILTER PANEL
   ========================================================================= */
#filter-panel {
  position: fixed;
  top: var(--header-h);
  right: 18px;
  width: 280px;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-top: none;
  padding: 18px;
  z-index: 95;
  box-shadow: 0 12px 32px rgba(26,22,20,0.12);
}
#filter-panel[hidden] { display: none; }

.filter-group { margin-bottom: 14px; }
.filter-group h3 {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 8px;
  font-weight: 500;
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: transparent;
  border: 1px solid var(--rule);
  padding: 4px 9px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-soft);
  border-radius: 2px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 120ms;
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip .chip-swatch {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--swatch, var(--ink));
}

.filter-actions { padding-top: 6px; border-top: 1px solid var(--rule-soft); }
.text-button {
  background: transparent;
  border: none;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-classified);
  padding: 4px 0;
}
.text-button:hover { text-decoration: underline; }

/* =========================================================================
   STAGE — the timeline surface
   ========================================================================= */
#stage {
  position: fixed;
  top: var(--header-h);
  bottom: var(--footer-h);
  left: 0; right: 0;
  overflow: hidden;
  cursor: grab;
  outline: none;
}
#stage.dragging { cursor: grabbing; }

#rule {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--rule-h);
  pointer-events: none;
  z-index: 5;
  border-bottom: 1px solid var(--rule);
  background:
    linear-gradient(to bottom, rgba(235,228,210,0.92), rgba(235,228,210,0.0));
}
#rule-ticks {
  position: absolute;
  inset: 0;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--ink-mute);
}
.tick {
  position: absolute;
  top: 0;
  bottom: 0;
}
.tick .tick-line {
  position: absolute;
  left: 0; top: calc(var(--rule-h) - 12px);
  width: 1px;
  background: var(--rule);
}
.tick.major .tick-line { background: var(--ink-soft); height: 14px; }
.tick.minor .tick-line { height: 8px; }
.tick.micro .tick-line { height: 4px; opacity: 0.5; }
.tick .tick-label {
  position: absolute;
  left: 4px;
  top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.tick.major .tick-label { color: var(--ink); font-weight: 600; font-size: 11px; }
.tick.minor .tick-label { color: var(--ink-mute); }
.tick.micro .tick-label { display: none; }

#rule-now {
  position: absolute;
  top: 0; bottom: -10000px;
  width: 1px;
  background: linear-gradient(to bottom, var(--c-classified), rgba(140,36,24,0));
  opacity: 0.5;
}
#rule-now::before {
  content: "NOW";
  position: absolute;
  top: 22px; left: 4px;
  font-family: var(--f-mono);
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--c-classified);
  background: var(--paper);
  padding: 1px 4px;
  border: 1px solid var(--c-classified);
  border-radius: 1px;
}

#track {
  position: absolute;
  top: var(--rule-h); left: 0;
  height: calc(100% - var(--rule-h) - var(--minimap-h));
  will-change: transform;
}

#lanes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.lane-divider {
  position: absolute;
  left: 0;
  height: 1px;
  background: var(--rule-soft);
  opacity: 0.4;
}

#events-layer {
  position: absolute;
  inset: 0;
}

#connections {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.connection-line {
  fill: none;
  stroke: var(--c-classified);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity 320ms;
}
.connection-line.active { opacity: 0.55; }

/* Event nodes */
.event {
  position: absolute;
  cursor: pointer;
  user-select: none;
  transform-origin: 0 50%;
  transition: opacity 180ms;
}

.event-stem {
  position: absolute;
  left: 0; top: -100px;
  width: 1px;
  height: 100px;
  background: var(--swatch, var(--ink-mute));
  opacity: 0.4;
}
.event-dot {
  position: absolute;
  left: -5px; top: -5px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--swatch, var(--ink));
  z-index: 3;
  transition: transform 160ms, box-shadow 160ms;
}
.event[data-significance="major"] .event-dot {
  background: var(--swatch, var(--ink));
}
.event-card {
  position: absolute;
  left: 8px;
  top: -2px;
  width: 240px;
  padding: 9px 12px 10px;
  background: var(--paper-soft);
  border-left: 2px solid var(--swatch, var(--ink));
  border-radius: 0 2px 2px 0;
  box-shadow: 1px 1px 0 rgba(26,22,20,0.04), 3px 3px 8px rgba(26,22,20,0.06);
  transition: transform 160ms, box-shadow 160ms, background 160ms;
}
.event-card::before {
  /* paper edge */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255,250,235,0.4), rgba(0,0,0,0));
  border-radius: inherit;
}

.event:hover .event-dot {
  transform: scale(1.4);
  box-shadow: 0 0 0 3px rgba(140,36,24,0.15);
}
.event:hover .event-card {
  transform: translateY(-1px);
  box-shadow: 1px 1px 0 rgba(26,22,20,0.06), 4px 6px 14px rgba(26,22,20,0.12);
  background: #fff;
}

.event-date {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--swatch, var(--ink-mute));
  font-weight: 500;
  text-transform: uppercase;
  margin-bottom: 3px;
  display: flex; align-items: center; gap: 6px;
}
.event-cat {
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  padding: 1px 4px;
  border: 1px solid var(--rule);
  border-radius: 1px;
}
.event-title {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  color: var(--ink);
  margin: 0 0 4px;
  letter-spacing: -0.005em;
  font-variation-settings: "SOFT" 100;
}
.event-summary {
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-soft);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.event.search-match .event-dot {
  box-shadow: 0 0 0 4px rgba(199,145,20,0.4);
  animation: pulse 1.6s ease-in-out infinite;
}
.event.search-match .event-card {
  background: #fff8e0;
  border-left-color: var(--c-foia);
}
.event.search-dim {
  opacity: 0.15;
}
.event.related-highlight .event-dot {
  box-shadow: 0 0 0 4px rgba(140,36,24,0.3);
}
.event.related-highlight .event-card {
  background: #fff;
}
.event.is-active .event-dot {
  background: var(--swatch);
  transform: scale(1.6);
  box-shadow: 0 0 0 4px rgba(140,36,24,0.25);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(199,145,20,0.4); }
  50%      { box-shadow: 0 0 0 7px rgba(199,145,20,0.08); }
}

/* Compact mode for zoomed-out events */
.event.compact .event-card { display: none; }
.event.compact .event-dot { width: 7px; height: 7px; left: -3.5px; top: -3.5px; }

/* =========================================================================
   MINIMAP
   ========================================================================= */
#minimap {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--minimap-h);
  background: linear-gradient(to top, rgba(235,228,210,0.97), rgba(235,228,210,0.5));
  border-top: 1px solid var(--rule);
  padding: 14px 22px 8px;
  z-index: 4;
}
#minimap-track {
  position: relative;
  height: 100%;
  width: 100%;
  cursor: pointer;
  border-bottom: 1px solid var(--ink-mute);
}
.minimap-dot {
  position: absolute;
  bottom: 0;
  width: 1.5px;
  background: var(--swatch, var(--ink-mute));
  opacity: 0.7;
  transform: translateX(-50%);
}
.minimap-dot[data-significance="major"] { height: 14px; opacity: 0.9; width: 2px; }
.minimap-dot[data-significance="notable"] { height: 9px; }
.minimap-dot[data-significance="contextual"] { height: 5px; opacity: 0.4; }

#minimap-window {
  position: absolute;
  top: 14px;
  bottom: 8px;
  background: rgba(140,36,24,0.10);
  border-left: 1px solid var(--c-classified);
  border-right: 1px solid var(--c-classified);
  pointer-events: none;
}

#zoom-indicator {
  position: absolute;
  top: calc(var(--rule-h) + 12px);
  right: 18px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  padding: 4px 9px;
  border-radius: 2px;
  z-index: 6;
  pointer-events: none;
}

#empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--ink-mute);
  font-family: var(--f-display);
}
#empty-state p { font-size: 18px; margin: 0 0 12px; }

/* =========================================================================
   DETAIL PANEL
   ========================================================================= */
#detail {
  position: fixed;
  top: var(--header-h);
  bottom: var(--footer-h);
  right: 0;
  width: 460px;
  max-width: 92vw;
  background: var(--paper-soft);
  border-left: 1px solid var(--rule);
  box-shadow: -16px 0 32px rgba(26,22,20,0.12);
  z-index: 80;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(0.4, 0, 0.2, 1);
}
#detail[aria-hidden="false"] { transform: translateX(0); }

#detail-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 32px; height: 32px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 20px;
  font-family: var(--f-body);
  color: var(--ink-soft);
  display: grid; place-items: center;
  z-index: 2;
  line-height: 1;
}
#detail-close:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

#detail-body { padding: 24px 30px 60px; }

.detail-stamp {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--c-classified);
  border: 1.5px solid var(--c-classified);
  padding: 3px 9px;
  text-transform: uppercase;
  transform: rotate(-2deg);
  margin-bottom: 14px;
  opacity: 0.85;
}
.detail-date {
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  margin-bottom: 4px;
}
.detail-title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.15;
  color: var(--ink);
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  font-variation-settings: "SOFT" 50, "WONK" 1;
}
.detail-summary {
  font-family: var(--f-display);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 18px;
  padding-left: 12px;
  border-left: 2px solid var(--swatch, var(--rule));
}
.detail-section {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--rule-soft);
}
.detail-section h3 {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 10px;
  font-weight: 500;
}
.detail-description {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink);
}
.detail-description p { margin: 0 0 12px; }

.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-list li {
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--paper);
  border-left: 2px solid var(--c-archive);
  border-radius: 0 2px 2px 0;
  font-size: 13px;
  line-height: 1.4;
}
.doc-list li.has-link { cursor: pointer; }
.doc-list li.has-link:hover { background: #fff; }
.doc-title { font-weight: 500; color: var(--ink); }
.doc-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 4px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--ink-mute);
  text-transform: uppercase;
}
.doc-meta a {
  color: var(--c-classified);
  text-decoration: none;
}
.doc-meta a:hover { text-decoration: underline; }

.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: var(--paper);
  padding: 2px 7px;
  border: 1px solid var(--rule-soft);
  border-radius: 1px;
}

.entity-list {
  display: flex; flex-wrap: wrap; gap: 5px;
  font-size: 12.5px;
}
.entity {
  background: var(--paper);
  padding: 3px 8px;
  border-radius: 2px;
  color: var(--ink-soft);
}

.related-list { list-style: none; padding: 0; margin: 0; }
.related-list li {
  padding: 9px 12px;
  margin-bottom: 4px;
  background: var(--paper);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-left: 2px solid transparent;
  transition: all 120ms;
}
.related-list li:hover {
  background: #fff;
  border-left-color: var(--c-classified);
}
.related-date {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--ink-mute);
  flex: 0 0 auto;
  width: 70px;
}
.related-title { color: var(--ink); }

/* =========================================================================
   ABOUT DIALOG
   ========================================================================= */
#about-dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 100vw;
  max-height: 100vh;
}
#about-dialog::backdrop {
  background: rgba(26,22,20,0.65);
  backdrop-filter: blur(4px);
}
#about-dialog article {
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  padding: 36px 44px 32px;
  max-width: 580px;
  font-family: var(--f-display);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  border-radius: 2px;
  box-shadow: 0 24px 60px rgba(26,22,20,0.4);
}
#about-dialog h2 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 26px;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
  font-variation-settings: "SOFT" 50;
}
#about-dialog h3 {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 22px 0 10px;
  font-weight: 500;
}
#about-dialog ul { margin: 0 0 6px; padding-left: 20px; font-size: 14px; }
#about-dialog code {
  font-family: var(--f-mono);
  font-size: 12.5px;
  background: var(--paper);
  padding: 1px 5px;
  border-radius: 2px;
}
#about-dialog kbd {
  font-family: var(--f-mono);
  font-size: 11px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1px 5px;
  box-shadow: 0 1px 0 var(--rule);
}
#about-categories {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 14px;
  font-size: 13px;
}
.about-cat {
  display: flex; align-items: center; gap: 8px;
}
.about-cat .swatch {
  width: 10px; height: 10px;
  background: var(--swatch);
  border-radius: 50%;
}
#about-close-btn { margin-top: 18px; }

/* =========================================================================
   FOOTER
   ========================================================================= */
#site-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(235,228,210,0.95);
  border-top: 1px solid var(--rule);
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
  z-index: 50;
  backdrop-filter: blur(4px);
}
#site-footer code {
  background: var(--paper);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--ink-soft);
}
.footer-label { color: var(--ink-soft); }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 760px) {
  :root { --header-h: 100px; }
  #masthead {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 14px;
    gap: 8px;
  }
  .masthead-tools { width: 100%; }
  #search { flex: 1; max-width: none; width: 100%; }
  #detail { width: 100vw; max-width: 100vw; }
  #filter-panel { right: 0; left: 0; width: auto; }
  .event-card { width: 180px; }
}
