/* ═══ КОРРЕКТОР v3 — STYLES ═══════════════════════════════════════
   Принципы:
   - Никаких внешних бордеров, только 5% opacity дивайдеры
   - 0px скруглений
   - Реальный RTDoc логотип
   - 9 теговых цветов + 4 метаполя
   ═════════════════════════════════════════════════════════════════ */

:root {
  /* Surfaces */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-soft: #f0f0f4;

  /* Text */
  --text: #1d1d1f;
  --text-2: #5a5a60;
  --text-3: #a0a0a8;
  --text-4: #c7c7cf;

  /* Dividers (5% / 10%) */
  --divider: rgba(0, 0, 0, .05);
  --divider-strong: rgba(0, 0, 0, .10);

  /* Brand */
  --primary: #7dc244;
  --primary-h: #6db33a;
  --primary-dim: #eaf5d8;
  --primary-txt: #3a7d1a;

  /* Tab colors */
  --tab-source: #7dc244;
  --tab-correct: #4a9fff;
  --tab-translate: #a855f7;
  --tab-transcr: #f97316;

  /* Tag colors */
  --tag-titre: #4a9fff;
  --tag-speech: #10b981;
  --tag-name: #a855f7;
  --tag-role: #f97316;
  --tag-quote: #eab308;
  --tag-titre169: #06b6d4;
  --tag-geo: #6b7280;
  --tag-courtesy: #475569;
  --tag-note: #94a3b8;
  --tag-meta: #ec4899;

  /* Counter states */
  --count-ok: #10b981;
  --count-warn: #eab308;
  --count-over: #ef4444;

  /* Diff */
  --diff-a-bg: #e6f6da;
  --diff-a-txt: #3a7d1a;
  --diff-d-bg: #ffebe9;
  --diff-d-txt: #cf222e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html { font-family: 'Inter', system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; overflow: hidden; height: 100vh; }

button { font: inherit; border: 0; background: transparent; cursor: pointer; color: inherit; }
input, textarea { font: inherit; border: 0; background: transparent; outline: none; color: inherit; }

.hidden { display: none !important; }

/* ═══ SCREENS ════════════════════════════════════════════════════ */
.screen { width: 100vw; height: 100vh; display: flex; flex-direction: column; }

/* ═══ LOGIN ══════════════════════════════════════════════════════ */
#login-screen { background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); }
.login-bg {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.login-bg::before {
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, .03) 1px, transparent 1px);
  background-size: 28px 28px;
}
.login-card {
  background: var(--surface);
  padding: 56px 48px; width: 440px;
  position: relative; z-index: 1;
}
.login-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--primary);
}
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-head .logo-img { height: 28px; }
.login-head h1 { font-size: 24px; font-weight: 700; }
.login-sub { font-size: 13px; color: var(--text-2); margin-bottom: 36px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 10px; font-weight: 600; color: var(--text-3); letter-spacing: .12em; text-transform: uppercase; margin-bottom: 8px; }
.field input { width: 100%; padding: 13px 14px; background: var(--bg); font-size: 14px; }
.field input:focus { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--primary); }
.btn-primary {
  width: 100%; padding: 14px; background: var(--primary); color: white;
  font-size: 14px; font-weight: 600; letter-spacing: .02em;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary.btn-sm { padding: 8px 14px; font-size: 12px; width: auto; }
.error { color: #cf222e; font-size: 12px; margin-top: 12px; }
.login-foot { text-align: center; margin-top: 22px; font-size: 11px; color: var(--text-3); }

/* ═══ APP ════════════════════════════════════════════════════════ */
#app-screen { background: var(--bg); }

/* Top bar */
#topbar {
  height: 52px; flex-shrink: 0;
  display: flex; align-items: center;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
  gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo-img { height: 22px; width: auto; display: block; }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text); }
