/* ============================================================
   Таверна · Доска Контрактов
   Фон — интерьер таверны (King's Tavern, Wikimedia PD).
   Доска — тёмный дуб (WoodFloor041, ambientCG CC0).
   Свитки — состаренный пергамент (opengameart CC0).
   ============================================================ */

:root {
  --parchment: #efdcae;
  --parchment-dark: #c5a86a;
  --ink: #2b1d0e;
  --ink-soft: #4a3418;
  --wax-red: #7a1010;
  --wax-red-hi: #a02020;
  --gold: #b48a3c;
  --gold-hi: #e0b455;
  --iron: #2a2018;
  --iron-hi: #4a3d2a;
  --shadow-deep: #0a0806;
}

* { box-sizing: border-box; }

html, body {
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  /* Скрываем нативный вертикальный скроллбар, скролл колёсиком остаётся */
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* IE/Edge */
}
html::-webkit-scrollbar,
body::-webkit-scrollbar { display: none; }

body {
  min-height: 100vh;
  font-family: 'Montserrat', system-ui, sans-serif;
  color: var(--parchment);
  background: var(--shadow-deep);
  position: relative;
  overflow-y: auto;
}

/* ===== Фон таверны (виден по бокам от доски) ===== */
.tavern-scene {
  position: fixed;
  inset: 0;
  z-index: -3;
  background-image: url("assets/textures/tavern_bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: brightness(1) saturate(0.95);
}
/* Видео поверх картинки: если не грузится / кодек не поддержан — остаётся фон */
.tavern-video {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  z-index: -2;
  filter: brightness(1) saturate(0.95);
  pointer-events: none;
}
.tavern-vignette {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  box-shadow: inset 0 0 240px 80px rgba(0,0,0,0.18);
  background: radial-gradient(ellipse at 50% 45%, transparent 40%, rgba(0,0,0,0.12) 100%);
}

/* ===== Стойка с доской ===== */
.board-stand {
  max-width: 1080px;
  width: 92vw;
  margin: 40px auto 0;
  position: relative;
  padding-bottom: 90px; /* место под опоры */
}

.board-frame {
  padding: 22px 22px 22px;
  background-image: url("assets/textures/Wood066_color.jpg");
  background-size: 512px auto;
  border-radius: 4px;
  /* Многослойная тень: контактная у поверхности + мягкая размытая + широкая под "стену" */
  box-shadow:
    0 0 0 2px #1a0f05,                    /* тонкая тёмная окантовка */
    0 2px 0 rgba(255,220,180,0.06),       /* тонкий свет по верхней кромке */
    inset 0 1px 0 rgba(255,220,180,0.12), /* highlight сверху внутри */
    inset 0 -2px 0 rgba(0,0,0,0.35),      /* тень снизу внутри */
    inset 0 0 60px rgba(0,0,0,0.35),      /* мягкая внутренняя виньетка */
    0 8px 16px rgba(0,0,0,0.6),           /* близкая тень (контакт со стеной) */
    0 24px 60px rgba(0,0,0,0.7),          /* средняя размытая тень */
    0 60px 120px rgba(0,0,0,0.45);        /* дальняя тень на "стене" */
  position: relative;
  z-index: 2;
}
/* Свет по верхнему краю рамки (как от факела сверху-слева) */
.board-frame::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 40%;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 210, 150, 0.10) 0%,
    rgba(255, 200, 130, 0.04) 40%,
    transparent 100%
  );
  border-radius: 4px 4px 0 0;
  z-index: 1;
}
/* Тень внутри рамки снизу (глубина) */
.board-frame::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 30%;
  pointer-events: none;
  background: linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.35) 0%,
    transparent 100%
  );
  border-radius: 0 0 4px 4px;
  z-index: 1;
}

/* Заклёпки */
.rivet {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #d4bfa0 0%, #7a6a55 25%, #2a2018 60%, #0a0806 100%);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.9),
    inset 0 1px 1px rgba(255,255,255,0.25);
  z-index: 3;
}
.rivet-tl { top: 8px; left: 8px; }
.rivet-tr { top: 8px; right: 8px; }
.rivet-bl { bottom: 8px; left: 8px; }
.rivet-br { bottom: 8px; right: 8px; }
/* Железные заклёпки по углам рамки */
.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  background: radial-gradient(circle at 35% 35%, #a89678 0%, #4a3d2a 55%, #1a0f05 100%);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.9);
}
.board-frame::before { top: 8px; left: 8px; }
.board-frame::after  { top: 8px; right: 8px; }

