/* FORMWORK — the customizable project workspace. Identity per the blueprint:
   cast-concrete ground, steel ink, safety-orange accent, mono labels.
   UI STANDARD: all type in rem (resolution-free — browser zoom and user font
   settings scale everything), fluid widths via clamp(), ＋/− expander boxes,
   accent = action, danger = destructive only. */
:root{
  --ground:#ECEBE7; --panel:#FAFAF8; --panel2:#F3F2EE;
  --ink:#1F2833; --muted:#5C6670; --line:#C9C7C0; --line2:#DDDBD5;
  --accent:#D95510; --accent-ink:#FFFFFF; --danger:#B3261E;
  --chip:#E4E2DC; --computed:#6E7883;
}
@media (prefers-color-scheme: dark){
  :root{
    --ground:#14171B; --panel:#1D2127; --panel2:#22262D;
    --ink:#E8E6E0; --muted:#9AA1A9; --line:#3A4049; --line2:#2C313A;
    --accent:#FF7A29; --accent-ink:#1A1408; --danger:#E5766F;
    --chip:#2B3038; --computed:#87919C;
  }
}
*{box-sizing:border-box}
html,body{height:100%;overflow:hidden}
body{margin:0;background:var(--ground);color:var(--ink);
  font-family:"Segoe UI",system-ui,sans-serif;font-size:.875rem;line-height:1.45}
button{font:inherit;cursor:pointer}
input,select,textarea{font:inherit;color:var(--ink);background:var(--panel);
  border:1px solid var(--line);border-radius:4px;padding:.4rem .5rem;width:100%}
input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}

#app{display:grid;grid-template-columns:var(--sidew, clamp(13rem,18vw,17.5rem)) 6px 1fr;height:100dvh}
#side-grip{cursor:col-resize;background:transparent;margin-left:-3px;z-index:5}
#side-grip:hover,#side-grip.dragging{background:var(--accent);opacity:.4}

/* ── sidebar ── */
#sidebar{background:var(--panel);border-right:1px solid var(--line);
  padding:1rem .875rem;display:flex;flex-direction:column;gap:.75rem;overflow-y:auto}
.brand{font-size:1.375rem;font-weight:800;letter-spacing:-.02em}
.brand span{color:var(--accent)}
.mono-label{font-family:Consolas,ui-monospace,monospace;font-size:.66rem;
  letter-spacing:.14em;text-transform:uppercase;color:var(--muted)}
.project-row{display:flex;flex-direction:column;gap:.25rem}
#modules,#templates,#items{display:flex;flex-direction:column;gap:.25rem}
.module{display:flex;align-items:center;gap:.5rem;padding:.45rem .625rem;border-radius:5px;
  border:1px solid transparent;background:none;color:var(--ink);text-align:left;width:100%;
  cursor:pointer;min-height:1.9rem}
.module:hover{background:var(--panel2)}
.module.on{background:var(--panel2);border-color:var(--accent);
  box-shadow:inset 3px 0 0 var(--accent)}
/* While a read is running, the item you picked pulses its accent bar — the
   selection says WHICH one, this says it is still working on it. Scoped to the
   selected module so the whole tree does not throb. */
body.busy .module.on{animation:mod-working 1.1s ease-in-out infinite}
@keyframes mod-working{
  0%,100%{box-shadow:inset 3px 0 0 var(--accent)}
  50%    {box-shadow:inset 3px 0 0 color-mix(in srgb,var(--accent) 30%,transparent)}
}
@media (prefers-reduced-motion: reduce){
  body.busy .module.on{animation:none}
}
.module .ico{width:1.25rem;text-align:center}
.module .cnt{margin-left:auto;color:var(--muted);font-size:.75rem}
.module.tpl{opacity:.65;font-style:italic}
#side-tabs{display:flex;gap:2px;background:var(--panel2);border:1px solid var(--line);
  border-radius:6px;padding:2px}
.side-tab{flex:1;padding:.4rem;border:0;background:none;color:var(--muted);
  border-radius:4px;font-weight:600}
.side-tab.on{background:var(--panel);color:var(--ink);box-shadow:0 1px 3px rgba(0,0,0,.15)}
#tab-project,#tab-library{display:flex;flex-direction:column;gap:.75rem;flex:1;min-height:0}
#tab-project[hidden],#tab-library[hidden]{display:none}
.tab-foot{margin-top:auto;display:flex;flex-direction:column;gap:.5rem}

/* expansion: the ＋/− box (tree-view idiom), not a caret glyph */
.caret{flex:none;width:.95rem;height:.95rem;display:inline-flex;align-items:center;
  justify-content:center;font-size:.7rem;line-height:1;color:var(--muted);
  border:1px solid var(--line);border-radius:2px;background:var(--panel2);
  cursor:pointer;user-select:none;font-family:Consolas,ui-monospace,monospace}
