:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #6b7280;
  --violet: #4f46e5;
  --stroke: #e5e7eb;
  --set-icon-stroke-width: 0.8;
}

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: grid;
  grid-template-columns: auto 1px 1fr;
  grid-template-rows: 50px 1px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Вертикальная разделительная линия — только под шапкой (между сайдбаром и контентом) */
.app::before {
  content: '';
  grid-column: 2;
  grid-row: 3;
  background: var(--stroke);
}

/* Горизонтальная разделительная линия — под единой шапкой на всю ширину */
.app::after {
  content: '';
  grid-column: 1 / 4;
  grid-row: 2;
  background: var(--stroke);
}

/* Единая горизонтальная шапка на всю ширину страницы */
.app-header {
  grid-column: 1 / 4;
  grid-row: 1;
}

/* Левый сайдбар (нижний левый) */
.sidebar {
  grid-column: 1;
  grid-row: 3;
}

/* Основной контент (нижний правый) */
.content-area {
  grid-column: 3;
  grid-row: 3;
}

/* ========== SIDEBAR ========== */
.sidebar {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100%;
  width: auto;
  min-width: fit-content;
  transition: width 0.3s ease;
}

.app.collapsed .sidebar {
  width: 120px;
  z-index: 100;
}

/* ========== APP HEADER (единая шапка) ========== */
.app-header {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 50px;
  padding: 10px 16px;
  flex-shrink: 0;
}

/* Левая группа: кнопка управления, логотип, название — всегда на своих местах */
.app-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Правая группа: постоянные действия */
.app-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Зона вкладок header (справа от названия сайта) */
.app-header-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Вкладка header — размер совпадает с кнопкой «Скачать БД» (40×40, иконка 24px) */
.app-header-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.app-header-tab i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 24px;
  line-height: 1;
}

.app-header-tab:hover {
  color: var(--violet);
}

/* Активная вкладка — белый квадратный фон со скруглёнными углами */
.app-header-tab.active {
  background: var(--panel);
  color: var(--ink);
}

/* Временная вкладка header — иконка + кнопка закрытия в углу */
.app-header-tab--temp {
  position: relative;
}

.app-header-tab__close {
  position: absolute;
  top: 1px;
  right: 1px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
  background: var(--stroke);
  color: var(--ink);
}

.app-header-tab--temp:hover .app-header-tab__close,
.app-header-tab--temp.active .app-header-tab__close {
  display: inline-flex;
}

.app-header-tab__close:hover {
  background: #fca5a5;
  color: #7f1d1d;
}

/* ========== WORKSPACE (рабочее пространство временных вкладок) ========== */
.workspace {
  grid-column: 1 / 4;
  grid-row: 3;
  display: block;
  height: 100%;
  overflow: auto;
  background: var(--panel);
}

.workspace[hidden] {
  display: none;
}

/* Когда активна временная вкладка — прячем «Домой»: sidebar, content-area
   и вертикальный разделитель между ними. */
.app.workspace-active .sidebar,
.app.workspace-active .content-area {
  display: none;
}

.app.workspace-active::before {
  display: none;
}

.workspace-panel {
  height: 100%;
}

.workspace-panel[hidden] {
  display: none;
}

.app-logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.app-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.app-title {
  font-size: 9px;
  font-weight: 500;
  color: var(--ink);
  white-space: normal;
  line-height: 1.2;
  max-width: 70px;
}

/* Кнопка управления сайдбаром — всегда видима, положение не зависит от collapsed */
.toggle-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toggle-btn:hover {
  background: var(--panel);
  color: var(--violet);
}

/* Меню контейнер */
.sidebar-menu {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  position: relative;
}

.app.collapsed .sidebar-menu {
  overflow: visible;
}

/* Левая колонка с основными разделами */
.sidebar-menu-main {
  display: flex;
  flex-direction: column;
  gap: 40px;
  padding: 8px 12px;
  border-right: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  width: 156px;
  flex: 0 0 156px;
}

.app.collapsed .sidebar-menu-main {
  width: 60px;
  flex: 0 0 60px;
  padding: 8px 0;
  z-index: 2;
}

.app.collapsed .sidebar-menu-main .menu-item {
  justify-content: center;
  padding: 6px 0;
  width: 60px;
  gap: 0;
  z-index: 1;
}