/* Заголовок ВНУТРИ доски, сверху */
.board-title {
  font-family: 'MedievalSharp', serif;
  font-size: 44px;
  margin: 0 0 18px;
  text-align: center;
  color: var(--gold-hi);
  text-shadow:
    0 2px 0 #000,
    0 4px 0 #1a0f05,
    0 6px 20px rgba(0,0,0,0.9),
    0 0 30px rgba(180,138,60,0.35);
  letter-spacing: 0.03em;
  padding: 10px 0 0;
  border-bottom: 3px double rgba(180,138,60,0.4);
  padding-bottom: 14px;
}

/* Опорные столбы */
.stand-post {
  position: absolute;
  bottom: 0;
  width: 26px;
  height: 90px;
  background-image: url("assets/textures/Wood066_color.jpg");
  background-size: 200px auto;
  background-position: center;
  box-shadow:
    0 0 0 2px #1a0f05,                       /* окантовка */
    inset 3px 0 6px rgba(255,220,180,0.15),  /* блик слева (свет от факела) */
    inset -4px 0 8px rgba(0,0,0,0.6),        /* тень справа */
    inset 0 -6px 8px rgba(0,0,0,0.5),        /* тень у пола */
    0 8px 16px rgba(0,0,0,0.7),
    0 20px 40px rgba(0,0,0,0.5);
  z-index: 1;
}
.stand-post-left  { left: 12%; }
.stand-post-right { right: 12%; }
.stand-post::after {
  /* Заклёпки на столбах */
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px; height: 8px;
  background: radial-gradient(circle at 35% 35%, #a89678 0%, #4a3d2a 55%, #1a0f05 100%);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

/* Нижняя перекладина между столбами */
.stand-base {
  position: absolute;
  bottom: 8px;
  left: 8%;
  right: 8%;
  height: 14px;
  background-image: url("assets/textures/Wood066_color.jpg");
  background-size: 400px auto;
  background-position: center;
  box-shadow:
    0 0 0 2px #1a0f05,
    0 6px 16px rgba(0,0,0,0.8);
  z-index: 0;
}

/* ===== Корзина под стойкой (видна только при zoom-out) ===== */
.trash {
  position: absolute;
  bottom: -700px;         /* глубоко за нижним краем экрана — доступна только через zoom-out */
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 2;
  filter: drop-shadow(0 12px 20px rgba(0,0,0,0.7));
}
.trash-svg {
  width: 140px;
  height: 160px;
  display: block;
  cursor: pointer;
  transition: transform 0.2s;
}
.trash-svg:hover { transform: translateY(-4px) scale(1.03); }

.trash-panel {
  width: 220px;
  padding: 10px 14px 14px;
  background: rgba(20, 14, 8, 0.9);
  border: 1px solid #4a3d2a;
  border-radius: 3px;
  color: var(--parchment);
  box-shadow: 0 8px 24px rgba(0,0,0,0.8);
  font-family: 'Montserrat', system-ui, sans-serif;
}
.trash-header {
  font-family: 'MedievalSharp', serif;
  font-size: 18px;
  color: var(--gold-hi);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed rgba(180,138,60,0.4);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.trash-count {
  background: #0a0806;
  color: var(--gold-hi);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 1px 10px;
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 12px;
}
.trash-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: none;
}
.trash-list::-webkit-scrollbar { display: none; }
.trash-list:empty::before {
  content: "— пусто —";
  color: var(--parchment-dark);
  opacity: 0.5;
  font-style: italic;
  font-size: 13px;
  padding: 4px 0;
}
.trash-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(60,40,15,0.35);
  border: 1px solid rgba(139,100,40,0.3);
  border-radius: 2px;
  font-size: 12px;
}
.trash-item-title {
  flex: 1;
  color: var(--parchment);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trash-restore {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold-hi);
  padding: 0 8px;
  height: 22px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.trash-restore:hover { background: var(--gold); color: #1a0f05; }
.trash-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--parchment-dark);
  opacity: 0.55;
  font-style: italic;
  text-align: center;
}

/* ===== Кнопка «Новый контракт» — свиток с пером на верхней рамке ===== */
.new-contract {
  position: absolute;
  top: 8px;
  right: 26px;
  z-index: 5;
  width: 90px;
  height: 70px;
  padding: 0;
  margin: 0;
  background: none;
  border: none;
  cursor: pointer;
  /* Тень предмета на дереве рамки (по альфе SVG) */
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.55)) drop-shadow(0 8px 12px rgba(0,0,0,0.35));
  transition: filter 0.25s ease;
}
.new-contract svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.new-contract .nc-quill,
.new-contract .nc-quill-shadow {
  transition: transform 0.28s ease;
  transform-origin: 30px 82px;
}
.new-contract .nc-warmth {
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
/* Hover: перо приподнимается («берётся в руку»), свет теплеет */
.new-contract:hover {
  filter: drop-shadow(0 7px 6px rgba(0,0,0,0.55)) drop-shadow(0 16px 22px rgba(0,0,0,0.4)) brightness(1.06) saturate(1.05);
}
.new-contract:hover .nc-quill { transform: translate(1.5px, -5px) rotate(-5deg); }
.new-contract:hover .nc-quill-shadow { transform: translate(4px, 1px) rotate(-5deg); opacity: 0.6; }
.new-contract:hover .nc-warmth { opacity: 1; }
.new-contract:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 4px;
}
@media (max-width: 920px) {
  .new-contract { width: 72px; height: 56px; top: 6px; right: 18px; }
}

