/* ==========================================================================
   Legal Evidence Portal — Styles
   Extends brand.css / layout.css / components.css
   ========================================================================== */

/* ---------- Layout ---------- */

.legal-page { padding-bottom: var(--space-4xl); }

.legal-hero {
  padding: var(--space-3xl) 0 var(--space-2xl);
  border-bottom: 1px solid var(--border);
}

.legal-hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

.legal-hero .subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  line-height: 1.8;
  max-width: 680px;
}

.legal-section {
  padding: var(--space-2xl) 0;
}

.legal-section + .legal-section {
  border-top: 1px solid var(--border);
}

.legal-section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin-bottom: var(--space-lg);
  color: var(--text-primary);
}

/* ---------- Breadcrumbs ---------- */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  font-family: var(--font-body);
}

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

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb .sep { color: var(--text-secondary); opacity: 0.5; }

/* ---------- Open Justice Banner ---------- */

.open-justice-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-warm);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
  line-height: 1.6;
}

.open-justice-banner a {
  color: var(--accent-link);
  text-decoration: none;
}

.open-justice-banner a:hover { text-decoration: underline; }

/* ---------- Stats Row ---------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-2xl);
}

.stat-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md);
  text-align: center;
}

.stat-block .stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  margin-bottom: 0.25rem;
}

.stat-block .stat-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Case Cards ---------- */

.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-md);
}

.case-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: block;
}

.case-card:hover {
  border-color: var(--accent-warm);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.case-card .case-ref {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.case-card .case-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.case-card .case-meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.case-card .case-quantum {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- Status Badges ---------- */

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15em 0.5em;
  border-radius: 3px;
  line-height: 1.4;
}

.badge-void {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
}

.badge-voidable {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #eab308;
}

.badge-stayed {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.badge-pending {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.badge-concluded {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #d1d5db;
}

.badge-locked {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.badge-verified {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.badge-mhcm {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.badge-category {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ---------- Ground Cards ---------- */

.ground-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.ground-card .ground-id {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--accent-warm);
  font-weight: 600;
}

.ground-card .ground-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin: 0.25rem 0 0.5rem;
}

.ground-card .ground-desc {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: var(--space-md);
}

.ground-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- Evidence Detail ---------- */

.evidence-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.nexis-code {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--accent-warm);
  background: var(--bg-surface);
  padding: 0.2em 0.5em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.evidence-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  font-size: var(--text-sm);
  margin-bottom: var(--space-lg);
}

.evidence-meta dt {
  color: var(--text-secondary);
  font-weight: 500;
}

.evidence-meta dd {
  color: var(--text-primary);
  margin: 0;
}

.annotation-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-link);
  border-radius: var(--radius);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
}

.annotation-box .annotation-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-link);
  margin-bottom: 0.5rem;
}

/* ---------- Order Row ---------- */

.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.order-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-sm) var(--space-sm);
  border-bottom: 2px solid var(--border);
}

