/* ==========================================================================
   Tree Builder — Ancestry-style interactive family tree
   ========================================================================== */
:root {
  --brand: #800000;
  --bg: #f4f1ea;
  --bg-dot: #e4ddd0;
  --panel: #ffffff;
  --ink: #1f1b16;
  --ink-2: #5b544b;
  --ink-3: #8c847a;
  --line: #b9ae9e;
  --line-soft: #ddd5c8;
  --male: #3a78c2;
  --male-bg: #eaf2fc;
  --female: #c2457a;
  --female-bg: #fcebf2;
  --unknown: #8a8f98;
  --unknown-bg: #f0f1f3;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --err: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 27, 22, .08), 0 4px 14px rgba(31, 27, 22, .08);
  --shadow-lg: 0 10px 40px rgba(31, 27, 22, .22);
  --card-w: 210px;
  --card-h: 76px;
  --top-h: 58px;
  --font: "Inter", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f; --bg-dot: #2a261e; --panel: #221f19; --ink: #f3eee6; --ink-2: #c9c1b5; --ink-3: #988f83;
    --line: #6f6556; --line-soft: #3b352b; --male-bg: #1b2a3c; --female-bg: #3a1d2a; --unknown-bg: #2b2d31;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.tb { font-family: var(--font); color: var(--ink); background: var(--bg); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.tb-top {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line-soft); box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.tb-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); min-width: 0; max-width: 260px; }
.tb-logo { font-size: 22px; }
.tb-brand-text { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-views { display: flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.tb-views button { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.tb-views button.active { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); }
.tb-search { position: relative; flex: 1; max-width: 380px; margin-left: auto; }
.tb-search input { width: 100%; height: 36px; border: 1px solid var(--line-soft); border-radius: 999px; padding: 0 14px 0 36px; background: var(--bg); outline: none; }
.tb-search::before { content: "⌕"; position: absolute; left: 13px; top: 6px; font-size: 18px; color: var(--ink-3); }
.tb-search input:focus { border-color: var(--brand); background: var(--panel); }
.tb-search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 60vh; overflow: auto; padding: 6px; }
.tb-top-actions { display: flex; align-items: center; gap: 6px; }
.tb-icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line-soft); background: var(--panel); cursor: pointer; font-size: 16px; }
.tb-icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.tb-select { height: 34px; border-radius: 8px; border: 1px solid var(--line-soft); background: var(--panel); padding: 0 6px; font-size: 13px; }
.tb-lang { font-size: 13px; font-weight: 600; text-decoration: none; padding: 0 6px; }

/* ---------- buttons ---------- */
.tb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.tb-btn:hover { filter: brightness(1.08); }
.tb-btn:disabled { opacity: .55; cursor: default; }
.tb-btn-ghost { background: transparent; color: var(--brand); }
.tb-btn-danger { background: var(--err); border-color: var(--err); }
.tb-btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.tb-link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font-weight: 600; font-size: 13px; }

/* ---------- stage ---------- */
.tb-stage { position: fixed; inset: var(--top-h) 0 0 0; overflow: hidden; cursor: grab; outline: none; touch-action: none;
  background-color: var(--bg); background-image: radial-gradient(var(--bg-dot) 1px, transparent 1px); background-size: 22px 22px; }
.tb-stage.dragging { cursor: grabbing; }
.tb-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.tb-canvas.animate { transition: transform .35s cubic-bezier(.2, .8, .2, 1); }
.tb-lines { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.tb-lines path { fill: none; stroke: var(--line); stroke-width: 1.6; }
.tb-lines path.spouse { stroke: var(--brand); stroke-width: 2; opacity: .55; }
.tb-lines path.ghost { stroke-dasharray: 4 4; opacity: .7; }
.tb-lines path.adopted { stroke-dasharray: 7 4; }
.tb-nodes { position: absolute; left: 0; top: 0; }

/* ---------- person card ---------- */
.tb-card {
  position: absolute; width: var(--card-w); height: var(--card-h); display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; user-select: none;
  border-left: 5px solid var(--unknown); transition: box-shadow .15s, transform .15s; animation: tbIn .25s ease both;
}
@keyframes tbIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.tb-card:hover { box-shadow: var(--shadow-lg); z-index: 3; }
.tb-card.g-M { border-left-color: var(--male); }
.tb-card.g-F { border-left-color: var(--female); }
.tb-card.focus { outline: 3px solid var(--brand); outline-offset: 2px; z-index: 2; }
.tb-card.selected { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 40%, transparent), var(--shadow-lg); }
.tb-card.dead .tb-av { filter: grayscale(.7); }
.tb-card.dead { background: color-mix(in srgb, var(--panel) 92%, var(--ink-3)); }
.tb-card.masked { opacity: .8; }
.tb-av { flex: 0 0 auto; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 16px; overflow: hidden;
  background: var(--unknown-bg); color: var(--unknown); }