.caret:hover{color:var(--accent);border-color:var(--accent)}
.caret.none{visibility:hidden;cursor:default}

.row-menu{margin-left:auto;background:none;border:0;color:var(--muted);
  border-radius:4px;padding:0 .375rem;visibility:hidden;font-weight:700;min-width:1.4rem}
.module:hover .row-menu{visibility:visible}
.row-menu:hover{color:var(--accent)}
#ctx-menu{position:fixed;z-index:50;min-width:11.5rem;display:flex;flex-direction:column;
  background:var(--panel);border:1px solid var(--line);border-radius:6px;
  box-shadow:0 8px 24px rgba(0,0,0,.18);padding:.25rem;gap:1px}
#ctx-menu button{background:none;border:0;color:var(--ink);text-align:left;
  padding:.45rem .625rem;border-radius:4px;font-size:.84rem}
#ctx-menu button:hover{background:var(--panel2)}
#ctx-menu button.danger{color:var(--danger)}

/* ── buttons ── */
.btn{background:var(--accent);color:var(--accent-ink);border:0;border-radius:4px;
  padding:.45rem .875rem;font-weight:600;min-height:2rem}
.btn.ghost{background:none;color:var(--ink);border:1px solid var(--line)}
.btn.danger{background:var(--danger);color:#fff}
.btn.wide{width:100%}
.btn:disabled{opacity:.5;cursor:default}

/* ── main / grid ── */
/* min-height:0 is load-bearing, not tidiness. A flex item defaults to
   min-height:auto and refuses to shrink below its content, so without it #main
   grows to fit every row, #grid-wrap's overflow:auto never engages, and the
   PAGE scrolls instead of the grid — taking the sidebar out of view and leaving
   a blank column (UI-9: scrolling inside the grid, never on the page body).
   min-width:0 was already here: someone hit the horizontal half of this same
   bug. The vertical half only shows once a grid is long enough. */
#main{display:flex;flex-direction:column;min-width:0;min-height:0}
#table-head{display:flex;align-items:center;gap:.875rem;padding:.875rem 1.25rem;
  border-bottom:1px solid var(--line);flex-wrap:wrap}
#table-head h1{font-size:1.25rem;margin:0;font-weight:700}
#table-head .btn{margin-left:auto}
/* Search sits between the count and the actions, and takes the slack — so the
   buttons stay right-aligned and the field grows with the window rather than
   being a fixed stub on a wide screen. */
#grid-search{flex:1 1 12rem;max-width:26rem;min-width:8rem;margin-left:auto}
#table-head #grid-search ~ .btn{margin-left:0}
#grid-search[hidden]{display:none}
/* Pager arrows live inside the count chip, so the header keeps one cluster
   rather than gaining a second row of controls. */
#table-count{display:inline-flex;align-items:center;gap:.25rem}
.pg{background:none;border:1px solid var(--line);color:var(--ink);border-radius:4px;
  min-width:1.4rem;height:1.4rem;line-height:1;padding:0;font-size:.9rem}
.pg:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
.pg:disabled{opacity:.35;cursor:default}
#grid-wrap{overflow:auto;flex:1;padding:0 1.25rem 1.25rem}
#grid{border-collapse:collapse;width:100%;background:var(--panel);
  border:1px solid var(--line);font-size:.84rem;margin-top:1rem}
#grid th{font-family:Consolas,ui-monospace,monospace;font-size:.66rem;
  letter-spacing:.12em;text-transform:uppercase;color:var(--muted);
  background:var(--panel2);text-align:left;padding:.5rem .75rem;
  border-bottom:1px solid var(--line);position:sticky;top:0;white-space:nowrap;cursor:pointer}
#grid th.drag-over{box-shadow:inset 3px 0 0 var(--accent)}
#grid td{padding:.5rem .75rem;border-bottom:1px solid var(--line2);white-space:nowrap;
  max-width:21rem;overflow:hidden;text-overflow:ellipsis}
#grid tbody tr:hover{background:var(--panel2);cursor:pointer}
#grid td.num{text-align:right;font-variant-numeric:tabular-nums}
#grid td.computed{color:var(--computed);font-style:italic}
.th-del,.th-edit{background:none;border:0;color:var(--muted);margin-left:.25rem;
  padding:0 .125rem;visibility:hidden}
th:hover .th-del,th:hover .th-edit{visibility:visible}
.th-del:hover{color:var(--danger)}
.th-edit:hover{color:var(--accent)}
/* The sort caret is always visible on the sorted column — it is state, not an
   affordance, so hover must not be the only way to know it is there (UI-3). */
