:root {
  --bg: #f4f5f7;
  --ink: #21303b;
  --accent: #7a1414;        /* the dissertation's dark-red edge colour */
  --focus: #e8821e;
  --pending: #2b6cb0;
  --panel: #ffffff;
  --line: #cdd3da;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; height: 100vh; }

#toolbar {
  display: flex; align-items: center; gap: .4rem;
  padding: .5rem .7rem; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { color: var(--accent); letter-spacing: .02em; }
.ver { color: #97a0a8; font-size: .72rem; font-variant-numeric: tabular-nums; margin: 0 .5rem 0 .15rem; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 .3rem; }
.map-title { color: #6a7681; font-size: .9rem; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#facet-menu {
  position: absolute; top: 52px; left: 12px; z-index: 20; width: 260px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: .6rem .7rem;
}
#facet-menu h3 { margin: 0 0 .4rem; font-size: .8rem; color: #6a7681; font-weight: 600; }
#facet-menu #facet-concept { color: var(--accent); }
#facet-list { list-style: none; margin: 0 0 .5rem; padding: 0; max-height: 220px; overflow: auto; }
#facet-list li { padding: .4rem .5rem; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
#facet-list li:hover { background: #eef1f4; }
#facet-list .tag { color: #97a0a8; font-size: .8rem; }
.facet-new { display: flex; gap: .4rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.facet-new input { flex: 1; min-width: 0; }

#gdrive-menu {
  position: absolute; top: 52px; right: 12px; z-index: 20; width: 250px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: .6rem .7rem;
}
#gdrive-menu h3 { margin: 0 0 .4rem; font-size: .8rem; color: #6a7681; font-weight: 600; }
#gdrive-menu h3 small { font-weight: normal; }
#gdrive-actions { list-style: none; margin: 0 0 .4rem; padding: 0; }
#gdrive-actions li { padding: .45rem .5rem; border-radius: 6px; cursor: pointer; }
#gdrive-actions li:hover { background: #eef1f4; }
#gdrive-actions li.disabled { color: #b5bcc2; cursor: default; }
#gdrive-actions li.disabled:hover { background: none; }
#gdrive-state { margin: .2rem 0 0; font-size: .75rem; }

.gdrive-conflict {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.32);
}
.gdrive-conflict-box {
  background: var(--panel); border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.3);
  padding: 1rem 1.2rem; width: min(420px, 92vw);
}
.gdrive-conflict-box h3 { margin: 0 0 .4rem; font-size: .95rem; }
.gdrive-conflict-box p { margin: 0 0 .8rem; color: #54616c; font-size: .85rem; }
.gdrive-conflict-acts { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.gdrive-conflict-acts button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

#batch-modal {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30;
  width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: .8rem 1rem;
}
#batch-modal h3 { margin: 0 0 .5rem; font-size: .85rem; color: #6a7681; font-weight: 600; }
#batch-modal h3 small { font-weight: normal; }
#batch-modal code { background: #eef1f4; padding: 0 .2rem; border-radius: 3px; }
#batch-text { width: 100%; font: 13px/1.5 ui-monospace, Menlo, monospace; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.batch-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .6rem; }
.batch-actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Knowledge-export ingest dialog (ADR-0021) — reuses the batch-modal shell */
#rvf-modal {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30;
  width: min(560px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: .8rem 1rem;
}
#rvf-modal h3 { margin: 0 0 .6rem; font-size: .85rem; color: #6a7681; font-weight: 600; }
#rvf-modal h3 small { font-weight: normal; color: #97a0a8; }
#rvf-modal .field-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: #6a7681; margin-bottom: .25rem; }
.rvf-field { display: block; margin: 0 0 .6rem; }
.rvf-types { display: flex; flex-wrap: wrap; gap: .35rem; }
.rvf-types label { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .5rem; border: 1px solid var(--line); border-radius: 999px; font-size: .8rem; cursor: pointer; }
.rvf-row { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem; margin-bottom: .6rem; font-size: .85rem; color: #54616c; }
.rvf-row input[type="number"] { width: 5rem; font: inherit; padding: .2rem .35rem; border: 1px solid var(--line); border-radius: 6px; }
.rvf-check { display: inline-flex; align-items: center; gap: .3rem; }
#rvf-query { width: 100%; }
#rvf-preview { margin: .2rem 0 0; min-height: 1.1em; }

button, select {
  font: inherit; padding: .35rem .6rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
  min-height: 38px;                 /* comfortable touch target (NFR-9) */
}
button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; transform: none; }
label { display: inline-flex; align-items: center; gap: .35rem; }

main { flex: 1; display: flex; min-height: 0; position: relative; overflow: hidden; }
/* min-width:0 lets the canvas flex item shrink below its (large) backing-store width,
   so the outline panel can claim its space instead of being pushed off-screen. */
#canvas { flex: 1; min-width: 0; display: block; touch-action: none; background:
  radial-gradient(circle at 1px 1px, #e2e6ea 1px, transparent 0) 0 0 / 26px 26px; }

#outline {
  width: min(360px, 42vw); border-left: 1px solid var(--line);
  background: var(--panel); padding: .6rem .8rem; overflow: auto;
}
#outline h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #6a7681; }
#outline pre { white-space: pre-wrap; font: 13px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }

input[type="search"] { font: inherit; padding: .35rem .6rem; border: 1px solid var(--line); border-radius: 8px; min-height: 38px; min-width: 180px; }

#search-results {
  width: min(320px, 42vw); border-left: 1px solid var(--line);
  background: var(--panel); padding: .6rem .8rem; overflow: auto;
}
#search-results h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #6a7681; }
#search-results h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
#search-list { list-style: none; margin: 0; padding: 0; }
#search-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem .5rem; border-radius: 6px; cursor: pointer; }
#search-list li:hover { background: #eef1f4; }
#search-list .score { color: #6a7681; font-variant-numeric: tabular-nums; }
#search-list .empty { color: #97a0a8; cursor: default; }

