/* The text bench. Loaded only by the text pages, on top of src/ui/style.css,
   whose tokens (--panel, --line, --accent, --radius…) it uses throughout so
   the two kinds of page read as one site. */

/* Two columns, not three: there is no agent panel or operations stack here,
   so the bench takes everything to the right of Browse. */
body[data-scope="text"] main { grid-template-columns: 232px minmax(0, 1fr); }
@media (max-width: 1200px) { body[data-scope="text"] main { grid-template-columns: 208px minmax(0, 1fr); } }
@media (max-width: 860px) { body[data-scope="text"] main { grid-template-columns: 1fr; } }

/* The bench is at least as tall as Browse beside it, and the boxes take up
   whatever height that gives them: the row stretches, the bench fills it, and
   the panes fill the bench. */
body[data-scope="text"] main { align-items: stretch; }
body[data-scope="text"] main > .sidenav { align-self: start; }
.textbench { min-width: 0; display: flex; flex-direction: column; }
.tb { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: calc(100vh - 150px); }
.tb-noscript { padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* --- head --------------------------------------------------------------- */
.tb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 18px; flex-wrap: wrap; }
.tb-pick { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-pick-label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tb-picker {
  font: inherit; font-size: 17px; font-weight: 600; letter-spacing: -.01em; color: var(--text);
  padding: 8px 38px 8px 14px; border: 1px solid var(--line); border-radius: 12px; background-color: var(--panel);
  appearance: none; cursor: pointer; max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235c574e' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
.tb-picker:hover, .tb-picker:focus-visible { border-color: var(--accent); outline: none; }
.tb-promise { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: var(--text-2); }
.tb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kind-text); box-shadow: 0 0 0 4px var(--kind-text-soft); flex: none; }