.th-sort{margin-left:.3rem;color:var(--accent);font-size:.7rem}
#empty-state{padding:3.75rem 1.25rem;color:var(--muted);text-align:center}

/* ── module entry point: child items with quick entry ── */
#child-launch{display:flex;flex-direction:column;gap:.375rem;padding:.75rem 1.25rem 0}
.cl-item{display:flex;align-items:center;gap:.625rem;background:var(--panel);
  border:1px solid var(--line);border-radius:6px;padding:.5rem .75rem}
.cl-open{background:none;border:0;color:var(--ink);font-weight:600;font-size:.9rem;text-align:left}
.cl-open:hover{color:var(--accent)}
.cl-item .mono-label{margin-left:auto}
.cl-new{padding:.25rem .625rem;min-height:1.6rem}

/* ── view tabs + renderers ── */
#view-bar{display:flex;gap:.5rem;align-items:center;padding:.5rem 1.25rem 0}
#view-bar[hidden]{display:none}
#view-bar .btn{min-height:1.75rem;padding:.3rem .625rem}
#view-tabs{display:flex;gap:.25rem;flex-wrap:wrap;flex:1}
.view-tab{background:none;border:1px solid transparent;color:var(--muted);
  border-radius:5px 5px 0 0;padding:.35rem .75rem;font-size:.84rem;display:flex;gap:.375rem;align-items:center}
.view-tab:hover{background:var(--panel2)}
.view-tab.on{background:var(--panel);border-color:var(--line);border-bottom-color:var(--panel);
  color:var(--ink);font-weight:600}
.view-tab.add{color:var(--accent)}
.view-x{color:var(--muted);visibility:hidden;padding:0 .125rem}
.view-tab.on .view-x{visibility:visible}
.view-x:hover{color:var(--danger)}
#view-wrap{overflow:auto;flex:1;padding:1rem 1.25rem}
.view-empty{color:var(--muted);padding:1rem 0;font-style:italic}
/* timeline */
.tl-head{display:flex;justify-content:space-between;font-family:Consolas,ui-monospace,monospace;
  font-size:.66rem;letter-spacing:.1em;color:var(--muted);padding:.125rem .75rem .375rem 13rem;
  border-bottom:1px solid var(--line2)}
.tl-today{position:absolute;top:0;bottom:0;width:2px;background:var(--accent);opacity:.6;
  transform:translateX(-1px);pointer-events:none}
/* fit-content lets the panel enclose rows wider than the viewport
   (many columns); min-width keeps it full-bleed when they are not */
.tl-body{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:.5rem 0;
  width:fit-content;min-width:100%}
.tl-section{font-family:Consolas,ui-monospace,monospace;font-size:.66rem;letter-spacing:.12em;
  text-transform:uppercase;color:var(--muted);padding:.5rem .75rem .25rem;border-top:1px solid var(--line2)}
.tl-section:first-child{border-top:0}
.tl-cols-head{padding:.25rem .75rem;border-bottom:1px solid var(--line2)}
.tl-wbs{font-size:.75rem;font-weight:700;color:var(--ink);padding:.4rem .75rem .15rem;
  background:var(--panel2);border-top:1px solid var(--line2)}
.tl-col-h{font-family:Consolas,ui-monospace,monospace;font-size:.62rem;letter-spacing:.1em;
  text-transform:uppercase;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding-right:.5rem}
.tl-cell{font-size:.78rem;color:var(--muted);overflow:hidden;text-overflow:ellipsis;
  white-space:nowrap;padding-right:.5rem}
.tl-row[style*="grid"] .tl-label{width:auto;min-width:0}
.tl-row{display:flex;align-items:center;gap:.5rem;padding:.2rem .75rem;cursor:pointer}
.tl-row:hover{background:var(--panel2)}
.tl-label{width:12rem;flex:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.8125rem}
.tl-track{position:relative;flex:1;height:.9rem;background:var(--panel2);border-radius:3px}
.tl-bar{position:absolute;top:0;bottom:0;background:var(--accent);border-radius:3px;min-width:3px}
.tl-milestone{position:absolute;top:50%;width:.55rem;height:.55rem;background:var(--accent);
  transform:translate(-50%,-50%) rotate(45deg)}
/* cards */
.cards-flat{display:grid;grid-template-columns:repeat(auto-fill,minmax(16rem,1fr));gap:.75rem}
.cards-board{display:flex;gap:.75rem;align-items:flex-start}
.cards-col{flex:1;min-width:14rem;background:var(--panel2);border:1px solid var(--line2);
  border-radius:8px;padding:.5rem;display:flex;flex-direction:column;gap:.5rem}
