/*
 * The template form (components/template_form) and the template builder
 * (components/template_builder), on the Atlas tokens.
 *
 *   tf-*   the form a template draws: fields, lists as cards and tables, tuples, errors
 *   tb-*   the builder around it: outline, preview, inspector, palette
 */

/* ---- the form --------------------------------------------------------------------- */

.tf { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }

.tf-summary {
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  background: var(--danger-soft);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
}
.tf-summary__title { font-weight: var(--weight-semibold); color: var(--danger); }
.tf-summary__hint { font-weight: var(--weight-regular); color: var(--fg-muted); }
.tf-summary ul { margin: var(--space-1) 0 0; padding-left: 18px; color: var(--fg); }
.tf-summary li { line-height: 18px; }

.tf-object {
  display: grid;
  gap: var(--space-3) var(--space-4);
  align-items: start;
  min-width: 0;
}
.tf-cols-1 { grid-template-columns: minmax(0, 1fr); }
.tf-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tf-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tf-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tf-object--selected { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--radius-sm); }

.tf-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; border-radius: var(--radius-base); }
.tf-field--wide { grid-column: 1 / -1; }
.tf--selectable .tf-field { cursor: pointer; padding: 4px; margin: -4px; transition: background 0.1s; }
.tf--selectable .tf-field:hover { background: var(--hover); }
.tf--selectable .tf-field input,
.tf--selectable .tf-field select,
.tf--selectable .tf-field textarea { cursor: auto; }
.tf-field--selected,
.tf--selectable .tf-field.tf-field--selected { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }

.tf-field__head { display: flex; align-items: baseline; gap: 6px; min-height: 18px; }
.tf-label { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--fg); }
.tf-key { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); }
.tf-help { margin: 0; font-size: var(--text-sm); color: var(--fg-muted); line-height: 16px; }
.tf-error { margin: 0; font-size: var(--text-sm); color: var(--danger); line-height: 16px; font-family: var(--font-mono); }
.tf-empty { margin: 0; font-size: var(--text-sm); color: var(--fg-subtle); }

.tf-field--invalid > .tf-input,
.tf-field--invalid > .tf-select,
.tf-field--invalid > .tf-color .tf-input { border-color: var(--danger); }

.tf-input {
  width: 100%;
  min-width: 0;
  height: var(--input-h);
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-base);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: var(--text-base);
  box-sizing: border-box;
}
.tf-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.tf-input:disabled { background: var(--muted); color: var(--fg-muted); }
.tf-input--number { font-variant-numeric: tabular-nums; }
.tf-input--mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.tf-textarea { height: auto; padding: 6px 9px; line-height: 18px; resize: vertical; }
.tf-select { padding-right: 24px; }

.tf-check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-base); color: var(--fg); cursor: pointer; }
.tf-check input { accent-color: var(--accent); }
.tf-radios { display: flex; flex-wrap: wrap; gap: 4px 14px; min-height: var(--input-h); align-items: center; }
.tf-radio { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-base); cursor: pointer; }
.tf-radio input { accent-color: var(--accent); }
.tf-color { display: flex; gap: 6px; align-items: center; }
.tf-color input[type='color'] { width: 34px; height: var(--input-h); padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-base); background: var(--card); }

.tf-add {
  align-self: flex-start;
  height: var(--btn-h);
  padding: 0 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-base);
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.tf-add:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.tf-add:disabled { color: var(--fg-subtle); cursor: default; }
.tf-add--small { height: 24px; padding: 0 6px; }

.tf-icon {
  width: 24px;
  height: 24px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: var(--text-md);
  cursor: pointer;
}
.tf-icon:hover:not(:disabled) { background: var(--active); color: var(--fg); }
.tf-icon:disabled { opacity: 0.35; cursor: default; }

.tf-nested { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-subtle); }
.tf-nested--section { background: var(--card); }