.topbar-spacer { flex: 1; }
.topbar-charcount { font-size: 12px; color: var(--text-3); margin-right: 4px; }
.topbar-btn {
  height: 32px; padding: 0 12px;
  font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.topbar-btn .icon { width: 14px; height: 14px; }
.topbar-btn.primary { background: var(--primary); color: white; }
.topbar-btn.primary:hover { background: var(--primary-h); }
.topbar-btn.ghost { color: var(--text-2); background: var(--surface-soft); }
.topbar-btn.ghost:hover { background: #e6e6ec; color: var(--text); }
.topbar-btn.ghost.active { background: var(--primary-dim); color: var(--primary-txt); }
.topbar-btn .badge {
  background: rgba(0,0,0,.15); color: inherit; padding: 1px 6px;
  font-size: 10px; font-weight: 700; margin-left: 2px;
  font-variant-numeric: tabular-nums;
}
.topbar-actions { display: flex; gap: 6px; }
.avatar {
  width: 30px; height: 30px;
  background: var(--primary-dim); color: var(--primary-txt);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.avatar:hover { background: var(--primary); color: white; }

.icon {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.icon.icon-sm { width: 12px; height: 12px; }

/* Main split */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

/* ═══ LEFT: CHAT ═════════════════════════════════════════════════ */
#chat-pane {
  width: 320px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--divider);
  display: flex; flex-direction: column;
  position: relative;
}
.chat-head {
  height: 36px; flex-shrink: 0;
  display: flex; align-items: center;
  padding: 0 14px;
  font-size: 9px; font-weight: 700;
  color: var(--text-3); letter-spacing: .14em; text-transform: uppercase;
  border-bottom: 1px solid var(--divider);
}
.chat-body {
  flex: 1; overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.55;
  max-width: 220px;
}
.chat-system {
  font-size: 10px; color: var(--text-3);
  padding: 5px 9px; background: var(--bg);
  align-self: center; letter-spacing: .02em;
}
.chat-msg { font-size: 13px; line-height: 1.5; max-width: 88%; }
.chat-msg.user { align-self: flex-end; background: var(--primary-dim); color: var(--primary-txt); padding: 7px 11px; }
.chat-msg.bot { align-self: flex-start; color: var(--text); padding: 4px 0; }
.chat-input-wrap {
  border-top: 1px solid var(--divider);
  padding: 10px 12px;
}
.chat-input {
  width: 100%;
  background: var(--bg);
  padding: 8px 10px;
  font-size: 13px;
  min-height: 56px;
  max-height: 200px;
  resize: vertical;
}
.chat-input:disabled { opacity: .5; cursor: not-allowed; }
.chat-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 8px; }
.chat-model-badge { font-size: 10px; color: var(--text-3); letter-spacing: .02em; }
.chat-send-btn {
  background: var(--primary); color: white;
  padding: 5px 12px; font-size: 11px; font-weight: 600;
}
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }
.chat-resize-handle {
  position: absolute; top: 0; right: -3px; bottom: 0; width: 6px;
  cursor: ew-resize; z-index: 10;
}

/* ═══ CENTER: WORKSPACE — grid с двумя колонками и двумя рядами
 * column 1: indicator-row (40px top) + col-source (rest)
 * column 2: card-deck (spans both rows) — внутри cards с собственными корешками
 * floating-stack — position absolute поверх всего */
#workspace {
  flex: 1; min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 40px 1fr;
  position: relative;
  background: var(--surface);
}

/* ═══ INDICATOR ROW — только source side (корешки карт переехали внутрь карт) */
.indicator-row {
  grid-column: 1; grid-row: 1;
  display: flex; align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
  padding-left: 4px;
  position: relative;
}
.tab {
  height: 100%;
  padding: 0 16px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600;
  color: var(--text);
  position: relative;
}
.tab .tab-color { width: 8px; height: 8px; display: inline-block; flex-shrink: 0; }
.tab[data-color="source"] .tab-color { background: var(--tab-source); }
.tab[data-color="source"].active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px;
  background: var(--tab-source);
}
.tab:disabled { cursor: default; }

/* Audit #3: маркер «перевод устарел» — мелкая ★ справа от названия таба
   (и на корешке карты тоже). Появляется, когда юзер правит RU-исходник
   после уже сделанного перевода. */
.tab.stale::after,
.deck-card-tab.stale::after {
  content: '★';
  margin-left: 4px;
  font-size: 11px;
  color: var(--tab-translate);
  font-weight: 700;
  line-height: 1;
}

.lang-hint {
  font-size: 11px;
  color: var(--tab-translate);
  margin-left: 4px;
  letter-spacing: .02em;
}
.lang-hint strong { color: var(--text-2); font-weight: 700; }

