/* ============================================================
   Конкурсы «Этажи» — админ-панель
   Дизайн: «бумажный реестр» — тёплая бумага, чернила, гроссбух.
   Golos Text (UI) + IBM Plex Mono (цифры, метаданные).
   ============================================================ */

:root {
  /* Палитра */
  --paper:       #F6F4EE;   /* фон приложения */
  --paper-2:     #FCFBF7;   /* карточки */
  --paper-3:     #EFECE3;   /* приглушённые зоны, hover */
  --ink:         #1F1D18;   /* основной текст */
  --ink-soft:    #55524A;   /* вторичный текст */
  --ink-faint:   #8B877C;   /* подписи, плейсхолдеры */
  --line:        #E2DED2;   /* тонкие линии */
  --line-strong: #C9C4B4;

  --accent:      #1D6A54;   /* глубокая зелень — действия */
  --accent-ink:  #114434;
  --accent-soft: #E3EEE7;

  --amber:       #B96F24;   /* внимание, черновики */
  --amber-soft:  #F4E8D7;
  --red:         #A83232;   /* опасные действия */
  --red-soft:    #F3DFDC;
  --blue:        #2C5F8A;   /* информационное */
  --blue-soft:   #E0EAF2;

  --font-ui: "Golos Text", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --shadow-pop: 0 12px 32px -12px rgba(31, 29, 24, 0.28);
  --sidebar-w: 232px;
}

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

html { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(29, 106, 84, 0.05), transparent 60%),
    var(--paper);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

/* ---------- Каркас ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--line);
}

/* «штамп» — фирменный знак панели */
.brand-stamp {
  display: inline-block;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  border: 1.5px solid var(--accent-ink);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  transform: rotate(-1.2deg);
  background: var(--paper-2);
}

.brand-sub {
  display: block;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

.nav { padding: 14px 10px; flex: 1; overflow-y: auto; }

.nav-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 120ms ease, color 120ms ease;
}

.nav-item:hover { background: var(--paper-3); color: var(--ink); }

.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(29, 106, 84, 0.25);
  color: var(--accent-ink);
}

.nav-item .ico { width: 18px; text-align: center; opacity: 0.85; }

.nav-item .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--paper-3);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 99px;
  padding: 0 7px;
  line-height: 18px;
}

.nav-item.active .count { background: #fff; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 14px 20px;
  font-size: 12.5px;
}

.sidebar-foot .who { font-weight: 600; }
.sidebar-foot .role {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}

.sidebar-foot .logout {
  margin-top: 8px;
  display: inline-block;
  color: var(--red);
  text-decoration: none;
  font-size: 12.5px;
  cursor: pointer;
}
.sidebar-foot .logout:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 24px 32px 0;
}

.topbar h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar .crumb {
  color: var(--ink-faint);
  text-decoration: none;
  font-size: 13px;
}
.topbar .crumb:hover { color: var(--ink); }

.content { padding: 20px 32px 48px; }

/* Появление вью */
.view-enter { animation: viewIn 240ms ease both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Ступенчатое появление карточек */
.stagger > * { animation: viewIn 260ms ease backwards; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 40ms; }
.stagger > *:nth-child(3) { animation-delay: 80ms; }
.stagger > *:nth-child(4) { animation-delay: 120ms; }
.stagger > *:nth-child(5) { animation-delay: 160ms; }
.stagger > *:nth-child(6) { animation-delay: 200ms; }

/* ---------- Карточки ---------- */

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title .spacer { flex: 1; }

.card-sub { color: var(--ink-faint); font-size: 12.5px; margin-top: -10px; margin-bottom: 14px; }

/* Статистические плитки */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px 14px;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  left: 18px; right: auto; bottom: 12px;
  width: 34px; height: 3px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.85;
}

.stat.amber::after { background: var(--amber); }
.stat.blue::after  { background: var(--blue); }

.stat .num {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat .lbl {
  margin-top: 2px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--ink-soft);
}

.stat a { color: inherit; text-decoration: none; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, transform 60ms ease, border-color 120ms;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost:hover:not(:disabled) { background: var(--paper-3); }

.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }

.btn-sm { font-size: 12.5px; padding: 5px 10px; }

.btn-icon { padding: 5px 8px; font-size: 13px; }

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }

table.tbl { width: 100%; border-collapse: collapse; }

.tbl th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.tbl tr:last-child td { border-bottom: none; }

.tbl tbody tr { transition: background 100ms ease; }
.tbl tbody tr:hover { background: rgba(29, 106, 84, 0.045); }
.tbl tbody tr.clickable { cursor: pointer; }

.tbl .mono, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.tbl .muted, .muted { color: var(--ink-faint); }

.tbl .num-cell { text-align: right; }

/* Медали рейтинга */
.pos-badge {
  font-family: var(--font-mono);
  font-weight: 600;
  display: inline-block;
  min-width: 30px;
  text-align: center;
  border-radius: var(--r-sm);
  padding: 2px 6px;
}
.pos-1 { background: #F4E7C3; border: 1px solid #D9C382; }
.pos-2 { background: #ECECEA; border: 1px solid #C9C9C4; }
.pos-3 { background: #EFDFCE; border: 1px solid #D3B490; }

/* ---------- Чипы статусов ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-radius: 99px;
  padding: 3px 10px;
  border: 1px solid;
  white-space: nowrap;
}

.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip-draft     { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }
.chip-active    { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.chip-completed { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }
.chip-archived  { color: var(--ink-faint); border-color: var(--line-strong); background: var(--paper-3); }
.chip-pending   { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }
.chip-approved  { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.chip-rejected  { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.chip-text      { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }
.chip-file      { color: var(--ink-soft); border-color: var(--line-strong); background: var(--paper-3); }
.chip-moderator   { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }
.chip-superadmin  { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.chip-participant { color: var(--ink-soft); border-color: var(--line-strong); background: var(--paper-3); }

/* ---------- Фильтры-сегменты ---------- */

.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--paper-2);
}

.seg button {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 13px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
}

.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--paper-3); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* ---------- Формы ---------- */

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--ink-soft);
}