/* Catalogue + Properties reuse the side-panel look */
#catalogue, #properties {
  width: min(320px, 44vw); border-left: 1px solid var(--line);
  background: var(--panel); padding: .6rem .8rem; overflow: auto;
}
#catalogue h2, #properties h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #6a7681; }
#catalogue h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
#catalogue-filter { width: 100%; margin-bottom: .4rem; }
.cat-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-bottom: .5rem; font-size: .78rem; color: #6a7681; }
.cat-controls select { font: inherit; padding: .15rem .25rem; border: 1px solid var(--line); border-radius: 5px; }
#catalogue-dir { padding: .1rem .4rem; border: 1px solid var(--line); border-radius: 5px; background: #fff; cursor: pointer; }
.cat-toggles { display: flex; gap: .25rem; margin-left: auto; }
.cat-controls .chip { padding: .15rem .4rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-size: .72rem; }
.cat-controls .chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
#catalogue-list { list-style: none; margin: 0; padding: 0; }
#catalogue-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem .5rem; border-radius: 6px; cursor: pointer; }
#catalogue-list li:hover { background: #eef1f4; }
#catalogue-list .empty { color: #97a0a8; cursor: default; }
#properties .muted { color: #97a0a8; }
#properties .field { display: block; margin: 0 0 .6rem; }
#properties .field-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: #6a7681; margin-bottom: .2rem; }
#properties input, #properties textarea { width: 100%; font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px; }
#properties .attr-row { display: flex; gap: .4rem; margin-bottom: .3rem; align-items: center; }
#properties .attr-key { font: 12px ui-monospace, monospace; color: #54616c; min-width: 70px; }
#properties button.primary { background: var(--accent); color: #fff; border-color: var(--accent); margin-top: .3rem; }