/* ===== Кнопка «Заткнуть барда» ===== */
.mute-btn {
  position: absolute;
  top: 14px;
  right: 130px;
  z-index: 5;
  width: 58px;
  height: 58px;
  padding: 0;
  margin: 0;
  background: none;
  border: none;
  cursor: pointer;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.55)) drop-shadow(0 8px 12px rgba(0,0,0,0.35));
  transition: filter 0.25s ease, transform 0.15s ease;
}
.mute-btn svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mute-btn:hover {
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.55)) drop-shadow(0 14px 20px rgba(0,0,0,0.4)) brightness(1.08) saturate(1.05);
}
.mute-btn:active { transform: translateY(1px); }
.mute-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 4px;
}
/* Косые черты видны только в muted-состоянии */
.mute-btn .mug-slash,
.mute-btn .mug-slash-hi { opacity: 0; transition: opacity 0.2s ease; }
.mute-btn.muted .mug-slash { opacity: 0.95; }
.mute-btn.muted .mug-slash-hi { opacity: 0.85; }
/* В muted эль тускнеет — «кружка пустая» */
.mute-btn.muted .mug-ale,
.mute-btn.muted .mug-foam { opacity: 0.35; }

@media (max-width: 920px) {
  .mute-btn { width: 48px; height: 48px; top: 10px; right: 100px; }
}

