:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel-2: #262a32;
  --line: #343a44;
  --text: #e8eaed;
  --muted: #9aa2ae;
  --photo: #35c08a;
  --photo-selected: #5ef0b4;
  --text-block: #d9a441;
  --danger: #d9534f;
  --accent: #4a8fe7;

  /* Пастельная палитра кнопок: мягкие, но достаточно насыщенные, чтобы на
     тёмном фоне не выглядеть выцветшими. Текст тёмный — белый на таком фоне
     читался бы хуже. */
  --pastel-green: #6fc08d;
  --pastel-green-ink: #0d2b1a;
  --pastel-red: #e9928e;
  --pastel-red-ink: #3d1412;
  --pastel-sand: #d9b97c;
  --pastel-sand-ink: #3a2c0c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

header h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.5px; }

/* Логотип университета. Основные контуры берут цвет текста, красная полоса
   задана прямо в разметке SVG. */
.public-home__logo {
  height: 30px;
  width: auto;
  flex: none;
  color: var(--text);
}
header .who { color: var(--muted); font-size: 13px; }

.spacer { flex: 1; }

footer {
  flex: none;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* --- Три колонки: действия, разметка, галерея --------------------------- */

/* Flex, а не grid: ширину центральной и правой колонок нужно менять
   перетаскиванием, а здесь это делается соотношением flex-grow.
   Отступы заданы полями, а не gap — иначе разделитель добавлял бы свой
   зазор к общему и между колонками зияла бы дыра. */
.layout {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 14px;
  --split: 0.5;
}

.col-editor,
.col-gallery { flex: 1 1 0; min-width: 0; }

/* Доля каждой колонки задаётся переменной на .layout, а не инлайновым
   flex-grow: инлайн перебил бы медиазапрос для узких экранов, и колонки
   начали бы расти уже по высоте. */
.col-editor { flex-grow: var(--split, 0.5); }
.col-gallery { flex-grow: calc(1 - var(--split, 0.5)); }

.col {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.col-actions {
  flex: 0 0 190px;
  margin-right: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: visible;
}

/* Перетаскиваемая граница между разметкой и галереей. */
.splitter {
  flex: 0 0 6px;
  margin: 0 4px;
  align-self: stretch;
  position: relative;
  cursor: col-resize;
  border-radius: 3px;
  touch-action: none;
  transition: background 0.15s;
}
.splitter::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 46px;
  border-radius: 1px;
  background: var(--line);
  transform: translate(-50%, -50%);
  transition: background 0.15s, height 0.15s;
}
.splitter:hover,
.splitter.dragging { background: rgba(74, 143, 231, 0.1); }
.splitter:hover::before,
.splitter.dragging::before { background: var(--accent); height: 62px; }

/* Во время перетаскивания курсор и выделение текста не должны сбиваться. */
body.resizing { user-select: none; cursor: col-resize; }
/* Кнопки левой колонки: иконка над подписью. Кнопка загрузки — квадратная,
   под двухстрочную подпись. */
.col-actions .big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  font-size: 14px;
}
.col-actions .big.upload { aspect-ratio: 1 / 1; font-size: 15px; }

.icon { width: 26px; height: 26px; flex: none; }
.caption { display: block; line-height: 1.25; }
.sub { display: block; font-weight: 400; font-size: 13px; opacity: 0.9; }

/* Центральная колонка: панель инструментов закреплена, прокручивается только
   сам снимок — иначе на длинном фото кнопки уезжали бы вверх вместе с ним. */