/* Card tabs row — внутри ir-card-side, левый край = стык с Source col */
.card-tabs {
  display: flex;
  align-items: stretch;
  height: 100%;
  position: relative;
}
.card-tab {
  height: 100%;
  min-width: 125px;
  padding: 0 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; font-weight: 700;
  letter-spacing: .04em;
  color: white;
  background: var(--ct-bg, var(--text-3));
  border-left: 1px solid rgba(255,255,255,.18);
  position: relative;
  transition: filter .15s, opacity .15s, transform .2s ease-out;
  cursor: pointer;
  user-select: none;
}
.card-tab[data-color="correct"]   { --ct-bg: var(--tab-correct); }
.card-tab[data-color="translate"] { --ct-bg: var(--tab-translate); }
.card-tab[data-color="transcr"]   { --ct-bg: var(--tab-transcr); }
.card-tab.active {
  z-index: 5;
  transform: translateX(-6px);   /* активная чуть «выезжает» влево */
  box-shadow: -4px 0 12px rgba(0,0,0,.18);
}
.card-tab:not(.active) { opacity: .85; }
.card-tab:not(.active):hover { opacity: 1; filter: brightness(.94); }
.card-tab.disabled { opacity: .35; cursor: not-allowed; }
.card-tab > span:first-child { white-space: nowrap; }

/* Кнопка «Сохранить всё» внутри активной card-tab */
.card-save {
  font-size: 10px; font-weight: 600;
  padding: 3px 9px;
  background: rgba(255,255,255,.85);
  color: var(--text);
  letter-spacing: .02em;
  text-transform: none;
  transition: background .12s;
}
.card-save:hover:not(:disabled) { background: white; }
.card-save:disabled { opacity: .55; cursor: not-allowed; background: rgba(255,255,255,.4); color: var(--text-2); }
.card-tab:not(.active) .card-save { display: none; }

/* Work columns (в grid #workspace) */
.work-cols {
  /* контейнер «прозрачен» — его дети явно размещены через #col-source / #card-deck в grid #workspace */
  display: contents;
}
.col {
  min-width: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
}
/* col-source в первой колонке grid'а, второй ряд */
#col-source {
  grid-column: 1; grid-row: 2;
  border-right: 1px solid var(--divider);
}
.col-head {
  min-height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px;
  font-size: 9px; font-weight: 700; color: var(--text-3); letter-spacing: .14em; text-transform: uppercase;
  border-bottom: 1px solid var(--divider);
  gap: 12px;
}

/* RU/EN переключатель в шапке Исходника */
.src-lang {
  font-size: 9px; font-weight: 700; letter-spacing: .14em;
  padding: 1px 4px;
  color: var(--text-4);
  background: transparent;
  cursor: pointer;
  transition: color .12s;
}
.src-lang.active { color: var(--text); }
.src-lang:not(.active):hover { color: var(--text-2); }

.src-actions { display: flex; gap: 4px; }
.src-copy-btn {
  font-size: 9px; font-weight: 700; letter-spacing: .08em;
  padding: 3px 8px;
  background: transparent;
  border: 1px solid var(--divider-strong);
  color: var(--text-2);
  text-transform: uppercase;
  transition: background .12s, color .12s, border-color .12s;
}
.src-copy-btn:hover { background: var(--surface-soft); color: var(--text); border-color: var(--text-3); }

/* ═══ CARD DECK — горизонтальная стопка карт с собственными корешками
 * Card-deck живёт во второй grid-колонке workspace, занимает оба ряда
 * (т.е. начинается с y=0 топбара workspace, занимая место indicator-row справа). */
.card-deck {
  grid-column: 2; grid-row: 1 / span 2;
  position: relative;
  background: var(--bg);        /* серый фон видно между корешками back-карт */
  overflow: hidden;             /* back-карты выходящие за правый край клипуются */
  min-width: 0;
  border-left: 1px solid var(--divider);
}
.deck-card {
  position: absolute;
  top: 0; bottom: 0;
  width: 100%;
  /* НЕТ background на самой карте — иначе активная (z=30, ширина 100%)
     закрасит back-корешки. Фон только у body. */
  background: transparent;
  display: flex; flex-direction: column;
  transition: left 200ms ease-out, opacity 180ms ease-out;
}
/* Позиция карты по data-stack — 0 = активная (left=0), >0 = back с offset вправо */
.deck-card[data-stack="0"] { left: 0;                z-index: 30; box-shadow: -8px 0 16px rgba(0,0,0,.08); }
.deck-card[data-stack="1"] { left: calc(100% - 250px); z-index: 20; }
.deck-card[data-stack="2"] { left: calc(100% - 125px); z-index: 10; }

/* Тело back-карт спрятано — поверх лежит body активной. Но header (корешок) виден сверху. */
.deck-card:not(.active) .deck-card-body { visibility: hidden; pointer-events: none; }

/* Корешок карты — цветной прямоугольник на её левой грани */
.deck-card-header {
  height: 32px; flex-shrink: 0;
  display: flex; align-items: center;
  position: relative;
  z-index: 5;
}