/* ===== Доска ===== */
.board {
  padding: 24px 18px 0;
  display: flex;
  gap: 18px;
  overflow-x: auto;
  min-height: 66vh;
  /* align-items: stretch (дефолт) — иначе пустая колонка схлопывается
     до высоты заголовка, и её нижние 90% визуальной полосы — это
     голый .board (без dragover preventDefault). Drop туда запрещён,
     карточка возвращается в исходную. Симптом: «средняя (пустая) не
     принимает». */
  /* Комбинируем: SVG-зерно + деревянная доска */
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.06  0 0 0 0 0.04  0 0 0 0 0.02  0 0 0 0.22 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
    url("assets/textures/WoodFloor041_color.jpg");
  background-size: 240px auto, 768px auto;
  background-blend-mode: overlay, normal;
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.7),
    inset 0 8px 12px rgba(0,0,0,0.55),  /* глубокая тень от верхнего края */
    inset 0 -6px 10px rgba(0,0,0,0.4),  /* тень от нижнего края */
    inset 8px 0 14px rgba(0,0,0,0.35),  /* тень слева (край рамки) */
    inset -8px 0 14px rgba(0,0,0,0.35), /* тень справа */
    inset 0 0 90px rgba(0,0,0,0.4);     /* общая виньетка */
  position: relative;
}
/* Направленный свет сверху-слева (как от факела) — блик на дереве */
.board::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 20% 0%,
    rgba(255, 200, 120, 0.13) 0%,
    rgba(255, 180, 100, 0.05) 25%,
    transparent 55%
  );
  z-index: 0;
  border-radius: 2px;
}
/* Дальний угол — темнее */
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 100% 100%,
    rgba(0, 0, 0, 0.35) 0%,
    transparent 45%
  );
  z-index: 0;
  border-radius: 2px;
}
.board::-webkit-scrollbar { height: 10px; }
.board::-webkit-scrollbar-track { background: rgba(0,0,0,0.4); border-radius: 5px; }
.board::-webkit-scrollbar-thumb { background: #4a3418; border-radius: 5px; border: 1px solid #1a0f05; }

/* ===== Колонки (3 штуки) ===== */
.column {
  flex: 1 1 0;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 260px);
  position: relative;
  padding: 6px;
}
.column:not(:last-child)::after {
  content: "";
  position: absolute;
  right: -12px;
  top: 4px;
  bottom: 4px;
  width: 6px;
  pointer-events: none;
  /* Кованая полоса: тёмная сердцевина + блик по левому краю + тень по правому */
  background: linear-gradient(
    90deg,
    rgba(0,0,0,0.5) 0%,
    #0a0806 20%,
    #2a2018 45%,
    #4a3d2a 55%,
    #1a0f05 80%,
    rgba(0,0,0,0.5) 100%
  );
  box-shadow:
    -2px 0 8px rgba(0,0,0,0.6),
    2px 0 8px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,220,180,0.2),
    inset 0 -1px 0 rgba(0,0,0,0.6);
  border-radius: 1px;
}
.column-header {
  padding: 8px 12px;
  font-family: 'MedievalSharp', serif;
  font-size: 20px;
  color: var(--gold-hi);
  text-shadow: 0 1px 0 #000, 0 2px 4px rgba(0,0,0,0.9);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--gold), transparent) 1;
  margin-bottom: 12px;
}
.column-count {
  background: #0a0806;
  color: var(--gold-hi);
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--gold);
  box-shadow: inset 0 0 6px rgba(0,0,0,0.9);
}
.column-cards {
  padding: 4px 4px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0; /* иначе overflow-y распирает колонку за max-height */
}
.column-cards::-webkit-scrollbar { width: 6px; }
.column-cards::-webkit-scrollbar-track { background: transparent; }
.column-cards::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.5); border-radius: 3px; }

/* ===== Карточка — свиток ===== */
.card {
  background-image: url("assets/textures/parchment_light.webp");
  background-size: cover;
  background-position: center;
  color: var(--ink);
  border-radius: 2px;
  padding: 22px 16px 14px;
  cursor: pointer;
  position: relative;
  box-shadow:
    0 1px 0 rgba(255,240,200,0.15),           /* highlight по верхнему краю */
    0 3px 6px rgba(0,0,0,0.55),               /* контактная тень */
    0 10px 22px rgba(0,0,0,0.55),             /* средняя размытая */
    0 20px 40px rgba(0,0,0,0.35);             /* дальняя мягкая */
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: 'Montserrat', system-ui, sans-serif;
  clip-path: polygon(
    2% 4%, 98% 2%, 100% 96%, 96% 100%, 4% 98%, 0% 4%
  );
  transform: rotate(-0.3deg);
  font-family: 'Montserrat', system-ui, sans-serif;
}
.card:nth-child(even) { transform: rotate(0.4deg); }
.card:nth-child(3n)   { transform: rotate(-0.6deg); }
.card:hover {
  transform: translateY(-4px) rotate(-0.5deg) scale(1.01);
  box-shadow:
    0 1px 0 rgba(255,240,200,0.2),
    0 6px 10px rgba(0,0,0,0.7),
    0 16px 30px rgba(0,0,0,0.6),
    0 28px 60px rgba(0,0,0,0.4);
}
/* Live-drag: карточка сохраняет размер (место), но становится «духом»,
   пока браузерный ghost плывёт за курсором. Соседи двигаются через
   transition у .card. */
