/* tabviz: one light theme, one accent (ledger green), hairlines over boxes.
   Design notes: lab/tabviz-README.md (outside the web root). */

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

:root {
  --accent: #1d5c4f;
  --accent-wash: #e6efec;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line2: #c3c2b7;
  --page: #f6f6f3;
  --surface: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff6df;
  --r: 6px;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ── Header ── */
.hdr {
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 10px 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  flex-shrink: 0; min-width: 0;
}
/* gtools and tabviz share one baseline, whatever their sizes. */
.brandbox { display: inline-flex; align-items: baseline; gap: 8px; flex-shrink: 0; }
.home { color: var(--muted); text-decoration: none; font-size: 12px; }
.brand { font-weight: 700; letter-spacing: -.01em; color: var(--accent); text-decoration: none; }
.doc {
  border: 0; background: none; cursor: pointer; font-weight: 600;
  max-width: 22vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 4px 6px; border-radius: var(--r);
}
.doc:hover { background: var(--page); }
.doc-link { font-size: 13px; text-decoration: none; opacity: .45; padding: 2px 3px; margin-left: -6px; border-radius: var(--r); transition: opacity .15s; }
.doc-link:hover, .doc-link:focus-visible { opacity: 1; background: var(--page); }
.views { display: flex; gap: 2px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.views button {
  border: 0; background: none; cursor: pointer; white-space: nowrap;
  padding: 5px 9px; border-radius: var(--r); color: var(--ink2);
}
.views button:hover { background: var(--page); }
.views button.on { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.views .add { color: var(--muted); }
.grow { flex: 1; }

.btn-h, .btn, .btn-t {
  border: 1px solid var(--line2); background: var(--surface); cursor: pointer;
  border-radius: var(--r); white-space: nowrap; text-decoration: none; color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn-h { height: 28px; padding: 0 10px; }
.btn { height: 30px; padding: 0 12px; }
.btn-t { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-h:hover, .btn:hover, .btn-t:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary, .btn-h.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover, .btn-h.primary:hover { color: #fff; filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn:disabled, .btn-h:disabled, .btn-t:disabled { opacity: .55; cursor: default; }
.btn-h.on { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

/* The pen: who may write right now. */
#pen { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
.pen { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink2); }
.pen .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line2); }
.pen.mine { color: var(--accent); font-weight: 600; }
.pen.mine .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.pen.other .dot { background: #eda100; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r);
  box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 4px; display: flex; flex-direction: column;
}
.menu button { border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.menu button:hover { background: var(--page); }

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
#tb-view, .tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.tb-search { height: 26px; width: 220px; border: 1px solid var(--line2); border-radius: var(--r); padding: 0 8px; font: inherit; }
.tb-search:focus { outline: 2px solid var(--accent-wash); border-color: var(--accent); }
.tb-count, .note { color: var(--muted); font-size: 12px; }
.note { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--danger); }
.crumbs { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 1px 8px; cursor: pointer; font-size: 12px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.sep { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 3px 8px; cursor: pointer; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--accent-wash); color: var(--accent); font-weight: 600; }

/* ── Main ── */
.main { flex: 1; display: flex; min-height: 0; }
.stage-wrap { flex: 1; position: relative; min-width: 0; background: var(--surface); }
.stage { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: grab; }
.stage.panning { cursor: grabbing; }
.stage [data-hit] { cursor: pointer; }
.stage.editing text[data-field], .stage.editing [data-edit] { cursor: text; }
.stage.editing text[data-field]:hover, .stage.editing [data-edit]:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.stage .drop-target > rect:nth-of-type(1), .stage .drop-target > rect:nth-of-type(2) { stroke: var(--accent); stroke-width: 3; }
.screen { position: absolute; inset: 0; overflow: auto; display: none; background: var(--page); }
.screen.show { display: block; }

.aside {
  width: 340px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--surface);
  overflow-y: auto; position: relative;
}
.aside-close { position: absolute; right: 6px; top: 6px; border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); width: 28px; height: 28px; border-radius: 50%; }
.aside-close:hover { background: var(--page); }
@media (max-width: 760px) {
  .aside { position: fixed; inset: auto 0 0 0; width: auto; max-height: 60vh; border-left: 0; border-top: 1px solid var(--line2); z-index: 40; box-shadow: 0 -8px 24px rgba(0,0,0,.12); }
  .doc { max-width: 30vw; }
  .tb-search { width: 150px; }
  .brandbox { display: none; }
}
@media (max-width: 480px) {
  .hdr { gap: 4px; padding: 0 6px; }
  .btn-h { padding: 0 7px; font-size: 12px; }
  .doc { max-width: 22vw; padding: 4px 2px; }
  .pen.mine { font-size: 0; gap: 0; }            /* keep the dot, drop the words */
  .pen.other { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }
  .tb-count { display: none; }
}

.panel-body { padding: 14px 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.panel-title { font-size: 16px; font-weight: 600; padding-right: 28px; }
.panel-sub { color: var(--ink2); font-size: 12px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; font-weight: 500; color: var(--ink2); font-size: 12px; width: 38%; padding: 5px 8px 5px 0; vertical-align: top; border-bottom: 1px solid var(--line); }
.kv td { padding: 5px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
.kv td.editable { cursor: text; }
.kv td.editable:hover { background: var(--accent-wash); }
.blank { color: var(--muted); font-style: italic; }
.fx { font-size: 10px; color: var(--muted); border: 1px solid var(--line2); border-radius: 3px; padding: 0 3px; }
.warn { background: var(--warn-bg); border-left: 3px solid #eda100; padding: 6px 8px; font-size: 12px; }
/* Mind map panel */
.mm-rich a { color: var(--accent); word-break: break-all; }
.mm-desc { font-size: 13px; line-height: 1.45; color: var(--ink2); white-space: normal; }
.htag { border: 0; background: var(--accent-wash); color: var(--accent); border-radius: 8px; padding: 0 5px; font: inherit; font-size: .92em; cursor: pointer; }
.htag:hover { text-decoration: underline; }
.mm-links { font-size: 12px; }
.mm-links b { font-weight: 500; color: var(--ink2); }
.mm-links ul { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.mm-links .lbl { color: var(--muted); }
.mm-links .warn-i { color: var(--danger); }
.tb-tags { height: 26px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--surface); font: inherit; font-size: 12px; max-width: 160px; }
.err-box { background: #fdecea; border-left: 3px solid var(--danger); padding: 8px 10px; }

/* Advanced */
.adv h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-top: 6px; }
.adv label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink2); }
.adv label.row { flex-direction: row; align-items: center; gap: 8px; }
.adv input[type=text], .adv input[type=number], .adv select, .screen input[type=text], .screen select {
  height: 30px; border: 1px solid var(--line2); border-radius: var(--r); padding: 0 8px; font: inherit; color: var(--ink); background: var(--surface); width: 100%;
}
.adv .hint { font-size: 11px; color: var(--muted); }
.adv .raw td, .adv .raw th { font-size: 12px; }
.adv .raw input { height: 24px; font-size: 12px; }
.adv .dirty { color: var(--accent); font-weight: 600; }

/* Screens (connect, pick, set up) */
.card {
  max-width: 560px; margin: 8vh auto 24px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 22px; display: flex; flex-direction: column; gap: 14px;
}
.card h1 { font-size: 20px; letter-spacing: -.01em; }
.card p { color: var(--ink2); }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); }
.list button { border: 0; background: none; text-align: left; padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.list button + button { border-top: 1px solid var(--line); }
.list button:hover { background: var(--page); }
.list .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.types button { border: 1px solid var(--line2); background: var(--surface); border-radius: var(--r); padding: 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.types button.on { border-color: var(--accent); background: var(--accent-wash); }
.types small { color: var(--muted); }

label.check { flex-direction: row; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink2); }
.card h2 { font-size: 15px; }
.card + .card { margin-top: 0; }
details.fold summary { cursor: pointer; font-weight: 600; color: var(--ink2); }
details.fold[open] summary { margin-bottom: 4px; }
details.fold .hint { font-size: 12px; color: var(--muted); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; margin-left: 6px; }
.card { margin-bottom: 14px; }

/* Inline editor */
.ied { position: fixed; z-index: 100; display: flex; flex-direction: column; gap: 2px; }
.ied input { height: 32px; border: 2px solid var(--accent); border-radius: var(--r); padding: 0 8px; font: inherit; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.15); background: #fff; }
.ied input:focus { outline: none; }
.ied-hint { font-size: 11px; color: var(--ink2); background: #fff; border-radius: 4px; padding: 1px 6px; align-self: flex-start; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.ied.busy input { opacity: .6; }
.ied textarea { border: 2px solid var(--accent); border-radius: var(--r); padding: 6px 8px; font: inherit; font-size: 14px; line-height: 1.4; box-shadow: 0 4px 16px rgba(0,0,0,.15); background: #fff; resize: vertical; }
.ied textarea:focus { outline: none; }
.ied.busy textarea { opacity: .6; }
.ied-list { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line2); border-radius: var(--r); box-shadow: 0 6px 20px rgba(0,0,0,.14); padding: 3px; max-height: 240px; overflow-y: auto; }
.ied-list button { display: flex; justify-content: space-between; gap: 12px; border: 0; background: none; text-align: left; padding: 5px 8px; border-radius: 4px; cursor: pointer; font: inherit; font-size: 13px; color: var(--ink); }
.ied-list button.on, .ied-list button:hover { background: var(--accent-wash); color: var(--accent); }
.ied-list small { color: var(--muted); }

/* Snackbar */
.snack {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(12px); opacity: 0; pointer-events: none;
  background: #1f1f1d; color: #fff; padding: 9px 14px; border-radius: 8px; display: flex; gap: 12px; align-items: center;
  max-width: min(92vw, 640px); z-index: 200; transition: opacity .15s, transform .15s;
}
.snack.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.snack.err { background: var(--danger); }
.snack button { border: 0; background: none; color: #8fd3bf; font-weight: 600; cursor: pointer; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(127,127,127,.35); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0; }

/* Clean view: nothing but the chart, for screenshots */
body.clean .hdr, body.clean .toolbar, body.clean .aside { display: none !important; }
body.clean .stage-wrap { background: #fff; }
.clean-exit { position: fixed; top: 8px; right: 8px; z-index: 60; opacity: 0; transition: opacity .2s; border: 1px solid var(--line2); background: #fff; border-radius: var(--r); padding: 4px 10px; cursor: pointer; }
.clean-exit:hover, .clean-exit.hint { opacity: 1; }
body.clean > div[title="Click to copy"] { display: none; }   /* the lab's build badge */
.doc-help { font-size: 12px; font-weight: 400; margin-left: 6px; color: var(--accent); }
/* Keyboard hint on hover (core/keys.js) */
.kbd-tip { position: fixed; z-index: 300; display: flex; align-items: center; gap: 8px; background: #1f1f1d; color: #fff; font-size: 12px; padding: 4px 6px 4px 9px; border-radius: 6px; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap; }
.kbd-tip kbd { font: 600 11px/1 system-ui, -apple-system, sans-serif; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28); border-radius: 4px; padding: 3px 5px; }

/* Command menu (core/commands.js) */
.cmd { position: fixed; inset: 0; z-index: 250; background: rgba(20,20,18,.28); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.cmd-panel { width: min(560px, 92vw); background: var(--surface); border-radius: 10px; box-shadow: 0 18px 48px rgba(0,0,0,.25); overflow: hidden; display: flex; flex-direction: column; max-height: 70vh; }
.cmd-q { border: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; font: inherit; font-size: 15px; outline: none; }
.cmd-list { overflow-y: auto; padding: 4px; }
.cmd-list button { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 12px; border: 0; background: none; text-align: left; padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 14px; color: var(--ink); }
.cmd-list button.on, .cmd-list button:hover { background: var(--accent-wash); color: var(--accent); }
.cmd-list kbd { font: 600 11px/1 system-ui, -apple-system, sans-serif; background: var(--page); border: 1px solid var(--line2); border-radius: 4px; padding: 3px 6px; color: var(--ink2); white-space: nowrap; }
.cmd-none { padding: 12px 16px; color: var(--muted); font-size: 13px; }
.cmd-foot { border-top: 1px solid var(--line); padding: 6px 14px; font-size: 11px; color: var(--muted); }
.cmd-btn { font-size: 12px; color: var(--ink2); }
@media (max-width: 480px) { .cmd-btn { display: none; } }
.pen.solo { color: #8a5a00; font-weight: 600; cursor: help; }
.pen.solo .dot { background: #eda100; }
.pen.solo .spin { width: 10px; height: 10px; border-width: 2px; }
.btn-t.on { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

/* Page-style views (the kanban): HTML in #hview instead of the SVG stage */
.hview { position: absolute; inset: 0; background: var(--page); }
.kb { height: 100%; overflow: auto; padding: 0 16px 24px; }
.kb-title { font-size: 18px; margin: 16px 0 4px; }
.hview.editing .kb-title { cursor: text; }
.kb-cols { display: flex; gap: 14px; align-items: flex-start; padding-top: 12px; min-width: min-content; }
.kb-col { width: var(--kb-w); flex: 0 0 var(--kb-w); background: #efeee9; border-radius: 8px; display: flex; flex-direction: column; }
.kb-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 8px; font-weight: 700; font-size: 13px; color: var(--mark); background: #efeee9; border-top: 4px solid var(--mark); border-radius: 8px 8px 0 0; box-shadow: 0 6px 6px -6px rgba(0,0,0,.12); }
.kb-n { font-weight: 500; color: var(--muted); }
.kb-list { display: flex; flex-direction: column; gap: 8px; padding: 4px 10px 10px; min-height: 40px; }
.kb-card { position: relative; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--mark); border-radius: 6px; padding: 9px 10px; cursor: pointer; }
.kb-card:hover { border-color: var(--line2); border-left-color: var(--mark); }
.kb-card.sel { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.kb-card.match { outline: 2.5px solid #eda100; outline-offset: 2px; }
.kb-card.dragging { opacity: .35; }
.kb-t { font-weight: 600; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.kb-d { font-size: 12.5px; color: var(--ink2); margin-top: 3px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: var(--kb-lines); -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.kb-o { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-top: 5px; }
.hview.editing .kb-t, .hview.editing .kb-d { cursor: text; }
.hview.editing .kb-t:hover, .hview.editing .kb-d:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.kb-card.saving::after { content: ''; position: absolute; top: 7px; right: 7px; width: 10px; height: 10px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.kb-add { margin: 0 10px 10px; border: 0; background: none; text-align: left; color: var(--accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 2px; }
.kb-add:hover { text-decoration: underline; }
.kb-drop { height: 3px; border-radius: 2px; background: var(--accent); margin: -2px 0; }
.kb-ghost { position: fixed; z-index: 300; pointer-events: none; box-shadow: 0 10px 28px rgba(0,0,0,.2); opacity: .95; }
body.clean .kb-add { display: none; }