/* На активной карте header сам по себе вытянулся бы на всю ширину карты
   (flex-item в parent flex-column), и save-кнопка вместе с ним
   растягивалась бы в правую часть, накрывая корешки back-карт.
   Сжимаем header под содержимое — тогда он физически заканчивается
   сразу после save-кнопки, и область над корешком EN свободна.
   pointer-events:none на header — страховка от случайного hit-test
   на любой невидимой области внутри. */
.deck-card.active .deck-card-header {
  pointer-events: none;
  width: max-content;
  align-self: flex-start;
}
.deck-card.active .deck-card-header > * { pointer-events: auto; }

/* Сама активная карта (position:absolute, width:100%, z=30) перекрывает
   bounding-box back-карт. По умолчанию её div ловит hit-test в области
   корешков EN/Расшифровка справа — клик «проваливается» в саму карту,
   а не в back-card. Делаем карту прозрачной для кликов, восстанавливаем
   слышимость на body и содержимом header'а отдельно. */
.deck-card.active { pointer-events: none; }
.deck-card.active .deck-card-body { pointer-events: auto; }
.deck-card-tab {
  height: 100%;
  width: 125px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 11px; font-weight: 700;
  letter-spacing: .04em;
  background: var(--dc-color, var(--text-3));
  cursor: pointer;
  user-select: none;
  transition: filter .12s;
}
.deck-card[data-color="correct"]   { --dc-color: var(--tab-correct); }
.deck-card[data-color="translate"] { --dc-color: var(--tab-translate); }
.deck-card[data-color="transcr"]   { --dc-color: var(--tab-transcr); }
.deck-card:not(.active):not(.disabled) .deck-card-tab:hover { filter: brightness(.94); }
.deck-card.disabled .deck-card-tab { opacity: .55; cursor: not-allowed; }

/* «Сохранить всё» рядом с активным корешком.
   Enabled — ярко-зелёный primary (call-to-action), сразу видно когда
   есть что сохранять. Disabled — серый блёклый, чтобы было понятно,
   что новых правок нет. */
.deck-card-save {
  height: 22px;
  margin-left: 4px;
  padding: 0 12px;
  background: var(--primary);
  color: white;
  font-size: 11px; font-weight: 600;
  letter-spacing: .02em;
  transition: background .12s, color .12s, opacity .12s;
}
.deck-card-save:hover:not(:disabled) { background: var(--primary-h); }
.deck-card-save:disabled {
  background: var(--surface-soft);
  color: var(--text-3);
  opacity: .6;
  cursor: not-allowed;
}
.deck-card:not(.active) .deck-card-save { display: none; }

.deck-card-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  border-top: 1px solid var(--divider);
  display: flex; flex-direction: column;
  background: var(--surface);    /* фон только на body, не на всей карте */
}
.deck-card.disabled { opacity: .8; }
.deck-card-body {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
  min-height: 0;
}
.deck-card .result-area {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  font-size: 14px; line-height: 1.6;
}

/* Source pane — textarea с overlay для подсветки тегов
   Подход: textarea с прозрачным текстом + overlay рендерит ВЕСЬ текст.
   Тэги в overlay покрашены в свой цвет, остальной текст — обычный. */
.source-wrap { flex: 1; display: flex; min-height: 0; position: relative; }
.source-editor {
  position: relative;
  flex: 1; min-width: 0;
}
.source-highlight, #source-text {
  position: absolute; inset: 0;
  padding: 16px 20px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: auto;
  border: 0;
  margin: 0;
  box-sizing: border-box;
  tab-size: 4;
}
.source-highlight {
  z-index: 1;
  color: var(--text);             /* рендерим весь текст нормальным цветом */
  pointer-events: none;
  background: transparent;
}
.source-highlight .tagspan {
  color: var(--tag-c, var(--text-3));
  font-weight: 600;
  text-shadow: 0 1px 1px rgba(0,0,0,.06), 0 0 1px rgba(0,0,0,.08);
  background: transparent;
  padding: 0;
}
#source-text {
  z-index: 2;
  color: transparent;                       /* текст в textarea невидим */
  -webkit-text-fill-color: transparent;     /* Safari/Chrome */
  caret-color: var(--text);                 /* но курсор виден */
  background: transparent;
  resize: none;
}
#source-text::selection {
  background: rgba(125, 194, 68, .25);      /* выделение видно как подсветка фона */
}
#source-text::placeholder {
  color: var(--text-4);
  -webkit-text-fill-color: var(--text-4);
  font-size: 13px; line-height: 1.55;
}