.field .hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }

.input, .select, .textarea {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.textarea { resize: vertical; min-height: 100px; line-height: 1.55; }

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 106, 84, 0.15);
}

.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.checkbox input { width: 15px; height: 15px; accent-color: var(--accent); }

/* ---------- Модальные окна ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 29, 24, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 20px 20px;
  z-index: 100;
  animation: fadeIn 140ms ease;
  overflow-y: auto;
}

@keyframes fadeIn { from { opacity: 0; } }

.modal {
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-width: 540px;
  animation: modalIn 180ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.modal.wide { max-width: 760px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.985); }
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 15px;
}

.modal-head .x {
  margin-left: auto;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-faint);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}
.modal-head .x:hover { background: var(--paper-3); color: var(--ink); }

.modal-body { padding: 20px; }

/* ---------- Тосты ---------- */

#toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.toast {
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  padding: 12px 16px;
  font-size: 13.5px;
  max-width: 360px;
  animation: toastIn 200ms cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.toast.error { border-left-color: var(--red); }
.toast.out { animation: toastOut 240ms ease forwards; }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* ---------- Загрузка / пустые состояния ---------- */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--ink-faint);
  padding: 60px 0;
}

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 44px 20px;
}

.empty .glyph {
  font-size: 26px;
  display: inline-block;
  border: 1.5px dashed var(--line-strong);
  border-radius: 50%;
  width: 54px; height: 54px;
  line-height: 52px;
  margin-bottom: 10px;
}

/* ---------- Разное ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }

.search {
  min-width: 220px;
  background: var(--paper-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238B877C' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 10px center;
  padding-left: 32px;
}

.stage-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: #fff;
}
.stage-card + .stage-card { margin-top: 10px; }

.stage-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stage-no {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 1px 7px;
  background: var(--accent-soft);
}

.stage-title { font-weight: 700; font-size: 14.5px; }

.stage-meta {
  margin-top: 6px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.stage-meta b { font-family: var(--font-mono); font-weight: 500; }

.stage-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.stage-img-thumb {
  max-height: 70px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  display: block;
}

/* Полосы прогресса в статистике */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar-row .bar-label { width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; height: 8px; background: var(--paper-3); border-radius: 4px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 500ms ease; }
.bar-row .bar-val { font-family: var(--font-mono); font-size: 12px; width: 52px; text-align: right; }

/* Telegram-предпросмотр рассылки */
.tg-preview {
  background: #E7EBE3;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
}

.tg-bubble {
  background: #fff;
  border-radius: 12px 12px 12px 3px;
  padding: 10px 14px;
  max-width: 420px;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(31,29,24,0.12);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.tg-bubble img { max-width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }

.tg-bubble code {
  font-family: var(--font-mono);
  background: var(--paper-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.tg-time {
  text-align: right;
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* Панель инструментов редактора */
.editor-tools { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }

.editor-tools button {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  cursor: pointer;
  color: var(--ink);
}
.editor-tools button:hover { background: var(--paper-3); }
.editor-tools .sep { width: 1px; background: var(--line); margin: 2px 4px; }

/* Вкладки */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line-strong);
  margin-bottom: 18px;
}

.tab {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--ink-faint);
  cursor: pointer;
  display: inline-flex;
  gap: 7px;
  align-items: center;
}

.tab:hover { color: var(--ink); }
.tab.on { color: var(--accent-ink); border-bottom-color: var(--accent); }

.tab .badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid var(--amber);
  border-radius: 99px;
  padding: 0 6px;
  line-height: 16px;
}

/* Детали ответа */
.answer-text {
  white-space: pre-wrap;
  background: var(--paper-3);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 13px;
  max-height: 130px;
  overflow-y: auto;
}

.file-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
  word-break: break-all;
}
.file-link:hover { text-decoration: underline; }

/* История баллов */
.hist-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.hist-item:last-child { border-bottom: none; }

.hist-pts {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 48px;
  text-align: right;
}
.hist-pts.plus { color: var(--accent-ink); }
.hist-pts.minus { color: var(--red); }

/* ---------- Страница входа ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 34px 32px 30px;
  animation: modalIn 300ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.login-card .brand-stamp { margin-bottom: 6px; }

.login-title { font-size: 17px; font-weight: 700; margin: 14px 0 20px; }

.login-error {
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: var(--red);
  font-size: 13px;
  border-radius: var(--r-sm);
  padding: 9px 12px;
  margin-bottom: 14px;
  display: none;
}
.login-error.show { display: block; }

/* ---------- Адаптив ---------- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .brand { border-bottom: none; padding: 12px 16px; }
  .brand-sub { display: none; }
  .nav { display: flex; padding: 8px; flex: 1; }
  .nav-label { display: none; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { border-top: none; padding: 8px 16px; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .form-row { flex-direction: column; gap: 0; }
}