/* --- options ------------------------------------------------------------ */
.tb-options {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.tb-opt { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }
.tb-opt[hidden] { display: none; }
.tb-opt select, .tb-opt input[type=number], .tb-opt input[type=text] {
  font: inherit; font-size: 13.5px; color: var(--text); padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
.tb-opt input[type=number] { width: 76px; }
.tb-opt select:focus-visible, .tb-opt input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tb-check { cursor: pointer; user-select: none; }
.tb-check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

/* --- panes -------------------------------------------------------------- */
.tb-panes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; flex: 1; }
.tb-panes:not(:has(.tb-in)) { grid-template-columns: minmax(0, 1fr); }
.tb[data-layout="stack"] .tb-out { grid-column: 1 / -1; }
.tb[data-layout="stack"] .tb-panes:not(:has(.tb-in + .tb-in)) .tb-in { grid-column: 1 / -1; }
@media (max-width: 1000px) { .tb-panes { grid-template-columns: minmax(0, 1fr); } }

.tb-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.tb-pane.is-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tb-pane-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--line-soft); background: var(--panel-2);
}
.tb-pane-title { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.tb-pane-tools { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }

.tb-text {
  flex: 1; width: 100%; min-height: 460px; height: auto; resize: vertical;
  border: 0; outline: none; padding: 14px 16px; background: transparent; color: var(--text);
  font: 15px/1.6 "Instrument Sans", system-ui, sans-serif; tab-size: 4;
}
.tb-text.is-mono { font: 13.5px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.tb-text::placeholder, .tb-rich:empty::before { color: var(--muted); }
.tb-text[hidden] { display: none; }
.tb-rich {
  flex: 1; min-height: 460px; height: auto; overflow: auto; padding: 14px 16px; outline: none;
  font: 15px/1.6 "Instrument Sans", system-ui, sans-serif;
}
.tb-rich:empty::before { content: attr(data-placeholder); pointer-events: none; }
.tb-rich img { max-width: 100%; }
.tb-rich table { border-collapse: collapse; }
.tb-rich td, .tb-rich th { border: 1px solid var(--line); padding: 4px 8px; }

.tb-frame { flex: 1; width: 100%; min-height: 460px; height: auto; border: 0; background: #fffdf8; }
.tb-frame[hidden] { display: none; }

.tb-tabs { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.tb-tab { border: 0; background: transparent; padding: 4px 11px; font-size: 13px; color: var(--text-2); border-radius: 7px; }
.tb-tab[aria-selected="true"] { background: var(--text); color: #fff; }

/* A file input: the dropzone, until a file is in. */
.tb-drop {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  margin: 12px; min-height: 420px; padding: 28px; text-align: center; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 14px; color: var(--kind-text);
}
.tb-drop:hover, .tb-drop:focus-visible, .tb-pane.is-over .tb-drop { border-color: var(--accent); background: #fdf9f4; outline: none; }
.tb-drop-main { margin: 8px 0 0; font-size: 17px; font-weight: 600; color: var(--text); }
.tb-drop-sub { margin: 0; font-size: 13.5px; color: var(--text-2); }
.tb-file-name:empty { display: none; }
.tb-file-name {
  margin-top: 14px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--kind-text-soft); color: var(--kind-text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tb-drop.has-file .tb-drop-main::after { content: " - or drop another"; font-weight: 400; color: var(--text-2); }

/* --- buttons ------------------------------------------------------------ */
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px;
  font-size: 13px; color: var(--text-2); background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
}
.tb-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.tb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tb-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tb-pane-foot { padding: 12px; border-top: 1px solid var(--line-soft); background: var(--panel-2); margin-top: auto; }
.tb-actions .tb-btn { padding: 10px 16px; font-size: 14.5px; font-weight: 500; border-radius: 11px; color: var(--text); }
.tb-actions .tb-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tb-actions .tb-primary:hover { background: #e05a1f; border-color: #e05a1f; color: #fff; }

.tb-status { margin: 0; padding: 10px 14px; border-radius: 12px; font-size: 14px; background: var(--panel); border: 1px solid var(--line); color: var(--text-2); }
.tb-status[hidden] { display: none; }
.tb-status[data-kind="error"] { background: #fff1ec; border-color: #f6c7b3; color: #9a3412; }
.tb-status[data-kind="warn"] { background: #fff8e6; border-color: #f2dca0; color: #7c5a0b; }
.tb-status[data-kind="ok"] { background: var(--kind-text-soft); border-color: #c4e2c8; color: #25552c; }
.tb-note, .tb-hint { margin: 0; font-size: 13px; color: var(--muted); }
.tb-empty { margin: 0; padding: 26px 18px; color: var(--muted); font-size: 14px; }

/* --- custom outputs ------------------------------------------------------ */
.tb-custom-out { flex: 1; overflow: auto; padding: 16px; min-height: 460px; max-height: min(84vh, 960px); }
.tb-custom-in { padding: 12px; overflow: auto; }

.tb-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 0; }
.tb-stat { padding: 12px 14px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel-2); }
.tb-stat dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tb-stat dd { margin: 4px 0 0; font-size: 17px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.tb-stat.is-big dd { font-size: 30px; letter-spacing: -.02em; }
.tb-sub { margin: 20px 0 8px; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.tb-freq { margin: 0; padding: 0; list-style: none; columns: 2 180px; column-gap: 18px; counter-reset: f; }
.tb-freq li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 2px; border-bottom: 1px solid var(--line-soft); break-inside: avoid; font-size: 14px; counter-increment: f; }
.tb-freq li span::before { content: counter(f) ". "; color: var(--muted); font-variant-numeric: tabular-nums; }
.tb-freq b { font-variant-numeric: tabular-nums; color: var(--text-2); }
.tb-limits { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.tb-limits li { display: grid; grid-template-columns: 150px 1fr 96px; align-items: center; gap: 12px; font-size: 14px; }
.tb-limit-bar { height: 8px; border-radius: 99px; background: var(--line-soft); overflow: hidden; }
.tb-limit-bar i { display: block; height: 100%; background: var(--kind-text); border-radius: inherit; }
.tb-limits .is-over .tb-limit-bar i { background: var(--danger); }
.tb-limit-n { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.tb-limits .is-over .tb-limit-n { color: var(--danger); font-weight: 600; }
.tb-invis, .tb-long { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 6px; }
.tb-invis code { font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }

/* diff */
.tb-diff-sum { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.tb-diff-sum.is-same { color: var(--kind-text); }
.tb-add { color: #1a7f37; } .tb-del { color: #c2410c; }
.tb-diff-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 10px; }
.tb-diff { width: 100%; border-collapse: collapse; font: 13px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; table-layout: fixed; }
.tb-diff td { padding: 1px 10px; vertical-align: top; white-space: pre-wrap; word-break: break-word; }
.tb-diff .tb-ln { width: 44px; text-align: right; color: var(--muted); user-select: none; background: var(--panel-2); }
.tb-diff .is-del { background: #fde8e4; }
.tb-diff .is-add { background: #e3f5e6; }
.tb-diff del { background: #f7c3b8; color: inherit; text-decoration: none; border-radius: 3px; }
.tb-diff ins { background: #b5e3bd; color: inherit; text-decoration: none; border-radius: 3px; }
.tb-diff .is-empty { background: repeating-linear-gradient(-45deg, transparent 0 6px, var(--line-soft) 6px 7px); }
.tb-inline-diff { white-space: pre-wrap; word-break: break-word; font: 14px/1.7 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.tb-inline-diff del { background: #fde0da; color: #9a3412; text-decoration: line-through; border-radius: 3px; }
.tb-inline-diff ins { background: #d5f0da; color: #14532d; text-decoration: none; border-radius: 3px; }

/* mind map */
.tb-map { overflow: auto; border-radius: 10px; background: #fffdf8; }
.tb-map svg { display: block; }
.tb-map .mm-node:hover rect { filter: brightness(1.06); }

/* table generator */
.tb-grid-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.tb-grid-hint { font-size: 12.5px; color: var(--muted); margin-left: 6px; }
.tb-grid-wrap { overflow-x: auto; }
.tb-grid { border-collapse: separate; border-spacing: 0; }
.tb-grid td, .tb-grid th { padding: 0; }
.tb-grid td { border: 1px solid var(--line-soft); }
.tb-grid input {
  width: 100%; min-width: 130px; border: 0; padding: 8px 10px; font: inherit; font-size: 14px; background: transparent; color: var(--text);
}
.tb-grid input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #fff; }
.tb-grid .is-head input { font-weight: 600; background: var(--panel-2); }
.tb-grid-align th { padding: 0 0 4px; }
.tb-align { width: 100%; border: 0; background: transparent; color: var(--muted); font-size: 15px; padding: 2px; border-radius: 6px; }
.tb-align:hover { background: var(--accent-soft); color: var(--accent-deep); }

@media (max-width: 720px) {
  .tb-text, .tb-rich, .tb-frame { min-height: 320px; height: 52vh; flex: none; }
  .tb { min-height: 0; }
  .tb-custom-out { min-height: 0; }
  .tb-limits li { grid-template-columns: 1fr 72px; }
  .tb-limit-bar { grid-column: 1 / -1; order: 3; }
  .tb-actions .tb-btn { flex: 1 1 auto; justify-content: center; }
}
