/* Δ8 webapp — dark theme modelled on claude.ai/new.
   Variables first so the whole shell can be re-themed in one place. */
:root {
  --bg:        #262624;   /* app background (warm near-black) */
  --bg-side:   #1f1e1d;   /* sidebar, a touch darker          */
  --bg-card:   #30302e;   /* raised panels / composer         */
  --bg-hover:  #3a3a37;   /* hover state for nav rows          */
  --border:    #3d3d3a;
  --text:      #f5f4ee;   /* primary text (warm off-white)     */
  --text-mut:  #b4b2a8;   /* secondary / labels                */
  --text-dim:  #82807a;   /* tertiary / hints                  */
  --accent:    #d97757;   /* Anthropic terracotta              */
  --accent-dim:#b35f43;
  --ok:        #6fb98f;
  --err:       #e0796a;
  --radius:    10px;
  --sidebar-w: 260px;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* mobile chrome — hidden on desktop, shown by the media query below */
#navtoggle { display: none; }
#backdrop { display: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  height: 100vh;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
}
.brand .logo {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--text);
}
.brand .logo .tri { font-weight: 400; color: var(--accent); }

.nav-section { margin-top: 6px; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  padding: 12px 8px 4px;
}

/* a nav row (top menu or sub-menu item) */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text-mut);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-hover); color: var(--text); }
.nav-item .ico { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav-item .chev { margin-left: auto; opacity: .5; transition: transform .15s ease; }
.nav-item.open .chev { transform: rotate(90deg); }

/* sub-menu (the bottom half that appears under Data) */
.submenu { margin: 2px 0 4px 8px; padding-left: 6px; border-left: 1px solid var(--border); }
.submenu .nav-item { font-size: 13.5px; color: var(--text-mut); }
.submenu[hidden] { display: none; }

/* catalog tree (tables + views nested under the Catalog item) */
.cat-tree { margin: 2px 0 2px 6px; padding-left: 8px; border-left: 1px solid var(--border); }
.cat-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding: 8px 8px 2px; }
.nav-item.cat-leaf { font-size: 13px; padding: 5px 10px; color: var(--text-mut); }
.nav-item.cat-leaf .pill { font-size: 10px; padding: 1px 7px; }