.card.is-dragging {
  opacity: 0.35;
  filter: grayscale(0.4) blur(0.3px);
  outline: 2px dashed rgba(180,138,60,0.7);
  outline-offset: -4px;
  transform: rotate(0deg);
}
.card { transition: transform 0.2s ease, box-shadow 0.2s ease; }

/* Гвоздь-заклёпка */
.card::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: radial-gradient(circle at 35% 35%, #a89678 0%, #4a3d2a 55%, #1a0f05 100%);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.9), 0 0 0 1px rgba(0,0,0,0.5);
  z-index: 2;
}

.card-title {
  font-family: 'MedievalSharp', serif;
  font-size: 19px;
  color: #1a0e04;
  margin: 0 0 8px;
  padding-right: 40px;
  line-height: 1.2;
  font-weight: 400;
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.45);
}
.card-desc {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  color: #2a1a08;
  margin: 0 0 12px;
  line-height: 1.5;
  max-height: 4.5em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
  color: #2a1a08;
  font-family: 'Montserrat', system-ui, sans-serif;
  font-weight: 600;
}
.card-diff {
  color: var(--wax-red);
  font-size: 14px;
  letter-spacing: 1px;
  font-family: sans-serif;
}
.card-assignee {
  position: absolute;
  top: 16px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--parchment);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'MedievalSharp', serif;
  font-size: 12px;
  border: 1px solid #1a0f05;
  box-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

