:root{
  --purple: #6b4eff;
  --purple-soft: #f4f1ff;
  --border: #e6e0fa;
  --muted: #666;
  --bg: #ffffff;
}

*{ box-sizing:border-box }
html,body{ height:100% }
body{ margin:0; font-family:Inter, "Helvetica Neue", Arial, sans-serif; background:#fafafa; color:#222; display:flex; flex-direction:column }

/* modal */
.modal{ display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); z-index:10000; align-items:center; justify-content:center; }
.modal.show{ display:flex; }
.modal-content{ background:#fff; border-radius:12px; padding:28px 32px; max-width:560px; width:90%; box-shadow:0 20px 60px rgba(0,0,0,0.2); max-height:90vh; overflow-y:auto; }
.modal-content h2{ margin:0 0 8px; font-size:22px; }
.modal-desc{ color:var(--muted); margin:0 0 24px; font-size:14px; }
.form-group{ margin-bottom:18px; }
.form-group label{ display:block; margin-bottom:6px; font-weight:600; font-size:14px; }
.form-group input{ width:100%; padding:10px 12px; border:1px solid var(--border); border-radius:8px; font-size:14px; font-family:inherit; }
.form-group small{ display:block; margin-top:4px; color:var(--muted); font-size:12px; }
.form-actions{ display:flex; gap:10px; margin-top:24px; }
.modal-note{ margin-top:20px; padding:12px; background:#fff9e6; border:1px solid #ffe4a3; border-radius:8px; font-size:13px; color:#7a5c00; }

/* legend modal */
.modal-legend{ max-width:800px; }
.modal-header{ display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; }
.modal-header h2{ margin:0; }
.btn-close{ background:transparent; border:none; font-size:32px; color:var(--muted); cursor:pointer; padding:0; width:32px; height:32px; line-height:1; }
.btn-close:hover{ color:#000; }
.legend-content{ max-height:60vh; overflow-y:auto; }
.legend-table{ width:100%; border-collapse:collapse; font-size:14px; }
.legend-table th{ background:var(--purple-soft); padding:12px; text-align:left; font-weight:600; border-bottom:2px solid var(--border); position:sticky; top:0; }
.legend-table td{ padding:10px 12px; border-bottom:1px solid var(--border); }
.legend-table tr:hover{ background:#fbf8ff; }

/* header compact */
.compact-header{ display:flex; align-items:center; justify-content:space-between; gap:16px; padding:8px 12px; background:var(--bg); border-bottom:1px solid var(--border); min-height:88px; box-sizing:border-box; flex-wrap:wrap; }
.header-left{ display:flex; align-items:center; gap:12px }
.header-image{ width:56px; height:56px; object-fit:cover; border-radius:6px }
.title-compact h1{ margin:0; font-size:16px; line-height:1; font-weight:600 }
.subtitle-compact{ margin:2px 0 0; font-size:12px; color:var(--muted) }
.header-right{ display:flex; align-items:center; gap:12px; flex-wrap:wrap; }

/* controls */
.controls-compact{
  display:flex;
  gap:8px;
  align-items:flex-start;
  flex-wrap:wrap;
  min-width:0;
  overflow: visible;
}
.filter-compact{ display:flex; flex-direction:column; gap:6px; min-width:120px; max-width:200px }

.filter-compact label{ font-size:11px; color:var(--muted); margin:0 6px 0 0 }

/* details-based multiselect */
.details-multi{ position:relative; width:100%; font-size:13px; }
.details-multi summary{ list-style:none; cursor:pointer; border:1px solid var(--border); background:#fff; padding:8px 10px; border-radius:10px; display:flex; gap:8px; align-items:center; min-height:38px; }
.details-multi summary::-webkit-details-marker{ display:none; }
.details-display{ display:flex; gap:6px; align-items:center; min-width:0; flex-wrap:wrap; overflow:hidden; }
.details-display .placeholder{ color:var(--muted); white-space:nowrap; text-overflow:ellipsis; overflow:hidden; }
.details-display .chip{ background: rgba(107,78,255,0.08); color:var(--purple); padding:4px 8px; border-radius:16px; font-weight:600; font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:140px; }
.details-caret{ margin-left:auto; opacity:0.65; transform:rotate(0deg); transition:transform .12s; }
details[open] .details-caret{ transform:rotate(180deg); }

/* panel */
.details-panel{ position:absolute; top:calc(100% + 8px); left:0; width:360px; max-width:90vw; background:#fff; border:1px solid var(--border); border-radius:10px; box-shadow:0 12px 36px rgba(10,6,40,.08); z-index:1500; padding:10px; max-height:360px; overflow:hidden; display:flex; flex-direction:column; }
.details-panel .panel-actions{ display:flex; justify-content:space-between; gap:8px; margin-bottom:8px; flex-shrink:0; }
.details-panel .panel-actions button{ padding:6px 8px; border-radius:6px; border:1px solid var(--border); background:#fff; cursor:pointer; font-size:13px; }

/* option row */
.opt{ display:flex; gap:8px; align-items:center; padding:6px; border-radius:6px; }
.opt:hover{ background:#f6f2ff; }
.options-list{ flex:1 1 auto; overflow-y:auto; overflow-x:hidden; min-height:0; }

/* department tree */
.dept-opt{ align-items:flex-start; }
.dept-toggle{ user-select:none; font-size:11px; }

/* buttons */
.actions-compact{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
button{ font-family:inherit }
.btn-light{ background:transparent; border:1px solid #ddd; padding:6px 10px; border-radius:6px; font-size:13px; cursor:pointer }
.btn-light:hover{ background:#f5f5f5; }
.btn-primary{ background:var(--purple); color:#fff; border:none; padding:6px 10px; border-radius:6px; font-size:13px; cursor:pointer }
.btn-primary:hover{ background:#5939e0; }
.btn-hidden{ display:none; }

/* export dropdown */
.export-dropdown{ position:relative; }
.export-menu{ display:none; position:absolute; top:calc(100% + 4px); right:0; background:#fff; border:1px solid var(--border); border-radius:8px; box-shadow:0 8px 24px rgba(0,0,0,0.12); min-width:150px; z-index:1000; }
.export-menu.show{ display:block; }
.export-menu button{ display:block; width:100%; text-align:left; padding:10px 14px; border:none; background:transparent; cursor:pointer; font-size:13px; border-bottom:1px solid var(--border); }
.export-menu button:last-child{ border-bottom:none; }
.export-menu button:hover{ background:#f6f2ff; }

/* main & table */
.main-area{ flex:1 1 auto; display:flex; flex-direction:column; padding:10px 12px 16px; min-height:0 }
.info{ padding:8px 10px; margin-bottom:8px; border-radius:8px; background:#fff6; color:#333; font-size:13px }
.hidden{ display:none }

.table-wrapper{ flex:1 1 auto; min-height:0; overflow:auto; background:var(--bg); border:1px solid var(--border); border-radius:8px }
table{ width:100%; border-collapse:collapse; background:#fff; font-size:12px; table-layout:fixed; }
thead th{ position:sticky; top:0; z-index:10; background:var(--purple-soft); border-bottom:2px solid var(--border); padding:8px 6px; text-align:left; font-weight:600; white-space:nowrap; vertical-align:middle; font-size:11px; }
th, td{ padding:7px 5px; border-bottom:1px solid var(--border); overflow:hidden; text-overflow:ellipsis; }
tbody td{ vertical-align:top; font-size:11px; }
tbody tr:hover{ background:#fbf8ff }

/* sort arrow */
.sort-arrow{ margin-left:3px; font-size:10px; color:var(--muted) }
th.sortable{ cursor:pointer; user-select:none; }
th.sortable:hover{ background:#ebe6ff; }
th.role-header{ cursor:pointer; user-select:none; }
th.role-header:hover{ background:#ebe6ff; }

/* КРИТИЧНО: ФИКСИРОВАННЫЕ ширины столбцов */
.col-num{ width:80px; min-width:75px; max-width:95px; }
.col-block{ width:150px; min-width:120px; max-width:200px; }
.col-func{ width:320px; min-width:250px; }
.col-product{ width:220px; min-width:180px; }
.col-role{ width:90px; min-width:90px; max-width:90px; }

/* role cells */
td.col-role-cell{ 
  text-align:left; 
  font-size:10px; 
  padding:5px 4px;
  white-space:normal; /* ИЗМЕНЕНО: разрешаем перенос */
  word-wrap:break-word;
  overflow-wrap:break-word;
  line-height:1.3;
}

/* НОВОЕ: Выделение выбранной должности */
td.highlighted-position{
  font-weight:700;
  box-shadow: inset 0 0 0 2px var(--purple);
  position: relative;
}

td.highlighted-position::after{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(107, 78, 255, 0.12);
  pointer-events: none;
}

/* floating tooltip */
.floating-tooltip{ position:fixed; display:block; background:#fff; border:1px solid var(--border); padding:12px 14px; border-radius:8px; box-shadow:0 12px 40px rgba(10,6,40,0.14); z-index:99999; max-width:420px; font-size:14px; color:#2b225a; line-height:1.35; }
.floating-tooltip.hidden{ display:none; opacity:0; transform:translateY(6px); transition:opacity .14s, transform .14s; }
.floating-tooltip.show{ display:block; opacity:1; transform:translateY(0); }

/* toast */
.toast{ position:fixed; right:20px; bottom:20px; background:#222; color:#fff; padding:10px 14px; border-radius:8px; box-shadow:0 6px 20px rgba(0,0,0,.18); z-index:20000; font-size:13px; opacity:1; transition:opacity .25s }
.toast.hidden{ opacity:0; pointer-events:none; transform:translateY(8px) }

/* responsive */
@media (max-width:1400px){
  .col-func{ width:280px; min-width:220px; }
  .col-product{ width:200px; min-width:160px; }
}

@media (max-width:1200px){
  .controls-compact{ flex-wrap:wrap; gap:10px }
  .filter-compact{ min-width:110px; max-width:180px }
  .details-panel{ width:320px }
  .compact-header{ min-height:auto; }
  .col-func{ width:250px; min-width:200px; }
  .col-product{ width:180px; min-width:150px; }
  .col-role{ width:85px; min-width:85px; max-width:85px; }
}

@media (max-width:1000px){
  .col-block{ width:130px; }
  .col-func{ width:220px; }
  .col-product{ width:160px; }
  .col-role{ width:80px; min-width:80px; max-width:80px; }
  td.col-role-cell{ font-size:9px; }
}

/* ==================== УМНЫЙ ПОИСК ==================== */
.search-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #faf8ff;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.search-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  flex: 1;
  max-width: 720px;
  transition: border-color 0.15s;
}

.search-bar-wrapper:focus-within {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(107, 78, 255, 0.12);
}

.search-icon {
  font-size: 16px;
  flex-shrink: 0;
  opacity: 0.6;
}

#smart-search {
  border: none;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  flex: 1;
  min-width: 0;
  background: transparent;
  color: #222;
}

#smart-search::placeholder {
  color: #aaa;
  font-style: italic;
}

.btn-clear-search {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: #eee;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  color: #666;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.btn-clear-search:hover {
  background: #ddd;
  color: #333;
}

.search-status {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 20px;
}

.search-status.search-found {
  background: rgba(107, 78, 255, 0.1);
  color: var(--purple);
}

.search-status.search-empty {
  background: #fff0f0;
  color: #c0392b;
}

/* Подсветка найденного текста */
mark.search-highlight {
  background: rgba(107, 78, 255, 0.18);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ==================== ПОИСК ВНУТРИ ВЫПАДАШКИ ==================== */
.panel-search-wrap {
  padding: 0 2px 6px;
  flex-shrink: 0;
}

.panel-search-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: #faf8ff;
  box-sizing: border-box;
}

.panel-search-input:focus {
  border-color: var(--purple);
  background: #fff;
}

.panel-search-input::placeholder {
  color: #bbb;
}

/* ==================== НЕСКОЛЬКО ДОЛЖНОСТЕЙ В ЯЧЕЙКЕ ==================== */
.pos-entry {
  display: block;
  line-height: 1.35;
  padding: 2px 0;
}

/* Цветной фон — только под текстом, не вся ячейка */
.pos-bg {
  display: inline-block;
  border-radius: 4px;
  padding: 1px 4px;
  margin: 1px 0;
  width: calc(100% - 2px);
  box-sizing: border-box;
}

.pos-sep {
  display: block;
  text-align: center;
  color: rgba(107, 78, 255, 0.4);
  font-size: 9px;
  line-height: 1;
  margin: 2px 0;
  border-top: 1px dashed rgba(107, 78, 255, 0.2);
  padding-top: 3px;
}

/* Выравниваем по верху когда несколько должностей */
td.col-role-cell:has(.pos-sep) {
  vertical-align: top;
}