/* Правая колонка с подразделами */
.sidebar-menu-sub {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  flex: 0 0 156px;
  width: 156px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.app.collapsed .sidebar-menu-sub {
  padding: 8px 0;
  width: 60px;
  flex: 0 0 60px;
}

/* Пункты меню основных разделов — тот же размер, что и подразделы */
.sidebar-menu-main .menu-item {
  font-size: 13px;
  padding: 6px 12px;
}

.sidebar-menu-main .menu-item i {
  font-size: 16px;
}

/* Заголовки разделов в левой колонке — без лишнего горизонтального padding */
.sidebar-menu-main .menu-section-title {
  padding: 4px 0;
}

/* Пункты меню подразделов */
.sidebar-menu-sub .menu-item {
  padding: 6px 12px;
  font-size: 13px;
}

.app.collapsed .sidebar-menu-sub .menu-item {
  justify-content: center;
  padding: 6px 0;
  width: 60px;
  gap: 0;
}

.sidebar-menu-sub .menu-item i {
  font-size: 16px;
}

.sidebar-menu-sub .menu-item span {
  transition: opacity 0.3s ease;
}

.app.collapsed .sidebar-menu-sub .menu-item span {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Разделы меню */
.menu-section {
  margin-bottom: 12px;
}

.sidebar-menu-main .menu-section {
  margin-bottom: 0;
}

.sidebar-menu-main .menu-section-personal {
  margin-top: 0;
  margin-bottom: 0;
}

.sidebar-menu-main .menu-section-params {
  margin-bottom: 0;
}

.menu-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 12px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.app.collapsed .menu-section-title {
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
}

.menu-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: none;
  border: none;
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  white-space: nowrap;
  border-radius: 0;
}

.menu-item i,
.menu-item .menu-icon {
  font-size: 18px;
  width: 18px;
  height: 18px;
  color: var(--violet);
  flex-shrink: 0;
  transition: color 0.2s;
}

.menu-item .menu-icon {
  display: block;
}

svg.menu-icon,
svg.set-icon {
  stroke-width: var(--set-icon-stroke-width);
}

.menu-item span {
  transition: opacity 0.3s ease, color 0.2s;
}

.app.collapsed .menu-item span {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.app.collapsed .menu-item {
  justify-content: center;
  padding: 6px 0;
  width: 60px;
  gap: 0;
  position: relative;
  z-index: 1;
  transition: none;
}

.app.collapsed .menu-item i,
.app.collapsed .menu-item .menu-icon {
  margin: 0;
  transition: none;
}

.app.collapsed .menu-item span {
  transition: none;
}

/* Tooltip для collapsed состояния */
.app.collapsed .menu-item::after {
  content: attr(data-tooltip);
  position: fixed;
  left: var(--tooltip-left, 68px);
  top: var(--tooltip-top, 50%);
  transform: translateY(-50%);
  background: var(--ink);
  color: #ffffff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s;
  z-index: 99999;
}

.app.collapsed .menu-item.show-tooltip::after {
  opacity: 1;
}

.app.collapsed .menu-item:hover::after {
  opacity: 1;
  animation: hideTooltip 1.5s forwards;
}

@keyframes hideTooltip {
  0%, 99% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.menu-item:hover {
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
}

.menu-item:hover i,
.menu-item:hover .menu-icon {
  color: #4338ca;
}

.menu-item.active {
  color: var(--ink);
  background: var(--panel);
  border-radius: 6px;
}

.app.collapsed .menu-item.active {
  width: 32px;
  padding: 6px;
  margin: 0 auto;
}

.menu-item.active i,
.menu-item.active .menu-icon {
  color: var(--violet);
}

.menu-item.active span {
  font-weight: 400;
}

/* ========== HEADER ACTIONS (постоянные действия в правой части шапки) ========== */
.top-menu-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  /* Кнопка «Скачать БД» всегда поверх всех элементов в плане обработки кликов:
     ни модалки (.modal-overlay), ни тултипы (z-index: 99999), ни рабочая область
     временных вкладок не должны перехватывать клик по ней. */
  position: relative;
  z-index: 2147483000;
  pointer-events: auto;
}

.top-menu-action {
  pointer-events: auto;
}

.top-menu-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: color 0.2s;
  flex-shrink: 0;
  flex-grow: 0;
}

.top-menu-action:hover {
  color: var(--violet);
}

.top-menu-action i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 24px;
  line-height: 1;
}