.cards-col-head{font-size:.78rem;color:var(--muted);display:flex;align-items:center;gap:.375rem;padding:.125rem .25rem}
.card{background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:.6rem .75rem;cursor:pointer}
.card:hover{border-color:var(--accent)}
.card-title{font-weight:600;margin-bottom:.25rem}
.card-line{display:flex;justify-content:space-between;gap:.5rem;font-size:.78rem;color:var(--muted)}
.card-line b{color:var(--ink);font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* ── chips ── */
.chip{display:inline-block;background:var(--chip);border-radius:10px;
  padding:.06rem .55rem;font-size:.75rem;margin:0 .1875rem .125rem 0;white-space:nowrap}
.chip.link{border:1px solid var(--accent);color:var(--accent);background:transparent}
.chip.opt{color:#fff}
.opt-x{background:none;border:0;color:inherit;padding:0 0 0 .25rem;opacity:.7}
.opt-x:hover{opacity:1}
#fd-cur-opts{display:flex;flex-wrap:wrap;gap:.25rem;margin-bottom:.5rem}
#fd-expr-fields{display:flex;flex-wrap:wrap;gap:.25rem;margin-top:.375rem}
.expr-chip{border:1px solid var(--line);cursor:pointer;color:var(--ink)}
.expr-chip:hover{border-color:var(--accent);color:var(--accent)}

.hist{width:100%}
.hist-row{font-size:.75rem;color:var(--muted);padding:.25rem 0;border-top:1px solid var(--line2)}
.hist-date{width:auto;padding:.1rem .3rem;font-size:.7rem;display:inline-block}
.hist-snap{background:var(--panel2);border:1px solid var(--line2);border-radius:6px;
  padding:.5rem .625rem;margin:.375rem 0;display:flex;flex-direction:column;gap:.2rem}
/* compare view */
.cmp-head{font-size:.84rem;color:var(--muted);padding:.25rem 0 .625rem;display:flex;
  gap:.375rem;align-items:center;flex-wrap:wrap}
.cmp-head select{width:auto;padding:.2rem .4rem}
.cmp-chg{color:var(--accent);font-weight:600}
.cmp-row{display:flex;gap:.75rem;padding:.375rem .75rem;border-top:1px solid var(--line2);
  background:var(--panel)}
.cmp-key{flex:none;width:11rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;font-size:.8125rem}
.cmp-diffs{display:flex;flex-wrap:wrap;gap:.375rem .75rem;font-size:.78rem}
.cmp-d s{color:var(--muted)}
.cmp-d b{color:var(--accent)}
.cmp-add{color:var(--good, #2E9E4F);font-weight:600}
.cmp-del{color:var(--danger);font-weight:600}

/* ── dialog: the standard centered modal for forms and entry details ── */
/* display:flex below would override the hidden attribute's display:none —
   restate it, or the dialog can never close (the original "panel is dead"
   bug) */
#panel[hidden],#backdrop[hidden]{display:none!important}
#backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:60}
#panel{position:fixed;z-index:61;top:50%;left:50%;transform:translate(-50%,-50%);
  width:min(92vw,30rem);max-height:85dvh;background:var(--panel);
  border:1px solid var(--line);border-radius:10px;
  box-shadow:0 20px 60px rgba(0,0,0,.35);display:flex;flex-direction:column}
#panel header{display:flex;align-items:center;justify-content:space-between;
  padding:.875rem 1rem;border-bottom:1px solid var(--line)}
#panel h2{margin:0;font-size:1rem}
#panel-body{overflow-y:auto}
#panel-form{padding:.875rem 1rem;display:flex;flex-direction:column;gap:.75rem}
#panel-form .field label{display:block;font-size:.78rem;color:var(--muted);margin-bottom:.1875rem}
#panel-form .field label .req{color:var(--danger)}
#panel-form .computed-val{color:var(--computed);font-style:italic;padding:.375rem 0}
#panel-error{margin:.625rem 1rem 0;padding:.55rem .75rem;background:color-mix(in srgb,var(--danger) 12%,transparent);
  border:1px solid var(--danger);border-radius:4px;color:var(--danger);font-size:.8125rem}
#conn-label{padding:.375rem 1rem 0}
#panel-backlinks{padding:.375rem 1rem;display:flex;flex-wrap:wrap;gap:.25rem}
#panel footer{padding:.75rem 1rem;border-top:1px solid var(--line);
  display:flex;gap:.5rem;align-items:center}