/* Source language sub-tabs */
.source-lang-tabs { display: flex; gap: 0; margin-left: auto; }
.lang-tab {
  padding: 2px 8px; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  color: var(--text-3); background: var(--bg);
  transition: background .15s, color .15s;
}
.lang-tab:hover { color: var(--text); }
.lang-tab.active { background: var(--primary-dim); color: var(--primary-txt); }

/* ═══ META STRIP ═════════════════════════════════════════════════ */
.meta-strip {
  background: var(--surface);
  border-bottom: 2px solid var(--tag-meta);
  padding: 10px 16px 12px;
  flex-shrink: 0;
}
.meta-strip-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 4px 14px;
  align-items: start;
  font-size: 13px;
}
.meta-strip-row + .meta-strip-row { margin-top: 4px; }
.meta-key {
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--tag-meta);
  text-align: right;
  padding-top: 6px;
}
.meta-val {
  width: 100%;
  padding: 4px 7px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  transition: background .15s;
}
.meta-val:focus { background: rgba(236, 72, 153, .06); }
.meta-val:hover:not(:focus) { background: rgba(0, 0, 0, .02); }
/* Подводка: textarea автоматически растёт под содержимое (без скролла, без drag).
   field-sizing: content — Chrome 123+ / Safari 18+. Fallback: JS auto-resize. */
.meta-val-area {
  resize: none;
  min-height: 1.5em;
  font-family: inherit;
  line-height: 1.45;
  field-sizing: content;
  overflow: hidden;
}
.meta-val::placeholder { color: var(--text-4); }

/* Cascade indicator (in result column header) */
.meta-strip-cascade {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 500;
  color: var(--text-2);
  background: rgba(236, 72, 153, .08);
  padding: 3px 8px;
  letter-spacing: 0;
  text-transform: none;
}
.meta-strip-cascade .icon { stroke: var(--tag-meta); }

/* ═══ FLOATING STACK — два независимых блока, выровненных по верху ═ */
#floating-stack {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;     /* TOP-aligned — счётчик и палитра по верху */
  gap: 12px;
  z-index: 30;
  pointer-events: none;        /* контейнер прозрачен для кликов */
}
#floating-stack > * { pointer-events: auto; }

.floating-card {
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .14), 0 1px 3px rgba(0, 0, 0, .08);
}
#counter-panel {
  width: 240px;
  /* Вся панель растягивается за нижний правый угол вниз */
  display: flex;
  flex-direction: column;
  height: 280px;
  min-height: 80px;
  max-height: 80vh;
  resize: vertical;
  overflow: hidden;
}
#palette-panel { width: 200px; }
.floating-card.collapsed > :not(.floating-card-head) { display: none; }

.floating-card-head {
  height: 28px; padding: 0 8px 0 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  font-size: 9px; font-weight: 700; color: var(--text-3); letter-spacing: .14em; text-transform: uppercase;
  cursor: move; flex-shrink: 0;
  user-select: none;
}
.floating-card-head .grip { color: var(--text-4); margin-right: 6px; cursor: grab; }
.floating-collapse {
  width: 20px; height: 20px;
  font-size: 14px; color: var(--text-3);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
}
.floating-collapse:hover { color: var(--text); background: var(--surface-soft); }

.tag-palette-list { padding: 6px; display: grid; gap: 3px; }

/* counter-list — занимает оставшееся место после шапки.
   Resize на родителе (.counter-panel) — это и есть «дёрнуть за угол вниз». */
.counter-list {
  padding: 2px 0;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.tag-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px;
  font-size: 12px;
  color: var(--text);
  cursor: grab;
  background: var(--surface-2);
  transition: background .12s, transform .08s;
  user-select: none;
}
.tag-chip:hover { background: var(--surface-soft); }
.tag-chip:active { cursor: grabbing; transform: scale(.97); }
.tag-chip.dragging { opacity: .4; }
.tag-swatch {
  width: 12px; height: 12px; flex-shrink: 0;
}
.tag-swatch[data-c="titre"]    { background: var(--tag-titre); }
.tag-swatch[data-c="speech"]   { background: var(--tag-speech); }
.tag-swatch[data-c="name"]     { background: var(--tag-name); }
.tag-swatch[data-c="role"]     { background: var(--tag-role); }
.tag-swatch[data-c="quote"]    { background: var(--tag-quote); }
.tag-swatch[data-c="titre169"] { background: var(--tag-titre169); }
.tag-swatch[data-c="geo"]      { background: var(--tag-geo); }
.tag-swatch[data-c="courtesy"] { background: var(--tag-courtesy); }
.tag-swatch[data-c="note"]     { background: var(--tag-note); }
.tag-chip .tag-hint {
  margin-left: auto;
  font-size: 10px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* Source textarea: highlight when dragging over */
#source-text.drag-over {
  background: rgba(236, 72, 153, .04);
  box-shadow: inset 0 0 0 2px var(--tag-meta);
}

