/* The Toolbox and the Toolbox Manager (Cad-Toolbox-Plan.md). ISA-101: calm grey normal state; colour only for exceptions (changed amber,
   conflict and broken red); every state also has its symbol and words (⊘ hidden, ◌ not built, ✎ changed, ⚠ conflict, ✖ broken). */

/* ---------------- the Toolbox: tab groups, the tab rail, groups, tools; list or icons ---------------- */
.tbx { display: flex; flex-direction: column; height: 100%; min-height: 0; font-size: 12px; }
.tbx.preview { height: auto; max-height: 100%; border: 1px solid var(--border); background: var(--panel); }
.tbx-top { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border-bottom: 1px solid var(--border-soft); }
.tbx-groups { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.tbx-group { padding: 1px 8px; background: transparent; border-color: transparent; min-height: 24px; }
.tbx-group.sel { background: var(--select); border-color: var(--accent); color: #fff; }
.tbx-viewbtn { padding: 0 6px; min-height: 24px; min-width: 24px; }
.tbx-search { margin: 4px; }
.tbx .cur-layer { display: flex; align-items: center; gap: 4px; padding: 0 4px 4px; }
.tbx .cur-layer select { flex: 1; }
.tbx-caption { color: var(--text-dim); font-size: 11px; }
.tbx-body { display: flex; flex: 1; min-height: 0; }
.tbx-rail { display: flex; flex-direction: column; gap: 1px; padding: 2px; border-right: 1px solid var(--border-soft); overflow-y: auto; }
.tbx-tab { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; border-color: transparent; }
.tbx-tab.sel { background: var(--select); border-color: var(--accent); }
.tbx-tab.dim { opacity: .45; }
.tbx-content { flex: 1; overflow-y: auto; min-width: 0; }
.tbx-tabname { padding: 4px 8px 2px; font-weight: 600; }
.tbx-grphead { display: block; width: 100%; text-align: left; background: transparent; border: none; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; padding: 4px 6px 2px; }
.tbx-item { min-height: 24px; }
.tbx-item .ico, .tbx-mini .ico, .tbx-tab .ico, .tbm .ico { width: 16px; height: 16px; flex: none; }
.ico.letter { display: inline-flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; border: 1px solid currentColor; border-radius: 2px; line-height: 1; letter-spacing: -.3px; }
.tbx-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbx-where { color: var(--text-dim); font-size: 10px; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-btn.off { opacity: .5; cursor: default; }
.tool-btn.unbuilt .tbx-label { font-style: italic; }
.tool-btn.ghost { opacity: .35; text-decoration: line-through; }
.tbx.icons .tbx-items { display: flex; flex-wrap: wrap; gap: 2px; padding: 2px 6px; }
.tbx.icons .tbx-item { width: 28px; height: 28px; margin: 0; padding: 0; justify-content: center; }
.tbx.icons .tbx-item .tbx-label, .tbx.icons .tbx-item .alias, .tbx.icons .tbx-item .tbx-where { display: none; }
.tbx-recent { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 6px; border-top: 1px solid var(--border-soft); margin-top: 4px; }
.tbx-mini { width: 26px; height: 26px; padding: 0; display: inline-flex; align-items: center; justify-content: center; background: transparent; border-color: transparent; }
.tbx-mini.on { background: #1f5fa8; color: #fff; }
.tbx-mini.off { opacity: .5; }
.tbx-empty { padding: 12px; }
.tbx-menu { position: absolute; z-index: 50; right: 8px; top: 60px; }
.tbx-save label { display: block; margin: 3px 0; }
.tb.gear { font-size: 13px; }
.gear-run, .gear-quick { display: none; }

/* ---------------- the Toolbox Manager: command bar, pages, work area · inspector · live preview, status line ---------------- */
.tbm { --tbm-preview: 320px; display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--panel); container-type: inline-size; outline: none; position: relative; }
.tbm-bar { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-bottom: 1px solid var(--border); flex-wrap: wrap; position: relative; }
.tbm-bar .spacer, .tbm-status .spacer, .tbm-ibtns .spacer { flex: 1; }
.tbm-find { min-width: 220px; text-align: left; color: var(--text-dim); }
.tbm kbd { font-size: 10px; border: 1px solid var(--border); border-radius: 2px; padding: 0 3px; color: var(--text-dim); margin-left: 6px; }
.tbm-saved { color: var(--ok); font-size: 11px; }
.tbm-link { background: transparent; border: none; color: #8ec1ff; padding: 0 4px; text-decoration: underline; }
.tbm-pages { display: flex; gap: 2px; padding: 4px 6px 0; border-bottom: 1px solid var(--border); }
.tbm-pages button { border-bottom: none; border-radius: 3px 3px 0 0; background: transparent; min-height: 24px; }
.tbm-pages button.sel { background: var(--bg); border-color: var(--accent); }
.tbm-main { display: grid; grid-template-columns: minmax(0, 1fr) 5px var(--tbm-preview); flex: 1; min-height: 0; }
.tbm-main.folded { grid-template-columns: minmax(0, 1fr) 5px 90px; }
.tbm-work { min-width: 0; min-height: 0; display: flex; }
.tbm-split { cursor: col-resize; background: var(--border-soft); }
.tbm-split:focus { background: var(--accent); }
.tbm-preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-left: 1px solid var(--border); }
.tbm-ph { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px; font-size: 11px; border-bottom: 1px solid var(--border-soft); }
.tbm-ph input[type=number] { width: 56px; }
.tbm-pv { flex: 1; overflow: auto; padding: 6px; }
.tbm-status { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-top: 1px solid var(--border); font-size: 11px; min-height: 24px; flex-wrap: wrap; }
.tbm-legend span { margin-left: 6px; }
.tbm-sugg { background: #2b3440; border: 1px solid #3c4b5e; border-radius: 3px; padding: 1px 6px; }
.st-changed { color: #e8b04a; }
.st-hidden, .st-unbuilt { color: var(--text-dim); }
.st-warn, .st-broken { color: var(--danger); }
.st-ok { color: var(--ok); }
.st-here { color: var(--ok); font-size: 11px; }
.tbm-page { display: grid; grid-template-columns: minmax(260px, 1.1fr) minmax(260px, 1fr); flex: 1; min-height: 0; min-width: 0; }
.tbm-p4 { grid-template-columns: minmax(0, 1.6fr) minmax(260px, .9fr); }
.tbm-left { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border-soft); }
.tbm-filters { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; align-items: center; border-bottom: 1px solid var(--border-soft); position: relative; }
.tbm-filters input[type=search] { flex: 1; min-width: 140px; }
.tbm-chips { display: flex; flex-wrap: wrap; gap: 3px; }
.chip { font-size: 11px; padding: 0 6px; border-radius: 10px; background: transparent; min-height: 24px; }
.chip.on { background: var(--select); border-color: var(--accent); }
.chip .n { color: var(--text-dim); margin-left: 3px; }
.tbm-tree { flex: 1; overflow: auto; outline: none; padding: 2px 0; }
.tbm-row { display: flex; align-items: center; gap: 4px; height: 24px; padding-right: 6px; cursor: default; white-space: nowrap; }
.tbm-row.d0 { padding-left: 2px; font-weight: 600; }
.tbm-row.d1 { padding-left: 16px; }
.tbm-row.d2 { padding-left: 30px; }
.tbm-row.d3 { padding-left: 50px; }
.tbm-row:hover { background: var(--hover); }
.tbm-row.sel { background: var(--select); }
.tbm-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.tbm-row.hid .tbm-label { color: var(--text-dim); text-decoration: line-through; }
.tbm-row.dim { opacity: .55; }
.tbm-row.unbuilt .tbm-label { color: var(--text-dim); }
.tbm .hint { color: var(--text-dim); font-size: 10px; }
.tbm-row .alias { margin-left: auto; color: var(--text-dim); font-size: 11px; }
.tbm-row.drop-before { box-shadow: inset 0 2px 0 #4a90e2; }
.tbm-row.drop-after { box-shadow: inset 0 -2px 0 #4a90e2; }
.tbm-row.drop-into { outline: 2px solid #4a90e2; outline-offset: -2px; }
.tw { width: 16px; padding: 0; background: transparent; border: none; color: var(--text-dim); }
.tbm-label { overflow: hidden; text-overflow: ellipsis; }
.tbm-rename { height: 20px; flex: 1; }
.tbm-bulk, .tbm-actions, .tbm-ibtns, .tbm-io { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px; border-top: 1px solid var(--border-soft); }
.tbm-bulk { background: #2b3440; }
.tbm-inspector { overflow: auto; padding: 8px; min-width: 0; outline: none; }
.tbm-inspector h3 { margin: 0 0 8px; font-size: 14px; }
.tbm-insp { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 8px; align-items: center; }
.tbm-insp > label { color: var(--text-dim); }
.tbm-chipsrow { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.tbm-addalias { width: 70px; }
.tbm-x { background: transparent; border: none; color: var(--text-dim); padding: 0 3px; min-width: 20px; }
.tbm-places { display: flex; flex-direction: column; gap: 2px; }
.tbm-places a, .tbm-in a, .tbm-check a { color: #8ec1ff; }
.tbm-more div { margin: 2px 0; }
.tbm-explain { margin-top: 8px; }
.tbm-explain ul { margin: 4px 0; padding-left: 18px; }
.tbm-ctx { position: fixed; z-index: 60; }
.tbm-pmenu, .tbm-hmenu, .tbm-smenu { position: absolute; z-index: 60; top: 34px; }
.tbm-hmenu { left: 230px; max-height: 360px; overflow: auto; }
.tbm-smenu { right: 8px; display: flex; flex-direction: column; gap: 6px; padding: 8px; min-width: 260px; }
.tbm-smenu label { display: flex; align-items: center; gap: 6px; }
.tbm-smenu input[type=number] { width: 50px; }
.tbm-filebtn { position: relative; overflow: hidden; display: inline-block; cursor: pointer; padding: 2px 8px; border: 1px solid var(--border); border-radius: 2px; background: var(--panel-2); }
.tbm-filebtn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
button.danger { border-color: #8a3030; }
.tbm-finder { position: fixed; z-index: 80; left: 50%; top: 80px; transform: translateX(-50%); width: min(640px, 90vw); background: var(--panel-2); border: 1px solid var(--accent); box-shadow: 0 8px 30px #000a; }
.tbm-finder input { width: 100%; padding: 6px 8px; font-size: 14px; border: none; border-bottom: 1px solid var(--border); }
.tbm-hits { max-height: 50vh; overflow: auto; }
.tbm-hitkind { padding: 4px 8px 0; font-size: 10px; text-transform: uppercase; color: var(--text-dim); }
.tbm-hit { display: flex; justify-content: space-between; gap: 8px; padding: 3px 12px; cursor: pointer; }
.tbm-hit.sel, .tbm-hit:hover { background: var(--select); }
.tbm-tour { position: absolute; z-index: 70; right: 20px; bottom: 40px; width: 340px; background: var(--panel-2); border: 1px solid var(--accent); padding: 10px 12px; box-shadow: 0 8px 30px #000a; }
.tbm-tour h3 { margin: 0 0 6px; }
.tbm-picker .tbm-pickgrid { display: grid; grid-template-columns: 90px 1fr; gap: 6px; align-items: center; margin: 8px 0; }
.tbm-picker select { min-width: 200px; }
.tbm-pickname { display: flex; gap: 4px; align-items: center; margin: 6px 0; }
.tbm-iconsgrid { display: grid; grid-template-columns: repeat(10, 32px); gap: 4px; max-height: 50vh; overflow: auto; margin: 8px 0; }
.tbm-iconsgrid button { width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; }
.tbm-compare ul { max-height: 50vh; overflow: auto; }

/* page 2: the commands grid */
.tbm-grid { flex: 1; overflow: auto; outline: none; }
.tbm-grow { display: grid; grid-template-columns: var(--cols); gap: 6px; align-items: center; min-height: 24px; padding: 0 6px; border-bottom: 1px solid #ffffff0d; white-space: nowrap; }
.tbm-grow > div { overflow: hidden; text-overflow: ellipsis; }
.tbm-grow.sel { background: var(--select); }
.tbm-grow:hover:not(.tbm-ghead) { background: var(--hover); }
.tbm-grow.unbuilt { color: var(--text-dim); }
.tbm-ghead { position: sticky; top: 0; z-index: 2; background: var(--panel-2); font-weight: 600; }
.tbm-gh { cursor: pointer; user-select: none; }
.tbm-in { display: flex; gap: 6px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 11px; }
.tbm-cols { position: absolute; z-index: 60; right: 4px; top: 30px; padding: 6px; display: flex; flex-direction: column; gap: 3px; }
.tbm-check { display: flex; flex-direction: column; gap: 2px; font-size: 11px; }
.tbm-import { margin-top: 8px; border: 1px solid var(--border); padding: 6px; }
.tbm-implist { max-height: 200px; overflow: auto; font-size: 11px; }
.tbm-implist .imp-conflict { color: var(--danger); }
.tbm-implist .imp-replace { color: #e8b04a; }
.tbm-implist .imp-same { color: var(--text-dim); }

/* page 3: custom tools */
.tbm-list { flex: 1; overflow: auto; }
.tbm-lrow { display: flex; align-items: center; gap: 6px; padding: 3px 8px; cursor: default; min-height: 24px; }
.tbm-lrow.sel { background: var(--select); }
.tbm-lrow .alias { margin-left: auto; color: var(--text-dim); }
.tbm-steps { display: flex; flex-direction: column; gap: 3px; }
.tbm-step { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; background: var(--panel-2); }
.tbm-step.first { background: transparent; }
.tbm-step.dragging { opacity: .5; }
.tbm-step input { flex: 0 0 140px; }
.tbm-grip { cursor: grab; color: var(--text-dim); }
.tbm-pick { color: #8ec1ff; flex: 0 0 140px; }
.tbm-stepadd { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.tbm-stepadd input { flex: 1; min-width: 140px; }
.tbm-short { width: 70px; }
button.rec { background: #8a3030; }

/* page 4: the states matrix */
.tbm-matrixwrap { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border-soft); }
.tbm-mbar { display: flex; gap: 10px; align-items: center; padding: 4px 6px; border-bottom: 1px solid var(--border-soft); }
.tbm-matrix { display: grid; overflow: auto; flex: 1; font-size: 11px; user-select: none; align-content: start; }
.tbm-matrix .mh { position: sticky; top: 0; z-index: 2; background: var(--panel-2); padding: 3px 4px; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 96px; text-align: left; border-bottom: 1px solid var(--border); }
.tbm-matrix .mh.corner { writing-mode: horizontal-tb; transform: none; left: 0; z-index: 3; }
.tbm-matrix .mh.grp { font-weight: 700; color: #cfe3ff; }
.tbm-matrix .mr { position: sticky; left: 0; z-index: 1; background: var(--panel); padding: 3px 6px; border-bottom: 1px solid #ffffff0d; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbm-matrix .mr.sel { background: var(--select); }
.tbm-matrix .mc { padding: 3px 2px; text-align: center; border-bottom: 1px solid #ffffff0d; border-left: 1px solid #ffffff08; cursor: pointer; }
.tbm-matrix .mc:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.tbm-matrix .mc.unset { color: #ffffff40; }
.tbm-matrix .mc.unset.effhid { color: #ffffff30; font-style: italic; }
.tbm-matrix .mc.show { color: var(--text); }
.tbm-matrix .mc.hide { color: #e8b04a; }

/* narrow windows: the preview folds into its button below 1000 px; the inspector goes under the work area below 700 px */
@container (max-width: 1000px) {
    .tbm-main { grid-template-columns: minmax(0, 1fr) 5px 90px; }
    .tbm-main .tbm-pv { display: none; }
}
@container (max-width: 700px) {
    .tbm-page { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    .tbm *, .tbx * { transition: none !important; animation: none !important; }
}