#panel footer .spacer{flex:1}
.link-pick{display:flex;flex-direction:column;gap:.25rem;max-height:9.5rem;overflow-y:auto;
  border:1px solid var(--line);border-radius:4px;padding:.375rem .5rem;background:var(--panel)}
.link-pick label{display:flex;gap:.4375rem;align-items:center;font-size:.8125rem;color:var(--ink)!important;margin:0!important}
.link-pick input{width:auto}
/* rich link options: primary field + muted context line */
.lp-rich label{align-items:flex-start;padding:.125rem 0}
.lp-rich input{margin-top:.2rem}
.lp-txt{display:flex;flex-direction:column;min-width:0}
.lp-main{font-size:.8125rem}
.lp-sum{font-size:.7rem;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.lp-filter{margin-bottom:.25rem}
#panel.wide{width:min(94vw,44rem)}
#panel.wide .link-pick{max-height:13rem}
.lib-row{display:flex;align-items:center;gap:.375rem;padding:.1875rem 0;cursor:pointer}
.lib-row input{width:auto;margin:0}

/* ── busy: a moving bar across the top, plus a cursor ────────────────────────
   A bar rather than a modal spinner, because the app stays usable while a read
   runs — blocking the screen would make a slow read feel like a frozen one. */
#busy-bar{position:fixed;top:0;left:0;right:0;height:2px;z-index:80;
  background:transparent;overflow:hidden;pointer-events:none;opacity:0;
  transition:opacity .15s}
body.busy #busy-bar{opacity:1}
#busy-bar::after{content:"";position:absolute;inset:0;width:35%;
  background:linear-gradient(90deg,transparent,var(--accent),transparent);
  animation:busy-slide 1.05s ease-in-out infinite}
@keyframes busy-slide{0%{transform:translateX(-100%)}100%{transform:translateX(385%)}}
body.busy{cursor:progress}
@media (prefers-reduced-motion: reduce){
  #busy-bar::after{animation:none;width:100%;opacity:.5}
}

#toast{position:fixed;bottom:1.25rem;left:50%;transform:translateX(-50%);z-index:70;
  background:var(--panel);color:var(--ink);border:1px solid var(--line);border-radius:6px;
  padding:.55rem 1rem;font-size:.84rem;box-shadow:0 8px 24px rgba(0,0,0,.25)}

/* narrow screens: the sidebar narrows; the dialog is already an overlay */
@media (max-width: 56rem){
  #app{grid-template-columns:var(--sidew, clamp(11rem,30vw,13rem)) 6px 1fr}
}

/* ── PHONES ────────────────────────────────────────────────────────────────
   Nobody in the field uses a laptop, and until this block the app was
   unusable on a phone: at 375px the three-column grid gave the sidebar 176px
   and left 193px for the entire workspace. Narrowing the sidebar (above) is
   not enough — below this width it has to LEAVE, and come back on demand.

   Deliberately additive. Every rule here is inside the media query, so the
   desktop layout, the drag-to-resize grip and the centred dialog are exactly
   as they were. ── */
#nav-toggle,#nav-scrim{display:none}

@media (max-width: 48rem){
  /* one column: the sidebar is out of the flow entirely, not squeezed */
  #app{grid-template-columns:1fr}
  #side-grip{display:none}          /* drag-to-resize is meaningless here */

  #sidebar{
    position:fixed;top:0;bottom:0;left:0;z-index:62;
    width:min(19rem,84vw);
    transform:translateX(-100%);
    transition:transform .18s ease-out;
    box-shadow:0 0 2.5rem rgba(0,0,0,.4);
  }
  body.nav-open #sidebar{transform:none}
  /* Someone who has asked their device for less motion gets the drawer
     instantly rather than sliding. Also makes the open/closed state testable
     without waiting on an animation clock. */
  @media (prefers-reduced-motion: reduce){
    #sidebar{transition:none}
  }

  #nav-scrim{position:fixed;inset:0;z-index:61;background:rgba(0,0,0,.45)}
  body.nav-open #nav-scrim{display:block}

  /* Top-left because that is where a hamburger is looked for, even though the
     bottom is easier to reach — familiarity beats ergonomics for a control
     people must find before they know the app. */
  #nav-toggle{
    display:flex;align-items:center;justify-content:center;
    position:fixed;top:.5rem;left:.5rem;z-index:63;
    width:2.25rem;height:2.25rem;font-size:1.1rem;
    background:var(--panel);color:var(--ink);
    border:1px solid var(--line);border-radius:6px;
  }
  /* Room for it, so it never sits on top of a title. */
  #table-head,#docs-head{padding-left:3.25rem}

  /* A centred dialog on a phone is a small window inside a small window.
     Full sheet instead — and 100dvh, not vh, so the browser's own chrome
     does not crop the footer buttons out of reach. */
  #panel,#panel.wide{
    top:0;left:0;transform:none;
    width:100vw;max-width:100vw;
    height:100dvh;max-height:100dvh;
    border:0;border-radius:0;
  }
  /* The pickers can breathe now that the sheet is full height. */
  #panel .link-pick,#panel.wide .link-pick{max-height:40dvh}

  /* Tighter gutters: 1.25rem each side of a 375px screen is 20% of it. */
  #grid-wrap{padding:0 .75rem 1rem}
  #table-head{gap:.5rem;padding-top:.625rem;padding-bottom:.625rem}
  #view-bar,#child-launch{padding-left:.75rem;padding-right:.75rem}
}