/* ═══ COUNTER LIST (inside floating-panel) ═══════════════════════ */
/* legacy .counter-list — финальные правила определены выше (flex: 1, без max-height) */
.counter-empty {
  text-align: center; padding: 20px 12px;
  color: var(--text-3); font-size: 12px;
}
.counter-item {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  font-size: 12px;
  gap: 10px;
  cursor: pointer;
  transition: background .12s;
}
.counter-item:hover { background: var(--surface-soft); }
.counter-item:active { background: var(--primary-dim); }
.counter-item + .counter-item { border-top: 1px solid var(--divider); }

/* Подсветка таргета при клике по строке счётчика */
@keyframes flash-target {
  0%   { background: rgba(125, 194, 68, .25); }
  100% { background: transparent; }
}
.source-highlight.flash-target {
  animation: flash-target .8s ease-out;
}
.counter-type {
  font-size: 9px; font-weight: 700; letter-spacing: .04em;
  color: white; padding: 2px 5px; text-align: center;
  text-transform: uppercase;
}
.counter-type[data-c="titre"]    { background: var(--tag-titre); }
.counter-type[data-c="speech"]   { background: var(--tag-speech); }
.counter-type[data-c="name"]     { background: var(--tag-name); }
.counter-type[data-c="role"]     { background: var(--tag-role); }
.counter-type[data-c="quote"]    { background: var(--tag-quote); }
.counter-type[data-c="titre169"] { background: var(--tag-titre169); }
.counter-type[data-c="geo"]      { background: var(--tag-geo); }
.counter-type[data-c="courtesy"] { background: var(--tag-courtesy); }
.counter-type[data-c="note"]     { background: var(--tag-note); }
.counter-label {
  color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.counter-num {
  font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.counter-num.ok   { color: var(--count-ok); }
.counter-num.warn { color: var(--count-warn); }
.counter-num.over { color: var(--count-over); font-weight: 700; }

/* ═══ RESULT AREA ════════════════════════════════════════════════ */
.col-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  font-size: 14px; line-height: 1.6;
  color: var(--text);
}
.placeholder {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
}
.placeholder-icon { font-size: 32px; opacity: .3; margin-bottom: 10px; }

.diff-content {
  white-space: pre-wrap;
  font-family: 'Inter', sans-serif;
}
.diff-add { background: var(--diff-a-bg); color: var(--diff-a-txt); padding: 0 2px; cursor: pointer; position: relative; }
.diff-add.accepted { background: transparent; color: inherit; cursor: default; }
.diff-add.active { background: #c8e6a8; }
.diff-del { background: var(--diff-d-bg); color: var(--diff-d-txt); padding: 0 2px; text-decoration: line-through; cursor: pointer; }
.diff-del.rejected { background: transparent; color: inherit; text-decoration: none; cursor: default; }
.diff-popup {
  /* Phase 5c: position:fixed, координаты ставит JS — чтобы overflow карты не клипал */
  padding: 4px 6px;
  background: var(--surface); box-shadow: 0 4px 16px rgba(0,0,0,.18);
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; white-space: nowrap;
}
.popup-accept, .popup-reject { padding: 3px 8px; font-size: 11px; }
.popup-accept { color: var(--diff-a-txt); }
.popup-accept:hover { background: var(--diff-a-bg); }
.popup-reject { color: var(--diff-d-txt); }
.popup-reject:hover { background: var(--diff-d-bg); }
.popup-sep { color: var(--text-4); }

.translate-content {
  white-space: pre-wrap;
  outline: none;
  font-family: 'Inter', sans-serif;
  font-size: 14px; line-height: 1.6;
}

.usage-info {
  padding: 4px 16px; font-size: 10px; color: var(--text-3);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
  text-align: right;
}

/* ═══ RIGHT: КАРТОТЕКА — стопка свёрнутых карточек ═══════════════
 * Каждая карточка — вертикальная полоса с цветным ярлыком.
 * Видны:
 *  - название вертикально (вращение)
 *  - кружок-индикатор (есть результат / пусто)
 *  - кнопка ▶ для прямого запуска без раскрытия
 *  - приглушённый цвет если карточка пустая
 * ──────────────────────────────────────────────────────────────── */
.collapsed-tabs {
  width: 40px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--divider);
  /* Лёгкая тень слева чтобы карточки выглядели "сзади" активной */
  box-shadow: inset 4px 0 8px -4px rgba(0,0,0,.08);
}
.ctab {
  flex: 1;
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, .20);
  transition: filter .15s, opacity .15s, background .15s;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
}
.ctab[data-color="source"]    { background: var(--tab-source); }
.ctab[data-color="correct"]   { background: var(--tab-correct); }
.ctab[data-color="translate"] { background: var(--tab-translate); }
.ctab[data-color="transcr"]   { background: var(--tab-transcr); }
.ctab:hover:not(.disabled):not(.empty) { filter: brightness(.94); }
.ctab.disabled { opacity: .35; cursor: not-allowed; }
.ctab.empty { opacity: .55; }      /* приглушённый цвет если карта пустая */
.ctab.empty:hover { opacity: .75; }

