/* KOS Litigation Intelligence System — Main Styles */
:root, [data-theme="light"] {
  --bg: #f8f6f3;
  --surface: #ffffff;
  --surface-2: #f0ece6;
  --text: #1a2332;
  --text-muted: #5c6778;
  --navy: #0f1a2e;
  --graphite: #2d3748;
  --brass: #b8956a;
  --brass-light: #d4bc96;
  --accent: #1e4d7b;
  --accent-hover: #163a5f;
  --border: rgba(26, 35, 50, 0.12);
  --shadow: 0 4px 24px rgba(15, 26, 46, 0.08);
  --glass: rgba(255, 255, 255, 0.85);
  --success: #2d6a4f;
  --warning: #b8860b;
  --danger: #9b2335;
  --radius: 12px;
  --radius-lg: 20px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

[data-theme="dark"] {
  --bg: #0a1018;
  --surface: #121c2b;
  --surface-2: #1a2738;
  --text: #eef2f7;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.1);
  --glass: rgba(18, 28, 43, 0.9);
}

[data-theme="accessible"] {
  --bg: #ffffff;
  --text: #000000;
  --text-muted: #333333;
  --accent: #000080;
  --border: #000000;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { animation: none !important; transition: none !important; } }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 9999;
  padding: 12px 20px; background: var(--navy); color: #fff;
}
.skip-link:focus { left: 0; }

h1, h2, h3 { font-family: var(--font-display); color: var(--navy); line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 3vw, 2.5rem); margin: 0 0 0.5rem; }
.lead { color: var(--text-muted); font-size: 1.05rem; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--brass); outline-offset: 2px;
}

.page-main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 48px; }

/* Top Navigation */
.top-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; height: 64px;
  background: var(--glass); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}

.nav-left, .nav-right { display: flex; align-items: center; gap: 12px; }
.nav-center { flex: 1; max-width: 480px; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--navy), var(--accent));
  color: var(--brass-light); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 0.75rem; letter-spacing: 0.14em; color: var(--navy); }
.brand-text span { font-size: 0.7rem; color: var(--text-muted); }

.search-trigger {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-muted); cursor: pointer; font-size: 0.9rem;
}
.search-trigger kbd { font-size: 0.75rem; padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px; }

.case-switcher { min-width: 180px; max-width: 280px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }

.sync-indicator { font-size: 0.7rem; }
.sync-indicator.online { color: var(--success); }
.sync-indicator.offline { color: var(--warning); }

/* Drawer — overlay only, never permanent sidebar */
.nav-drawer {
  position: fixed; top: 0; left: 0; width: min(320px, 92vw); height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  z-index: 200; overflow-y: auto; box-shadow: var(--shadow);
  transform: translateX(-105%); transition: transform 0.22s ease;
}
.nav-drawer:not([hidden]) { transform: translateX(0); }
.nav-drawer[hidden] { display: block; transform: translateX(-105%); pointer-events: none; }
.nav-drawer:not([hidden]) { pointer-events: auto; }

.top-nav-links {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 0 20px 10px; background: var(--glass); border-bottom: 1px solid var(--border);
}
.top-nav-link {
  padding: 6px 12px; border-radius: 999px; font-size: 0.82rem; color: var(--text-muted);
  text-decoration: none; border: 1px solid transparent; background: transparent; cursor: pointer;
}
.top-nav-link:hover, .top-nav-link.active { color: var(--accent); background: var(--surface-2); border-color: var(--border); }
.top-nav-more { font-weight: 600; color: var(--navy); }

.nav-overlay { position: fixed; inset: 0; background: rgba(15, 26, 46, 0.45); z-index: 190; }
.nav-overlay[hidden] { display: none; pointer-events: none; }

.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); margin-top: 64px; }
.drawer-content { padding: 12px; }
.nav-group { margin-bottom: 16px; }
.nav-group-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); padding: 8px 12px; }
.nav-link { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav-link:hover, .nav-link.active { background: var(--surface-2); color: var(--accent); }
.nav-overlay { position: fixed; inset: 0; top: 0; background: rgba(15, 26, 46, 0.45); z-index: 190; }
.nav-overlay[hidden] { display: none; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius); border: 1px solid transparent; font-weight: 600; cursor: pointer; font-size: 0.95rem; text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); border: none; padding: 8px 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-icon { background: none; border: none; font-size: 1.25rem; cursor: pointer; padding: 8px; border-radius: 8px; }

/* Panels & Layout */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 20px; }
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }

.metric-card { padding: 20px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.metric-card b { display: block; font-size: 2rem; color: var(--navy); }
.metric-card span { font-size: 0.85rem; color: var(--text-muted); }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--surface-2); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.data-table tr:hover td { background: rgba(30, 77, 123, 0.04); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 32px !important; }

/* Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border); }
.badge-success, .badge.good { background: rgba(45, 106, 79, 0.12); color: var(--success); }
.badge-warning, .badge.warn { background: rgba(184, 134, 11, 0.12); color: var(--warning); }
.badge-danger, .badge.bad { background: rgba(155, 35, 53, 0.12); color: var(--danger); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--graphite); }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-error-summary { grid-column: 1 / -1; padding: 12px; background: rgba(155, 35, 53, 0.08); border: 1px solid var(--danger); border-radius: var(--radius); color: var(--danger); }
input, select, textarea, .search-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 1rem;
}
textarea { min-height: 100px; resize: vertical; }

/* Timeline */
.timeline-track { border-left: 3px solid var(--brass); padding-left: 24px; margin-left: 8px; }
.timeline-event { position: relative; margin-bottom: 24px; padding: 16px; background: var(--surface-2); border-radius: var(--radius); }
.timeline-event::before { content: ''; position: absolute; left: -31px; top: 20px; width: 12px; height: 12px; border-radius: 50%; background: var(--brass); border: 3px solid var(--surface); }
.timeline-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 0.85rem; }

/* Toast & Modal */
#toast-region { position: fixed; bottom: 24px; right: 24px; z-index: 200; }
.toast { padding: 14px 20px; border-radius: var(--radius); background: var(--navy); color: #fff; box-shadow: var(--shadow); animation: slideIn 0.25s ease; }
.toast-warning { background: var(--warning); color: #000; }
.toast-danger { background: var(--danger); }
@keyframes slideIn { from { transform: translateY(12px); opacity: 0; } }

.modal-root { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 20px; }
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 26, 46, 0.5); }
.modal-card { position: relative; width: min(720px, 96vw); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); z-index: 1; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 24px; }

/* Command Palette */
.command-palette { position: fixed; inset: 0; z-index: 160; display: grid; place-items: start center; padding-top: 15vh; }
.command-palette.hidden { display: none; }
.cmd-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.cmd-panel { position: relative; width: min(560px, 92vw); background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; z-index: 1; }
.cmd-input { width: 100%; padding: 16px 20px; border: none; border-bottom: 1px solid var(--border); font-size: 1.1rem; }
.cmd-results { list-style: none; margin: 0; padding: 8px; max-height: 360px; overflow-y: auto; }
.cmd-item { display: flex; justify-content: space-between; padding: 12px 16px; border-radius: 8px; cursor: pointer; }
.cmd-item:hover, .cmd-item.selected { background: var(--surface-2); }

/* Landing */
.landing-hero { text-align: center; padding: 80px 24px; max-width: 800px; margin: 0 auto; }
.landing-hero h1 { font-size: clamp(2rem, 5vw, 3rem); }
.landing-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 32px; }
.landing-badge { display: inline-block; padding: 6px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--brass); color: var(--brass); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 16px; }

/* Loading & Empty */
.loading-state, .error-state, .empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { padding: 14px 16px; border-radius: var(--radius); background: rgba(184, 149, 106, 0.12); border: 1px solid var(--brass); color: var(--graphite); font-size: 0.9rem; }
.disclaimer { font-size: 0.85rem; color: var(--text-muted); font-style: italic; border-left: 3px solid var(--warning); padding-left: 12px; margin: 16px 0; }

.graph-container { min-height: 400px; background: var(--surface-2); border-radius: var(--radius); padding: 24px; position: relative; }
.graph-node { display: inline-block; padding: 8px 14px; margin: 6px; border-radius: 999px; border: 1px solid var(--accent); background: var(--surface); font-size: 0.85rem; }

@media (max-width: 900px) {
  .col-8, .col-6, .col-4 { grid-column: span 12; }
  .form-grid { grid-template-columns: 1fr; }
  .nav-center { display: none; }
  .top-nav-links { overflow-x: auto; flex-wrap: nowrap; }
}
@media (max-width: 600px) {
  .page-main { padding: 16px 12px 32px; }
  .top-nav { padding: 0 12px; }
}

@media print {
  .top-nav, .nav-drawer, .page-actions, .btn { display: none !important; }
  body { background: white; }
  .panel { box-shadow: none; break-inside: avoid; }
}
