/* ── ATP Portal — Tables tab (banner + crosstabs) ─────────────────── */

/* Banner builder card */
.bn-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  /* No overflow:hidden — would clip the question-picker dropdown
     (and any other absolutely-positioned panel anchored to the foot). */
}
/* Match the head/foot background to the rounded card boundary
   even without overflow:hidden on the parent. */
.bn-card-head { border-top-left-radius: 10px; border-top-right-radius: 10px; }
.bn-card-foot { border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; }
.bn-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
}
.bn-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
  margin-right: auto;
}
.bn-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bn-card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg1);
}
.bn-base-line {
  font-size: 12px;
  color: var(--text3);
}

/* Buttons */
.bn-btn {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text1);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.bn-btn:hover { border-color: var(--teal); }
.bn-btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.bn-btn-add {
  border-style: dashed;
  color: var(--text2);
}
.bn-btn-apply {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 600;
  opacity: .5;
  cursor: default;
  padding: 6px 18px;
}
.bn-btn-apply.dirty {
  opacity: 1;
  cursor: pointer;
  animation: bn-pulse 2s ease-in-out infinite;
}
@keyframes bn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(64, 196, 196, .35); }
  50%      { box-shadow: 0 0 0 6px rgba(64, 196, 196, 0); }
}
.bn-btn-plus { font-weight: 700; margin-right: 2px; color: var(--teal); }

/* Saved-banner dropdown */
.bn-saved-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
  min-width: 180px;
}
.bn-saved-select:hover, .bn-saved-select:focus { border-color: var(--teal); }

/* Filter dropdown (independent base filter for the Tables tab) */
.bn-filter-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text3);
  margin-left: 6px;
}
.bn-filter-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
  min-width: 160px;
}
.bn-filter-select:hover, .bn-filter-select:focus { border-color: var(--teal); }

/* Collapse chevron — borderless icon, pinned to the right of the head */
.bn-collapse-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.bn-collapse-btn:hover { color: var(--text1); background: rgba(255,255,255,.04); }

/* Collapsed card — compact summary row replaces the body */
.bn-card-collapsed .bn-card-head {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.bn-collapsed-summary {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text2);
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.bn-collapsed-n {
  font-weight: 600;
  color: var(--text1);
}
.bn-collapsed-labels {
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Banner point ───────────────────────────────────────────────── */
.bn-point {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg1);
}
.bn-point-total {
  background: rgba(64, 196, 196, .06);
  border-color: rgba(64, 196, 196, .35);
}
.bn-point-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.bn-point-label-input {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text1);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  min-width: 160px;
}
.bn-point-label-input:focus { border-color: var(--teal); }
.bn-point-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
}
.bn-point-label-lock { color: var(--teal); }
.bn-lock-note {
  font-size: 10px;
  font-weight: 400;
  color: var(--text3);
  margin-left: 6px;
}
.bn-conj-lead {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text3);
}
.bn-conj-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text1);
  font-size: 12px;
  font-weight: 600;
  outline: none;
}
.bn-chip-x {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 16px;
  cursor: pointer;
  padding: 0 6px;
  margin-left: auto;
}
.bn-chip-x:hover { color: var(--red, #f33); }

.bn-point-body { display: flex; flex-direction: column; gap: 6px; }
.bn-point-foot { margin-top: 8px; }
.bn-total-note {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
}
.bn-empty-conds {
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
  padding: 4px 0;
}

/* ── Condition row (inline) ──────────────────────────────────────── */
.bn-cond-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bn-op-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text2);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  min-width: 80px;
}
.bn-op-select:hover, .bn-op-select:focus { border-color: var(--teal); }

