:root {
  --bg: #0a0c10;
  --bg-gradient: linear-gradient(180deg, #0a0c10 0%, #0d1117 100%);
  --surface: #12151c;
  --card: #161a24;
  --card-hover: #1a1f2a;
  --text: #f0f3f8;
  --text-secondary: #c9d1dc;
  --muted: #8b95a5;
  --border: rgba(255,255,255,0.06);
  --border-subtle: rgba(255,255,255,0.04);
  --accent: #5e9fff;
  --accent-hover: #74adff;
  --accent-glow: rgba(94,159,255,0.15);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { 
  box-sizing: border-box; 
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text);
  line-height: 1.5;
  letter-spacing: -0.01em;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

p {
  margin-bottom: 12px;
}

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

a:hover { 
  color: var(--accent-hover);
}

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

.topbar {
  background: rgba(18, 21, 28, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.brand a { 
  display: flex;
  align-items: center;
}

.brand-logo {
  height: 42px;
  width: auto;
  transition: opacity var(--transition);
  filter: brightness(1.1);
}

.brand-logo:hover {
  opacity: 0.85;
}

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

.nav a, .nav button.linklike {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.nav a:hover, .nav button.linklike:hover {
  color: var(--text);
  background: var(--card);
  border-color: rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.linklike {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
  border-color: rgba(255,255,255,0.08);
}

.narrow { max-width: 560px; }

label { 
  display: block; 
  margin-top: 16px; 
  margin-bottom: 8px; 
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

input, textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(22, 26, 36, 0.8);
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

textarea { 
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  resize: vertical;
}

.button {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(180deg, var(--accent) 0%, #4d8beb 100%);
  color: #fff;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.15);
}

.button:active {
  transform: translateY(0);
}

.button.secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
}

.button.secondary:hover {
  background: var(--accent-glow);
  border-color: var(--accent-hover);
  color: var(--accent-hover);
  transform: translateY(-1px);
}

.button.tertiary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  box-shadow: none;
}

.button.tertiary:hover {
  background: var(--card);
  border-color: rgba(255,255,255,0.1);
  color: var(--text);
}

.row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.space-between { justify-content: space-between; }
.align-center { align-items: center; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .container { padding: 20px 16px; }
}

.checkbox {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 12px;
  cursor: pointer;
}

.checkbox input { 
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

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

.alert {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--danger);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin-top: 16px;
  font-size: 0.9rem;
}

.alert.warning {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

.pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.6;
}

/* ---- Audit trail UI (click-to-source provenance) ---- */

.audit-pre {
  white-space: pre-wrap;
}

.audit-header {
  display: block;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
}

.audit-sentence {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  display: inline;
}

.audit-sentence:hover {
  background: rgba(94,159,255,0.12);
}

.audit-direct {
  outline: 1px solid rgba(52, 211, 153, 0.35);
}

.audit-partial {
  outline: 1px solid rgba(251, 191, 36, 0.35);
}

.audit-unsupported {
  outline: 1px solid rgba(248, 113, 113, 0.45);
}

.audit-derived {
  outline: 1px solid rgba(255,255,255,0.10);
  opacity: 0.85;
}

.audit-support-card {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin: 10px 0;
}

.audit-support-source {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.audit-support-quote {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.5;
  white-space: pre-wrap;
}

.audit-highlight {
  background: rgba(251, 191, 36, 0.2);
  border-radius: 4px;
  padding: 0 2px;
}

/* Generic modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  max-width: 900px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 14px 12px;
  text-align: left;
}

.table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.table tr {
  transition: background var(--transition);
}

.table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

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

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.pill.finalized { 
  background: rgba(52, 211, 153, 0.1);
  color: var(--success); 
}

.pill.draft { 
  background: rgba(251, 191, 36, 0.1);
  color: var(--warning); 
}

.pill.saved {
  background: rgba(96, 165, 250, 0.1);
  color: #60a5fa;
}

.model-switcher {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0;
}

.small-input {
  width: auto;
  min-width: 220px;
  padding: 8px 12px;
  font-size: 0.8125rem;
}

.button.small {
  padding: 8px 14px;
  font-size: 0.8125rem;
  margin-top: 0;
}

.button.danger {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--danger);
  box-shadow: none;
}

.button.danger:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.4);
  transform: translateY(-1px);
}

.inline-delete {
  display: inline-block;
  margin-left: 12px;
}

.actions-cell {
  white-space: nowrap;
}

.input-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.input-section:last-of-type {
  border-bottom: none;
  margin-bottom: 16px;
  padding-bottom: 0;
}

.input-section label {
  margin-top: 0;
  font-size: 0.9375rem;
}

.required {
  color: var(--danger);
  opacity: 0.8;
}

.optional {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8125rem;
}

.muted.small {
  font-size: 0.8125rem;
  margin-bottom: 10px;
  margin-top: 4px;
}

.options-row {
  margin: 20px 0;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

::selection {
  background: var(--accent);
  color: #fff;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}

.admin-stats-row {
  display: flex;
  gap: 16px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.admin-stat-card {
  flex: 1;
  min-width: 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
}

.admin-stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}

.admin-stat-label {
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-mini-stat {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-mini-number {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}