.sidebar-spacer { flex: 1 1 auto; }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-foot .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* ── Main area ───────────────────────────────────────────────────────── */
.main { flex: 1 1 auto; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.view { flex: 1 1 auto; display: flex; flex-direction: column; }

/* Home / hero */
.hero {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 22px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 40px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
.hero h1 .tri { color: var(--accent); }
.hero .tagline { color: var(--text-mut); font-size: 17px; max-width: 620px; margin: 0; }
.hero .lede { color: var(--text-dim); font-size: 14.5px; max-width: 640px; line-height: 1.7; }
.hero .cards { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.hero .card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  width: 220px;
  text-align: left;
  cursor: pointer;
}
.hero .card:hover { border-color: var(--accent-dim); }
.hero .card h3 { margin: 0 0 4px; font-size: 14px; }
.hero .card p { margin: 0; font-size: 12.5px; color: var(--text-dim); }

/* Home that scrolls (problem/solution narrative under the hero) */
.home { width: 100%; max-width: 920px; margin: 0 auto; padding: 56px 28px 72px; }
.home .hero { padding: 8px 0 40px; gap: 18px; }
.home section { margin-top: 40px; }
.home section > h2 {
  font-family: var(--serif); font-weight: 500; font-size: 24px; text-align: center; margin: 0 0 6px;
}
.home section > .sub { color: var(--text-mut); text-align: center; margin: 0 auto 22px; max-width: 620px; }

/* article-style prose blocks on the home page */
.prose { max-width: 720px; margin: 0 auto; text-align: left; }
.prose p { color: var(--text-mut); line-height: 1.75; margin: 0 0 14px; }
.prose p:last-child { margin-bottom: 0; }
.prose b { color: var(--text); font-weight: 600; }
.prose em { color: var(--text); font-style: italic; }
.prose .eq { font-family: var(--mono); color: var(--accent); font-style: normal; white-space: nowrap; }

/* explained list (the three questions, the six operations) — not bare bullets */
.deflist { max-width: 720px; margin: 14px auto 0; text-align: left; display: grid; gap: 8px; }
.deflist > div { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 15px; color: var(--text-mut); line-height: 1.6; }
.deflist b { color: var(--accent); }

/* eight-primitives cards (home) */
.primgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px;
  max-width: 920px; margin: 4px auto 0; }
.prim { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; text-align: left; }
.prim h3 { margin: 0; font-size: 14px; color: var(--accent); }
.prim .sig { font-family: var(--mono); font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; margin: 3px 0 9px; }
.prim p { margin: 0 0 5px; font-size: 12.5px; color: var(--text-mut); line-height: 1.45; }
.prim .fields { color: var(--text-dim); font-size: 11.5px; margin: 0; }

/* the 8×6 grid (home) — primitives (rows) × operations (columns); fixed layout so
   columns are even and long tokens wrap instead of bleeding into the next cell */
.grid8-wrap { overflow-x: auto; margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.grid8 { border-collapse: collapse; width: 100%; min-width: 900px; font-size: 11px; table-layout: fixed; }
.grid8 col.rowcol { width: 156px; }
.grid8 th, .grid8 td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top;
  line-height: 1.4; overflow-wrap: break-word; word-break: break-word; }
.grid8 thead th { background: var(--bg-card); text-align: left; }
.grid8 .corner { font-size: 9.5px; color: var(--text-dim); font-weight: 400; }
.grid8 .opn { font-family: var(--mono); font-size: 10.5px; letter-spacing: .03em; color: var(--accent); }
.grid8 .opv { font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.grid8 .rowh { background: var(--bg-card); color: var(--accent); font-weight: 600; font-size: 11.5px; white-space: nowrap; }
.grid8 td { color: var(--text-mut); }
.grid8 .ctl { background: rgba(217, 119, 87, .06); }        /* subtle tint: the two control columns */
.grid8 thead th.ctl { background: rgba(217, 119, 87, .12); }

/* domain pill list on the home page */
.domains { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 660px; margin: 4px auto 0; }
.domains .pill { font-size: 13px; padding: 6px 13px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-mut); }

/* paired problem ↔ Δ8 rows */
.compare { display: flex; flex-direction: column; gap: 12px; }
.compare-row {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: stretch;
  gap: 0;
}
.compare-row .cell {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.compare-row .cell h4 { margin: 0 0 4px; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.compare-row .cell p { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.55; }
.compare-row .problem { border-color: #4a3a35; }
.compare-row .problem h4 { color: var(--err); }
.compare-row .solution { border-color: #3a4a40; }
.compare-row .solution h4 { color: var(--ok); }
.compare-row .arrow { display: flex; align-items: center; justify-content: center; color: var(--text-dim); }
@media (max-width: 680px) {
  .compare-row { grid-template-columns: 1fr; }
  .compare-row .arrow { transform: rotate(90deg); height: 18px; }
}

/* Working views (ingest/catalog/query) share a padded column */
.pane { padding: 28px 36px; max-width: 960px; width: 100%; margin: 0 auto; }
.pane h2 { font-family: var(--serif); font-weight: 500; font-size: 26px; margin: 4px 0 4px; }
.pane .sub { color: var(--text-mut); margin: 0 0 22px; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h3 { margin: 0 0 10px; font-size: 14px; }

/* Drop zone (ingest) */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  color: var(--text-mut);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: #2c2b29; color: var(--text); }
.dropzone .big { font-size: 15px; margin-bottom: 6px; color: var(--text); }

.btn {
  background: var(--accent);
  color: #1a1a18;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dim); color: var(--text); }
.btn.ghost { background: transparent; color: var(--text-mut); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.danger { background: transparent; color: var(--err); border: 1px solid #5a3a35; }
.btn.danger:hover { background: #3a2a27; color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

select, input[type=text] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

/* SQL editor (query) */
.sql {
  width: 100%;
  min-height: 160px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}
.sql:focus { outline: none; border-color: var(--accent-dim); }

/* tables */
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}
table.grid th { color: var(--text-mut); font-weight: 600; }
table.grid td { font-family: var(--mono); color: var(--text); }
table.grid tr:hover td { background: #2c2b29; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: #3a3a37; }

/* Substrate demo: model grid + active requirement toggle */
.modelgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.modelgrid h4 { margin: 0 0 6px; font-size: 13px; }
.btn.ghost.on { background: var(--accent-dim); color: var(--text); border-color: var(--accent); }
.diag.err { color: var(--err); font-size: 12.5px; margin: 4px 0; }

/* live metrics row (watch view) */
.metrics { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.metric { display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; min-width: 110px; }
.metric b { font-size: 18px; font-family: var(--mono); color: var(--text); }
.metric small { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* a row that just changed value flashes the accent colour and fades back */
@keyframes flashrow { from { background: rgba(217,119,87,.35); } to { background: transparent; } }
table.grid tr.flash td { animation: flashrow 1s ease-out; }

/* EventStorming designer canvas (stickies are inline-styled by StormCanvas) */
.storm-canvas:focus { outline: none; }
.storm-canvas .sticky.sel { outline: 2px solid var(--accent); outline-offset: 1px; }

/* designer inspector — per-kind sticky editor */
#inspector .ihead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#inspector .chip { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 4px; color: #1a1a18; }
#inspector .lbledit { flex: 1 1 160px; font-weight: 600; font-size: 13px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 9px; }
#inspector .irow { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: center;
  padding: 6px 0; font-size: 12px; border-top: 1px solid var(--border); }
#inspector .irow > span { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: .03em; }
#inspector .ed { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; font: 12px/1.4 var(--sans); }
#inspector textarea.ed { font-family: var(--mono); min-height: 44px; resize: vertical; }
#inspector .ed.bad { border-color: var(--err); }
#inspector .ckrow { display: flex; align-items: center; gap: 6px; color: var(--text-mut); font-size: 12px; }

/* inline diagnostic markers: a transparent mirror behind the textarea draws squiggles */
.ed-wrap > textarea.sql { position: relative; z-index: 1; background: transparent; }
.ed-backdrop {
  position: absolute; inset: 0; z-index: 0; margin: 0; box-sizing: border-box;
  overflow: hidden; pointer-events: none; color: transparent;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: break-word;
  /* must mirror .sql box + text metrics exactly */
  padding: 14px; border: 1px solid transparent; border-radius: var(--radius);
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
}
.mk-err, .mk-warn { text-decoration: underline wavy; text-decoration-skip-ink: none; }
.mk-err { text-decoration-color: var(--err); }
.mk-warn { text-decoration-color: var(--accent); }

/* check/lint diagnostics (SQL · DSL · process) */
.diags { margin-top: 8px; }
.diag { font-size: 12px; line-height: 1.6; color: var(--text-mut); }
.diag .dot { margin-right: 6px; }

/* publication cards — cover art + blurb */
.pubcard { display: flex; gap: 18px; align-items: flex-start; }
.pubcard .pubcover { flex: 0 0 120px; display: block; }
.pubcard .pubcover img { width: 120px; height: auto; border-radius: 6px; display: block;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4); background: var(--bg); }
.pubcard.nocover .pubcover { display: none; }
.pubcard .pubbody { flex: 1 1 auto; min-width: 0; }
@media (max-width: 620px) {
  .pubcard { flex-direction: column; }
  .pubcard .pubcover, .pubcard .pubcover img { width: 96px; flex-basis: auto; }
}

.muted { color: var(--text-dim); }
.ok  { color: var(--ok); }
.err { color: var(--err); }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--bg-hover); color: var(--text-mut); font-size: 11.5px;
}
.status { font-size: 12.5px; color: var(--text-mut); min-height: 18px; margin-top: 10px; }
pre.json { background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow: auto; font-family: var(--mono); font-size: 12px; color: var(--text-mut); }

/* ── Mobile: retracting off-canvas sidebar ───────────────────────────── */
@media (max-width: 820px) {
  #navtoggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; left: 12px; z-index: 60;
    width: 40px; height: 40px; border-radius: 9px;
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
    cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 55;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 2px 0 18px rgba(0, 0, 0, .45);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open #backdrop {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(0, 0, 0, .5);
  }
  .main { width: 100%; }
  .pane { padding: 64px 16px 32px; }
  .home { padding: 64px 16px 48px; }
  .hero { padding-top: 8px; }
  .hero h1 { font-size: 32px; }
  /* let wide grids (transactions, lineage) scroll inside their panel */
  .panel { overflow-x: auto; }
  .metric { min-width: 96px; flex: 1 1 40%; }
}