.tf-list { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.tf-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.tf-row > .tf-input { flex: 1 1 120px; width: auto; }
.tf-index { min-width: 18px; color: var(--fg-subtle); font-size: var(--text-sm); font-variant-numeric: tabular-nums; text-align: right; }

.tf-card { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); box-shadow: var(--shadow-sm); min-width: 0; }
.tf-card__head { display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--border-row); background: var(--bg-subtle); border-radius: var(--radius-md) var(--radius-md) 0 0; }
.tf-card__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--fg); }
.tf-card__body { padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }

.tf-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.tf-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.tf-table th { text-align: left; font-weight: var(--weight-medium); color: var(--fg-muted); padding: 6px 8px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tf-table td { padding: 5px 6px; border-bottom: 1px solid var(--border-row); vertical-align: top; }
.tf-table td .tf-input { height: 28px; }
.tf-table__errors td { padding: 0 8px; border-bottom: none; }
.tf-table__errors td:empty { display: none; }
.tf-table .tf-list { gap: 4px; }
.tf-row-tools { white-space: nowrap; width: 1%; }
.tf--selectable .tf-table td { cursor: pointer; }
.tf-cell--selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

.tf-tuple { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.tf-tuple__item { display: flex; align-items: center; gap: 6px; flex: 1 1 140px; min-width: 0; }
.tf-tuple__label { font-size: var(--text-sm); color: var(--fg-muted); white-space: nowrap; }
.tf-union { display: flex; flex-direction: column; gap: var(--space-3); }

@media (max-width: 900px) {
  .tf-cols-2, .tf-cols-3, .tf-cols-4 { grid-template-columns: minmax(0, 1fr); }
}

/* The event dialog's template column. */
.data-column--template { min-width: min(720px, 80vw); max-width: 1100px; }

/* ---- the builder ------------------------------------------------------------------ */

.tb-dialog .el-dialog__body { padding-top: 0; }
.tb-toolbar { display: flex; align-items: center; gap: var(--space-3); padding: 0 0 var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); flex-wrap: wrap; }
.tb-tabs { border-bottom: none; }
.tb-start { display: inline-flex; align-items: center; gap: 6px; }
.tb-start .tf-select { width: 260px; }

.tb-panes { display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; gap: var(--space-4); height: max(420px, calc(100vh - 330px)); }
.tb-pane { min-width: 0; overflow: auto; }
.tb-pane__caption { display: flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-subtle); margin: var(--space-3) 0 var(--space-1); }

.tb-outline { border-right: 1px solid var(--border); padding-right: var(--space-2); }
.tb-tree { display: flex; flex-direction: column; }
.tb-node {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 28px;
  padding: 2px 8px;
  border: none;
  border-radius: var(--radius-base);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: var(--text-base);
  text-align: left;
  cursor: pointer;
}
.tb-node:hover { background: var(--hover); }
.tb-node.is-selected { background: var(--accent-soft); color: var(--accent-ink); }
.tb-node--doc { font-weight: var(--weight-semibold); }
.tb-node--variant { cursor: default; color: var(--fg-muted); }
.tb-node__glyph { flex: none; width: 26px; font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); text-align: center; }
.tb-node.is-selected .tb-node__glyph { color: var(--accent); }
.tb-node__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 24px; }
.tb-node__key { overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.tb-node__key { font-size: var(--text-2xs); color: var(--fg-subtle); white-space: nowrap; }
.tb-node__meta { font-size: var(--text-2xs); color: var(--fg-muted); white-space: nowrap; }
.tb-node__checks { font-size: var(--text-2xs); color: var(--success); }
.tb-defs__caption { margin-top: var(--space-4); }
.tb-defs__none { margin: 0 8px; }

.tb-add { position: relative; }
.tb-add__button { height: 22px; padding: 0 6px; border: none; background: transparent; color: var(--accent-ink); font: inherit; font-size: var(--text-sm); cursor: pointer; border-radius: var(--radius-sm); }
.tb-add__button:hover { background: var(--accent-soft); }
.tb-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin: 4px 0 6px; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); box-shadow: var(--shadow-md); }
.tb-palette__item { padding: 5px 8px; border: none; border-radius: var(--radius-sm); background: transparent; font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; color: var(--fg); }
.tb-palette__item:hover { background: var(--hover); }
.tb-palette__item--accent { grid-column: 1 / -1; color: var(--accent-ink); font-weight: var(--weight-medium); }