/* Кнопка «выбросить пергамент» — сургучная печать в левом верхнем углу */
.card-trash {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a02020 0%, #7a1010 55%, #3a0505 100%);
  color: #f2e4c5;
  border: 1px solid #3a0505;
  cursor: pointer;
  font-family: sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s, transform 0.15s;
  box-shadow:
    inset 0 1px 1px rgba(255,180,180,0.35),
    0 1px 3px rgba(0,0,0,0.6);
  z-index: 3;
}
.card:hover .card-trash { opacity: 0.9; transform: scale(1); }
.card-trash:hover { opacity: 1 !important; background: radial-gradient(circle at 35% 30%, #c93030 0%, #a02020 55%, #500707 100%); }

.column.done .card::after {
  content: "ИСПОЛНЕНО";
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-16deg);
  font-family: 'MedievalSharp', serif;
  font-size: 24px;
  color: var(--wax-red);
  border: 3px double var(--wax-red);
  padding: 4px 14px;
  border-radius: 6px;
  opacity: 0.4;
  pointer-events: none;
  letter-spacing: 0.06em;
}

/* ===== Модалки ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5,3,1,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-backdrop.hidden { display: none; }
/* Плавное появление: пергамент опускается на стол */
.modal-backdrop:not(.hidden) { animation: backdropIn 0.25s ease-out; }
.modal-backdrop:not(.hidden) .modal { animation: modalIn 0.3s cubic-bezier(0.22, 0.9, 0.35, 1); }
@keyframes backdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) rotate(0.4deg) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.modal {
  /* Рваные края идут из самого PNG (альфа), никаких clip-path/фонов не надо */
  background-image: url("assets/textures/parchment_light.webp");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #1a0f05;
  /* Верх/низ увеличены — у пергамента рваные края съедают ~50-70px */
  padding: 76px 68px 96px;
  max-width: 780px;
  width: 90%;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  filter: drop-shadow(0 20px 40px rgba(0,0,0,0.9));
  font-family: 'Montserrat', system-ui, sans-serif;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.modal::-webkit-scrollbar { display: none; }
.modal h2 {
  font-family: 'MedievalSharp', serif;
  color: #1a0e04;
  margin: 0 0 14px;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.005em;
}
.modal .modal-meta {
  display: flex;
  gap: 14px;
  margin: 6px 0 26px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 16px;
  color: #1a0e04;
}
.modal-section {
  margin: 26px 0;
  padding-top: 20px;
  border-top: 1px dashed rgba(90, 60, 20, 0.65);
}
.modal-section h3 {
  font-family: 'MedievalSharp', serif;
  color: #1a0e04;
  margin: 0 0 14px;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.01em;
}
.modal-body-text {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.7;
  white-space: pre-wrap;
  color: #1a0e04;
}
/* Кнопка «править» в шапке модалки деталей */
.modal-edit-btn {
  background: transparent;
  border: 1px solid rgba(90, 60, 20, 0.65);
  color: #4a3418;
  padding: 3px 12px;
  border-radius: 2px;
  cursor: pointer;
  font-family: 'MedievalSharp', serif;
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: all 0.15s;
}
.modal-edit-btn:hover {
  background: rgba(180, 138, 60, 0.2);
  border-color: var(--wax-red);
  color: var(--wax-red);
}

.modal-lead {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.5;
  color: #1a0e04;
  margin: 0 0 20px;
  font-style: italic;
}
.links-list { display: flex; flex-direction: column; gap: 6px; }
.links-list a {
  color: var(--wax-red);
  text-decoration: underline dotted;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Montserrat', system-ui, sans-serif;
}
.links-list a:hover { color: var(--wax-red-hi); }

/* ===== Форма «Новый контракт» (внутри модалки-пергамента) ===== */
.nc-sub {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 14px;
  font-style: italic;
  color: #4a3418;
  margin: -4px 0 22px;
}
.nc-form { display: flex; flex-direction: column; gap: 16px; }
.nc-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.nc-field { display: flex; flex-direction: column; gap: 5px; }
.nc-label {
  font-family: 'MedievalSharp', serif;
  font-size: 16px;
  color: #3a2812;
  letter-spacing: 0.01em;
}
.nc-input, .nc-textarea {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: #1a0e04;
  background: rgba(255, 250, 235, 0.4);
  border: 1px solid rgba(90, 60, 20, 0.55);
  border-radius: 2px;
  padding: 8px 10px;
  width: 100%;
  box-shadow: inset 0 1px 3px rgba(60, 40, 10, 0.18);
  transition: border-color 0.15s, background 0.15s;
}
.nc-input::placeholder, .nc-textarea::placeholder { color: rgba(74, 52, 24, 0.5); font-style: italic; }
.nc-input:focus, .nc-textarea:focus {
  outline: none;
  border-color: var(--wax-red);
  background: rgba(255, 252, 240, 0.6);
}
select.nc-input { cursor: pointer; }
.nc-textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.55;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nc-textarea::-webkit-scrollbar { display: none; }
.nc-stars { display: flex; gap: 2px; padding: 4px 0 0; }
.nc-star {
  background: none;
  border: none;
  padding: 0 3px;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: rgba(90, 60, 20, 0.30);
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.4);
  transition: color 0.12s, transform 0.12s;
}
.nc-star.lit { color: var(--wax-red); }
.nc-star:hover { transform: scale(1.18); }
.nc-error {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--wax-red);
  min-height: 0;
}
.nc-error:empty { display: none; }
.nc-error-global { font-size: 13px; margin-top: 4px; }
.nc-actions {
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 10px;
  padding-top: 18px;
  border-top: 1px dashed rgba(90, 60, 20, 0.65);
}
.nc-btn {
  font-family: 'MedievalSharp', serif;
  font-size: 16px;
  letter-spacing: 0.02em;
  padding: 10px 22px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
}
.nc-cancel {
  background: transparent;
  border: 1px dashed rgba(90, 60, 20, 0.6);
  color: #4a3418;
}
.nc-cancel:hover {
  border-color: var(--wax-red);
  color: var(--wax-red);
  background: rgba(122, 16, 16, 0.06);
}
.nc-submit {
  background: linear-gradient(180deg, var(--wax-red-hi) 0%, var(--wax-red) 55%, #560b0b 100%);
  border: 1px solid #3d0707;
  color: var(--parchment);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 200, 180, 0.25),
    0 2px 5px rgba(40, 10, 5, 0.5);
}
.nc-submit:hover {
  background: linear-gradient(180deg, #b62c2c 0%, #8a1616 55%, #5c0b0b 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 200, 180, 0.3),
    0 3px 8px rgba(40, 10, 5, 0.6);
}
.nc-submit:disabled { opacity: 0.6; cursor: wait; }
@media (max-width: 640px) {
  .nc-row { grid-template-columns: 1fr; }
}

.empty-column {
  padding: 20px;
  text-align: center;
  color: var(--parchment-dark);
  opacity: 0.4;
  font-style: italic;
  font-family: 'Montserrat', system-ui, sans-serif;
}

/* ===== Аттачи ===== */
.attach-list { display: flex; flex-direction: column; gap: 6px; }
.attach-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px dashed rgba(90, 60, 20, 0.4);
  border-radius: 3px;
  text-decoration: none;
  color: #2c1a08;
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.attach-link:hover {
  background: rgba(180, 138, 60, 0.12);
  border-color: rgba(90, 60, 20, 0.7);
}
.attach-icon { font-size: 16px; }
.attach-name { flex: 1; word-break: break-all; }
.attach-size { font-size: 12px; color: #7a5a2a; font-style: italic; }

.attach-edit-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.attach-empty {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13px;
  color: #7a5a2a;
  font-style: italic;
  opacity: 0.7;
  padding: 4px 0;
}
.attach-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.attach-row .attach-link { flex: 1; }
.attach-del {
  background: transparent;
  border: 1px solid rgba(122, 16, 16, 0.5);
  color: var(--wax-red);
  width: 30px;
  height: 30px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.attach-del:hover {
  background: var(--wax-red);
  color: var(--parchment);
}
.attach-deleting { opacity: 0.4; pointer-events: none; }

.nc-file-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  font-family: 'MedievalSharp', serif;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: #f2e0b3;
  background:
    linear-gradient(180deg, rgba(255, 220, 170, 0.08) 0%, rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, #4a2d13 0%, #3a1f0a 55%, #1f120a 100%);
  border: 1px solid #1e0f05;
  border-radius: 3px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.18),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5),
    0 2px 5px rgba(20, 8, 2, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  transition: all 0.15s;
  align-self: flex-start;
  user-select: none;
}
.nc-file-btn:hover {
  background:
    linear-gradient(180deg, rgba(255, 220, 170, 0.12) 0%, rgba(0, 0, 0, 0) 55%),
    linear-gradient(180deg, #5a3818 0%, #47270c 55%, #29160c 100%);
  color: #ffdf9f;
  border-color: var(--gold);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.55),
    0 3px 10px rgba(20, 8, 2, 0.55),
    0 0 12px rgba(180, 138, 60, 0.25);
}
.nc-file-btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 1px 2px rgba(20, 8, 2, 0.3);
}
.nc-file-btn-icon { font-size: 16px; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6)); }

