/* Страница «Подразделения» */

.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 20px 32px; margin-bottom: 26px; }
.head > div { flex: 1 1 460px; min-width: 0; }
.pricebar { flex: 0 1 400px; min-width: 0; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.pricebar p { margin: 0; }
.pb-label { font: 700 15px var(--caps); letter-spacing: .1em; color: var(--gold); }
.pb-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 6px; }
.pb-status { color: #e6d6b4; font-size: 14px; }
.pb-status:empty { display: none; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who-text { min-width: 0; }
.who .face { width: 48px; height: 48px; font-size: 18px; }
.pricebar .who-name { font: 700 21px/1.15 var(--caps); letter-spacing: .04em; color: #f1e3c1; overflow-wrap: anywhere; }
.pricebar .who-sub { font-size: 13px; color: var(--bone-muted); overflow-wrap: anywhere; }
.tag-gold { font: 600 12px var(--text); letter-spacing: .02em; color: var(--gold); border: 1px solid var(--gold-dim); padding: 0 6px; vertical-align: 3px; }

.btn-sm { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.btn[aria-pressed="true"] { background: linear-gradient(#93261a, #661810); border-color: #c79a52; color: #f8ead0; }
.link-ink { color: var(--rubric); }
.link-ink:hover { color: var(--rubric-deep); }
.link-danger { color: var(--rubric); }
.link-danger:hover { color: var(--rubric-deep); }
.link-ink:focus-visible, .link-danger:focus-visible { outline-color: var(--rubric); }

.hint { margin: 2px 0 10px; font-size: 14px; color: var(--ink-muted); }
.sub { margin: 22px 0 6px; font: 700 19px var(--caps); letter-spacing: .1em; color: #6b2a1a; }
.empty { margin: 18px 0; text-align: center; color: var(--ink-muted); }
.lbl { display: block; font: 700 14px var(--caps); letter-spacing: .1em; color: #6b2a1a; margin-bottom: 2px; }

/* Подразделения над древом */
.tree-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 20px; margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--bone-dim); }
.chip i { width: 13px; height: 13px; background: var(--u); box-shadow: 0 0 0 1px #120d09, 0 0 0 2px var(--gold-dim); }
.chip small { color: var(--bone-muted); font-size: 13px; }
.officer { display: flex; flex-wrap: wrap; gap: 8px; }
.officer[hidden] { display: none; }
.tree-status { margin: 0 0 10px; min-height: 1.5em; font-size: 15px; color: #e6d6b4; }

/* Древо */
.frame { position: absolute; inset: 12px; border: 1px solid rgba(74, 44, 18, .4); pointer-events: none; }
.tree-page { --line: rgba(74, 44, 18, .6); padding: 30px 30px 26px; }
.tree-title { text-align: center; margin-bottom: 14px; }
.edit-hint { text-align: center; }
.grip-sample { font-size: 16px; }
.tree-scroll { position: relative; overflow-x: auto; padding: 4px 2px 14px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; }
.tree { width: max-content; min-width: 100%; gap: 0 26px; }
.tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 20px 7px 0; }
.tree > li { padding-top: 0; }
.tree ul { position: relative; padding-top: 20px; }
.tree ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 20px; border-left: 1.5px solid var(--line); }
.tree ul > li::before, .tree ul > li::after { content: ""; position: absolute; top: 0; width: 50%; height: 20px; border-top: 1.5px solid var(--line); }
.tree ul > li::before { right: 50%; }
.tree ul > li::after { left: 50%; border-left: 1.5px solid var(--line); }
.tree ul > li:first-child::before, .tree ul > li:last-child::after { border-top: 0; }
.tree ul > li:last-child::before { border-right: 1.5px solid var(--line); border-radius: 0 6px 0 0; }
.tree ul > li:first-child::after { border-radius: 6px 0 0 0; }
.tree ul > li:only-child::before { display: none; }
.tree ul > li:only-child::after { border-top: 0; border-radius: 0; }
@media (min-width: 721px) { /* столбик: линия от левого края начальника, отводы к каждому */
  .tree ul.stack { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 0 0 24px; }
  .tree ul.stack::before { left: 11px; top: 0; bottom: 31px; height: auto; }
  .tree ul.stack > li { padding: 0; align-items: flex-start; }
  .tree ul.stack > li::before { display: block; left: -13px; right: auto; top: 31px; width: 13px; height: 0; border: 0; border-top: 1.5px solid var(--line); border-radius: 0; }
  .tree ul.stack > li::after { display: none; }
}

.unit-flag { position: relative; z-index: 1; padding: 1px 12px 2px; font: 700 13px/1.3 var(--caps); letter-spacing: .1em; color: #fbf3df; background: var(--u); box-shadow: 0 1px 2px rgba(40, 20, 6, .35); max-width: 196px; overflow-wrap: anywhere; text-align: center; }

.node { position: relative; width: 196px; display: flex; flex-direction: column; color: var(--ink); background: linear-gradient(#f1e6ca, #e3d0a9); border: 1px solid rgba(74, 44, 18, .55); box-shadow: inset 0 3px 0 var(--u), 0 2px 5px rgba(50, 26, 8, .3); }
.node.mine { box-shadow: inset 0 3px 0 var(--u), 0 0 0 2px #b8862f, 0 2px 5px rgba(50, 26, 8, .3); }
.node-main { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 62px; padding: 10px 10px 8px; cursor: pointer; }
.node-main:hover { background: rgba(143, 29, 20, .07); }
.node-main:focus-visible { outline: 2px solid var(--rubric); outline-offset: -2px; }
.node-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.node-name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.node-rank { margin-top: 2px; font: 600 14px var(--caps); letter-spacing: .06em; color: var(--rubric); overflow-wrap: anywhere; }
.node-tools { display: flex; justify-content: space-between; border-top: 1px dashed rgba(74, 44, 18, .35); }
.node-tools button { all: unset; box-sizing: border-box; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 36px; font-size: 20px; color: var(--ink-soft); cursor: pointer; }
.node-tools button:hover { background: rgba(143, 29, 20, .08); color: var(--rubric); }
.node-tools button:focus-visible { outline: 2px solid var(--rubric); outline-offset: -2px; }
.node-tools .grip { flex: 1.4; cursor: grab; touch-action: none; font-size: 18px; }
.node.dragging { opacity: .35; }
.node.over { outline: 2px dashed var(--rubric); outline-offset: 3px; background: linear-gradient(#f6ecd4, #ead9b6); }
.ghost { position: fixed; z-index: 100; pointer-events: none; transform: translate(-50%, -30%) rotate(-2deg); box-shadow: 0 12px 26px rgba(0, 0, 0, .45); opacity: .95; }

.face { flex: 0 0 auto; display: block; width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: #3a2816; box-shadow: 0 0 0 1.5px var(--u, #6b5432), 0 0 0 3px rgba(255, 248, 230, .6); }
.face-none { display: flex; align-items: center; justify-content: center; font: 700 16px var(--caps); letter-spacing: .04em; color: #f1e3c1; background: linear-gradient(#5a4128, #3a2816); }
.face-lg { width: 84px; height: 84px; font-size: 30px; }

.drop-zone { margin: 0 auto 16px; max-width: 520px; padding: 12px; border: 1.5px dashed rgba(143, 29, 20, .55); text-align: center; font-size: 15px; color: var(--ink-muted); }
.drop-zone[hidden] { display: none; }
.drop-zone.over { background: rgba(143, 29, 20, .1); color: var(--rubric); }

/* Резерв */
.reserve { margin-top: 40px; }
.reserve[hidden] { display: none; }
.sec-head { display: flex; align-items: center; gap: 14px; }
.sec-head h2 { margin: 0; font: 700 26px var(--caps); letter-spacing: .16em; color: #e2c98f; white-space: nowrap; }
.rule { flex: 1; height: 1px; }
.rule-l { background: linear-gradient(90deg, transparent, var(--gold-dim)); }
.rule-r { background: linear-gradient(90deg, var(--gold-dim), transparent); }
.gem { width: 7px; height: 7px; transform: rotate(45deg); background: var(--red); box-shadow: 0 0 0 2px #120d09, 0 0 0 3px var(--gold-dim); }
.sec-lead { margin: 10px auto 18px; max-width: 74ch; text-align: center; color: var(--bone-dim); }
.reserve-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; min-height: 84px; padding: 14px; border: 1.5px dashed transparent; }
.reserve-list.drop-on { border-color: rgba(217, 181, 108, .45); }
.reserve-list.over { background: rgba(217, 181, 108, .08); border-color: var(--gold); }
.reserve-list .sec-lead { margin: auto; }

/* Правила */
.rules { margin-top: 44px; padding: 32px 36px 26px; }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 40px; }
.rules li { font-size: 16px; color: var(--ink-soft); }
.more { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* Окно карточки */
.card-dlg { position: fixed; inset: 0; margin: auto; width: min(900px, calc(100vw - 32px)); height: min(880px, calc(100vh - 48px)); padding: 22px 26px 0; border: 0; color: var(--ink); overflow: hidden; display: none; flex-direction: column; }
.card-dlg-sm { width: min(720px, calc(100vw - 32px)); }
.card-dlg[open] { display: flex; }
.card-dlg::backdrop { background: rgba(10, 6, 3, .7); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px solid rgba(74, 44, 18, .35); }
.dlg-head .rubric { font-size: 24px; overflow-wrap: anywhere; min-width: 0; }
.dlg-close { all: unset; flex: 0 0 auto; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--rubric); cursor: pointer; }
.dlg-close:focus-visible { outline: 2px solid var(--rubric); }
.dlg-body { flex: 1; overflow-y: auto; margin: 0 -10px; padding: 14px 10px 22px; }

.cv-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 18px; align-items: center; }
.cv-who p { margin: 0; }
.cv-nick { font: italic 600 18px var(--text); color: var(--ink-soft); }
.cv-rank { font: 700 19px var(--caps); letter-spacing: .06em; color: var(--rubric); }
.cv-line { font-size: 15px; color: var(--ink-soft); }
.cv-faint { color: var(--ink-faint); }
.cv-actions { display: flex; flex-direction: column; gap: 8px; }
.unit-chip { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.unit-chip::before { content: ""; width: 11px; height: 11px; background: var(--u); box-shadow: 0 0 0 1px rgba(42, 28, 16, .6); }
.cv-subs { margin: 12px 0 0; font-size: 15px; color: var(--ink-soft); }
.cv-locked { margin: 22px 0 0; padding: 14px 16px; border: 1px dashed rgba(74, 44, 18, .45); color: var(--ink-muted); }
.cv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 34px; }
.cv-wide { grid-column: 1 / -1; }
.cv-sec { min-width: 0; }
.cv-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; color: var(--ink-soft); }
.cv-h4 { margin: 14px 0 4px; font: 700 15px var(--caps); letter-spacing: .1em; color: var(--rubric); }
.cv-foot { margin: 24px 0 0; font-size: 13px; color: var(--ink-faint); }
.cv-status { margin: 6px 0 0; font-size: 14px; color: var(--ink-muted); overflow-wrap: anywhere; }

.meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 6px 0 0; border-top: 1px solid rgba(74, 44, 18, .45); border-bottom: 1px solid rgba(74, 44, 18, .45); }
.meta div { padding: 8px 4px; text-align: center; min-width: 0; }
.meta div + div { border-left: 1px solid rgba(74, 44, 18, .3); }
.meta dt { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); overflow-wrap: anywhere; }
.meta dd { margin: 0; font: 700 26px var(--display); font-variant-numeric: lining-nums; }
.meta dd small { margin-left: 3px; font: 400 13px var(--text); color: var(--ink-muted); }
.meta-sm dd { font-size: 22px; }

.levels { list-style: none; margin: 0; padding: 0; }
.levels li { display: grid; grid-template-columns: minmax(0, 1fr) 84px 26px; gap: 10px; align-items: center; padding: 4px 0; border-bottom: 1px dashed rgba(74, 44, 18, .25); font-size: 15px; }
.levels b { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: rgba(74, 44, 18, .15); }
.bar i { display: block; height: 100%; background: var(--rubric); border-radius: 0 3px 3px 0; }

.set-name { margin: 0 0 4px; font-weight: 700; }
.set-list { list-style: none; margin: 10px 0 8px; padding: 0; columns: 2; column-gap: 28px; }
.set-list li { break-inside: avoid; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; padding: 3px 0; border-bottom: 1px dashed rgba(74, 44, 18, .22); font-size: 15px; }
.set-slot { font-size: 13px; color: var(--ink-faint); }

.prop { width: 100%; border-collapse: collapse; font-size: 15px; }
.prop th { text-align: left; font: 700 13px var(--caps); letter-spacing: .1em; color: var(--rubric); border-bottom: 1px solid rgba(74, 44, 18, .45); padding: 4px 8px 4px 0; }
.prop td { vertical-align: top; padding: 5px 8px 5px 0; border-bottom: 1px dashed rgba(74, 44, 18, .25); overflow-wrap: anywhere; }

/* Правка карточки */
.cf-sec { border: 0; padding: 0; margin: 0 0 8px; min-width: 0; }
.cf-sec legend { padding: 0; }
.cf-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.cf-f { display: block; margin-bottom: 12px; min-width: 0; }
textarea.fld { resize: vertical; line-height: 1.4; padding-top: 8px; font-size: 16px; }
select.fld { font-size: 16px; }
.lv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 22px; }
.lv { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; border-bottom: 1px dashed rgba(74, 44, 18, .22); }
.fld-num { width: 64px; flex: 0 0 64px; min-height: 40px; text-align: center; font-size: 17px; }
.prop-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1.4fr) 44px; gap: 8px; margin-bottom: 8px; }
.prop-row .fld { font-size: 16px; }
.prop-del { all: unset; display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--rubric); cursor: pointer; }
.prop-del:focus-visible { outline: 2px solid var(--rubric); }
.cf-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; margin-top: 18px; }
.cf-actions .link-danger { margin-left: auto; }
.cf-status { margin: 8px 0 0; min-height: 1.4em; font-size: 15px; color: var(--rubric); }

/* Подразделения: правка */
.unit-form { padding: 14px 0 10px; border-bottom: 1px solid rgba(74, 44, 18, .3); }
.unit-form .cf-actions { margin-top: 4px; }
.unit-status { font-size: 14px; color: var(--rubric); }
.swatches { border: 0; padding: 0; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.swatches legend { width: 100%; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch span:first-of-type { display: block; width: 36px; height: 36px; background: var(--c); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .2), 0 0 0 1px #2a1c10; }
.swatch input:checked + span { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25), 0 0 0 2px #f3e6c4, 0 0 0 4px var(--rubric); }
.swatch input:focus-visible + span { outline: 2px solid #d9a857; outline-offset: 5px; }

@media (max-width: 720px) {
  .tree-page { padding: 24px 16px 20px; }
  .tree-scroll { overflow: visible; padding: 0; }
  .tree, .tree ul { display: block; width: auto; min-width: 0; }
  .tree li { display: block; padding: 10px 0 0; }
  .tree > li + li { margin-top: 14px; }
  .tree ul { padding: 0 0 0 22px; }
  .tree ul::before { display: none; }
  .tree ul > li::before, .tree ul > li:first-child::before, .tree ul > li:last-child::before, .tree ul > li:only-child::before {
    display: block; left: -13px; right: auto; top: 0; bottom: 0; width: 0; height: auto; border: 0; border-left: 1.5px solid var(--line); border-radius: 0;
  }
  .tree ul > li:last-child::before { bottom: auto; height: 40px; }
  .tree ul > li::after, .tree ul > li:first-child::after, .tree ul > li:last-child::after, .tree ul > li:only-child::after {
    left: -13px; top: 40px; width: 13px; height: 0; border: 0; border-top: 1.5px solid var(--line); border-radius: 0;
  }
  .node { width: auto; }
  .unit-flag { display: inline-block; max-width: none; }
  .rules { padding: 24px 18px 20px; }
  .sec-head h2 { font-size: 21px; }
  .card-dlg { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 14px 16px 0; }
  .cv-top { grid-template-columns: auto minmax(0, 1fr); }
  .cv-actions { grid-column: 1 / -1; flex-direction: row; }
  .face-lg { width: 64px; height: 64px; font-size: 24px; }
  .cv-grid, .cf-row { grid-template-columns: minmax(0, 1fr); }
  .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta div:nth-child(3) { border-left: 0; }
  .meta div:nth-child(n+3) { border-top: 1px solid rgba(74, 44, 18, .2); }
  .set-list { columns: 1; }
  .prop-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; }
  .prop-row [name=p-note] { grid-column: 1 / 3; }
  .prop-row .prop-del { grid-row: 1; grid-column: 3; }
  .lv-grid { grid-template-columns: minmax(0, 1fr); }
}
