/* P3 «База филиалов» — таблица. Тёмная NOC-тема, как основной интерфейс. */

.page-body {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.bt-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

/* ---- панель фильтров ---- */
.bt-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--surface), var(--surface));
  border: 1px solid var(--border);
  border-radius: 14px;
}
.bt-field { display: flex; flex-direction: column; gap: 5px; }
.bt-field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted);
}
.bt-field input, .bt-field select {
  padding: 8px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 14px; font-family: inherit; outline: none; min-width: 150px;
}
.bt-field input:focus, .bt-field select:focus { border-color: var(--accent); }
.bt-field--check { flex-direction: row; align-items: center; gap: 8px; }
.bt-field--check input { min-width: 0; width: 17px; height: 17px; accent-color: var(--accent); }
.bt-field--check label { text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); }
.bt-filters__spacer { flex: 1; }
.bt-count { font-size: 13px; color: var(--text-muted); align-self: center; white-space: nowrap; }
.bt-reset {
  padding: 8px 14px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; font-size: 13.5px; cursor: pointer;
}
.bt-reset:hover { border-color: var(--accent); }

/* ---- таблица ---- */
.bt-wrap {
  overflow: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  max-height: calc(100vh - 210px);
}
.bt-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13.5px; }
.bt-table th, .bt-table td {
  padding: 9px 13px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--surface-3); border-right: 1px solid var(--border);
}
.bt-table thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface); backdrop-filter: blur(8px);
  color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border-strong); user-select: none;
}
.bt-table thead th > span, .bt-table thead th { white-space: nowrap; }
.bt-table thead th { padding: 0; }
.bt-th-label { display: inline-block; padding: 9px 6px 9px 13px; cursor: pointer; }
.bt-th-label:hover { color: var(--text); }
.bt-sort { color: var(--accent); margin-left: 5px; font-size: 11px; }
.bt-th-filter {
  border: none; background: none; color: var(--text-dim); cursor: pointer; font-size: 12px;
  padding: 9px 10px 9px 2px;
}
.bt-th-filter:hover { color: var(--text); }
.bt-table thead th.bt-filter-active { background: var(--surface-3); }
.bt-table thead th.bt-filter-active .bt-th-filter { color: var(--accent); }
.bt-table thead th.bt-filter-active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent);
}
.bt-table thead th { position: sticky; } /* сохранить sticky после position:relative-эффекта */
/* № — зафиксирован слева */
.bt-table th.bt-sticky, .bt-table td.bt-sticky {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  border-right: 1px solid var(--border); font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600;
}
.bt-table thead th.bt-sticky { z-index: 4; }
.bt-table tbody tr:nth-child(even) td { background: #0f16240f; }
.bt-table tbody tr:hover td { background: var(--surface-3); }
.bt-table tbody tr:hover td.bt-sticky { background: var(--surface-3); }
.bt-num-cell { font-variant-numeric: tabular-nums; text-align: right; }
/* длинные тексты (адрес, материалы, окружение…) — обрезка, полный текст в title */
.bt-long-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }

.bt-empty-val { color: var(--text-dim); }