.nc-file-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}
.nc-file-item {
  display: flex;
  gap: 10px;
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13px;
  color: #4a3418;
}
.nc-file-item span:first-child { flex: 1; word-break: break-all; }
.nc-file-size { color: #7a5a2a; font-style: italic; font-size: 12px; }

/* ===== Кнопка «Скопировать ссылку» в модалке ===== */
.modal-copy-btn {
  background: transparent;
  border: 1px solid rgba(90, 60, 20, 0.65);
  color: #4a3418;
  padding: 3px 12px;
  border-radius: 2px;
  cursor: pointer;
  font-family: 'MedievalSharp', serif;
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: all 0.15s;
}
.modal-copy-btn:hover {
  background: rgba(180, 138, 60, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

/* ===== Панель пользователя (logout + имя) ===== */
.board-topbar {
  position: absolute;
  top: 10px;
  left: 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
}
.current-user {
  font-family: 'MedievalSharp', serif;
  font-size: 13px;
  color: var(--parchment-dark);
  opacity: 0.7;
  letter-spacing: 0.02em;
}
.logout-btn {
  background: transparent;
  border: none;
  color: var(--parchment-dark);
  font-family: 'MedievalSharp', serif;
  font-size: 13px;
  letter-spacing: 0.02em;
  cursor: pointer;
  opacity: 0.55;
  padding: 2px 0;
  transition: opacity 0.15s, color 0.15s;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.logout-btn:hover {
  opacity: 0.9;
  color: var(--gold-hi);
}

/* ===== Подконтракты и упоминания ===== */

/* Хлебная крошка над заголовком контракта */
.modal-crumb {
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 13px;
  font-style: italic;
  color: #6a4a20;
  margin-bottom: 8px;
  opacity: 0.85;
}

/* Ссылки в крошке и упоминаниях в тексте */
.crumb-link,
.mention {
  color: var(--gold);
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  font-weight: 600;
  transition: color 0.15s;
}
.crumb-link:hover,
.mention:hover {
  color: var(--gold-hi);
  text-decoration: underline;
}

/* Секция подконтрактов */
.subcontracts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Карточка-строка подконтракта */
.subcontract {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: rgba(60, 40, 15, 0.10);
  border: 1px dashed rgba(90, 60, 20, 0.45);
  border-radius: 3px;
  text-decoration: none;
  color: #2c1a08;
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.subcontract:hover {
  background: rgba(180, 138, 60, 0.12);
  border-color: rgba(90, 60, 20, 0.7);
}
.sub-id {
  font-family: 'MedievalSharp', serif;
  font-size: 13px;
  color: var(--gold);
  white-space: nowrap;
}
.sub-title {
  flex: 1;
  color: #1a0e04;
  font-weight: 500;
}
.sub-stars {
  color: var(--wax-red);
  font-size: 13px;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ===== Чат (Разговоры у стойки) ===== */

/* Список сообщений */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px 0 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(90,60,20,0.3) transparent;
}
.chat-list::-webkit-scrollbar { width: 5px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(90,60,20,0.3); border-radius: 3px; }

/* Одно сообщение */
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 10px 6px;
  background: rgba(255,245,225,0.35);
  border: 1px dashed rgba(90,60,20,0.25);
  border-radius: 3px;
  font-family: Montserrat, system-ui, sans-serif;
}

/* Своё сообщение — тонкая рамка слева золотого цвета */
.chat-msg--mine {
  background: rgba(180,138,60,0.08);
  border-color: rgba(90,60,20,0.18);
  border-left: 3px solid var(--gold);
  padding-left: 8px;
}

/* Шапка сообщения */
.chat-msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-msg-author {
  font-family: MedievalSharp, serif;
  font-size: 13px;
  color: #3a2208;
  font-weight: 400;
}
.chat-msg-time {
  font-size: 11px;
  color: #7a5a2a;
  font-style: italic;
  margin-right: auto;
  cursor: default;
}
.chat-msg-del {
  background: transparent;
  border: none;
  color: rgba(122,16,16,0.55);
  font-size: 11px;
  padding: 0 2px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.chat-msg-del:hover { color: var(--wax-red); }
.chat-msg-del[hidden] { display: none; }

/* Тело сообщения */
.chat-msg-body {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.55;
  color: #1a0e04;
  word-break: break-word;
}

/* Форма отправки */
.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 10px;
}
.chat-input {
  flex: 1;
  font-family: Montserrat, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: #1a0e04;
  background: rgba(255,250,235,0.45);
  border: 1px solid rgba(90,60,20,0.5);
  border-radius: 2px;
  padding: 7px 9px;
  resize: none;
  line-height: 1.5;
  transition: border-color 0.15s, background 0.15s;
  scrollbar-width: none;
}
.chat-input::-webkit-scrollbar { display: none; }
.chat-input::placeholder { color: rgba(74,52,24,0.45); font-style: italic; }
.chat-input:focus { outline: none; border-color: var(--gold); background: rgba(255,252,240,0.6); }
.chat-input:disabled { opacity: 0.5; }

.chat-send {
  font-family: MedievalSharp, serif;
  font-size: 14px;
  letter-spacing: 0.02em;
  padding: 8px 16px;
  background: linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 55%, #7a5a20 100%);
  border: 1px solid #4a3010;
  color: #1a0e04;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255,240,200,0.4);
  box-shadow: inset 0 1px 0 rgba(255,240,200,0.3), 0 2px 4px rgba(0,0,0,0.3);
  transition: all 0.15s;
  flex-shrink: 0;
}
.chat-send:hover {
  background: linear-gradient(180deg, #f0c060 0%, var(--gold-hi) 55%, #906030 100%);
  box-shadow: inset 0 1px 0 rgba(255,240,200,0.4), 0 3px 8px rgba(0,0,0,0.4);
}
.chat-send:active { transform: translateY(1px); }
.chat-send:disabled { opacity: 0.5; cursor: wait; }