/* Вертикальный текст с названием */
.ctab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  flex: 1;
  display: flex; align-items: center; justify-content: center;
}

/* Индикатор: есть результат — белая точка, пусто — пустой кружок */
.ctab-dot {
  width: 6px; height: 6px;
  border: 1.5px solid rgba(255,255,255,.6);
  border-radius: 50%;
  flex-shrink: 0;
}
.ctab.has-data .ctab-dot {
  background: white;
  border-color: white;
}

/* Кнопка прямого запуска ▶ */
.ctab-run {
  width: 22px; height: 22px;
  border-radius: 0;
  background: rgba(0,0,0,.18);
  color: white;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .12s;
}
.ctab-run:hover { background: rgba(0,0,0,.35); }
.ctab.empty .ctab-run { background: rgba(0,0,0,.10); }

/* legacy: #col-result удалён в Phase 5c — используется .deck-card вместо */

/* ═══ REWRITE MENU (selection-based) ═════════════════════════════ */
.rewrite-menu {
  /* Дефолт — центр экрана (если JS не успел спозиционировать у курсора).
     При showRewriteMenu() JS задаёт top/left у позиции последнего mouseup
     с clamp в viewport, тогда срабатывает .positioned. */
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  width: 320px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .14), 0 1px 3px rgba(0, 0, 0, .08);
  z-index: 25;
}
.rewrite-menu.positioned {
  /* Координаты заданы из JS — отключаем дефолтное центрирование. */
  transform: none;
}
.rewrite-menu-head {
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  font-size: 11px; font-weight: 700; color: var(--text);
  cursor: move;
}
.rewrite-presets {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--divider);
}
.rewrite-preset {
  padding: 8px 10px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text-2);
  text-align: left;
  transition: background .12s, color .12s;
}
.rewrite-preset:hover { background: var(--surface-soft); color: var(--text); }
.rewrite-custom { display: flex; gap: 4px; padding: 8px; border-top: 1px solid var(--divider); }
.rewrite-custom input {
  flex: 1; padding: 5px 8px; font-size: 12px;
  background: var(--bg);
}
.rewrite-custom input:focus { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--primary); }
.rewrite-custom button { padding: 5px 12px; font-size: 12px; }

/* ═══ LOADING ════════════════════════════════════════════════════ */
.loading {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--surface);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label { color: white; font-size: 13px; font-weight: 500; }

/* ═══ TEMPLATES DROPDOWN ═════════════════════════════════════════ */
.topbar-dropdown-wrap { position: relative; }
.templates-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0,0,0,.16), 0 1px 3px rgba(0,0,0,.08);
  width: 320px;
  z-index: 200;
  padding: 8px;
  max-height: 70vh;
  overflow-y: auto;
}
.templates-dropdown .td-section {
  padding: 6px 10px;
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--divider);
  margin-bottom: 4px;
}
.templates-dropdown .td-save {
  display: flex; gap: 6px;
  padding: 6px 6px 10px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 6px;
}
.templates-dropdown .td-save input {
  flex: 1;
  background: var(--bg);
  padding: 7px 10px;
  font-size: 13px;
}
.templates-dropdown .td-save input:focus { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--primary); }
.templates-dropdown .td-save button {
  padding: 7px 14px;
  font-size: 12px;
  background: var(--primary);
  color: white;
  font-weight: 600;
}
.templates-dropdown .td-save button:disabled { opacity: .4; cursor: not-allowed; }
.td-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s;
}
.td-item:hover { background: var(--surface-soft); }
.td-item-name { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-item-date { font-size: 10px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.td-item-delete {
  width: 22px; height: 22px;
  font-size: 14px;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .12s, color .12s;
}
.td-item:hover .td-item-delete { opacity: 1; }
.td-item-delete:hover { color: var(--count-over); }
.td-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.5;
}
.td-meta {
  padding: 6px 10px;
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  border-top: 1px solid var(--divider);
  margin-top: 6px;
}

/* ═══ USER DROPDOWN MENU ═════════════════════════════════════════ */
.user-menu { position: relative; }
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0,0,0,.16), 0 1px 3px rgba(0,0,0,.08);
  min-width: 180px;
  z-index: 200;
  padding: 4px;
}
.user-dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.user-dropdown-item:hover { background: var(--surface-soft); }
.user-dropdown-item .icon { width: 14px; height: 14px; color: var(--text-3); }