/* ========== CONTENT AREA ========== */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* Вкладки раздела (бывший top-menu-tabs) — первый ряд nav.content-nav внутри
   центрального блока. Вид берём от .content-nav / .content-nav-item, здесь
   только иконки (собственные вкладки контента остаются без иконок). */
.content-nav--tabs .content-nav-item {
  gap: 8px;
}

.content-nav--tabs .content-nav-item i {
  font-size: 16px;
  color: var(--violet);
}

/* Контейнер контента */
.content-container {
  background: var(--panel);
  border-radius: 12px;
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Навигация разделов внутри контента */
.content-nav {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  border-bottom: 1px solid var(--stroke);
  position: relative;
}

.content-nav-item {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  position: relative;
  white-space: nowrap;
}

.content-nav-item:hover {
  color: var(--ink);
}

.content-nav-item.active {
  color: var(--violet);
}

.content-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--violet);
}

/* Основной контент раздела */
.content-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

.embedded-page-frame {
  display: block;
  width: 100%;
  min-height: 680px;
  border: 0;
  background: transparent;
}

/* Панель инструментов в контенте */
.content-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  justify-content: space-between;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

/* Поисковое поле */
.search-container {
  flex: 1;
  display: flex;
  align-items: center;
  position: relative;
  max-width: 500px;
}

.search-input {
  width: 100%;
  padding: 10px 44px 10px 16px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  transition: border-color 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--violet);
}

.search-input::placeholder {
  color: var(--muted);
}

.search-btn {
  position: absolute;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.search-btn:hover {
  background: var(--bg);
  color: var(--violet);
}

.search-btn i {
  font-size: 18px;
}

/* Кнопки панели инструментов */
.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: var(--bg);
  color: var(--violet);
  border-color: var(--violet);
}

.toolbar-btn i {
  font-size: 18px;
}

.toolbar-btn.primary {
  background: var(--violet);
  color: white;
  border-color: var(--violet);
}

.toolbar-btn.primary:hover {
  background: #4338ca;
  border-color: #4338ca;
}

/* ========== MODAL ========== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--stroke);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--ink);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--stroke);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Form elements */
.form-group {
  margin-bottom: 24px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 8px;
}

.language-options {
  display: flex;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--panel);
}

.language-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.language-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--stroke);
  transition: accent-color 0.2s;
}

.language-option input[type="checkbox"]:checked {
  accent-color: var(--violet);
}

.language-option label {
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
}

/* Toggle switch - tab switcher style */
.toggle-container {
  display: flex;
  align-items: center;
  padding: 4px;
  background: var(--stroke);
  border-radius: 8px;
  position: relative;
}

.toggle-option {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  font-weight: 500;
  z-index: 1;
}

.toggle-option.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Three option toggle container */
.toggle-container-three .toggle-option {
  padding: 10px 12px;
  font-size: 13px;
}

/* Document type options container - fixed height */
.doc-type-container {
  position: relative;
  min-height: 180px;
}

.doc-type-container > .form-group {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.doc-type-container > .form-group.active {
  opacity: 1;
  visibility: visible;
}

/* Select dropdown with search */
.select-wrapper {
  position: relative;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.select-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  min-width: 120px;
  flex-shrink: 0;
}

.custom-select-container {
  position: relative;
  flex: 1;
}

.custom-select-input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  border: 2px solid var(--stroke);
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
  background: var(--panel);
  cursor: text;
  transition: all 0.2s;
}

.custom-select-input::placeholder {
  color: var(--muted);
}

.custom-select-input:hover {
  border-color: var(--violet);
}

.custom-select-input:focus {
  outline: none;
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.1);
}

.custom-select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: #6b7280;
  transition: transform 0.2s;
}

.custom-select-container.open .custom-select-arrow {
  transform: translateY(-50%) rotate(180deg);
}

.custom-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 250px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: none;
  flex-direction: column;
}

.custom-select-container.open .custom-select-dropdown {
  display: flex;
}

.custom-select-option {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s;
}

.custom-select-option:hover {
  background: var(--bg);
}