/* статус-пилюли */
.bt-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.bt-pill--online { background: rgba(52,211,153,.14); color: #34d399; }
.bt-pill--offline { background: rgba(251,113,133,.14); color: #fb7185; }
.bt-pill--unknown { background: rgba(99,112,140,.16); color: var(--text-muted); }

/* uptime */
.bt-uptime { font-variant-numeric: tabular-nums; font-weight: 600; }

/* редактируемая ячейка */
.bt-table td.bt-edit { cursor: text; }
.bt-table td.bt-edit:hover { box-shadow: inset 0 0 0 1px var(--border-strong); }
.bt-table td.bt-edit::after {
  content: '✎'; opacity: 0; margin-left: 7px; color: var(--text-dim); font-size: 11px; transition: opacity .12s;
}
.bt-table td.bt-edit:hover::after { opacity: .8; }
.bt-cell-input {
  width: 100%; min-width: 90px; padding: 4px 7px; background: var(--surface-2);
  border: 1px solid var(--accent); border-radius: 6px; color: var(--text); font: inherit; outline: none;
}
.bt-saved { animation: bt-flash .9s ease; }
@keyframes bt-flash { 0% { background: rgba(223,126,24,.25); } 100% { background: transparent; } }
.bt-error-cell { box-shadow: inset 0 0 0 1px #fb7185; }

/* навигация Карта/База */
.bt-nav { display: flex; gap: 4px; margin-left: 20px; }
.bt-nav a {
  padding: 7px 15px; border-radius: 9px; color: var(--text-muted); text-decoration: none;
  font-size: 14px; font-weight: 600; border: 1px solid transparent;
}
.bt-nav a:hover { color: var(--text); background: rgba(255,255,255,.04); }
.bt-nav a.active { color: var(--accent); background: rgba(223,126,24,.1); border-color: var(--border); }

.bt-loading, .bt-fail { padding: 40px; text-align: center; color: var(--text-muted); font-size: 15px; }
.bt-empty-reset { margin-left: 8px; padding: 7px 14px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; cursor: pointer; }
.bt-empty-reset:hover { border-color: var(--accent); color: var(--accent); }

/* тулбар-кнопки */
.bt-tool-btns { display: flex; gap: 8px; align-items: flex-end; }
.bt-tool {
  padding: 9px 13px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.bt-tool:hover { border-color: var(--accent); color: var(--text); }

/* всплывающие меню (автофильтр / выбор колонок) */
.bt-pop {
  position: fixed; z-index: 1300; width: 268px; max-width: 92vw;
  background: linear-gradient(180deg, var(--surface), var(--surface)); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: 0 24px 60px -18px rgba(0,0,0,.8); overflow: hidden;
  display: flex; flex-direction: column;
}
.bt-pop-head { padding: 10px; border-bottom: 1px solid var(--border); }
.bt-pop-search {
  width: 100%; padding: 8px 11px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13.5px; outline: none;
}
.bt-pop-search:focus { border-color: var(--accent); }
.bt-pop-tools { display: flex; gap: 6px; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.bt-pop-tools button {
  flex: 1; padding: 6px 8px; background: var(--surface); color: var(--text-muted); border: 1px solid var(--border);
  border-radius: 7px; font-size: 12px; cursor: pointer;
}
.bt-pop-tools button:hover { border-color: var(--accent); color: var(--text); }
.bt-pop-list { max-height: 280px; overflow: auto; padding: 6px; }
.bt-pop-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px;
  cursor: pointer; font-size: 13.5px; color: var(--text);
}
.bt-pop-item:hover { background: var(--surface-3); }
.bt-pop-item input { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.bt-pop-lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-pop-n { color: var(--text-dim); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.bt-pop-actions { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.bt-pop-apply { flex: 1; padding: 8px; background: var(--accent); color: var(--accent-ink, #1a0d02); border: none; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; }
.bt-pop-ghost { padding: 8px 12px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; cursor: pointer; }

/* Фирменная модалка (замена нативных prompt/confirm) */
.bt-modal-ov { position: fixed; inset: 0; z-index: 1400; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.bt-modal { width: 400px; max-width: 94vw; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.85); overflow: hidden; animation: bt-modal-in .14s ease; }
@keyframes bt-modal-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.bt-modal-h { padding: 17px 20px 2px; font-size: 15.5px; font-weight: 700; color: var(--text); }
.bt-modal-msg { padding: 6px 20px 4px; font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.bt-modal-b { padding: 10px 20px 4px; }
.bt-modal-input { width: 100%; padding: 11px 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 14px; outline: none; font-family: inherit; }
.bt-modal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bt-modal-f { display: flex; gap: 9px; justify-content: flex-end; padding: 16px 20px 18px; }
.bt-modal-btn { padding: 9px 17px; border-radius: 10px; font-size: 13.5px; font-weight: 700; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-family: inherit; }
.bt-modal-btn:hover { border-color: var(--accent-line); color: var(--text); }
.bt-modal-btn--primary { background: var(--accent); color: var(--accent-ink, #1a0d02); border-color: transparent; }
.bt-modal-btn--primary:hover { filter: brightness(1.06); }
.bt-modal-btn--danger { background: var(--offline, #e5484d); color: #fff; border-color: transparent; }
.bt-modal-btn--danger:hover { filter: brightness(1.06); }
.bt-modal-lbl { display: block; font-size: 12px; color: var(--text-dim); margin: 0 0 5px; font-weight: 600; }
.bt-modal-row { display: flex; gap: 12px; align-items: flex-end; }
.bt-modal-input--err { border-color: var(--offline, #e5484d) !important; }

/* ═══════════ Оборудование: таблица с объединённой ячейкой филиала (rowspan) ═══════════ */
.bt-eq-table { table-layout: fixed; }
.bt-eq-c-branch { width: 220px; }
.bt-eq-c-type { width: 220px; }
.bt-eq-c-qty { width: 120px; text-align: right; }
.bt-eq-c-descr { width: auto; }
.bt-eq-c-act { width: 46px; text-align: center; }
/* объединённая ячейка филиала слева */
.bt-eq-branch-cell {
  vertical-align: top; background: var(--accent-soft); border-right: 2px solid var(--accent-line);
  padding: 12px 14px !important;
}
.bt-eq-bhead { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.bt-eq-num {
  display: inline-block; min-width: 26px; text-align: center; padding: 2px 7px;
  background: var(--accent); color: var(--accent-ink, #1a0d02); border-radius: 6px; font-size: 12.5px;
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.bt-eq-bname { font-size: 14px; font-weight: 700; color: var(--accent); line-height: 1.3; }
.bt-eq-addpos {
  padding: 4px 11px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.bt-eq-addpos:hover { border-color: var(--accent); color: var(--accent); }
/* строки позиций */
.bt-eq-row td { padding: 9px 14px; }
.bt-eq-row .bt-eq-c-type { color: var(--text); font-weight: 600; }
/* разделитель между филиалами — жирнее у последней строки группы */
.bt-eq-row--last > td { border-bottom: 2px solid var(--border-strong); }
.bt-eq-empty { color: var(--text-dim); font-size: 12.5px; font-style: italic; }
.bt-eq-del {
  width: 24px; height: 24px; line-height: 1; padding: 0; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-dim); border: 1px solid transparent; font-size: 13px;
}
.bt-eq-del:hover { background: var(--offline, #e5484d); color: #fff; }

/* ═══════════ Ф3: сохранённые виды + закреп столбцов + лёгкие фильтры ═══════════ */
.bt-filters { flex-direction: column; align-items: stretch; gap: 12px; }
.bt-views { display: flex; flex-wrap: wrap; gap: 6px; }
.bt-view-chip { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--chip-bg); color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; }
.bt-view-chip:hover { color: var(--text); border-color: var(--accent-line); }
.bt-view-chip.is-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.bt-view-chip:disabled { opacity: .7; cursor: default; }
.bt-toolrow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.bt-toolrow .bt-field { flex: 0 0 auto; }
.bt-toolrow .bt-field input { min-width: 240px; }

/* закрепление первых столбцов */
.bt-table th.bt-frozen, .bt-table td.bt-frozen { position: sticky; z-index: 2; background: var(--surface); }
.bt-table thead th.bt-frozen { z-index: 6; top: 0; }
/* фон закреплённых ячеек ДОЛЖЕН быть непрозрачным на любой строке (иначе просвечивает контент) */
.bt-table tbody tr:nth-child(even) td.bt-frozen { background: var(--surface); }
.bt-table tbody tr:hover td.bt-frozen { background: var(--surface-3); }
.bt-table .bt-frozen-last { box-shadow: 2px 0 6px -3px rgba(0,0,0,.35); }
.bt-table td[data-key="branch_num"], .bt-table th[data-key="branch_num"] { font-variant-numeric: tabular-nums; }
.bt-table td[data-key="branch_num"] { font-weight: 600; color: var(--text); }

/* лёгкая иконка фильтра (не агрессивная стрелка в каждом столбце) */
.bt-th-filter { opacity: .22; transition: opacity .14s; }
.bt-table thead th:hover .bt-th-filter { opacity: .8; }
.bt-table thead th.bt-filter-active .bt-th-filter { opacity: 1; }

/* группы в «Колонки» */
.bt-pop-group { padding: 4px 2px; }
.bt-pop-group + .bt-pop-group { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
.bt-pop-group-t { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); padding: 2px 8px 5px; }

/* Печать: тёмная тема на бумаге = сплошной тонер либо белым по белому.
   Печатают вид «Аренда»/«Интернет» для руководителя — даём чистый лист. */
@media print {
  .railnav, .topbar, .bt-filters, .bt-tool-btns, .bt-th-filter, .bt-empty-reset { display: none !important; }
  .bt-main, .bt-wrap { overflow: visible !important; height: auto !important; }
  .bt-table { width: 100% !important; font-size: 11px; border-collapse: collapse; }
  .bt-table th, .bt-table td {
    color: #000 !important; background: #fff !important;
    border: 1px solid #ccc !important; white-space: normal !important;
    max-width: none !important; padding: 4px 6px !important;
  }
  .bt-table th.bt-frozen, .bt-table td.bt-frozen { position: static !important; box-shadow: none !important; }
  .bt-long-cell { overflow: visible !important; text-overflow: clip !important; }
  .bt-pill, .bt-uptime { color: #000 !important; background: none !important; border: 1px solid #999; }
  .bt-empty-val { color: #666 !important; }
}