.g-M .tb-av, .tb-av.g-M { background: var(--male-bg); color: var(--male); }
.g-F .tb-av, .tb-av.g-F { background: var(--female-bg); color: var(--female); }
.tb-av img { width: 100%; height: 100%; object-fit: cover; }
.tb-ci { min-width: 0; flex: 1; }
.tb-cn { font-weight: 650; font-size: 13.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tb-cy { font-size: 12px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-hint { position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #5d8c2f; color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--panel); }
.tb-hint::before { content: "🍃"; font-size: 10px; margin-right: 1px; }
.tb-tag { position: absolute; left: 12px; bottom: -9px; font-size: 10px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px;
  background: var(--panel); color: var(--ink-3); border: 1px solid var(--line-soft); }
.tb-plus { position: absolute; right: -13px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--brand); color: #fff;
  font-size: 17px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity .15s; box-shadow: var(--shadow); }
.tb-card:hover .tb-plus, .tb-card.selected .tb-plus, .tb-card:focus-within .tb-plus { opacity: 1; }
@media (hover: none) { .tb-plus { opacity: 1; } }
.tb-more { position: absolute; left: 50%; transform: translateX(-50%); bottom: -24px; font-size: 11px; border: 1px solid var(--line-soft); background: var(--panel);
  border-radius: 999px; padding: 1px 9px; cursor: pointer; color: var(--ink-2); }
.tb-more.up { bottom: auto; top: -24px; }
.tb-more.right { left: auto; right: -30px; bottom: auto; top: 50%; transform: translate(100%, -50%); }

/* ghost “Add father” card */
.tb-ghost { position: absolute; width: var(--card-w); height: var(--card-h); border: 2px dashed var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 55%, transparent);
  display: flex; align-items: center; gap: 10px; padding: 0 14px; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 13px; transition: border-color .15s, color .15s, background .15s; }
.tb-ghost:hover { border-color: var(--brand); color: var(--brand); background: var(--panel); }
.tb-ghost .tb-gplus { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; border: 2px dashed currentColor; font-size: 18px; }
.tb-ghost.small { width: 150px; height: 46px; font-size: 12px; }
.tb-ghost.small .tb-gplus { width: 24px; height: 24px; font-size: 14px; }

.tb-row-label { position: absolute; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; }

/* ---------- context menu ---------- */
.tb-menu { position: fixed; z-index: 60; min-width: 190px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; animation: tbIn .12s ease; }
.tb-menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.tb-menu button:hover, .tb-menu button:focus { background: var(--bg); outline: none; }
.tb-menu hr { border: 0; border-top: 1px solid var(--line-soft); margin: 4px 0; }
.tb-menu .mi { width: 20px; text-align: center; }

/* ---------- zoom + legend ---------- */
.tb-zoom { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 5; }
.tb-zoom button { width: 40px; height: 38px; border: 0; background: none; cursor: pointer; font-size: 17px; border-bottom: 1px solid var(--line-soft); }
.tb-zoom button:last-child { border-bottom: 0; }
.tb-zoom button:hover { background: var(--bg); color: var(--brand); }
.tb-legend { position: absolute; left: 16px; bottom: 16px; display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--ink-2); background: var(--panel);
  padding: 7px 12px; border-radius: 999px; box-shadow: var(--shadow); z-index: 5; flex-wrap: wrap; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.lg-m { background: var(--male); } .lg-f { background: var(--female); } .lg-d { background: color-mix(in srgb, #fff 80%, var(--ink-3)); border: 1px solid var(--ink-3); border-radius: 50%; }
.tb-stats { color: var(--ink-3); border-left: 1px solid var(--line-soft); padding-left: 12px; }

/* ---------- empty / loading ---------- */
.tb-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; }
.tb-empty-card { max-width: 420px; text-align: center; background: var(--panel); padding: 36px 30px; border-radius: 20px; box-shadow: var(--shadow-lg); }
.tb-empty-icon { font-size: 48px; }
.tb-empty-card h2 { margin: 10px 0 6px; }
.tb-empty-card p { color: var(--ink-2); line-height: 1.5; }
.tb-loading { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: var(--panel); border-radius: 999px; padding: 8px; box-shadow: var(--shadow); z-index: 6; }
.tb-spinner { display: block; width: 20px; height: 20px; border: 2.5px solid var(--line-soft); border-top-color: var(--brand); border-radius: 50%; animation: tbSpin .7s linear infinite; }
@keyframes tbSpin { to { transform: rotate(360deg); } }

/* ---------- drawer ---------- */
.tb-drawer { position: fixed; top: var(--top-h); right: 0; bottom: 0; width: 430px; max-width: 100vw; background: var(--panel); z-index: 25; box-shadow: var(--shadow-lg);
  transform: translateX(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); display: flex; flex-direction: column; }
.tb-drawer.open { transform: none; }
.tb-drawer-inner { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.tb-dh { position: relative; padding: 22px 22px 16px; display: flex; gap: 16px; align-items: center; border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 8%, var(--panel)), var(--panel)); }
.tb-dh .tb-av { width: 76px; height: 76px; font-size: 24px; position: relative; cursor: default; }
.tb-dh .tb-av.editable { cursor: pointer; }
.tb-dh .tb-av.editable:hover::after { content: "📷"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); font-size: 22px; }
.tb-dh h2 { margin: 0; font-size: 19px; line-height: 1.25; }
.tb-dh .sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.tb-dh .tb-close { position: absolute; top: 10px; right: 10px; }
.tb-completeness { height: 5px; background: var(--line-soft); border-radius: 3px; margin-top: 8px; overflow: hidden; width: 160px; }
.tb-completeness i { display: block; height: 100%; background: #5d8c2f; }
.tb-dactions { display: flex; gap: 8px; padding: 12px 22px; flex-wrap: wrap; border-bottom: 1px solid var(--line-soft); }
.tb-tabs { display: flex; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--panel); z-index: 2; overflow-x: auto; }
.tb-tabs button { border: 0; background: none; padding: 12px 10px; font-weight: 600; font-size: 13px; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tb-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tb-pane { padding: 18px 22px 40px; }
.tb-sec { margin-bottom: 22px; }
.tb-sec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; }
.tb-kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.tb-kv dt { color: var(--ink-3); }
.tb-kv dd { margin: 0; word-break: break-word; }
.tb-bio { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }

.tb-hints { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tb-hints li { display: flex; align-items: center; gap: 8px; background: #eef5e6; color: #2f4d14; border-radius: 8px; padding: 8px 10px; font-size: 13px; cursor: pointer; }
@media (prefers-color-scheme: dark) { .tb-hints li { background: #24331a; color: #cfe6b5; } }
.tb-hints li::before { content: "🍃"; }

.tb-rel { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.tb-rel:hover { background: var(--bg); }
.tb-rel .tb-av { width: 38px; height: 38px; font-size: 13px; }
.tb-rel .nm { font-weight: 600; font-size: 13.5px; }
.tb-rel .yr { font-size: 12px; color: var(--ink-3); }
.tb-rel .x { margin-left: auto; opacity: 0; border: 0; background: none; cursor: pointer; color: var(--ink-3); font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.tb-rel:hover .x { opacity: 1; }
.tb-rel .x:hover { background: var(--line-soft); color: var(--err); }
.tb-chip { font-size: 10.5px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 999px; background: var(--bg); color: var(--ink-3); margin-left: 6px; }

/* timeline */
.tb-tl { position: relative; padding-left: 22px; }
.tb-tl::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line-soft); }
.tb-ev { position: relative; padding: 4px 0 16px; }
.tb-ev::before { content: ""; position: absolute; left: -20px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 2.5px solid var(--brand); }
.tb-ev .t { font-weight: 650; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.tb-ev .d { font-size: 12.5px; color: var(--ink-3); }
.tb-ev .p { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.tb-ev .ds { font-size: 13px; margin-top: 3px; }
.tb-ev .src { font-size: 12px; margin-top: 4px; color: var(--ok); }
.tb-ev .ed { opacity: 0; margin-left: auto; }
.tb-ev:hover .ed { opacity: 1; }
@media (hover: none) { .tb-ev .ed, .tb-rel .x { opacity: 1; } }

/* ---------- forms ---------- */
.tb-form { display: grid; gap: 12px; }
.tb-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tb-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tb-grid .full { grid-column: 1 / -1; }
.tb-f label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.tb-f input[type=text], .tb-f input[type=date], .tb-f input[type=url], .tb-f input[type=number], .tb-f input[type=search], .tb-f select, .tb-f textarea {
  width: 100%; height: 38px; border: 1px solid var(--line-soft); border-radius: 8px; padding: 0 10px; background: var(--panel); outline: none; font-size: 14px; }
.tb-f textarea { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.tb-f input:focus, .tb-f select:focus, .tb-f textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
.tb-f .help { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }
.tb-seg { display: inline-flex; border: 1px solid var(--line-soft); border-radius: 8px; overflow: hidden; }
.tb-seg label { margin: 0; padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); border-right: 1px solid var(--line-soft); }
.tb-seg label:last-child { border-right: 0; }
.tb-seg input { position: absolute; opacity: 0; pointer-events: none; }
.tb-seg input:checked + span { color: var(--brand); }
.tb-seg label:has(input:checked) { background: color-mix(in srgb, var(--brand) 10%, var(--panel)); }
.tb-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.tb-check input { width: 17px; height: 17px; accent-color: var(--brand); }
.tb-details summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--brand); padding: 4px 0; }
.tb-details[open] summary { margin-bottom: 10px; }

/* ---------- modal ---------- */
.tb-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.tb-modal-backdrop { position: absolute; inset: 0; background: rgba(20, 16, 10, .45); backdrop-filter: blur(2px); animation: tbFade .2s; }
@keyframes tbFade { from { opacity: 0; } }
.tb-modal-card { position: relative; width: 640px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 18px;
  box-shadow: var(--shadow-lg); animation: tbIn .2s ease; }
.tb-mh { padding: 18px 22px 12px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tb-mh h2 { margin: 0; font-size: 18px; flex: 1; }
.tb-mh .ctx { font-size: 12.5px; color: var(--ink-3); font-weight: 500; display: block; margin-top: 2px; }
.tb-mb { padding: 18px 22px; }
.tb-mf { padding: 14px 22px; border-top: 1px solid var(--line-soft); display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--panel); flex-wrap: wrap; }
.tb-mf .left { margin-right: auto; }
.tb-mtabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tb-mtabs button { flex: 1; border: 1px solid var(--line-soft); background: var(--panel); border-radius: 10px; padding: 10px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.tb-mtabs button.active { border-color: var(--brand); color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, var(--panel)); }

.tb-dupes { border: 1px solid #e8c77a; background: #fff8e6; border-radius: 12px; padding: 10px 12px; }
@media (prefers-color-scheme: dark) { .tb-dupes { background: #3a2f12; border-color: #7a6223; } }
.tb-dupes h4 { margin: 0 0 6px; font-size: 13px; }
.tb-dupe { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.tb-dupe .tb-av { width: 32px; height: 32px; font-size: 12px; }
.tb-dupe .score { font-size: 11px; font-weight: 700; color: var(--warn); }
.tb-dupe button { margin-left: auto; }

.tb-pick { display: grid; gap: 4px; max-height: 300px; overflow: auto; margin-top: 8px; }
.tb-pick .tb-rel.sel { background: color-mix(in srgb, var(--brand) 10%, var(--panel)); outline: 2px solid var(--brand); }
.tb-sr { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.tb-sr:hover, .tb-sr.active { background: var(--bg); }
.tb-sr .tb-av { width: 34px; height: 34px; font-size: 12px; }
.tb-sr .nm { font-weight: 600; font-size: 13.5px; }
.tb-sr .yr { font-size: 12px; color: var(--ink-3); }
.tb-muted { color: var(--ink-3); font-size: 13px; }
.tb-relpath { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; margin-top: 8px; }
.tb-relpath span.arrow { color: var(--ink-3); }
.tb-relbig { font-size: 20px; font-weight: 700; color: var(--brand); }

/* ---------- toasts ---------- */
.tb-toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 70; width: min(92vw, 460px); }
.tb-toast { background: #1f1b16; color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; gap: 10px; align-items: center; animation: tbIn .2s; }
.tb-toast.err { background: var(--err); }
.tb-toast.warn { background: var(--warn); }
.tb-toast.ok { background: var(--ok); }
.tb-toast button { margin-left: auto; background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-weight: 600; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .tb-brand-text, .tb-lang, #tbDepth { display: none; }
  .tb-views button { padding: 7px 10px; font-size: 12px; }
}
@media (max-width: 680px) {
  :root { --top-h: 104px; }
  .tb-top { flex-wrap: wrap; height: var(--top-h); padding: 8px 10px; gap: 8px; align-content: center; }
  .tb-search { order: 5; flex-basis: 100%; max-width: none; margin: 0; }
  .tb-top-actions .tb-btn { height: 32px; padding: 0 10px; font-size: 12px; }
  .tb-drawer { top: auto; height: 78vh; width: 100%; border-radius: 18px 18px 0 0; transform: translateY(105%); }
  .tb-drawer.open { transform: none; }
  .tb-grid, .tb-grid-3 { grid-template-columns: 1fr 1fr; }
  .tb-legend { display: none; }
  .tb-kv { grid-template-columns: 110px 1fr; }
}

/* ---------- children reorder ---------- */
.tb-kidrow { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.tb-kidrow .tb-rel { flex: 1; min-width: 0; }
.tb-kidrow.dragging { opacity: .45; }
.tb-kidrow.over { box-shadow: inset 0 2px 0 var(--brand); }
.tb-grip { cursor: grab; color: var(--ink-3); font-size: 12px; letter-spacing: -2px; padding: 0 2px; user-select: none; }
.tb-ord { display: flex; flex-direction: column; gap: 2px; }
.tb-ord button { border: 1px solid var(--line-soft); background: var(--panel); border-radius: 5px; font-size: 9px; width: 22px; height: 17px; cursor: pointer; color: var(--ink-2); padding: 0; }
.tb-ord button:disabled { opacity: .3; cursor: default; }
.tb-ord button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.tb-print-head { display: none; }

/* ---------- print ---------- */
@media print {
  @page { size: landscape; margin: 10mm; }
  html, body.tb { height: auto; overflow: hidden; background: #fff; }
  .tb-modal, .tb-menu, .tb-loading, .tb-empty { display: none !important; }
  .tb-top, .tb-zoom, .tb-legend, .tb-drawer, .tb-toasts, .tb-plus, .tb-ghost, .tb-more, .tb-hint { display: none !important; }
  .tb-stage { position: relative; inset: auto; background: #fff; overflow: hidden; height: 168mm; margin-top: 14mm; }
  .tb-card { box-shadow: none; border: 1px solid #bbb; border-left-width: 5px; break-inside: avoid; animation: none; }
  .tb-print-head { display: block; position: absolute; top: 0; left: 0; right: 0; font-family: var(--font); }
  .tb-print-head h1 { font-size: 18pt; margin: 0; color: var(--brand); }
  .tb-print-head p { margin: 2pt 0 0; color: #555; font-size: 10pt; }
  .tb-canvas { position: relative; }
  .tb-lines path.ghost, .tb-row-label { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