/* ═══ ADMIN OVERLAY ══════════════════════════════════════════════ */
.admin-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 250;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  backdrop-filter: blur(2px);
}
.admin-modal {
  background: var(--surface);
  width: 100%; max-width: 1100px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.admin-head {
  height: 48px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  font-size: 13px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text);
}
.admin-close {
  width: 28px; height: 28px;
  font-size: 22px; color: var(--text-3);
  display: inline-flex; align-items: center; justify-content: center;
}
.admin-close:hover { color: var(--text); background: var(--surface-soft); }
.admin-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
  padding: 0 12px;
  flex-shrink: 0;
}
.admin-tab {
  padding: 10px 16px;
  font-size: 12px; font-weight: 600;
  color: var(--text-2);
  position: relative;
  transition: color .15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--primary-txt); }
.admin-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px;
  background: var(--primary);
}
.admin-body { flex: 1; overflow-y: auto; padding: 20px 24px; min-height: 200px; }
.admin-tab-pane { display: none; }
.admin-tab-pane.active { display: block; }
.admin-loading { text-align: center; color: var(--text-3); padding: 40px; font-size: 13px; }

/* Stats cards */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface-2);
  padding: 14px 16px;
}
.stat-card-label {
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 4px;
}
.stat-card-value {
  font-size: 22px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-card-sub {
  font-size: 11px; color: var(--text-3); margin-top: 4px;
}

/* Admin tables */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 24px;
}
.admin-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
}
.admin-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--divider);
  color: var(--text);
}
.admin-table tr:hover td { background: var(--surface-2); }
.admin-table td.num { font-variant-numeric: tabular-nums; text-align: right; }
.admin-table td.cost { font-weight: 600; color: var(--primary-txt); }
.admin-section-head {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-2);
  margin: 0 0 10px;
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase;
}
.role-badge.master { background: var(--primary); color: white; }
.role-badge.senior_editor { background: var(--tag-titre); color: white; }
.role-badge.editor { background: var(--surface-soft); color: var(--text-2); }

/* Admin: user CRUD */
.admin-warn {
  background: rgba(234, 179, 8, .10);
  border-left: 3px solid var(--count-warn);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 18px;
}
.admin-warn code {
  background: var(--surface-soft);
  padding: 1px 5px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}
.admin-warn a { color: var(--primary-txt); text-decoration: underline; }

.row-actions { text-align: right; white-space: nowrap; }
.link-btn {
  font-size: 11px; font-weight: 600;
  color: var(--text-2);
  padding: 3px 8px;
  background: transparent;
  border: 1px solid var(--divider-strong);
  margin-left: 4px;
  transition: background .12s, color .12s, border-color .12s;
}
.link-btn:hover { background: var(--surface-soft); color: var(--text); }
.link-btn.danger { color: var(--count-over); border-color: rgba(239, 68, 68, .25); }
.link-btn.danger:hover { background: rgba(239, 68, 68, .08); border-color: var(--count-over); }

.user-form {
  display: flex; gap: 8px; align-items: center;
  background: var(--surface-2);
  padding: 12px;
}
.user-form input, .user-form select {
  background: var(--surface);
  padding: 7px 10px;
  font-size: 13px;
  flex: 1;
  border: 1px solid var(--divider);
}
.user-form input:focus, .user-form select:focus {
  border-color: var(--primary);
  outline: none;
}
.user-form select { flex: 0 0 130px; }
.user-form button { flex: 0 0 auto; }

/* ═══ DRAG GHOST ═════════════════════════════════════════════════ */
.tag-drag-ghost {
  position: fixed; pointer-events: none; z-index: 1000;
  background: var(--text);
  color: white;
  padding: 6px 12px;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: .92;
  transform: rotate(-3deg);
}
