/* ============================================================
   Admin Mode — редактор эталона (canon-data.js)
   Все admin-стили вынесены сюда из game.css и admin-mode.js
   ============================================================ */

/* ---------- Базовая структура ---------- */
#admin-overlay .admin-canvas-wrapper { background: var(--bg-soft) !important; }
#admin-overlay .admin-fact-item.selected {
    border-color: var(--gold) !important;
    background: rgba(201, 169, 110, 0.12) !important;
}
#admin-overlay .admin-space-tabs button.active { border-bottom-color: var(--gold) !important; }

.admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}
.admin-topbar-title { font-size: 18px; font-weight: 600; }
.admin-topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.admin-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.admin-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border);
}

.admin-right {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 14px;
    overflow-y: auto;
    background: var(--bg-soft);
}

/* ---------- Табы ---------- */
.admin-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 12px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.admin-tabs button {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 14px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}
.admin-tabs button.active {
    color: var(--text);
    border-bottom-color: var(--gold);
    font-weight: 600;
}

/* ---------- Фильтры ---------- */
.admin-filters-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    align-items: center;
    flex-shrink: 0;
}
.admin-filters-bar input,
.admin-filters-bar select {
    font-size: 14px;
    padding: 6px 10px;
}
.admin-filters-bar input { flex: 1; }