.custom-select-option.disabled {
  color: var(--muted);
  cursor: pointer;
  opacity: 0.5;
  order: 2;
}

.custom-select-option.disabled:hover {
  background: var(--bg);
}

.custom-select-option:not(.disabled) {
  order: 1;
}

.custom-select-option.selected {
  background: #ede9fe;
  color: var(--violet);
}

.custom-select-option.hidden {
  display: none;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: var(--violet);
  color: white;
}

.btn-primary:hover {
  background: #4338ca;
}

.btn-secondary {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--stroke);
}

.btn-secondary:hover {
  background: var(--stroke);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary:disabled {
  background: var(--violet);
}

.btn-primary:disabled:hover {
  background: var(--violet);
}

/* Warning Modal */
.warning-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10001;
  align-items: center;
  justify-content: center;
}

.warning-modal-overlay.active {
  display: flex;
}

.warning-modal {
  background: var(--panel);
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  padding: 24px;
}

.warning-modal-icon {
  width: 48px;
  height: 48px;
  background: #fef3c7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: #f59e0b;
  font-size: 24px;
}

.warning-modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  margin-bottom: 12px;
}

.warning-modal-message {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

.warning-modal-actions {
  display: flex;
  gap: 12px;
}

.warning-modal-actions .btn {
  flex: 1;
}

/* ========== MEDIA QUERIES ========== */
@media (max-width: 700px) {
  .app-header {
    padding: 10px 12px;
  }

  .app-title {
    font-size: 12px;
  }

  /* На мобильных фиксируем ширину sidebar */
  .app .sidebar {
    width: 120px;
  }

  /* При раскрытии сайдбара на мобильном убираем collapsed стили */
  .app:not(.collapsed) .sidebar {
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  }
}

/* Скроллбар для левой колонки */
.sidebar-menu-main::-webkit-scrollbar {
  width: 6px;
}

.sidebar-menu-main::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-menu-main::-webkit-scrollbar-thumb {
  background: var(--stroke);
  border-radius: 3px;
}

.sidebar-menu-main::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Скроллбар для правой колонки */
.sidebar-menu-sub::-webkit-scrollbar {
  width: 6px;
}

.sidebar-menu-sub::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-menu-sub::-webkit-scrollbar-thumb {
  background: var(--stroke);
  border-radius: 3px;
}

.sidebar-menu-sub::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ========== TABLE — переиспользуемая таблица данных ========== */
table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  table-layout: auto;
}

table caption {
  padding: 12px 16px;
  text-align: left;
  caption-side: top;
  font-weight: 650;
  color: var(--ink);
}

table th,
table td {
  padding: 12px 16px;
  text-align: left;
  vertical-align: middle;
  border-radius: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

table thead th {
  font-weight: 650;
  color: var(--ink);
  background: var(--bg);
  border-bottom: 1px solid var(--stroke);
  white-space: nowrap;
}

table tbody th {
  font-weight: 650;
  color: var(--ink);
}

table tbody td,
table tbody th {
  border-bottom: 1px solid var(--stroke);
}

table tbody tr:last-child td,
table tbody tr:last-child th {
  border-bottom: 0;
}

table tbody tr:hover td,
table tbody tr:hover th {
  background: var(--bg);
}

/* ========== BOS MODAL — переиспользуемый каркас (BEM) ==========
   Открыть: Modal.open('id') либо data-modal-open="id" на любой кнопке. */

.bos-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10000;
}
.bos-modal-overlay[hidden] { display: none; }

.bos-modal {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.25);
  width: max-content;
  min-width: 500px;
  max-width: min(800px, 100vw - 32px);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (max-width: 540px) {
  .bos-modal { min-width: 0; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--stroke);
}
.modal__title {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}
.modal__close {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
}
.modal__close:hover { background: var(--bg); color: var(--ink); }

.modal__tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  border-bottom: 1px solid var(--stroke);
  overflow-x: auto;
}
.modal__tab {
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 400;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.modal__tab:hover { color: var(--ink); }
.modal__tab--active {
  color: var(--violet);
  border-bottom-color: var(--violet);
  font-weight: 650;
}

.modal__body {
  padding: 20px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal__panel { display: block; }
.modal__panel[hidden] { display: none; }

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--stroke);
  background: #fafafa;
}
.modal__footer-right { display: flex; gap: 8px; }