/* Field picker (mirrors q-field-* in tab-questions.css) */
.bn-field-wrap { position: relative; display: inline-block; }
.bn-field-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text1);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  min-width: 200px;
  max-width: 360px;
  text-align: left;
}
.bn-field-btn:hover, .bn-field-btn:focus { border-color: var(--teal); }
.bn-field-btn-lbl {
  flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bn-field-btn-caret { flex: 0 0 auto; color: var(--text3); font-size: 11px; }
.bn-field-missing {
  border-color: var(--amber, #e0a500) !important;
  color: var(--amber, #e0a500);
}
.bn-field-panel {
  position: absolute;
  z-index: 31;
  top: 100%; left: 0;
  margin-top: 6px;
  min-width: 320px; max-width: 460px; max-height: 360px;
  overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.bn-field-search {
  flex: 0 0 auto;
  width: 100%;
  background: var(--bg1);
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}
.bn-field-search::placeholder { color: var(--text3); }
.bn-field-list { flex: 1 1 auto; overflow-y: auto; padding: 4px; }
.bn-field-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text1);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  outline: none;
}
.bn-field-opt:hover, .bn-field-opt.is-highlight {
  background: rgba(127, 119, 221, .12);
}
.bn-field-opt.is-selected .bn-field-opt-lbl { color: var(--teal); font-weight: 600; }
.bn-field-opt-lbl {
  flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bn-field-type {
  flex: 0 0 auto; font-size: 10px; color: var(--text3); white-space: nowrap;
}
.bn-field-empty {
  padding: 16px 10px; text-align: center; font-size: 12px;
  color: var(--text3); font-style: italic;
}

/* Value picker (mirrors q-val-*) */
.bn-val-wrap { position: relative; display: inline-block; }
.bn-val-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text1);
  font-size: 13px;
  cursor: pointer;
  min-width: 120px;
  text-align: left;
}
.bn-val-btn:hover { border-color: var(--teal); }
.bn-val-panel {
  position: absolute;
  z-index: 30;
  top: 100%; left: 0;
  margin-top: 6px;
  min-width: 240px; max-height: 260px;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.bn-val-panel-actions {
  display: flex; justify-content: flex-end;
  padding: 6px 4px 2px;
  position: sticky; bottom: 0; background: var(--bg2);
}
.bn-picker-opt {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text1);
  cursor: pointer;
  border-radius: 4px;
}
.bn-picker-opt:hover { background: rgba(127, 119, 221, .08); }
.bn-picker-opt code { color: var(--text3); font-size: 10px; }

.bn-num {
  width: 90px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
}
.bn-num:focus { border-color: var(--teal); }
.bn-val-num-wrap { display: inline-flex; align-items: center; gap: 6px; }
.bn-num-sep { font-size: 12px; color: var(--text3); }
.bn-val-text {
  width: 200px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
}
.bn-val-text:focus { border-color: var(--teal); }

.bn-add-row { padding-top: 4px; }

/* ── Question picker (multi-select dropdown) ─────────────────────── */
.bn-q-wrap { position: relative; display: inline-block; }
.bn-q-picker-btn {
  background: var(--bg2);
  font-weight: 600;
}
.bn-q-panel {
  position: absolute;
  z-index: 30;
  /* Anchor ABOVE the button — the picker sits at the bottom of the card,
     so opening downward (top: 100%) would push the panel off-viewport. */
  bottom: 100%; left: 0;
  margin-bottom: 6px;
  min-width: 360px; max-height: 380px;
  display: flex; flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.bn-q-panel-head {
  display: flex; gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
}
.bn-q-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 6px; }
.bn-q-opt {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  font-size: 12px;
  color: var(--text1);
  cursor: pointer;
  border-radius: 4px;
}
.bn-q-opt:hover { background: rgba(127, 119, 221, .08); }
.bn-q-key { color: var(--text1); font-weight: 500; }
.bn-q-type { font-size: 10px; color: var(--text3); }
.bn-q-empty {
  padding: 16px; text-align: center;
  font-size: 12px; color: var(--text3); font-style: italic;
}

/* ── Tables (crosstab cards) ─────────────────────────────────────── */
.bn-tables-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
/* Match the Questions-tab .card look: white (light) / dark (dark) card body
   with a slightly different header strip, soft borders, row hover. */
.bn-q-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.bn-q-card-head {
  margin-bottom: 8px;
}
.bn-q-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text1);
}
.bn-q-card-sub {
  font-size: 11px;
  color: var(--text3);
}
.bn-q-card-sub code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}