/* ---------- Таблица фактов ---------- */
.admin-table-wrap {
    flex: 1;
    overflow: auto;
    padding: 0 12px;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.admin-table th {
    text-align: left;
    padding: 8px 10px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    position: sticky;
    top: 0;
}
.admin-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.admin-table-row { cursor: pointer; }
.admin-table-row:hover { background: rgba(201, 169, 110, 0.08); }
.admin-table-row.selected { background: rgba(201, 169, 110, 0.15); }

/* ---------- Статус и списки ---------- */
.admin-status-bar {
    padding: 8px 16px;
    font-size: 13px;
    opacity: 0.7;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.admin-staging-list {
    flex: 1;
    overflow-y: auto;
    font-size: 13px;
}

/* ---------- Оверлей окон оформления (W17 🧪 / W18 / W19) ----------
   БЕЗ затемнения и blur: поле за окном должно быть спокойно видно,
   пока правится графика. Оверлей прозрачный — ловит клик мимо окна
   для закрытия. */
.admin-theme-panel {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.atp-window {
    width: min(1100px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: none;
    border-radius: 24px;
    padding: 26px 30px;
    box-shadow: 0 24px 70px rgba(44,42,38,0.30), 0 4px 16px rgba(44,42,38,0.12);
}
.atp-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.atp-close {
    border: none;
    background: var(--bg);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--text);
    opacity: 0.55;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.atp-close:hover { opacity: 1; transform: scale(1.06); }
.atp-columns {
    display: grid;
    grid-template-columns: 1fr 1.25fr 1fr;
    gap: 18px;
}
.atp-col {
    background: var(--bg);
    border-radius: 18px;
    padding: 16px 18px;
    box-shadow: inset 0 0 0 1px var(--border);
}
.atp-col h4 {
    margin: 0 0 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
}
.atp-col h4:not(:first-child) { margin-top: 18px; }

/* Аккордеон (разворачивающиеся секции панели оформления) */
.atp-accordion { display: flex; flex-direction: column; gap: 8px; }
.atp-section {
    background: var(--bg);
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px var(--border);
    overflow: hidden;
}
.atp-section > summary {
    cursor: pointer;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    list-style: none;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.atp-section > summary::-webkit-details-marker { display: none; }
.atp-section > summary::after {
    content: '▸';
    font-size: 14px;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}
.atp-section[open] > summary::after { transform: rotate(90deg); }
.atp-section[open] > summary { border-bottom: 1px solid var(--border); }
.atp-section-body { padding: 14px 16px; }
.atp-foot {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}
.atp-foot button { flex: 1; border-radius: 12px; }
.atp-shapes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.atp-shape {
    width: 74px;
    padding: 12px 4px 8px;
    border: 1px solid transparent;
    border-radius: 14px;
    cursor: pointer;
    text-align: center;
    font-size: 10px;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    box-shadow: inset 0 0 0 1px var(--border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.atp-shape:hover { transform: translateY(-1px); box-shadow: inset 0 0 0 1px var(--text-secondary), 0 3px 8px rgba(44,42,38,0.10); }
.atp-shape.sel { box-shadow: inset 0 0 0 2px var(--accent); background: rgba(93,138,228,0.08); color: var(--text); }
.atp-shape .demo {
    width: 40px;
    height: 24px;
    margin: 0 auto 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--text-secondary);
}
.atp-shape .demo.sh-rounded { border-radius: 10px; }
.atp-shape .demo.sh-soft { border-radius: 6px; }
.atp-shape .demo.sh-square { border-radius: 1px; }
.atp-shape .demo.sh-pill { border-radius: 999px; }
.atp-shape .demo.sh-notch { clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px); }

/* Текстуры блоба */
.atp-shape .demo.tx-watercolor {
    background-image: radial-gradient(ellipse 22px 13px at 30% 40%, rgba(110,88,60,0.34), transparent 70%),
                      radial-gradient(ellipse 18px 11px at 68% 62%, rgba(110,88,60,0.28), transparent 70%),
                      radial-gradient(ellipse 26px 15px at 52% 30%, rgba(110,88,60,0.18), transparent 72%);
}
.atp-shape .demo.tx-paper {
    background-color: #FBF8F1;
    background-image: radial-gradient(rgba(150,135,110,0.55) 0.7px, transparent 0.8px),
                      radial-gradient(rgba(150,135,110,0.4) 0.6px, transparent 0.7px);
    background-size: 5px 5px, 7px 7px;
    background-position: 0 0, 2px 3px;
}
.atp-shape .demo.tx-baize {
    background-color: #E8E2D2;
    background-image: radial-gradient(rgba(72,63,50,0.5) 0.8px, transparent 0.9px),
                      radial-gradient(rgba(72,63,50,0.38) 0.7px, transparent 0.8px);
    background-size: 4px 4px, 6px 6px;
    background-position: 0 0, 2px 2px;
}
.atp-shape .demo.tx-fabric {
    background-image: repeating-linear-gradient(0deg, rgba(90,78,60,0.42) 0 1px, transparent 1px 4px),
                      repeating-linear-gradient(90deg, rgba(90,78,60,0.42) 0 1px, transparent 1px 4px);
}
.atp-shape .demo.tx-canvas {
    background-image: repeating-linear-gradient(0deg, rgba(90,78,60,0.5) 0 1.5px, transparent 1.5px 6px),
                      repeating-linear-gradient(90deg, rgba(90,78,60,0.5) 0 1.5px, transparent 1.5px 6px);
}

.atp-title { font-weight: 600; font-size: 16px; }
.atp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 8px;
}
.atp-row input[type=color],
#theme-spheres input[type=color] {
    width: 40px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 9px;
    background: none;
    box-shadow: inset 0 0 0 1px var(--border);
    cursor: pointer;
}
.atp-sub { font-size: 12px; opacity: 0.6; margin: 10px 0 6px; }
#theme-spheres label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
    margin-bottom: 8px;
    padding: 3px 4px;
    border-radius: 10px;
    transition: background 0.15s ease;
}
#theme-spheres label:hover { background: var(--bg-elevated); }
.atp-slider {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    margin-bottom: 10px;
    padding: 4px 2px;
}
.atp-slider span { flex: 0 0 108px; }
.atp-slider input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 4px; }
.atp-slider b { flex: 0 0 44px; text-align: right; font-weight: 600; font-size: 11px; }
.atp-hint { font-size: 11px; opacity: 0.55; margin-top: 10px; line-height: 1.5; }

/* ---------- Внутренние панели админки (legacy container styles) ---------- */
.admin-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
}
.admin-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}
.admin-toolbar h2 { margin: 0; font-size: 18px; }
.admin-actions { display: flex; gap: 8px; }
.admin-body { flex: 1; display: flex; overflow: hidden; }
.admin-panel { display: flex; flex-direction: column; }
.admin-list-panel {
    width: 380px;
    min-width: 380px;
    border-right: 1px solid var(--border);
}
.admin-list-panel h3 {
    margin: 0;
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}
.admin-filters {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.admin-filters input,
.admin-filters select {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
}
.admin-fact-list { flex: 1; overflow-y: auto; padding: 8px; }
.admin-fact-item {
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.admin-fact-item:hover { background: var(--bg-elevated); }
.admin-fact-item.selected {
    border-color: var(--accent);
    background: rgba(93,138,228,0.08);
}
.admin-fact-item .fact-id { font-size: 10px; opacity: 0.5; font-family: monospace; }
.admin-fact-item .fact-title { font-weight: 500; font-size: 13px; margin: 2px 0; }
.admin-fact-item .fact-meta {
    font-size: 11px;
    opacity: 0.6;
    display: flex;
    gap: 8px;
}
.admin-fact-item .fact-sphere {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.admin-canvas-panel { flex: 1; position: relative; }
.admin-canvas-panel h3 {
    margin: 0;
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}
.admin-canvas-wrapper { flex: 1; position: relative; overflow: hidden; background: var(--bg-soft); }
#admin-canvas { position: absolute; top: 0; left: 0; cursor: grab; }
#admin-canvas:active { cursor: grabbing; }
.admin-edge-form {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    z-index: 100;
}
.admin-edge-form input,
.admin-edge-form select {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
}
.admin-status {
    display: flex;
    justify-content: space-between;
    padding: 8px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: 12px;
    opacity: 0.7;
}
.admin-fact-editor {
    padding: 10px;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}

/* ---------- Пространства (space tabs) ---------- */
.admin-space-tabs {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.admin-space-tabs button {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
}
.admin-space-tabs button.active {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
}

/* ---------- Выбор пространства для .docx ---------- */
.docx-chooser {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    flex-direction: column;
}
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.docx-chooser-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    width: 400px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.dc-title { font-weight: 600; margin-bottom: 4px; }
.dc-hint { font-size: 12px; opacity: 0.6; margin-bottom: 12px; }
.dc-buttons { display: flex; gap: 8px; }
.anchor-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}
.anchor-row .anchor-text { flex: 1; font-size: 12px; word-break: break-word; }
.anchor-row select {
    flex: 1.3;
    padding: 4px 6px;
    font-size: 11px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    max-width: 60%;
}

/* ---------- Плавающая панель (float) ---------- */
.admin-float {
    position: fixed;
    top: 60px;
    right: 12px;
    width: 380px;
    max-height: calc(100vh - 80px);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
    display: flex;
    flex-direction: column;
    z-index: 500;
    overflow: hidden;
    resize: both;
}
.admin-float.collapsed { width: 48px; height: 48px; resize: none; overflow: hidden; }
.admin-float-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    user-select: none;
}
.admin-float-title { font-size: 13px; font-weight: 600; }
.admin-float-tools { display: flex; gap: 4px; }
.admin-float-tools button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}
.admin-float-tools button:hover { background: var(--border); }
.admin-float-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.admin-float.collapsed .admin-float-body { display: none; }
.admin-float-panel {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
}
.admin-float-panel h4 {
    margin: 0 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

/* ---------- Адаптив окна «Оформление» ---------- */
@media (max-width: 1000px) {
    .atp-columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
    .atp-columns { grid-template-columns: 1fr; }
}

/* ---------- Icon picker (в редакторе фактов) ---------- */
.icon-picker {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin: 4px 0 6px;
}
.icon-pick {
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    background: var(--bg);
    overflow: hidden;
}
.icon-pick:hover { border-color: var(--text-secondary); }
.icon-pick.sel { border-color: var(--accent); background: rgba(93,138,228,0.12); color: var(--accent); }
.icon-pick svg { width: 22px; height: 22px; }
.icon-grp {
    grid-column: 1 / -1;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin: 8px 0 2px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--border);
}
.icon-grp:first-child { margin-top: 0; }

/* ---------- Модальное окно редактора фактов ---------- */
.admin-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(44,42,38,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    padding: 20px;
}
.aem-window {
    width: min(1400px, 96vw);
    height: 92vh;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px 24px;
    box-shadow: 0 18px 60px rgba(44,42,38,0.35);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}
/* Две колонки: слева свойства, справа текст */
.aem-cols {
    display: flex;
    gap: 18px;
    flex: 1;
    min-height: 0;
}
.aem-side {
    flex: 0 0 340px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-height: 0;
}
.aem-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}
.rt-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}
/* Панель форматирования */
.rt-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: var(--bg-soft);
}
.rt-btn {
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    border-radius: 6px;
    min-width: 32px;
    height: 30px;
    padding: 0 8px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}
