@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@500;700&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-alt: #f0f3f6;
  --ink: #18202a;
  --muted: #5a6776;
  --accent: #1d4ed8;
  --accent-ink: #0f2a5f;
  --border: #d4dbe4;
  --shadow: 0 12px 30px rgba(18, 33, 54, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fdfdfb 0%, #f6f4f0 40%, #eef1f5 100%);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid rgba(29, 78, 216, 0.35);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--accent);
  color: white;
  padding: 8px 12px;
  border-radius: 999px;
  z-index: 50;
}

.skip-link:focus {
  left: 16px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-link {
  font-family: 'Fraunces', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
}

.badge {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.nav a {
  margin-left: 16px;
  font-weight: 600;
  color: var(--accent-ink);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 24px;
  padding: 28px 0 12px;
}

.hero-text h1 {
  font-family: 'Fraunces', serif;
  font-size: clamp(2.4rem, 2.6vw, 3.2rem);
  margin: 6px 0 12px;
}

.hero-text p {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 520px;
}

.hero-panel {
  display: grid;
  gap: 12px;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.hero-card h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.hero-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}

.search-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin: 16px 0 12px;
  box-shadow: var(--shadow);
}

.search-input {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.search-input input {
  flex: 1;
  min-width: 220px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: #fff;
}

.search-mode {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.95rem;
  color: var(--ink);
}

.search-meta {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.meta-left {
  display: flex;
  gap: 12px;
  align-items: center;
}

.muted {
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
}

.button.outline {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.search-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
  padding-bottom: 48px;
}

.filters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  position: sticky;
  top: 88px;
  box-shadow: var(--shadow);
}

.filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.filters-fields label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
  color: var(--muted);
}

.filters-fields select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.filters-fields select[multiple] {
  min-height: 120px;
  padding: 6px;
}

.filters-fields select[multiple] option {
  padding: 6px 8px;
  border-radius: 4px;
  margin: 2px 0;
}

.filters-fields select[multiple] option:checked {
  background: var(--accent);
  color: white;
}

.filter-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.filter-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 12px 0;
}

.date-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 0.95rem;
}

.slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.filter-open {
  display: none;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.result-card h3 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.result-meta {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.tag {
  background: var(--surface-alt);
  color: var(--accent-ink);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.result-snippet {
  margin: 8px 0 0;
  color: var(--muted);
}

.result-snippet mark {
  background: rgba(29, 78, 216, 0.15);
  color: var(--accent-ink);
  padding: 0 2px;
}

.state-banner {
  background: var(--surface);
  border: 1px dashed var(--border);
  padding: 14px 16px;
  border-radius: 12px;
  margin: 12px 0;
  color: var(--muted);
}

.state-banner.empty {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #7c2d12;
}

.detail {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--shadow);
}

.detail-header h1 {
  font-family: 'Fraunces', serif;
  font-size: 2rem;
  margin: 8px 0 12px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.viewer-frame-wrap {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.viewer-frame {
  width: 100%;
  height: min(80vh, 900px);
  border: 0;
  background: white;
}

.viewer-note {
  color: var(--muted);
  margin-top: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.85rem;
}

.prose {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-footer {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 16px 0 24px;
  font-size: 0.85rem;
  color: var(--muted);
}

.filters-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 32, 42, 0.4);
  z-index: 30;
}

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

/* Phase 3: Mobile drawer swipe-up from bottom */
@media (max-width: 960px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .search-layout {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80vh;
    max-height: 600px;
    width: 100%;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40;
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
    box-shadow: 0 -8px 32px rgba(18, 33, 54, 0.2);
    touch-action: pan-y;
  }

  .filters-panel.open {
    transform: translateY(0);
  }

  /* Drawer handle for swipe gesture */
  .filters-panel::before {
    content: '';
    position: sticky;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    display: block;
    width: 48px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 8px;
    z-index: 1;
  }

  .filter-open {
    display: inline-flex;
  }

  /* Phase 3: Sticky search toolbar on mobile */
  .search-toolbar {
    position: sticky;
    top: 73px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
  }
}

/* PDF Viewer Styles */
.pdf-viewer-wrap {
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.pdf-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 600px;
  background: var(--gray-50);
  border-radius: var(--radius);
  overflow: auto;
  padding: 2rem;
}

.pdf-container canvas {
  max-width: 100%;
  height: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.pdf-container .loading,
.pdf-container .error {
  text-align: center;
  color: var(--gray-600);
  padding: 2rem;
}

.pdf-container .error {
  color: var(--red-600);
}

.page-navigation {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0;
  justify-content: center;
}

.page-info {
  font-size: 0.9rem;
  color: var(--gray-700);
  min-width: 120px;
  text-align: center;
}

.page-navigation button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Phase 3: Mobile PDF Viewer Responsiveness */
@media (max-width: 768px) {
  .pdf-container {
    padding: 0.5rem;
    min-height: 400px;
    max-height: 60vh;
  }

  .pdf-container canvas {
    /* Lower resolution for mobile performance - handled in JS */
    image-rendering: auto;
  }

  .page-navigation {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.5rem;
  }

  .page-navigation button {
    flex: 1;
    min-width: 100px;
    min-height: 48px;
    font-size: 1rem;
  }

  .page-info {
    width: 100%;
    order: -1;
    margin-bottom: 0.5rem;
    font-size: 1rem;
  }

  /* Phase 3: PDF viewer frame adjustments */
  .viewer-frame {
    height: min(70vh, 600px);
  }

  .viewer-frame-wrap {
    border-radius: 12px;
  }
}

/* Phase 3: iPhone SE PDF viewer */
@media (max-width: 480px) {
  .pdf-container {
    padding: 0.25rem;
    min-height: 350px;
    max-height: 50vh;
  }

  .viewer-frame {
    height: min(65vh, 500px);
  }
}

/* Phase 3: Enhanced Mobile/iOS Optimizations - iPad breakpoint (768px) */
@media (max-width: 768px) {
  /* Phase 3: Touch-friendly tap targets (min 48x48px for accessibility) */
  .button,
  button,
  a.button,
  select,
  input[type="button"],
  input[type="submit"] {
    min-height: 48px;
    min-width: 48px;
    padding: 12px 16px;
  }

  /* Phase 3: Larger touch targets for result actions */
  .result-actions .button {
    min-height: 48px;
    font-size: 1rem;
  }

  /* Prevent text size adjustment on iOS */
  html {
    -webkit-text-size-adjust: 100%;
  }

  /* Smooth scrolling on iOS */
  body {
    -webkit-overflow-scrolling: touch;
  }

  /* Hero section mobile layout */
  .hero {
    flex-direction: column;
    padding: 1.5rem 1rem;
  }

  .hero-text h1 {
    font-size: 1.75rem;
  }

  .hero-panel {
    flex-direction: column;
    gap: 1rem;
  }

  /* Search toolbar mobile - enhanced padding for touch */
  .search-toolbar {
    padding: 1rem;
    border-radius: 12px;
  }

  .search-input {
    flex-direction: column;
    gap: 0.75rem;
  }

  #searchInput {
    width: 100%;
    font-size: 16px; /* Prevent iOS zoom on focus */
    min-height: 48px;
  }

  .search-mode {
    width: 100%;
    font-size: 16px;
    min-height: 48px;
  }

  /* Phase 3: Result cards - better touch targets */
  .result-card {
    padding: 1.25rem;
    border-radius: 12px;
  }

  .result-card h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
  }

  .result-title {
    font-size: 1rem;
  }

  .detail-actions {
    flex-direction: column;
    gap: 0.75rem;
  }

  .detail-actions .button {
    width: 100%;
    justify-content: center;
    min-height: 48px;
  }

  /* Filters mobile drawer */
  .filters-fields label {
    font-size: 0.9rem;
    margin: 14px 0 8px;
  }

  .filters-fields select {
    font-size: 16px; /* Prevent iOS zoom */
    min-height: 48px;
  }

  .filters-fields input[type="date"] {
    font-size: 16px;
    min-height: 48px;
  }

  /* Results meta mobile */
  .result-meta {
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.85rem;
  }

  .meta-left,
  .meta-right {
    width: 100%;
    justify-content: flex-start;
  }

  /* Phase 3: Filter buttons larger for touch */
  .filter-open,
  #closeFilters,
  #clearFilters {
    min-height: 48px;
    min-width: 48px;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Fix iOS Safari bottom bar overlap */
  .search-toolbar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Fix for iOS input shadows */
  input,
  select,
  textarea {
    -webkit-appearance: none;
    border-radius: 8px;
  }

  /* Prevent iOS button styling */
  button,
  .button {
    -webkit-appearance: none;
  }
}

/* Document metadata display */
.doc-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: var(--gray-100);
  border-radius: 4px;
  color: var(--gray-700);
}

.meta-badge.type-text {
  background: var(--blue-50);
  color: var(--blue-700);
}

.meta-badge.type-image {
  background: var(--purple-50);
  color: var(--purple-700);
}

.meta-badge.type-hybrid {
  background: var(--orange-50);
  color: var(--orange-700);
}

.meta-badge.quality-high {
  background: var(--green-50);
  color: var(--green-700);
}

.meta-badge.quality-medium {
  background: var(--yellow-50);
  color: var(--yellow-700);
}

.meta-badge.quality-low {
  background: var(--red-50);
  color: var(--red-700);
}

.file-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.file-number {
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  background: var(--gray-100);
  border-radius: 3px;
  color: var(--gray-700);
}

/* Phase 3: iPhone SE and small screens (375px breakpoint) */
@media (max-width: 480px) {
  .container {
    padding: 0 16px;
  }

  .hero-text h1 {
    font-size: 1.5rem;
    line-height: 1.2;
  }

  .hero-text p {
    font-size: 0.9rem;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .result-card {
    padding: 1rem;
    border-radius: 10px;
  }

  .doc-metadata {
    font-size: 0.75rem;
  }

  .meta-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }

  /* Phase 3: Smaller text for compact mobile display */
  .result-meta {
    font-size: 0.8rem;
  }

  .result-snippet {
    font-size: 0.85rem;
  }

  /* Phase 3: Adjust hero cards for small screens */
  .hero-card {
    padding: 12px;
    border-radius: 12px;
  }

  .hero-card h2 {
    font-size: 0.95rem;
  }

  .hero-card p {
    font-size: 0.85rem;
  }

  /* Phase 3: Navigation adjustments */
  .nav a {
    margin-left: 10px;
    font-size: 0.9rem;
  }

  /* Phase 3: Search toolbar compact */
  .search-toolbar {
    padding: 0.875rem;
  }

  .search-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* Stats Page */
.stats-hero {
  text-align: center;
  padding: 2rem 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 2rem;
}

.stats-hero h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.stats-hero .subtitle {
  color: var(--text-muted);
  font-size: 1.125rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.stat-card {
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1.5rem;
}

.stat-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

.stat-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.stat-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

.stat-list li:last-child {
  border-bottom: none;
}

.stat-list strong {
  color: var(--text-primary);
}

.stats-detail {
  margin-bottom: 3rem;
}

.stats-detail h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
}

.stats-table th {
  background: var(--accent);
  color: white;
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
}

.stats-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr:hover {
  background: var(--bg-hover);
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-table {
    font-size: 0.875rem;
  }

  .stats-table th,
  .stats-table td {
    padding: 0.5rem;
  }
}

/* PDF Fallback */
.pdf-fallback {
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-alt);
  border-radius: 8px;
  max-width: 500px;
  margin: 2rem auto;
}

.pdf-fallback p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.pdf-fallback .hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 1.5rem;
}

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover, #3a5bc7);
}