/* Кнопки внутри bos-модалки */
.bos-modal .btn,
.bos-btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 400;
  cursor: pointer;
  transition: 0.15s ease;
}
.bos-modal .btn--primary,
.bos-btn--primary {
  background: var(--violet);
  color: #fff;
  font-weight: 650;
}
.bos-modal .btn--primary:hover,
.bos-btn--primary:hover { background: #4338ca; }
.bos-modal .btn--secondary,
.bos-btn--secondary {
  background: #fff;
  border-color: var(--stroke);
  color: var(--ink);
}
.bos-modal .btn--secondary:hover,
.bos-btn--secondary:hover { background: var(--bg); }
.bos-modal .btn--ghost,
.bos-btn--ghost { color: var(--muted); }
.bos-modal .btn--ghost:hover,
.bos-btn--ghost:hover { background: var(--bg); color: var(--ink); }

/* Поля формы внутри bos-модалки */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  max-width: 100%;
}
.field__label {
  font-weight: 650;
  color: var(--ink);
}
.field__hint { color: var(--muted); }

.field-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.field-row > .field { flex: 1 1 300px; margin-bottom: 16px; }

.bos-modal input[type="text"],
.bos-modal input[type="email"],
.bos-modal input[type="tel"],
.bos-modal input[type="number"],
.bos-modal input[type="password"],
.bos-modal input[type="search"],
.bos-modal input[type="url"],
.bos-modal select,
.bos-modal textarea {
  width: 100%;
  min-width: 300px;
  max-width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.bos-modal textarea {
  height: auto;
  min-height: 80px;
  padding: 8px 12px;
  resize: vertical;
}

.field--w300 { width: 300px; flex: 0 0 300px; }
.field--w350 { width: 350px; flex: 0 0 350px; }
.field--w400 { width: 400px; flex: 0 0 400px; }
.field--w450 { width: 450px; flex: 0 0 450px; }
.field--w500 { width: 500px; flex: 0 0 500px; }
.field--w550 { width: 550px; flex: 0 0 550px; }
.field--w600 { width: 600px; flex: 0 0 600px; }
.field--w650 { width: 650px; flex: 0 0 650px; }
.field--w700 { width: 700px; flex: 0 0 700px; }
.field--w750 { width: 750px; flex: 0 0 750px; }
.field--full { width: 100%; flex: 1 1 100%; }

.bos-modal input[type="date"] {
  width: 160px;
  min-width: 160px;
  max-width: 160px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field--date { width: 160px; flex: 0 0 160px; }

.bos-modal input:focus,
.bos-modal select:focus,
.bos-modal textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* Двухпозиционный переключатель внутри модалки (Срочный / Обычный) */
.bos-toggle {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px;
  background: var(--stroke);
  border-radius: 8px;
}
.bos-toggle__btn {
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.15s ease;
}
.bos-toggle__btn--active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Стили вкладки «Компании» (.portal-companies-view*) переехали в
   portal/companies.js — весь код этой вкладки держим в одном файле. */

.modal-error {
  margin: 6px 0 0;
  color: #dc2626;
  font-weight: 400;
}
.modal-error--global {
  margin-top: 12px;
}

.modal-segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--bg);
  width: max-content;
}
.modal-segmented__btn {
  min-height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 400;
}
.modal-segmented__btn:hover { color: var(--ink); }
.modal-segmented__btn.active {
  background: var(--panel);
  color: var(--ink);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.modal-segmented__btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

/* ========================================================================
   Информационная база · редактор компании во временной вкладке хедера
   (db/companies.html → CompanyEditor, открывается через window.BosTabs).
   Зеркалит редактор «Люди» (person-editor).
   ===================================================================== */
.company-editor {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
}
.company-editor__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--stroke);
}
.company-editor__title {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
}
.company-editor__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.company-editor__saved {
  color: #047857;
  font-weight: 560;
}
.company-editor__grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.company-editor__field {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.company-editor__label {
  color: var(--ink);
  font-weight: 560;
}
.company-editor__control {
  min-width: 0;
}
.company-editor__input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.company-editor__input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.company-editor__input:disabled {
  background: var(--bg);
  color: var(--muted);
}
@media (max-width: 600px) {
  .company-editor__field {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 6px;
  }
}