.col-editor {
  position: relative; /* в нём центрируется корзина при очистке */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.col-editor > .col-head,
.col-editor > .hint { flex: none; }

.viewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.col-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.col-head h2 { margin: 0; }

/* На экране поуже колонки встают друг под друга. */
@media (max-width: 1100px) {
  body { height: auto; overflow: auto; }
  .layout { flex-direction: column; }
  .col { overflow: visible; }
  .col-actions { flex: none; margin-right: 0; }
  /* Перебивает и общий flex, и переменную доли: колонки встают друг под друга. */
  .col-editor,
  .col-gallery { flex: none; }
  .splitter { display: none; }
  .viewer { overflow: visible; }
  .col-actions .spacer { display: none; }
}

/* --- Элементы управления ------------------------------------------------ */

h2 {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

button, .button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Пастельные кнопки: мягкий фон, тёмный текст. */
button.pastel-green, .button.pastel-green {
  background: var(--pastel-green);
  border-color: #52a273;
  color: var(--pastel-green-ink);
  font-weight: 600;
}
button.pastel-green:hover:not(:disabled), .button.pastel-green:hover { background: #7fcd9d; }

button.pastel-red, .button.pastel-red {
  background: var(--pastel-red);
  border-color: #c9716d;
  color: var(--pastel-red-ink);
}
button.pastel-red:hover:not(:disabled), .button.pastel-red:hover { background: #f0a5a1; }

button.pastel-sand, .button.pastel-sand {
  background: var(--pastel-sand);
  border-color: #bb9a58;
  color: var(--pastel-sand-ink);
}
button.pastel-sand:hover:not(:disabled), .button.pastel-sand:hover { background: #e5c98f; }

input[type="text"], input[type="password"], input[type="file"] {
  font: inherit;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

#page-nav { display: flex; align-items: center; gap: 8px; }
#page-nav button { padding: 3px 9px; }

/* Поле имени всплывает прямо над рамкой, а не живёт отдельной панелью над
   снимком: так фото остаётся у верхнего края и ничего его не оттесняет. */
.name-editor {
  position: absolute;
  z-index: 30;
  width: 380px;
  /* Прижимается к ширине снимка: длинные ФИО должны быть видны целиком. */
  max-width: calc(100% - 12px);
  padding: 7px 11px;
  font-size: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}

/* --- Анимация обработки ------------------------------------------------- */

.processing {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
}

.processing-stack {
  position: relative;
  width: 132px;
  height: 168px;
  animation: stack-breathe 2.6s ease-in-out infinite;
}

/* Три стопки карточек и луч, ходящий по ним сверху вниз. */
.card-ghost {
  position: absolute;
  inset: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
}
.card-ghost:nth-child(1) { transform: translate(-15px, -11px) rotate(-7deg); opacity: 0.4; }
.card-ghost:nth-child(2) { transform: translate(-5px, -3px) rotate(-2deg); opacity: 0.65; }
.card-ghost:nth-child(3) { transform: translate(6px, 6px) rotate(4deg); }

/* В верхнюю карточку кладём миниатюру загруженного снимка — так видно, что
   обрабатывается именно он. Пропорции на таком размере неразличимы. */
.card-ghost.top { overflow: hidden; }
.card-ghost.top img { width: 100%; height: 100%; object-fit: cover; display: block; }

.scan-line {
  position: absolute;
  left: -14px;
  right: -14px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--photo), transparent);
  box-shadow: 0 0 18px 4px rgba(53, 192, 138, 0.5);
  animation: scan 2.1s ease-in-out infinite;
}

@keyframes stack-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

@keyframes scan {
  0%, 100% { top: 4%; opacity: 0.25; }
  50% { top: 92%; opacity: 1; }
}

.dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes blink {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .card-ghost, .scan-line, .dots i, .processing-stack { animation: none; }
}

/* --- Очистка каталога --------------------------------------------------- */

.basket {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 124px;
  height: 124px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--danger);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 83, 79, 0.2), transparent 70%);
  color: #ff9b96;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.35);
  transition:
    transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.25s ease-out;
}
.basket.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.basket .icon { width: 54px; height: 54px; }

/* Миниатюра «схлопывается» в светящийся шар и улетает в корзину. */
.collapse-ball {
  position: fixed;
  z-index: 120;
  overflow: hidden;
  pointer-events: none;
  will-change: transform, filter, opacity;
}
.collapse-ball img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Пока шары летят, исходные миниатюры не показываем. */
.gallery.clearing .card { opacity: 0; transition: opacity 0.25s ease-out; }

/* --- Выгрузка архива ---------------------------------------------------- */

/* Двойник миниатюры: сначала поднимается с ней в первый ряд, потом съезжает
   в первый слот — там и собирается стопка. Лежит НИЖЕ коробки: уезжая вниз,
   пачка прячется за ней. */
.flying-card {
  position: fixed;
  z-index: 110;
  overflow: hidden;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition:
    left 0.34s ease-in-out,
    top 0.34s ease-in-out,
    transform 0.34s ease-in-out,
    opacity 0.34s ease-in-out;
}
.flying-card img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Коробка нарисована как посылка: картон и скотч поперёк. Крышка не
   открывается — пачка просто уезжает за коробку и пропадает. */
.download-box {
  position: fixed;
  z-index: 115; /* выше «летящих» миниатюр: за неё они и прячутся */
  border: 2px solid #8a5a2b;
  border-radius: 4px;
  background: linear-gradient(180deg, #b98449, #8a5f31);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 6px 18px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.65);
  transition:
    opacity 0.22s ease-out,
    transform 0.22s ease-out,
    left 0.58s cubic-bezier(0.5, -0.25, 0.75, 0.35),
    top 0.58s cubic-bezier(0.5, -0.25, 0.75, 0.35);
}
.download-box.show { opacity: 1; transform: scale(1); }

/* Скотч-лента поперёк посылки. */
.download-box::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 24%;
  transform: translateY(-50%);
  background: rgba(226, 205, 168, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

/* --- Слот, ожидающий кроп ----------------------------------------------- */

/* Пустой слот показывается сразу, а фотография «влетает» в него и проявляется. */
.card.pending {
  border-style: dashed;
  border-color: #47505d;
  background: transparent;
}
.card.pending img,
.card.pending input,
.card.pending .row { opacity: 0; }
.card img,
.card input,
.card .row { transition: opacity 0.35s ease-in; }

/* Кроп «перелетает» из большой фотографии в свой слот в галерее. */
.flying-crop {
  position: fixed;
  z-index: 100;
  object-fit: cover;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  transition:
    left 0.7s ease-in-out,
    top 0.7s ease-in-out,
    width 0.7s ease-in-out,
    height 0.7s ease-in-out,
    opacity 0.7s ease-in-out;
}

.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

/* --- Изображение и оверлей --------------------------------------------- */

/* Снимок растягивается на всю ширину колонки — это основная рабочая область.
   Обёртка занимает ту же площадь, поэтому SVG с viewBox в пикселях
   изображения ложится ровно на картинку без пересчётов координат. */
.canvas-wrap {
  position: relative;
  display: block;
  width: 100%;
}
.canvas-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}
.canvas-wrap svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  /* По пустому месту рисуем новую рамку — курсор об этом и сообщает. */
  cursor: crosshair;
}
.canvas-wrap polygon { cursor: move; }

.legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

/* --- Галерея ------------------------------------------------------------ */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
}
.card img {
  width: 100%;
  height: 108px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  display: block;
}
.card input {
  width: 100%;
  margin-top: 6px;
  font-size: 12px;
  padding: 4px 6px;
}
.card .row { display: flex; gap: 6px; margin-top: 5px; }
.card .row button { flex: 1; font-size: 12px; padding: 3px; }

/* --- Экран входа -------------------------------------------------------- */

.auth {
  max-width: 380px;
  margin: 12vh auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.auth h1 { margin: 0 0 4px; font-size: 20px; }
.auth p.sub { margin: 0 0 20px; color: var(--muted); }
.auth label { display: block; margin-bottom: 14px; }
.auth label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.auth input { width: 100%; }
.auth button { width: 100%; margin-top: 6px; }

.error { color: #ff9b96; min-height: 20px; margin-top: 12px; font-size: 13px; }

.toast {
  position: fixed;
  /* Выше подвала, иначе всплывающее сообщение накрывало бы подпись. */
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; }

[hidden] { display: none !important; }
