/* Template builder (TemplateBuilderUI.js). All rules are under .tb-root. */
.WebTemplateBuilder_Box { position: relative; height: 500px; overflow: hidden; }
.tb-root { --tb-line: #dfe2e7; --tb-muted: #6b7280; --tb-accent: #2563eb; --tb-accent-soft: #eff4ff; --tb-bg: #eef0f3; --tb-warn: #b45309; --tb-warn-soft: #fff7ed; --tb-text: #1f2937;
  position: relative; height: 100%; min-height: 400px; display: grid; grid-template-rows: 40px 1fr; overflow: hidden;
  font: 13px/1.45 "Segoe UI", system-ui, sans-serif; color: var(--tb-text); background: var(--tb-bg); box-sizing: border-box; }
.tb-root *, .tb-root *::before, .tb-root *::after { box-sizing: border-box; }
.tb-root button, .tb-root select, .tb-root input, .tb-root textarea { font: inherit; color: inherit; }
.tb-root button { padding: 4px 10px; border: 1px solid var(--tb-line); background: #fff; border-radius: 6px; cursor: pointer; line-height: 1.4; }
.tb-root button:hover:not(:disabled) { border-color: #a5adba; background: #fafbfc; }
.tb-root button:disabled { opacity: .4; cursor: default; }
.tb-root button.tb-primary { background: var(--tb-accent); color: #fff; border-color: var(--tb-accent); }
.tb-root button.tb-primary:hover { background: #1d4ed8; }
.tb-root button.tb-ghost { border-color: transparent; background: transparent; }
.tb-root button.tb-ghost:hover { background: #f1f3f6; border-color: transparent; }

.tb-bar { display: flex; align-items: center; gap: 6px; padding: 0 10px; background: #fff; border-bottom: 1px solid var(--tb-line); }
.tb-spacer { flex: 1; }
.tb-state { color: var(--tb-muted); font-size: 12px; min-width: 90px; text-align: right; }
.tb-seg { display: inline-flex; border: 1px solid var(--tb-line); border-radius: 6px; overflow: hidden; }
.tb-root .tb-seg button { border: 0; border-radius: 0; padding: 4px 10px; }
.tb-root .tb-seg button.on { background: var(--tb-accent-soft); color: var(--tb-accent); }

.tb-main { display: grid; grid-template-columns: 220px 1fr 300px; min-height: 0; }
.tb-left, .tb-right { background: #fff; overflow: auto; min-height: 0; }
.tb-left { border-right: 1px solid var(--tb-line); display: grid; grid-template-rows: auto 1fr; }
.tb-right { border-left: 1px solid var(--tb-line); padding: 14px; }
.tb-tabs { display: flex; border-bottom: 1px solid var(--tb-line); }
.tb-root .tb-tabs button { flex: 1; border: 0; border-radius: 0; padding: 8px 0; background: #fff; color: var(--tb-muted); border-bottom: 2px solid transparent; }
.tb-root .tb-tabs button.on { color: var(--tb-text); border-bottom-color: var(--tb-accent); font-weight: 600; }
.tb-pane { overflow: auto; padding: 10px; }

.tb-pal { border: 1px solid var(--tb-line); background: #fff; border-radius: 6px; user-select: none; display: grid; grid-template-columns: 30px 1fr; gap: 0 8px; align-items: center; width: 100%; text-align: left; margin-bottom: 6px; padding: 7px 8px; cursor: grab; }
.tb-pal:hover { border-color: #a5adba; background: #fafbfc; }
.tb-pal:focus-visible { outline: 2px solid #bfd3fe; }
.tb-pal .tb-ic { grid-row: span 2; width: 30px; height: 30px; display: grid; place-items: center; background: var(--tb-accent-soft); color: var(--tb-accent); border-radius: 6px; font-size: 15px; }
.tb-pal .tb-t { font-weight: 600; }
.tb-pal .tb-d { font-size: 11px; color: var(--tb-muted); }
.tb-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--tb-muted); margin: 12px 2px 6px; }
.tb-group:first-child { margin-top: 2px; }

.tb-struct { list-style: none; margin: 0; padding: 0; }
.tb-struct li { display: grid; grid-template-columns: 16px 1fr; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.tb-struct li:hover { background: #f6f7f9; }
.tb-struct li.on { background: var(--tb-accent-soft); border-color: #c7d6fb; }
.tb-struct li .tb-grip { color: #b0b6c0; cursor: grab; font-size: 11px; }
.tb-struct li .tb-n { font-weight: 600; }
.tb-struct li .tb-cond { color: var(--tb-warn); font-weight: 400; }
.tb-struct li .tb-s { grid-column: 2; font-size: 11px; color: var(--tb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-struct li.drop-before { box-shadow: inset 0 2px 0 var(--tb-accent); }
.tb-struct li.drop-after { box-shadow: inset 0 -2px 0 var(--tb-accent); }

.tb-stage { overflow: auto; padding: 24px 24px 120px; min-height: 0; position: relative; }
.tb-blockbar { position: absolute; display: none; flex-direction: column; gap: 2px; width: 34px; background: #2563eb; border-radius: 8px; padding: 3px; z-index: 5; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.tb-root .tb-blockbar button { border: 0; background: transparent; color: #fff; padding: 4px 0; border-radius: 5px; font-size: 14px; }
.tb-root .tb-blockbar button:hover { background: rgba(255,255,255,.2); }
.tb-blockbar .tb-grip { cursor: grab; color: #fff; text-align: center; padding: 4px 0; border-radius: 5px; font-size: 14px; user-select: none; }
.tb-blockbar .tb-grip:hover { background: rgba(255,255,255,.2); }
.tb-blockbar .tb-lbl { writing-mode: vertical-rl; transform: rotate(180deg); color: #dbe6ff; font: 600 11px "Segoe UI", sans-serif; padding: 6px 0; text-align: center; align-self: center; }
.tb-canvas { display: block; width: var(--tb-w, 640px); margin: 0 auto; border: 0; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); border-radius: 2px; transition: width .2s; }
.tb-stage.mobile .tb-canvas { width: 375px; }

.tb-right h2 { font-size: 15px; margin: 0 0 2px; }
.tb-right .tb-sub { color: var(--tb-muted); font-size: 12px; margin: 0 0 12px; }
.tb-right h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--tb-muted); margin: 18px 0 8px; }
.tb-field { margin-bottom: 10px; }
.tb-field > label { display: block; font-size: 12px; color: #4b5563; margin-bottom: 3px; }
.tb-help { font-size: 11px; color: var(--tb-muted); margin-top: 3px; }
.tb-field input[type=text], .tb-field input[type=number], .tb-field select, .tb-field textarea { width: 100%; padding: 4px 8px; border: 1px solid var(--tb-line); border-radius: 6px; background: #fff; }
.tb-field input:focus, .tb-field select:focus { outline: 2px solid #bfd3fe; border-color: var(--tb-accent); }
.tb-unit { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px; }
.tb-unit span { color: var(--tb-muted); font-size: 12px; }
.tb-color { display: grid; grid-template-columns: 34px 1fr; gap: 6px; }
.tb-color input[type=color] { width: 34px; height: 30px; padding: 0 2px; border: 1px solid var(--tb-line); border-radius: 6px; background: #fff; }
.tb-color input[type=text] { width: 100%; padding: 4px 8px; border: 1px solid var(--tb-line); border-radius: 6px; }
.tb-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tb-segf { display: flex; }
.tb-root .tb-segf button { flex: 1; border-radius: 0; margin-left: -1px; }
.tb-root .tb-segf button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.tb-root .tb-segf button:last-child { border-radius: 0 6px 6px 0; }
.tb-root .tb-segf button.on { background: var(--tb-accent-soft); color: var(--tb-accent); border-color: #c7d6fb; position: relative; }
.tb-cols { display: grid; gap: 6px; }
.tb-colrow { display: grid; grid-template-columns: 1fr 62px 28px; gap: 4px; align-items: center; }
.tb-colrow input { width: 100%; padding: 4px 6px; border: 1px solid var(--tb-line); border-radius: 6px; }
.tb-sum { font-size: 11px; color: var(--tb-muted); text-align: right; margin-top: 2px; }
.tb-sum.bad { color: #b91c1c; }
.tb-listrow { display: grid; grid-template-columns: 1fr 28px 28px; gap: 4px; margin-bottom: 4px; }
.tb-listrow input { padding: 4px 6px; border: 1px solid var(--tb-line); border-radius: 6px; min-width: 0; }
.tb-root .tb-sm { padding: 3px 6px; font-size: 12px; }
.tb-note { font-size: 12px; color: var(--tb-muted); background: #f8f9fb; border: 1px solid var(--tb-line); border-radius: 6px; padding: 8px 10px; margin: 10px 0; }
.tb-warn { font-size: 12px; color: var(--tb-warn); background: var(--tb-warn-soft); border: 1px solid #fed7aa; border-radius: 6px; padding: 8px 10px; margin: 10px 0; }
.tb-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 4px; }
.tb-root kbd { font: 11px Consolas, monospace; background: #f3f4f6; border: 1px solid var(--tb-line); border-radius: 3px; padding: 0 3px; }

.tb-textbar { position: absolute; display: none; align-items: center; gap: 2px; padding: 4px; background: #111827; border-radius: 8px; z-index: 30; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tb-root .tb-textbar button, .tb-root .tb-textbar select { background: transparent; color: #f9fafb; border: 0; padding: 4px 8px; border-radius: 5px; min-width: 28px; }
.tb-root .tb-textbar button:hover { background: #374151; }
.tb-root .tb-textbar select { background: #1f2937; border: 1px solid #374151; max-width: 220px; }
.tb-textbar .tb-sep { width: 1px; height: 18px; background: #4b5563; margin: 0 3px; }
.tb-root .tb-textbar .tb-done { background: var(--tb-accent); }

.tb-addMenu { position: absolute; display: none; width: 260px; max-height: 420px; overflow: auto; background: #fff; border: 1px solid var(--tb-line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; z-index: 30; }
.tb-addMenu .tb-pal { cursor: pointer; margin-bottom: 2px; border-color: transparent; }
.tb-addMenu .tb-pal:hover { border-color: var(--tb-line); }

.tb-toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111827; color: #fff; padding: 8px 12px; border-radius: 8px; display: none; align-items: center; gap: 12px; z-index: 40; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.tb-root .tb-toast button { background: transparent; color: #93c5fd; border: 0; padding: 0; font-weight: 600; }

.tb-modal { position: absolute; inset: 0; background: rgba(17,24,39,.45); display: none; z-index: 50; }
.tb-modal .tb-box { position: absolute; inset: 16px 24px; background: #fff; border-radius: 10px; display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.tb-modal .tb-head { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--tb-line); flex-wrap: wrap; }
.tb-modal .tb-head strong { margin-right: auto; }
.tb-modalActions { display: contents; }
.tb-modal .tb-head label { font-size: 12px; color: #4b5563; display: inline-flex; gap: 4px; align-items: center; }
.tb-modalBody { min-height: 0; background: #eef0f3; overflow: auto; }
.tb-modalBody textarea { width: 100%; height: 100%; border: 0; padding: 12px; font: 12px Consolas, monospace; resize: none; }
.tb-modalBody iframe { display: block; margin: 16px auto; width: 680px; height: calc(100% - 32px); border: 0; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.tb-modalBody.mobile iframe { width: 375px; }
.tb-imgGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 12px; }
.tb-root .tb-imgItem { height: 100px; padding: 4px; display: grid; place-items: center; background: #fff; }
.tb-imgItem img { max-width: 100%; max-height: 90px; }
