/* Модуль «Раскладка плитки». Используем токены панели (--surface, --border, --ink ...). */

/* ---------- Полноэкранная оболочка (этап 1) ---------- */
body.tl-app .tl-shell {
    margin-left: 0;
    padding-top: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

body.tl-app .tl-page {
    display: flex;
    flex-direction: column;
    max-width: none;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

.tl-appbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-md);
    min-height: 52px;
    padding: 0 var(--sp-md);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.tl-appbar-start,
.tl-appbar-end {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    flex-wrap: wrap;
}

body.tl-app .tl-page > .flash-list {
    flex-shrink: 0;
    margin: var(--sp-md) var(--sp-md) 0;
}

.tl-page-pad {
    flex: 1;
    padding: var(--sp-xl);
}

.tl-landing {
    max-width: 640px;
}

.tl-landing-list {
    margin: var(--sp-md) 0;
    padding-left: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

.tl-landing-cta {
    flex-wrap: wrap;
    gap: var(--sp-sm);
    margin-top: var(--sp-lg);
}

.tl-credit-history {
    list-style: none;
    margin: 0;
    padding: 0;
    gap: var(--sp-xs);
}

.tl-credit-row {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-md);
    align-items: baseline;
}

.tl-credit-plus { color: var(--growth, #059669); font-weight: 600; }
.tl-credit-minus { color: var(--ink-2); font-weight: 600; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body.tl-app-editor .tl-page {
    padding: 0;
}

body.tl-app-editor .tl-editor {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tl-editor-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-md);
    min-height: 52px;
    padding: 0 var(--sp-md);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.tl-editor-bar-start {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.tl-editor-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-xs);
    flex: 1 1 200px;
    min-width: 0;
    max-width: 360px;
}

.tl-editor-bar .tl-name {
    flex: 1 1 120px;
    min-width: 0;
    max-width: none;
    margin: 0;
    font-weight: 600;
}

.tl-editor-status {
    flex: 0 0 12.5rem;
    min-width: 12.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-editor-bar-end { flex-shrink: 0; flex-wrap: wrap; }

.tl-editor-logout { margin: 0; display: inline; }

.tl-editor-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(300px, 330px) minmax(0, 1fr);
}

.tl-editor.tl-inspector-collapsed .tl-editor-body {
    grid-template-columns: auto minmax(0, 1fr);
}

.tl-inspector {
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tl-editor.tl-inspector-collapsed .tl-inspector-panels,
.tl-editor.tl-inspector-collapsed .tl-inspector-tabs {
    display: none;
}

.tl-inspector-head {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-xs);
    padding: var(--sp-sm);
    border-bottom: 1px solid var(--border);
}

.tl-inspector-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}

.tl-inspector-tab {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 6px 10px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.tl-inspector-tab.is-active {
    border-color: var(--ink);
    background: var(--surface-sunken);
    font-weight: 600;
}

.tl-inspector-panels {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-sm);
    min-height: 0;
}

.tl-inspector-panel .tl-sec { padding: var(--sp-sm) 0; }

.tl-work-toolbar {
    display: flex;
    flex-direction: column;
    gap: var(--sp-xs);
    padding: var(--sp-sm) var(--sp-sm) 0;
}

.tl-surfaces-bar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    flex-wrap: nowrap;
}

.tl-surfaces-bar .tl-surf {
    flex: 0 0 auto;
    white-space: nowrap;
}

.tl-views-inline {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.tl-view-chip { display: inline-flex; gap: 2px; align-items: center; }

.tl-stage-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0 var(--sp-sm);
}

body.tl-app-editor .tl-work {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

body.tl-app-editor .tl-stage {
    flex: 1;
    min-height: 200px;
    height: auto;
    max-height: none;
}

.tl-help-btn {
    position: absolute;
    right: var(--sp-md);
    bottom: var(--sp-md);
    z-index: 2;
}

.tl-help-text { padding: 0 var(--sp-sm); margin: 0; }

.tl-mat-bar {
    flex-shrink: 0;
    width: calc(100% - var(--sp-md) * 2);
    margin: 0 var(--sp-sm) var(--sp-sm);
    padding: 10px var(--sp-md);
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    cursor: pointer;
}

.tl-mat-bar-warn { border-color: var(--outflow-border); color: #9f1239; }

.tl-zone-tile {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: var(--sp-sm);
    align-items: center;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.tl-zone-tile-empty { grid-template-columns: auto 1fr auto; }

.tl-zone-tile-faces { display: flex; gap: 4px; flex-wrap: wrap; }

.tl-zone-tile-btns { display: flex; flex-direction: column; gap: 4px; }

.tl-lib-dialog { width: min(1200px, 94vw); max-width: min(1200px, 94vw); max-height: 88vh; display: flex; flex-direction: column; }

.tl-lib-dialog .tl-modal-body {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(88vh - 4rem);
}

.tl-lib-scroll { overflow-y: auto; flex: 1; min-height: 0; max-height: calc(88vh - 10rem); }

body.tl-modal-open,
body.tl-inspector-sheet-open { overflow: hidden; }

.tl-projects-head {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-md);
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: var(--sp-lg);
}

.tl-projects-head .tl-newform {
    flex: 1 1 280px;
    min-width: 0;
    max-width: 520px;
}

.tl-projects-head-title { flex: 0 0 auto; }

.tl-pgroups { display: flex; flex-direction: column; gap: var(--sp-lg); }

.tl-pgroup { display: flex; flex-direction: column; gap: 6px; }

.tl-prow {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--sp-md);
    align-items: center;
    padding: var(--sp-sm) var(--sp-md);
}

.tl-pthumb {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--surface-sunken);
    text-decoration: none;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.tl-pthumb-main {
    width: clamp(144px, 12vw, 168px);
    height: 112px;
}

.tl-pthumb-variant {
    width: clamp(96px, 10vw, 112px);
    height: 68px;
}

.tl-pthumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tl-pinfo { min-width: 0; }

.tl-pinfo-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.tl-pname {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.25;
    text-decoration: none;
    color: var(--ink);
}

.tl-pmeta {
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-pactions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
}

.tl-pgroup-variants {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: calc(clamp(144px, 12vw, 168px) + var(--sp-md) * 2);
    padding-left: var(--sp-md);
    border-left: 2px solid var(--border);
}

@media (max-width: 720px) {
    .tl-prow {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .tl-pactions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .tl-pgroup-variants {
        margin-left: var(--sp-md);
    }
}

.tl-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-sunken);
    color: var(--ink-2);
}

.tl-badge-shared { background: #eff6ff; color: #1d4ed8; }

.tl-w100 { width: 100%; }

/* ---------- Тосты и диалоги ---------- */
.tl-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.tl-toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius-lg); font-size: 14px; box-shadow: var(--shadow-3); transition: opacity .35s; }
.tl-toast-error { background: var(--outflow); }
.tl-toast.is-out { opacity: 0; }

