:root {
  --bg: #0f1115;
  --bg-elev: #181b23;
  --bg-elev-2: #20232c;
  --text: #e7e9ee;
  --text-muted: #8a8f9c;
  --accent: #6ea8fe;
  --accent-2: #8ed4a3;
  --warn: #e6a157;
  --bad: #d96d6d;
  --border: #2a2e39;
  --radius: 6px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); font-size: 0.9em; }
.empty { padding: 3em 0; text-align: center; color: var(--text-muted); }

/* Top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 0.75em 1.5em;
}
.topbar .brand a { color: var(--text); font-weight: 600; font-size: 1.1em; }
.topbar nav a {
  margin-left: 1.5em;
  color: var(--text); font-weight: 500;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--accent); }

main { max-width: 1300px; margin: 1.5em auto; padding: 0 1.5em; }

/* Headings */
h1 { margin: 0.5em 0 0.7em; font-weight: 600; font-size: 1.6em; }
h2 { font-size: 1.2em; margin-top: 1.5em; }
h3 { font-size: 1em; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Forms */
input, select, textarea {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5em 0.7em; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, SF Mono, monospace; line-height: 1.55; }
button {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5em 1em; cursor: pointer; font: inherit;
}
button:hover { background: var(--border); }
button.primary { background: var(--accent); color: #0c0e14; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--text-muted); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.small { padding: 0.3em 0.7em; font-size: 0.9em; }
.action-row { margin-top: 1em; display: flex; gap: 0.7em; }
.inline-form { display: inline-flex; gap: 0.5em; align-items: center; margin-top: 0.7em; }

/* Status pills */
.status { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.status-draft { background: rgba(230, 161, 87, 0.15); color: var(--warn); }
.status-confirmed { background: rgba(142, 212, 163, 0.15); color: var(--accent-2); }
.status-skipped { background: rgba(138, 143, 156, 0.15); color: var(--text-muted); }
.status-verified { background: rgba(142, 212, 163, 0.15); color: var(--accent-2); }
.status-unverified { background: rgba(230, 161, 87, 0.15); color: var(--warn); }
.status-rejected { background: rgba(217, 109, 109, 0.15); color: var(--bad); }
.status-pending { background: rgba(110, 168, 254, 0.15); color: var(--accent); }
.status-answered { background: rgba(142, 212, 163, 0.15); color: var(--accent-2); }
.status-dismissed { background: rgba(138, 143, 156, 0.15); color: var(--text-muted); }

/* Tags */
.tag { display: inline-block; padding: 1px 8px; border-radius: var(--radius); font-size: 0.78em; background: var(--bg-elev-2); color: var(--text-muted); border: 1px solid var(--border); }
.tag-time_sensitive { background: rgba(217, 109, 109, 0.2); color: var(--bad); }
.tag-normal { background: rgba(110, 168, 254, 0.15); color: var(--accent); }
.tag-low { background: var(--bg-elev-2); }
.tag-person { background: rgba(110, 168, 254, 0.12); color: var(--accent); }
.tag-vendor { background: rgba(230, 161, 87, 0.12); color: var(--warn); }
.tag-event { background: rgba(142, 212, 163, 0.12); color: var(--accent-2); }
.tag-place { background: rgba(138, 143, 156, 0.18); }

/* Narrative layout */
.layout-narrative { display: grid; grid-template-columns: 250px 1fr; gap: 2em; }
.sidebar { border-right: 1px solid var(--border); padding-right: 1em; max-height: 80vh; overflow-y: auto; }
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li { margin-bottom: 0.6em; }
.recent-list a { display: flex; justify-content: space-between; color: var(--text); padding: 0.3em 0.4em; border-radius: var(--radius); }
.recent-list a:hover { background: var(--bg-elev); text-decoration: none; }
.recent-list a.current { background: var(--bg-elev-2); }
.recent-list .excerpt { color: var(--text-muted); font-size: 0.82em; margin-top: 0.1em; padding-left: 0.4em; }

.nav-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1em; }
.nav-row h1 { margin: 0; }
.meta-row { color: var(--text-muted); margin: 0.7em 0 1em; display: flex; gap: 1.2em; align-items: center; }
.narrative-edit { min-height: 30em; font-size: 1em; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin-top: 1em; }
th, td { text-align: left; padding: 0.5em 0.8em; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; font-size: 0.9em; }

/* Filters bar */
.filters { display: flex; gap: 0.7em; align-items: center; margin-bottom: 1em; }

/* World */
.entities-table tr:hover { background: var(--bg-elev); }
.entity-edit { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 0.6em; align-items: end; }
.entity-edit label { display: flex; flex-direction: column; font-size: 0.82em; color: var(--text-muted); }
.entity-edit input, .entity-edit select { margin-top: 0.2em; }

.block { background: var(--bg-elev); padding: 1em 1.3em; border-radius: var(--radius); margin-top: 1.5em; }
.block.danger { border: 1px solid var(--bad); }
ul.aliases, ul.facts { list-style: none; padding: 0; }
ul.aliases li, ul.facts li { padding: 0.3em 0; border-bottom: 1px solid var(--border); }

/* Patterns */
.patterns-list { list-style: none; padding: 0; }
.pattern-item { padding: 1em; margin-bottom: 0.8em; background: var(--bg-elev); border-radius: var(--radius); border-left: 3px solid var(--border); }
.pattern-item.status-verified { border-left-color: var(--accent-2); }
.pattern-item.status-rejected { border-left-color: var(--bad); opacity: 0.6; }
.pattern-meta { display: flex; gap: 0.7em; align-items: center; margin-bottom: 0.4em; }
.pattern-desc { font-size: 1.05em; }

/* Sources */
.sources-table .bar {
  background: var(--bg-elev-2);
  padding: 2px 8px; border-radius: var(--radius);
  position: relative; min-width: 60px; display: inline-block;
}
.sources-table .bar::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--p) * 1%);
  background: rgba(110, 168, 254, 0.3); border-radius: var(--radius);
}

/* Inbox */
.filter-tabs { display: flex; gap: 0.3em; margin-bottom: 1em; border-bottom: 1px solid var(--border); }
.filter-tabs a { padding: 0.5em 1em; color: var(--text-muted); }
.filter-tabs a.active { color: var(--text); border-bottom: 2px solid var(--accent); margin-bottom: -1px; }
.gaps-list { list-style: none; padding: 0; }
.gap-item { background: var(--bg-elev); padding: 1em 1.3em; margin-bottom: 0.8em; border-radius: var(--radius); border-left: 3px solid var(--border); }
.gap-item.gap-time_sensitive { border-left-color: var(--bad); }
.gap-meta { display: flex; gap: 0.7em; align-items: center; margin-bottom: 0.4em; font-size: 0.85em; }
.gap-question { font-size: 1.05em; margin: 0.3em 0 0.6em; }
.gap-evidence pre { background: var(--bg-elev-2); padding: 0.7em; border-radius: var(--radius); font-size: 0.85em; overflow-x: auto; }
.gap-answer-form input { flex: 1; min-width: 250px; }
.gap-answer { background: var(--bg-elev-2); padding: 0.6em 0.9em; border-radius: var(--radius); margin-top: 0.5em; }

/* Misc */
details summary { cursor: pointer; }