/* form view: printing shows the sheet alone */
@media print {
  body.printing-form > *:not(#main):not(main) { display: none !important; }
  body.printing-form #sidebar, body.printing-form nav, body.printing-form header,
  body.printing-form #view-wrap > div:first-child { display: none !important; }
  body.printing-form .fm-sheet { border: none !important; max-width: 100% !important; }
}

/* docs: the main pane swaps between tables and the file manager */
[data-docs-hidden] { display: none !important; }
#docs-head{display:flex;flex-direction:column;gap:.5rem;margin-bottom:.75rem}
#docs-title-row{display:flex;align-items:baseline;gap:.75rem;flex-wrap:wrap}
#docs-title{font-size:.95rem;font-weight:700;display:flex;flex-wrap:wrap;column-gap:.35rem;align-items:baseline}
.doc-crumb{color:var(--muted);text-decoration:none;font-weight:600}
.doc-crumb:hover{color:var(--accent)}
.crumb-sep{color:var(--line2);font-weight:400;user-select:none}
#docs-actions{display:flex;gap:.5rem;flex-wrap:wrap;align-items:center;
  padding-bottom:.5rem;border-bottom:1px solid var(--line2)}
#docs-actions .btn{white-space:nowrap}
#docs-selmove{width:auto}
/* grouping levels in the gear */
.sh-group-row{display:flex;gap:.375rem;align-items:center;margin-top:.375rem}
.sh-group-row select{flex:1}
.sh-group-row .btn{padding:.3rem .55rem;min-height:0;line-height:1}
/* nested group bands: deeper levels sit lighter and smaller */
tr.grid-group[data-depth="1"] td{background:var(--panel);font-size:.8rem}
tr.grid-group[data-depth="2"] td{background:transparent;font-size:.78rem;opacity:.85}
tr.grid-group[data-depth="3"] td{background:transparent;font-size:.76rem;opacity:.72}
tr.grid-group td .mono-label{margin-right:.375rem}
tr.grid-group td{cursor:default}
.grp-fold{margin-right:.45rem;vertical-align:middle}
/* upload progress: a live row in the folder listing */
.up-cell{display:flex;align-items:center;gap:.625rem}
.up-track{flex:1;max-width:22rem;height:.5rem;background:var(--panel2);
  border-radius:999px;overflow:hidden;display:inline-block}
.up-fill{display:block;height:100%;width:0;background:var(--accent);
  border-radius:999px;transition:width .15s linear}
.up-stat{white-space:nowrap}
.up-row.err .up-fill{background:var(--danger)}
.up-row.done .up-fill{opacity:.5}
.up-line{display:flex;align-items:center;gap:.625rem;padding:.3rem .25rem}
.up-line > span:first-child{flex:0 0 16rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.up-line .up-cell{flex:1}
#docs-tree .tree-row.sel { background: var(--sel, #e8eefb); border-radius: 6px; }

/* ── file viewer: full overlay; content fills, header floats ── */
#viewer{position:fixed;inset:1.25rem;z-index:60;background:var(--panel);
  border:1px solid var(--line);border-radius:8px;display:flex;flex-direction:column;
  box-shadow:0 12px 48px rgba(0,0,0,.35)}
#viewer[hidden]{display:none}
#viewer-head{display:flex;align-items:center;gap:.75rem;padding:.6rem .9rem;
  border-bottom:1px solid var(--line2)}
#viewer-title{font-weight:700}
#viewer-body{flex:1;min-height:0;overflow:auto;display:flex;
  align-items:center;justify-content:center;background:var(--panel2)}
#viewer-body img{max-width:100%;max-height:100%;object-fit:contain}
#viewer-body iframe,#viewer-body .viewer-fill{width:100%;height:100%;border:0}
#viewer-body video{max-width:100%;max-height:100%}
#viewer-body pre{align-self:stretch;width:100%;margin:0;padding:1rem;overflow:auto;
  font-family:Consolas,ui-monospace,monospace;font-size:.8rem;white-space:pre-wrap}