.rt-btn:hover { background: var(--bg); border-color: var(--text-secondary); }
.rt-btn.rt-wide { padding: 0 12px; font-size: 13px; }
.rt-btn.rt-sub { font-size: 10px; font-weight: 700; }
.rt-sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.rt-toolbar select {
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    padding: 0 6px;
}
.rt-toolbar input[type="color"] {
    width: 36px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    cursor: pointer;
}
/* Редактор текста — тёмная «бумага» как в предпросмотре статьи (.wiki-body) */
.rt-editor {
    flex: 1;
    min-height: 260px;
    overflow-y: auto;
    border: 1px solid #2A2F36;
    border-radius: 0 0 8px 8px;
    background: #18212C;
    color: #E8EAED;
    padding: 20px 28px;
    font-size: 18px;
    line-height: 1.65;
    font-family: inherit;
    text-align: left;
    hyphens: auto;
    outline: none;
    box-sizing: border-box;
    caret-color: #E8EAED;
}
.rt-editor:focus { border-color: var(--gold); }
.rt-editor p { margin: 0 0 1em; }
.rt-editor a.wiki-link, .rt-editor a[data-node] {
    color: #84B5F8;
    border-bottom: 1px solid rgba(132, 181, 248, 0.4);
    text-decoration: none;
    cursor: text;
}
.rt-editor::-webkit-scrollbar { width: 10px; }
.rt-editor::-webkit-scrollbar-thumb { background: #3A4048; border-radius: 6px; }
.rt-editor::-webkit-scrollbar-track { background: transparent; }
/* Попап выбора факта для гиперссылки */
.rt-linkpop {
    position: absolute;
    top: 44px;
    left: 8px;
    right: 8px;
    max-width: 480px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(44,42,38,0.25);
    padding: 10px;
}
.rt-linkpop input {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.rt-link-list {
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.rt-link-item {
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
}
.rt-link-item:hover { background: var(--bg-soft); }
.rt-link-empty { padding: 10px; font-size: 13px; opacity: 0.6; }
.rt-linkpop .btn { align-self: flex-end; }
/* Плашка подтверждения выхода */
.aem-exit-confirm {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(44,42,38,0.4);
    border-radius: 16px;
}
.aem-exit-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 26px;
    box-shadow: 0 18px 60px rgba(44,42,38,0.35);
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 420px;
}
.aem-exit-text { font-size: 15px; line-height: 1.45; text-align: center; }
.aem-exit-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
@media (max-width: 900px) {
    .aem-cols { flex-direction: column; }
    .aem-side { flex: 0 0 auto; }
    .aem-window { height: auto; max-height: 94vh; }
}
.aem-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.aem-title { font-weight: 600; font-size: 16px; }
.aem-close {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text);
    opacity: 0.5;
    padding: 4px 8px;
    border-radius: 6px;
}
.aem-close:hover { opacity: 1; background: var(--bg); }
.aem-head-btns { display: flex; align-items: center; gap: 6px; }

/* Кнопки на строчках списка фактов */
.row-actions { white-space: nowrap; width: 64px; }
.fact-del {
    border: none;
    width: 24px; height: 24px;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 4px;
    transition: filter 0.15s ease;
}
.fact-del { background: #C0392B; color: #fff; }
.fact-del:hover { filter: brightness(1.15); }
/* Перетаскивание строк списка фактов */
.admin-table-row[draggable] { cursor: grab; }
.admin-table-row.dragging { opacity: 0.4; }
.admin-table-row.drag-over-top { box-shadow: 0 -2px 0 var(--accent); }
.admin-table-row.drag-over-bottom { box-shadow: 0 2px 0 var(--accent); }
/* Подтверждение удаления */
.aem-ask-overlay {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(44,42,38,0.45);
}
.aem-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.aem-row label {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.7;
    min-width: 100px;
    flex-shrink: 0;
}
.aem-row input,
.aem-row select,
.aem-row textarea {
    flex: 1;
    min-width: 180px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
}
.aem-row textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
}
.aem-row input[readonly] { opacity: 0.5; }

/* W6: длинные подписи и плашки переносятся по словам — ничего не выпирает вправо */
.aem-side { overflow-x: hidden; }
.aem-row label { flex-shrink: 1; overflow-wrap: break-word; }
.aem-title { overflow-wrap: break-word; }
#edit-gates > div { min-width: 0; }
#edit-gates span { min-width: 0; overflow-wrap: break-word; }
#edit-anchors, .anchor-row { min-width: 0; }
.anchor-row .anchor-text { overflow-wrap: anywhere; }
#edit-image-box img { max-width: 100%; }
.aem-foot {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}
@media (max-width: 1000px) {
    .atp-columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
    .atp-columns { grid-template-columns: 1fr; }
}

/* ---------- Связи на игровом поле (режим администратора) ---------- */
.node.edge-source {
    outline: 2.5px dashed var(--gold);
    outline-offset: 3px;
}
#edge-popover,
#epoch-popover {
    position: fixed;
    z-index: 4000;
    width: 270px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: modalIn 0.2s ease-out;
}
#edge-popover .ep-title,
#epoch-popover .ep-title {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text);
}
#edge-popover input,
#edge-popover select,
#epoch-popover input {
    width: 100%;
    padding: 7px 9px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
}
#edge-popover input:focus,
#edge-popover select:focus,
#epoch-popover input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.15);
}
#edge-popover .ep-buttons,
#epoch-popover .ep-buttons { display: flex; gap: 8px; }
#epoch-popover .epo-years { display: flex; gap: 8px; }
#epoch-popover .epo-years input { width: 50%; }
#edge-popover .ep-buttons .btn,
#epoch-popover .ep-buttons .btn { flex: 1; padding: 7px 10px; font-size: 12px; }