.bn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.bn-table thead th {
  background: var(--bg2);
  color: var(--text2);
  font-weight: 600;
  font-size: 13px;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bn-th-code  { width: 60px; }
.bn-th-label { min-width: 140px; }
.bn-th-col {
  text-align: left;
  min-width: 90px;
}
.bn-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text1);
  vertical-align: middle;
}
.bn-table tbody tr:last-child td { border-bottom: none; }
/* Row shading on hover — matches .q-table hover token */
.bn-table tbody tr:not(.bn-base-row):hover td {
  background: rgba(127, 119, 221, .05);
}
.bn-td-code { color: var(--text3); font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.bn-td-label { color: var(--text1); }
.bn-td-cell {
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.bn-cell-n  { color: var(--text1); }
.bn-cell-pct {
  display: inline-block;
  margin-left: 4px;
  color: var(--text3);
  font-size: 12px;
}
/* Base row — pinned just under the header, same shade as the header strip */
.bn-base-row td {
  background: var(--bg2);
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
}
.bn-td-base-cell {
  text-align: left;
  font-weight: 600;
  color: var(--text2);
}
.bn-foot-label {
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .04em;
}
/* Grid base column (now the first answer column) */
.bn-td-base {
  text-align: left;
  font-weight: 600;
  color: var(--text2);
}
.bn-th-base {
  text-align: left;
  font-weight: 600;
  color: var(--text2);
  min-width: 60px;
}

/* Numeric table */
.bn-table-numeric .bn-th-stat,
.bn-table-numeric .bn-td-stat {
  width: 80px;
  font-weight: 600;
  color: var(--text2);
}

/* Binned numeric table — bin rows + Mean/n footer rows */
.bn-table-binned .bn-th-binlbl { min-width: 140px; }
.bn-table-binned .bn-td-binlbl { color: var(--text1); font-weight: 500; }
.bn-bin-stat-row td {
  background: var(--bg2);
  font-weight: 600;
  color: var(--text2);
  border-top: 1px solid var(--border);
}

/* ── Numeric bin editor (inline panel under the question head) ─── */
.bn-bin-edit-btn {
  /* Inline with the title/sub so the button anchors on the LEFT side of the
     header in both numeric cards and grid cards (parity). */
  margin-left: 8px;
  vertical-align: middle;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
}
.bn-bin-edit-btn:hover { color: var(--text1); border-color: var(--teal); }
.bn-bin-editor {
  margin: 10px 0;
  padding: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.bn-bin-editor-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text3);
  margin-bottom: 8px;
}
.bn-bin-editor-head code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text2);
  text-transform: none;
}
.bn-bin-list { display: flex; flex-direction: column; gap: 6px; }
.bn-bin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bn-bin-input {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text1);
  font-size: 13px;
  outline: none;
}
.bn-bin-input:focus { border-color: var(--teal); }
.bn-bin-label { width: 140px; }
.bn-bin-min, .bn-bin-max { width: 80px; }
.bn-bin-sep { font-size: 12px; color: var(--text3); }
.bn-bin-row-rm {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 16px;
  cursor: pointer;
  padding: 0 6px;
}
.bn-bin-row-rm:hover { color: var(--red, #f33); }
.bn-bin-editor-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.bn-bin-foot-spacer { flex: 1 1 auto; }
.bn-bin-error {
  margin-top: 8px;
  font-size: 12px;
  color: var(--red, #f33);
}

/* Grid card */
.bn-q-card-grid {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

/* ── Loop card (Tables tab) ──────────────────────────────────────── */
.bn-q-card-loop {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.bn-loop-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.bn-loop-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text1);
}
.bn-loop-sub {
  font-size: 11px;
  color: var(--text3);
}
.bn-loop-sub code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}
.bn-loop-iter-pick {
  margin-left: auto;
  font-size: 12px;
  color: var(--text3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.bn-loop-iter-select {
  background: var(--bg1);
  border: 1px solid var(--teal);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--text1);
  font-size: 13px;
  font-weight: 600;
  outline: none;
}
.bn-loop-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bn-loop-child {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.bn-loop-child-head {
  margin-bottom: 8px;
}
.bn-loop-child-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
}
.bn-loop-child-sub {
  font-size: 11px;
  color: var(--text3);
  margin-left: 4px;
}
.bn-loop-child-sub code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}
.bn-loop-grid-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
.bn-loop-grid-col-pick {
  font-size: 12px;
  color: var(--text3);
}
/* Inside a loop child, inner tables use the slightly darker bg2 to read
   against the outer card's bg1 — keep table cells on bg2 here. */
.bn-loop-child .bn-table thead th { background: var(--bg1); }
.bn-loop-child .bn-base-row td    { background: var(--bg1); }
.bn-grid-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.bn-grid-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text1);
}
.bn-grid-sub {
  font-size: 11px;
  color: var(--text3);
}
.bn-grid-col-pick {
  margin-left: auto;
  font-size: 12px;
  color: var(--text3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.bn-grid-col-select {
  background: var(--bg1);
  border: 1px solid var(--teal);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--text1);
  font-size: 12px;
  font-weight: 600;
  outline: none;
}
.bn-grid-wrap { overflow-x: auto; }
.bn-table-grid .bn-th-row,
.bn-table-grid .bn-td-rowlbl {
  min-width: 220px;
  position: sticky;
  left: 0;
  z-index: 1;
}
/* Sticky cells need an opaque bg or the scrolled content shows through. */
.bn-table-grid .bn-td-rowlbl { background: var(--bg1); }
.bn-table-grid .bn-th-row    { background: var(--bg2); }
.bn-table-grid tbody tr:hover .bn-td-rowlbl {
  background: rgba(127, 119, 221, .05);
}
.bn-th-grid {
  min-width: 80px;
  text-align: left;
}

/* Empty state */
.bn-empty-state {
  background: var(--bg1);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 28px;
  text-align: center;
  color: var(--text3);
  font-size: 13px;
}
.bn-text-note {
  padding: 12px;
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
}