.viewer-msg{color:var(--muted);text-align:center;padding:2rem}

/* ── docs selection bar ── */
#docs-selbar{display:flex;align-items:center;gap:.5rem;padding:.4rem .9rem;
  border-bottom:1px solid var(--line2);background:var(--panel2)}
#docs-selbar[hidden]{display:none}
.sel-td{width:1.6rem;text-align:center}
.sel-td input{width:auto;cursor:pointer}

/* ── ✏ parameter panel (CAPS loop) docked right inside the viewer ── */
#param-panel{position:absolute;top:3.2rem;right:.75rem;bottom:.75rem;width:20rem;
  background:var(--panel);border:1px solid var(--line);border-radius:8px;
  display:flex;flex-direction:column;box-shadow:0 8px 32px rgba(0,0,0,.3);z-index:5}
#param-panel input{font-size:.8rem;padding:.25rem .4rem}
.pp-group{border-bottom:1px solid var(--line2);padding:.25rem 0 .375rem;margin-bottom:.25rem}
.pp-group summary{cursor:pointer;padding:.25rem 0;user-select:none;font-weight:700}
#grid-selbar{display:flex;gap:.5rem;align-items:center;padding:.3rem .9rem;border-bottom:1px solid var(--line2)}
#grid-selbar[hidden]{display:none}

/* ── SHEET view: spreadsheet-style rapid entry ── */
.sh-wrap{overflow:auto;border:1px solid var(--line);border-radius:6px}
.sh-table{border-collapse:collapse;width:100%;font-size:.8rem}
.sh-table th{position:sticky;top:0;z-index:1;background:var(--panel2);text-align:left;
  padding:.35rem .5rem;border-bottom:1px solid var(--line);white-space:nowrap;font-weight:600}
.sh-table td{padding:0;border-bottom:1px solid var(--line2);border-right:1px solid var(--line2)}
.sh-table td:last-child,.sh-table th:last-child{border-right:0}
.sh-table input,.sh-table select{border:0;border-radius:0;background:transparent;padding:.3rem .5rem;
  width:100%;min-width:7rem}
.sh-table input[type=checkbox]{width:auto;min-width:0;margin:.35rem .5rem}
.sh-table input:focus,.sh-table select:focus{outline:2px solid var(--accent);outline-offset:-2px;
  background:var(--panel)}
.sh-ro{padding:.3rem .5rem;color:var(--computed);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:16rem}
.sh-state{width:1.4rem;text-align:center;color:var(--muted);font-size:.7rem}
.sh-row.dirty .sh-state{color:var(--accent)}
.sh-open{width:1.8rem;text-align:center}
.sh-panel{border:0;background:none;cursor:pointer;color:var(--muted);padding:.2rem .3rem}
.sh-panel:hover{color:var(--ink)}

/* ── PAGE LAYOUT view: a real sheet of paper, measured in mm ── */
.pl-bar{display:flex;gap:.5rem;align-items:center;flex-wrap:wrap;margin-bottom:.5rem}
.pl-tools{display:flex;gap:.5rem;align-items:center;flex-wrap:wrap;margin-bottom:.5rem;
  padding:.4rem .5rem;background:var(--panel2);border:1px solid var(--line2);border-radius:6px}
.pl-tools select,.pl-tools input[type=number],.pl-tools input[type=text]{width:auto}
.pl-props{display:inline-flex;gap:.4rem;align-items:center;padding-left:.5rem;
  border-left:1px solid var(--line)}
.pl-props[hidden]{display:none}
.pl-canvas{overflow:auto;padding:.75rem;background:var(--panel2);border-radius:6px}
.pl-page{position:relative;background:#fff;color:#111;background-size:100% 100%;
  background-repeat:no-repeat;box-shadow:0 2px 14px rgba(0,0,0,.3);margin:0 auto}