/* Попап эпохи «название, годы, текстура и цвет» (ПКМ по блобу) */
#texture-picker {
    position: fixed;
    z-index: 4000;
    width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: modalIn 0.2s ease-out;
}
#texture-picker .ep-title {
    font-size: 12px; font-weight: 600; line-height: 1.45; color: var(--text);
}
/* Поля «Название и годы» (унаследованы от бывшего epoch-popover) */
#texture-picker input[type="text"],
#texture-picker input[type="number"] {
    width: 100%;
    padding: 7px 9px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
}
#texture-picker input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.15);
}
#texture-picker .epo-years { display: flex; gap: 8px; }
#texture-picker .epo-years input { width: 50%; }
#texture-picker .ep-buttons { display: flex; gap: 8px; }
#texture-picker .ep-buttons .btn { flex: 1; padding: 7px 10px; font-size: 12px; }
#texture-picker .tx-grid {
    display: grid;
    /* Широкое окно: 7 колонок — вся сетка узоров (21 плитка = 3 ряда)
       видна целиком, без внутренней прокрутки */
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}
#texture-picker .tx-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    cursor: pointer;
    font-size: 10px;
    line-height: 1.2;
    color: var(--text-secondary);
}
#texture-picker .tx-item canvas {
    width: 48px; height: 48px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