.tl-modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow-y: auto; }
.tl-modal { background: var(--surface); border-radius: var(--radius-lg); padding: var(--sp-lg); width: 100%; max-width: 560px; box-shadow: var(--shadow-3); }
.tl-modal-wide { max-width: 980px; }
.tl-ai-review { margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--canvas); }
.tl-ai-review .tl-ai-text { max-height: 7rem; overflow-y: auto; white-space: pre-wrap; margin: 0 0 8px; font-size: 13px; }
.tl-ai-review .t-label { margin: 6px 0 4px; font-size: 12px; }
.tl-ai-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tl-ai-feedback { width: 100%; min-height: 4rem; resize: vertical; font-size: 13px; }
.tl-modal-sm { max-width: 420px; display: flex; flex-direction: column; gap: var(--sp-sm); align-self: center; }
.tl-modal h3 { margin: 0; }
.tl-modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-md); }
.tl-modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-xs); margin: var(--sp-md) 0; flex-wrap: wrap; }

/* ---------- Поля ---------- */
.tl-f { display: block; min-width: 0; }
.tl-f .field { width: 100%; }
.tl-f-wide { grid-column: 1 / -1; }
.tl-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.tl-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tl-color { width: 100%; height: 38px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.tl-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); margin: 4px 0; }
.tl-bad { color: var(--outflow); }
.tl-outline-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--canvas); }
.tl-outline-points { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.tl-outline-point { display: grid; grid-template-columns: 24px 1fr 1fr 34px; gap: 6px; align-items: end; }
.tl-outline-point > b { align-self: center; text-align: center; color: var(--ink-3); }
.tl-outline-point .btn { min-width: 34px; padding-inline: 6px; }
.tl-outline-point .field-label { font-size: 11px; }
.tl-outline-point .field { padding-inline: 6px; }
.tl-outline-points + .t-meta { margin-bottom: 0; }
.tl-outline-measure { margin-top: 10px; }
.tl-outline-measure > .t-meta { margin: 4px 0; }
.tl-outline-point.is-edge-corner > b { color: var(--ink); }
.tl-outline-dimensions { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.tl-outline-label {
    position: absolute; transform: translate(-50%, -50%); min-height: 24px; padding: 0 6px;
    border: 1px solid #bfdbfe; border-radius: 4px; background: #fff; color: #1e3a8a;
    font: 600 12px system-ui, sans-serif; white-space: nowrap; cursor: pointer; pointer-events: auto;
}
.tl-outline-label[aria-pressed="true"] { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.tl-outline-label:focus-visible { outline: 2px solid #1d4ed8; outline-offset: 2px; }
@media (max-width: 719px) { .tl-grid3 { grid-template-columns: 1fr 1fr; } }

/* ---------- Список проектов (legacy / shared) ---------- */
.tl-newform { display: flex; gap: var(--sp-sm); align-items: flex-end; flex-wrap: wrap; }
.tl-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-md); }

/* ---------- Редактор ---------- */
.tl-editor { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: var(--sp-md); align-items: start; }
.tl-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); position: sticky; top: calc(var(--header-h) + 12px); max-height: calc(100vh - var(--header-h) - 24px); overflow-y: auto; }
.tl-sec { padding: var(--sp-md); border-bottom: 1px solid var(--border); }
.tl-sec:last-child { border-bottom: 0; }
.tl-sec h3 { margin: 0 0 8px; }
.tl-name { width: 100%; margin: 6px 0; font-weight: 600; }
.tl-surfaces { display: flex; flex-direction: column; gap: 4px; }
.tl-surf { display: flex; justify-content: space-between; gap: 8px; text-align: left; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font: inherit; font-size: 14px; color: var(--ink); cursor: pointer; }
.tl-surf:hover { background: var(--surface-sunken); }
.tl-surf.is-active { border-color: var(--ink); background: var(--surface-sunken); font-weight: 600; }
.tl-surf-sum { font-size: 12px; font-weight: 400; color: var(--ink-3); white-space: nowrap; }
.tl-links { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.tl-zone { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--canvas); }
.tl-zone-head { display: flex; justify-content: space-between; align-items: center; }
.tl-zone-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tl-thumb { border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-sunken); display: block; }
.tl-thumb-empty { width: 40px; height: 40px; }
.tl-view { display: flex; align-items: center; gap: 4px; font-size: 14px; }