.pl-el{position:absolute;overflow:hidden;line-height:1.15;display:flex;align-items:center;gap:.6mm}
.pl-field{border-bottom:0.2mm solid rgba(0,0,0,.25)}
.pl-lab{color:#666;font-size:.75em;white-space:nowrap}
.pl-val{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.pl-el input,.pl-el select{flex:1;min-width:0;border:0;background:transparent;padding:0 .5mm;
  font:inherit;color:inherit;height:100%}
.pl-el input:focus,.pl-el select:focus{outline:1px solid var(--accent)}
.pl-editable{cursor:move;outline:0.2mm dashed rgba(0,0,0,.25)}
.pl-editable.sel{outline:0.4mm solid #d95510}
.pl-grip{position:absolute;right:0;bottom:0;width:4mm;height:4mm;background:#d95510;
  border-top:0.3mm solid #fff;border-left:0.3mm solid #fff;border-radius:1mm 0 0 0;
  cursor:nwse-resize;z-index:6}
.pl-grip::after{content:"";position:absolute;right:0;bottom:0;width:7mm;height:7mm}
.pl-editable:hover .pl-grip{background:#ff7a29}
.pl-actions{position:absolute;right:4mm;bottom:4mm;display:flex;gap:.5rem}

/* printing a layout: the page alone, at its exact size, background included */
@media print {
  body.printing-layout #sidebar, body.printing-layout #table-head, body.printing-layout #view-bar,
  body.printing-layout #child-launch, body.printing-layout .pl-bar, body.printing-layout .pl-tools,
  body.printing-layout .pl-actions, body.printing-layout #grid-selbar { display:none !important }
  body.printing-layout #app{display:block !important}
  body.printing-layout .pl-canvas{overflow:visible !important;padding:0 !important;background:#fff !important}
  body.printing-layout .pl-page{box-shadow:none !important;margin:0 !important;
    -webkit-print-color-adjust:exact;print-color-adjust:exact}
  body.printing-layout .pl-editable{outline:none !important}
}

/* ── SKETCH field: draw a signature, a markup, a site detail ── */
.sketch-box{display:flex;flex-direction:column;gap:.25rem}
.sketch-cv{width:100%;height:var(--sk-h,40mm);background:#fff;border:1px solid var(--line);
  border-radius:4px;touch-action:none;cursor:crosshair;display:block}
.sketch-tools{display:flex;gap:.5rem;align-items:center}
.sketch-tools .btn{padding:.15rem .5rem;font-size:.75rem}
.sk-thumb{height:1.6rem;background:#fff;border-radius:2px}
/* on a page layout the element's own box decides the size — a signature
   strip is small, a sketch panel is large; the field never dictates it */
.pl-sketch{position:absolute;inset:0;gap:0}
.pl-sketch .sketch-cv{height:100%;border:0;border-radius:0;background:transparent}
.pl-sketch .sketch-tools{position:absolute;top:0;right:0;z-index:2;gap:.25rem;
  background:rgba(255,255,255,.82);border-radius:0 0 0 3px;padding:0 .15rem;
  opacity:0;transition:opacity .12s}
.pl-sketch:hover .sketch-tools,.pl-sketch:focus-within .sketch-tools{opacity:1}
.pl-sketch .sketch-tools .btn{padding:0 .3rem;font-size:.65rem;line-height:1.4}
.pl-sketch .sketch-hint{font-size:.6rem}
.pl-sk{width:100%;height:100%;object-fit:contain;object-position:left bottom}
@media print{ .sketch-tools{display:none !important} }

/* ── login ── */
#login{position:fixed;inset:0;z-index:200;display:flex;align-items:center;justify-content:center;
  background:var(--bg)}
#login[hidden]{display:none}
#login-card{width:20rem;padding:1.5rem;border:1px solid var(--line);border-radius:10px;
  background:var(--panel)}
#login-card .field{margin-bottom:.75rem}
#login-err{color:#e66;font-size:.8rem;margin-bottom:.75rem}
#login-err[hidden]{display:none}
.who-chip{font-weight:600;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#who-row .btn{padding:.15rem .45rem}

/* attachment fields: the whole field is a dropzone */
.field[data-kind=file]{border:1px dashed transparent;border-radius:6px;transition:border-color .12s}
.field[data-kind=file].file-over{border-color:var(--accent);background:color-mix(in srgb, var(--accent) 8%, transparent)}
.field[data-kind=file].file-busy{opacity:.6;pointer-events:none}

/* layout elements: wrapped text flows in the box instead of clipping a line */
.pl-el.pl-wrap{white-space:normal}
.pl-el.pl-wrap .pl-val{white-space:pre-wrap;overflow:hidden;text-overflow:clip;align-self:stretch}

/* layout child-lines box: a compact table; file columns render as thumbs */
.pl-lines{overflow:hidden}
.pl-lines-host{width:100%;height:100%;overflow:hidden;align-self:stretch}
.pl-lines-tbl{border-collapse:collapse;width:100%;font-size:inherit;color:inherit}
.pl-lines-tbl th{ text-align:left;border-bottom:0.25mm solid rgba(0,0,0,.5);padding:.4mm 1mm;font-weight:700}
.pl-lines-tbl td{border-bottom:0.15mm solid rgba(0,0,0,.2);padding:.4mm 1mm;vertical-align:top}
.pl-thumb{height:14mm;margin:.4mm .4mm 0 0;object-fit:cover}