#texture-picker .tx-item:hover { border-color: var(--gold); }
#texture-picker .tx-item.active {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.25);
}
#texture-picker .tx-item span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}

/* Строка цвета блоба: нативный пикер (любой цвет) + hex-поле + сброс */
#texture-picker .tx-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 6px;
}
#texture-picker input[type="color"] {
    width: 48px; height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    cursor: pointer;
    flex: 0 0 auto;
}
#texture-picker .tx-hex {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--font-mono, monospace);
    letter-spacing: 0.03em;
    text-transform: lowercase;
}
#texture-picker .tx-color-row .btn { flex: 0 0 auto; margin-left: auto; }
#texture-picker .tx-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 4px;
}
#texture-picker .tx-swatch {
    width: 22px; height: 22px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}
#texture-picker .tx-swatch:hover { border-color: var(--gold); }
#texture-picker .tx-swatch.active {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.25);
}
/* Заголовки секций и исторических периодов */
#texture-picker .tx-sep {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin: 10px 0 6px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}
#texture-picker .tx-period {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 8px 0 4px;
}
#texture-picker .tx-period.suggested {
    color: var(--gold);
}
/* Плитка-мозаика подходящего эпохе периода — золотая рамка */
#texture-picker .tx-item.suggested {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px var(--gold) inset;
}
#texture-picker #tx-hist { margin-bottom: 4px; }

/* Меню ПКМ по пустому полю (W15) */
#canvas-menu {
    position: fixed;
    z-index: 4000;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: modalIn 0.15s ease-out;
}
#canvas-menu .btn { white-space: nowrap; font-size: 13px; padding: 8px 14px; }