/* Event-log inspector (ADR-0016) — reuses the side-panel look */
#eventlog {
  width: min(360px, 46vw); border-left: 1px solid var(--line);
  background: var(--panel); padding: .6rem .8rem; overflow: auto;
}
#eventlog h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #6a7681; }
#eventlog h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
.ev-controls { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.ev-controls .muted { color: #97a0a8; font-size: .78rem; font-variant-numeric: tabular-nums; }
#eventlog-clear { padding: .15rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: .78rem; }
#eventlog-list { list-style: none; margin: 0; padding: 0; }
#eventlog-list li { display: grid; grid-template-columns: auto auto 1fr; align-items: baseline; gap: .4rem; padding: .3rem .4rem; border-radius: 6px; cursor: pointer; font-size: .82rem; }
#eventlog-list li:hover { background: #eef1f4; }
#eventlog-list li.ev-noref { cursor: default; }
#eventlog-list .empty { display: block; color: #97a0a8; cursor: default; }
.ev-seq { color: #aab3bb; font: 11px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.ev-kind { font: 11px ui-monospace, monospace; white-space: nowrap; color: #54616c; }
.ev-desc { color: #2b333a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-kind.ev-create { color: #2f855a; }
.ev-kind.ev-delete { color: #c53030; }
.ev-kind.ev-link   { color: #2b6cb0; }
.ev-kind.ev-edit   { color: #6b46c1; }
.ev-kind.ev-place  { color: #b7791f; }
.ev-kind.ev-map    { color: #0f766e; }
.ev-kind.ev-note   { color: #97612b; }

/* Overview — the synchronized 2nd view (FR-12) */
#miniview {
  width: min(320px, 44vw); border-left: 1px solid var(--line);
  background: var(--panel); padding: .6rem .8rem; display: flex; flex-direction: column;
}
#miniview[hidden] { display: none; }
#miniview h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #6a7681; margin: 0 0 .5rem; }
#miniview h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
#minicanvas { flex: 1; min-height: 220px; width: 100%; background: #fbfcfd; border: 1px solid var(--line); border-radius: 8px; }

#statusbar {
  display: flex; align-items: center; gap: .8rem;
  padding: .35rem .7rem; background: var(--panel);
  border-top: 1px solid var(--line); color: #54616c; font-size: .85rem;
}
#status { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#saved {
  flex: none; white-space: nowrap; color: #6a7681; font-variant-numeric: tabular-nums;
  max-width: 46%; overflow: hidden; text-overflow: ellipsis;
}
#saved.stale { color: #b7791f; }

/* Live-collaboration room + relay indicator (ADR-0006) */
.sync-status { flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; padding: 0 .3rem; }
.sync-status.sync-on  { color: #2f855a; }   /* relay connected */
.sync-status.sync-off { color: #b7791f; }   /* connecting / disconnected */
.sync-status.sync-local { color: #6a7681; } /* room set but no relay (this browser only) */

/* Presence roster — who else is in the room (ADR-0006) */
.presence { flex: none; display: inline-flex; align-items: center; gap: .25rem; padding: 0 .3rem; }
.presence[hidden] { display: none; }
.presence .presence-n { font-variant-numeric: tabular-nums; color: #54616c; margin-right: .1rem; }
.presence .presence-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px rgba(255,255,255,.7); }

/* π request activity: pending indicator + elapsed time + abort (ADR-0015) */
#pi-activity { flex: none; display: inline-flex; align-items: center; gap: .45rem; color: #0f766e; white-space: nowrap; }
#pi-activity[hidden] { display: none; }
#pi-activity-label { font-variant-numeric: tabular-nums; }
.pi-spinner { width: 13px; height: 13px; border: 2px solid #b8d8d3; border-top-color: #0f766e; border-radius: 50%; animation: pi-spin 0.7s linear infinite; }
@keyframes pi-spin { to { transform: rotate(360deg); } }
#pi-abort { min-height: 0; padding: .1rem .5rem; font-size: .78rem; border-radius: 6px; }

@media (max-width: 600px) {
  #outline { position: absolute; inset: 0 0 0 auto; width: 88vw; z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.12); }
  .brand { width: 100%; }
}