.tl-mat { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; background: var(--canvas); }
.tl-mat-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.tl-mt { width: 100%; border-collapse: collapse; font-size: 13px; }
.tl-mt td { padding: 2px 0; border-bottom: 1px dashed var(--border); }
.tl-mt .num { text-align: right; font-variant-numeric: tabular-nums; }
.tl-warns { display: flex; flex-direction: column; gap: 4px; }
.tl-warn { font-size: 13px; padding: 4px 8px; border-radius: var(--radius); }
.tl-warn-bad { background: var(--outflow-bg); color: #9f1239; border: 1px solid var(--outflow-border); }
.tl-warn-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.tl-work { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.tl-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tl-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; flex: 1; }
.tl-stage { position: relative; height: clamp(420px, calc(100vh - 230px), 900px); background: #f4f3ee; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.tl-stage canvas { display: block; touch-action: none; cursor: grab; }
.tl-stage canvas:active { cursor: grabbing; }
.tl-stage canvas.tl-canvas-shift { cursor: move; }
.tl-note { position: absolute; left: 10px; bottom: 10px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 4px 10px; border-radius: var(--radius); font-size: 13px; }
.tl-popup { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 16px); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: 6px 10px; box-shadow: var(--shadow-3); }
.tl-faces { display: flex; gap: 4px; flex-wrap: wrap; }
.tl-face-btn { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 2px; border: 2px solid transparent; border-radius: var(--radius); background: transparent; cursor: pointer; font-size: 11px; color: var(--ink-2); }
.tl-face-btn.is-active { border-color: #2563eb; }
.tl-face-btn canvas { border-radius: 2px; }
.tl-face-btn.is-empty { opacity: .35; }
.tl-move { display: inline-flex; gap: 2px; }
.tl-move .btn { min-width: 30px; padding-left: 6px; padding-right: 6px; }
.tl-stock { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.tl-stock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.tl-stock-empty { margin-top: 6px; }
.tl-stock-t th { font-weight: 500; font-size: 12px; color: var(--ink-2); text-align: right; padding: 2px 0 2px 6px; white-space: nowrap; overflow: hidden; max-width: 90px; }
.tl-stock-t th:first-child { text-align: left; padding-left: 0; }
.tl-stock-t td { padding-left: 6px; white-space: nowrap; }
.tl-stock-t td:first-child { padding-left: 0; display: flex; align-items: center; gap: 4px; }
.tl-stock-sum td { font-weight: 600; border-bottom: none; }
.tl-stock-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 10px 0; }
.tl-stock-face { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; }
.tl-stock-face input { width: 90px; text-align: center; }
#tl-stage-3d canvas { display: block; }


body.tl-app-editor .tl-editor.tl-editor {
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: stretch;
    padding: 0;
}

/* ---------- Библиотека ---------- */
.tl-tcard { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.5fr) auto; gap: var(--sp-md); align-items: center; }
.tl-tfaces { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.tl-tfaces canvas { border-radius: 2px; border: 1px solid var(--border); }
.tl-more { font-size: 13px; color: var(--ink-3); padding: 0 6px; }
.tl-tactions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 899px) { .tl-tcard { grid-template-columns: 1fr; } .tl-tactions { justify-content: flex-start; } }

.tl-fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin: 8px 0; }
.tl-fitem { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 6px; cursor: grab; background: var(--surface); }
.tl-fitem.is-drag { opacity: .4; }
.tl-fitem.is-target { outline: 2px solid #2563eb; }
.tl-fimg { position: relative; display: flex; justify-content: center; }
.tl-fimg canvas { max-width: 100%; border-radius: 2px; }
.tl-fnum { position: absolute; left: 4px; top: 4px; background: rgba(15, 23, 42, .7); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 9px; }
.tl-fcrop { position: absolute; right: 4px; bottom: 4px; background: rgba(5, 150, 105, .85); color: #fff; font-size: 10px; padding: 0 6px; border-radius: 9px; }
.tl-forigin { position: absolute; left: 4px; bottom: 4px; background: rgba(15, 23, 42, .75); color: #fff; font-size: 10px; padding: 0 6px; border-radius: 9px; }
.tl-forigin-net { background: rgba(37, 99, 235, .85); }
.tl-fbtns { display: flex; flex-direction: column; gap: 4px; }
.tl-fbtns .btn { justify-content: center; }
.tl-drop { border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 16px; text-align: center; margin: 12px 0; }
.tl-drop p { margin: 0 0 8px; }
.tl-drop.is-over { border-color: #2563eb; background: #eff6ff; }
.tl-drop.is-busy { opacity: .5; pointer-events: none; }

.tl-crop-stage { position: relative; margin: 8px auto; user-select: none; touch-action: none; max-width: 100%; }
.tl-crop-stage img { display: block; max-width: none; }
.tl-crop-rect { position: absolute; border: 2px solid #2563eb; box-shadow: 0 0 0 9999px rgba(15, 23, 42, .5); cursor: move; touch-action: none; }
.tl-crop-rect i { position: absolute; width: 16px; height: 16px; background: #fff; border: 2px solid #2563eb; border-radius: 50%; }
.tl-crop-rect i[data-c="nw"] { left: -9px; top: -9px; cursor: nwse-resize; }
.tl-crop-rect i[data-c="ne"] { right: -9px; top: -9px; cursor: nesw-resize; }
.tl-crop-rect i[data-c="sw"] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.tl-crop-rect i[data-c="se"] { right: -9px; bottom: -9px; cursor: nwse-resize; }

.tl-bar { height: 6px; background: var(--surface-sunken); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.tl-bar > div { height: 100%; background: var(--growth); transition: width .4s; }
.tl-bar-busy > div { width: 30%; animation: tl-busy 1.4s ease-in-out infinite; }
@keyframes tl-busy { from { margin-left: -30%; } to { margin-left: 100%; } }

/* Подбор лиц из интернета: свои лица сверху, галерея найденного снизу */
.tl-mfaces { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 8px 0 16px; }
.tl-mface { position: relative; border: 2px solid var(--border); border-radius: var(--radius); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.tl-mface.is-active { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, .2); }
.tl-mpair { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-items: center; }
.tl-mpair img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface-sunken); border-radius: 2px; }
.tl-mempty { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text-muted, #64748b); border: 1px dashed var(--border-strong); border-radius: 2px; }
.tl-mcands { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tl-msite { position: absolute; right: 4px; bottom: 4px; background: rgba(15, 23, 42, .7); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 9px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.tl-img { position: relative; border: 2px solid var(--border); border-radius: var(--radius); cursor: pointer; overflow: hidden; aspect-ratio: 1; background: var(--surface-sunken); }
.tl-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tl-img.is-on { border-color: #2563eb; }
.tl-order { position: absolute; left: 4px; top: 4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #2563eb; color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; }

.tl-icompare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 12px 0; }
.tl-icompare-side { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.tl-icompare-img { width: 100%; aspect-ratio: 16/10; background: var(--surface-sunken); border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.tl-icompare-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tl-ithumb { display: inline-flex; min-width: 28px; height: 28px; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 6px; margin: 0 4px 4px 0; cursor: pointer; font-size: 12px; }
.tl-ithumb.is-on { border-color: #2563eb; font-weight: 600; }
.tl-ithumb.is-done { background: rgba(37, 99, 235, .12); }
.tl-img.is-busy { opacity: .55; }

/* ---------- Этап 5: a11y, модалки, адаптив редактора ---------- */

.tl-inspector-scrim {
    position: fixed;
    inset: 0;
    z-index: 80;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(15, 23, 42, .45);
    cursor: pointer;
}

.tl-inspector-fab {
    position: fixed;
    right: max(var(--sp-md), env(safe-area-inset-right, 0px));
    bottom: max(var(--sp-md), env(safe-area-inset-bottom, 0px));
    z-index: 70;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    box-shadow: var(--shadow-3);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

body.tl-app :is(.btn, .tl-inspector-tab, .tl-surf, .segmented button, .tl-mat-bar):focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

body.tl-app .btn-sm {
    min-height: 40px;
}

.tl-inspector-tab {
    min-height: 40px;
}

@media (min-width: 1280px) {
    .tl-editor-body {
        grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    }
}

@media (min-width: 1024px) and (max-width: 1279px) {
    .tl-editor-body {
        grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
    }
}

@media (max-width: 1023px) {
    body.tl-app-editor .tl-editor-body {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    body.tl-app-editor .tl-work {
        flex: 1 1 auto;
        min-height: 0;
        order: 1;
    }

    body.tl-app-editor .tl-inspector {
        order: 2;
        flex: 0 0 auto;
        border-right: 0;
        border-top: 1px solid var(--border);
        max-height: 38vh;
    }

    body.tl-app-editor .tl-editor.tl-inspector-collapsed .tl-inspector {
        display: none;
    }

    body.tl-app-editor .tl-editor.tl-inspector-open:not(.tl-inspector-collapsed) .tl-inspector {
        display: flex;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(400px, 92vw);
        max-height: none;
        z-index: 90;
        box-shadow: var(--shadow-3);
        border-top: 0;
    }

    body.tl-app-editor .tl-stage-wrap {
        min-height: clamp(220px, 52vh, 560px);
    }

    .tl-editor-bar {
        flex-wrap: wrap;
        gap: var(--sp-sm);
    }

    .tl-editor-bar-end {
        overflow-x: auto;
        max-width: 100%;
        flex-wrap: nowrap;
        padding-bottom: 2px;
    }
}

@media (max-width: 767px) {
    body.tl-app-editor .tl-editor.tl-inspector-open:not(.tl-inspector-collapsed) .tl-inspector {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: auto;
        height: min(78vh, calc(100dvh - 3.5rem));
        max-height: calc(100dvh - 3.5rem);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    body.tl-app-editor .tl-stage-wrap {
        min-height: clamp(240px, 58vh, 640px);
    }

    body.tl-app-editor .btn-sm,
    body.tl-app-editor .tl-inspector-fab,
    body.tl-app-editor .tl-mat-bar,
    body.tl-app-editor .tl-surfaces-bar .tl-surf {
        min-height: 44px;
    }

    .tl-editor-bar-start {
        flex-direction: column;
        align-items: stretch;
    }

    .tl-editor-title,
    .tl-editor-bar .tl-name {
        flex: 1 1 100%;
        max-width: none;
    }

    .tl-editor-status {
        flex: 0 0 auto;
        min-width: 0;
        width: 100%;
    }

    .tl-editor-bar-end {
        overflow-x: visible;
        flex-wrap: wrap;
        padding-bottom: 0;
    }

    .tl-page-pad {
        padding: var(--sp-md);
    }
}

@media (max-width: 420px) {
    body.tl-app {
        overflow-x: hidden;
    }

    .tl-surfaces-bar,
    .tl-editor-bar-end {
        -webkit-overflow-scrolling: touch;
    }
}

/* Класс .hidden панели должен побеждать display из правил модуля. */
.tl-popup.hidden, .tl-tools.hidden, .tl-stage.hidden, .tl-note.hidden, .tl-order.hidden, .tl-sec.hidden { display: none !important; }