.order-table td {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.order-table tr.order-void td { background: #fffbeb; }
.order-table tr.order-voidable td { background: #fefce8; }
.order-table tr.order-institutional td { background: #fff7ed; }

.order-table .order-date {
  font-family: var(--font-mono);
  white-space: nowrap;
}

.mhcm-day {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 3px;
  padding: 0.1em 0.4em;
  white-space: nowrap;
}

/* ---------- Timeline ---------- */

.timeline {
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0.5rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-entry {
  position: relative;
  padding-bottom: var(--space-lg);
}

.timeline-entry::before {
  content: '';
  position: absolute;
  left: calc(-2rem + 0.35rem);
  top: 0.4rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  border: 2px solid var(--bg-primary);
}

.timeline-entry.critical::before {
  background: var(--accent-warm);
  box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.2);
}

.timeline-date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.timeline-event {
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 0.25rem;
}

.timeline-significance {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---------- Authority Links ---------- */

.authority-list {
  list-style: none;
  padding: 0;
}

.authority-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
}

.authority-item a {
  color: var(--accent-link);
  text-decoration: none;
  font-weight: 500;
}

.authority-item a:hover { text-decoration: underline; }

/* ---------- Evidence Matrix ---------- */

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  overflow-x: auto;
}

.matrix-table th {
  padding: 0.4rem;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  min-width: 2rem;
  white-space: nowrap;
}

.matrix-table td {
  padding: 0.4rem;
  text-align: center;
  border: 1px solid var(--border);
}

.matrix-table td.matrix-filled {
  background: var(--accent-warm);
  opacity: 0.8;
}

.matrix-table td.matrix-filled a {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  display: block;
}

.matrix-table .matrix-ground-label {
  text-align: left;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  padding-right: 1rem;
  background: var(--bg-surface);
}

/* ---------- Cross-Reference Links ---------- */

a.xref {
  color: var(--accent-link);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-surface);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: border-color 0.15s;
}

a.xref:hover {
  border-color: var(--accent-link);
  text-decoration: none;
}

/* Links that open in the side panel get a subtle indicator */
a.panel-link::after {
  content: ' \25A8'; /* small square icon */
  font-size: 0.7em;
  opacity: 0.5;
}

/* ---------- SPLIT-SCREEN SIDE PANEL ---------- */

.legal-wrapper {
  display: flex;
  min-height: calc(100vh - var(--nav-height, 64px));
}

.legal-main {
  flex: 1;
  min-width: 0;
  transition: margin-right 0.25s ease;
}

.legal-panel {
  position: fixed;
  top: var(--nav-height, 64px);
  right: 0;
  bottom: 0;
  width: 50vw;
  max-width: 640px;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.08);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.legal-panel.open {
  transform: translateX(0);
}

.legal-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.legal-panel-title {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legal-panel-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3em 0.6em;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  transition: border-color 0.15s;
}

.legal-panel-close:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.legal-panel-nav {
  display: flex;
  gap: 0.5rem;
  padding: var(--space-xs) var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.legal-panel-nav a {
  font-size: var(--text-xs);
  color: var(--accent-link);
  text-decoration: none;
}

.legal-panel-nav a:hover { text-decoration: underline; }

.legal-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.legal-panel-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* When panel is open, shrink main content on wide screens */
@media (min-width: 1200px) {
  .legal-main.panel-active {
    margin-right: min(50vw, 640px);
  }
}

/* Mobile: panel is full-width overlay */
@media (max-width: 768px) {
  .legal-panel {
    width: 100vw;
    max-width: none;
  }
}

/* ---------- Tabs for annotations ---------- */

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.panel-tab {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.panel-tab:hover { color: var(--text-primary); }

.panel-tab.active {
  color: var(--accent-link);
  border-bottom-color: var(--accent-link);
}

/* ---------- Schedule Tables ---------- */

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.schedule-table th,
.schedule-table td {
  padding: var(--space-sm);
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.schedule-table th {
  background: var(--bg-surface);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

/* ---------- Hash Badge ---------- */

.hash-badge {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-surface);
  padding: 0.2em 0.5em;
  border-radius: 3px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}

.hash-badge:hover { border-color: var(--text-secondary); }

/* ---------- Filter Bar (progressive enhancement) ---------- */

.filter-bar {
  display: none; /* shown by JS */
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--space-lg);
  padding: var(--space-sm) 0;
}

.js-enabled .filter-bar { display: flex; }

.filter-btn {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  padding: 0.3em 0.8em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--accent-link); color: var(--text-primary); }

.filter-btn.active {
  background: var(--accent-link);
  color: #fff;
  border-color: var(--accent-link);
}

/* ---------- Search (progressive enhancement) ---------- */

.legal-search-box {
  display: none; /* shown by JS */
  position: relative;
  margin-bottom: var(--space-lg);
}

.js-enabled .legal-search-box { display: block; }

.legal-search-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.legal-search-input:focus { border-color: var(--accent-link); }

.legal-search-input::placeholder { color: var(--text-secondary); opacity: 0.6; }

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

.search-results.visible { display: block; }

.search-result-item {
  display: block;
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.search-result-item:hover { background: var(--bg-surface); }

.search-result-item .result-type {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent-warm);
}

.search-result-item .result-title {
  font-size: var(--text-sm);
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .case-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .evidence-header { flex-direction: column; }
  .legal-hero h1 { font-size: var(--text-2xl); }
  .order-table { font-size: var(--text-xs); }
}

/* ---------- PRINT ---------- */

@media print {
  /* Hide interactive elements */
  .site-nav,
  .site-footer,
  .filter-bar,
  .legal-search-box,
  .legal-panel,
  .legal-panel-close,
  .panel-link::after,
  .open-justice-banner a[href]::after { display: none !important; }

  /* Show print header */
  .print-header { display: block !important; }

  /* Force colours */
  body {
    color: #000 !important;
    background: #fff !important;
  }

  .case-card,
  .ground-card,
  .stat-block,
  .annotation-box {
    border-color: #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  /* Show URLs after links */
  a[href^="http"]::after {
    content: ' (' attr(href) ')';
    font-size: 0.8em;
    color: #666;
    font-family: var(--font-mono);
    word-break: break-all;
  }

  /* Internal links: do not show URL */
  a[href^="/"]::after { content: none; }
  a.xref::after { content: none; }

  /* Page breaks */
  .legal-section { break-before: auto; }
  h1, h2, h3 { break-after: avoid; }

  .print-header {
    text-align: center;
    padding: 1rem 0;
    border-bottom: 2px solid #000;
    margin-bottom: 1rem;
    font-family: var(--font-display);
  }

  .print-header .print-url {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: #666;
  }
}

.print-header { display: none; }

/* ---------- Utility ---------- */

.mono { font-family: var(--font-mono); }
.text-sm { font-size: var(--text-sm); }
.text-secondary { color: var(--text-secondary); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.flex-wrap { display: flex; flex-wrap: wrap; gap: 0.5rem; }