.tb-problems { margin-top: var(--space-3); }
.tb-problem { display: flex; flex-direction: column; gap: 1px; width: 100%; padding: 5px 8px; border: none; border-left: 2px solid var(--danger); background: var(--danger-soft); color: var(--fg); font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; margin-bottom: 4px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tb-problem__at { font-size: var(--text-2xs); color: var(--danger); }

.tb-preview { display: flex; flex-direction: column; gap: var(--space-3); padding: 0 var(--space-1); }
.tb-preview__head { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; position: sticky; top: 0; background: var(--card); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border-row); z-index: 1; }
.tb-preview__head .tb-pane__caption { margin-top: 0; }
.tb-preview__form { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); }
.tb-timing { display: inline-flex; align-items: center; gap: 6px; }
.tb-timing__input { width: 72px; }
.tb-stored { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-subtle); }
.tb-stored summary { display: flex; align-items: center; gap: 6px; padding: 6px 10px; cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium); }
.tb-stored__body { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 260px; overflow: auto; font-size: var(--text-xs); line-height: 16px; white-space: pre-wrap; }

.tb-inspector { border-left: 1px solid var(--border); padding-left: var(--space-3); }
.tb-inspector__head { padding: var(--space-2) 0 var(--space-3); border-bottom: 1px solid var(--border-row); }
.tb-inspector__kind { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.tb-inspector__path { font-size: var(--text-xs); color: var(--fg-muted); word-break: break-all; }
.tb-section { padding: var(--space-3) 0; border-bottom: 1px solid var(--border-row); display: flex; flex-direction: column; gap: var(--space-2); }
.tb-section__title { font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-muted); }
.tb-section__title .a-hint { text-transform: none; letter-spacing: 0; font-weight: var(--weight-regular); }
.tb-row { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tb-row__label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg); }
.tb-row__help { font-size: var(--text-xs); color: var(--fg-subtle); line-height: 15px; }
.tb-row--inline { display: flex; flex-direction: row; gap: 6px; align-items: center; }
.tb-row--inline .tf-input { flex: 1 1 0; }
.tb-bound__mode { flex: 0 0 104px !important; }
.tb-bound__small { flex: 0 0 74px !important; }
.tb-check { font-size: var(--text-sm); }
.tb-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.tb-action { height: 26px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-base); background: var(--card); color: var(--fg); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.tb-action:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-ink); }
.tb-action:disabled { opacity: 0.45; cursor: default; }
.tb-action--danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.tb-check-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--bg-subtle); }
.tb-check-card__head { display: flex; align-items: center; gap: 2px; }
.tb-check-card__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.tb-report summary { cursor: pointer; font-size: var(--text-xs); color: var(--fg-muted); }
.tb-report[open] { display: flex; flex-direction: column; gap: 6px; }

.tb-json { display: flex; flex-direction: column; gap: var(--space-2); }
.tb-json__text { min-height: calc(100vh - 420px); }
.tb-footer__hint { max-width: 60%; }

.tb-summary { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.tb-summary__card { width: 100%; padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-subtle); box-sizing: border-box; }
.tb-summary__title { font-weight: var(--weight-semibold); }

@media (max-width: 1100px) {
  .tb-panes { grid-template-columns: minmax(0, 1fr); height: auto; }
  .tb-outline, .tb-inspector { border: none; padding: 0; }
}
.tb-json .el-button { align-self: flex-start; }