/* Phase 1: Person Names, Locations, Case Numbers */
.person-names,
.locations,
.case-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.person-name,
.location,
.case-number {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--bg-alt);
  border-radius: 4px;
  font-size: 0.875rem;
  color: var(--text);
}

.person-name {
  border-left: 3px solid #4a90e2;
}

.clickable-person {
  cursor: pointer;
  transition: all 0.2s;
}

.clickable-person:hover {
  background: #4a90e2;
  color: white;
  transform: translateY(-1px);
}

.person-profile-link {
  margin-left: 0.25rem;
  color: #4a90e2;
  text-decoration: none;
  font-weight: bold;
  font-size: 1.1em;
}

.clickable-person:hover .person-profile-link {
  color: white;
}

.person-profile-link:hover {
  text-decoration: underline;
}

.location {
  border-left: 3px solid #e24a4a;
}

.case-number {
  border-left: 3px solid #9b59b6;
}

/* Phase 1: OCR Confidence Badges */
.meta-badge.ocr-high {
  background: #27ae60;
  color: white;
}

.meta-badge.ocr-medium {
  background: #f39c12;
  color: white;
}

.meta-badge.ocr-low {
  background: #e74c3c;
  color: white;
}

/* Phase 2: Related Documents */
.related-docs {
  margin: 0.75rem 0;
  padding: 0.75rem;
  background: var(--bg-alt);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  font-size: 0.9rem;
}

.related-docs strong {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 0.5rem;
}

.related-link {
  color: var(--accent);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.2s;
}

.related-link:hover {
  color: var(--accent-ink);
  text-decoration: underline;
}

/* Phase 2: Search suggestions enhancement */
#searchSuggestions {
  font-family: 'Manrope', sans-serif;
}
