:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #242f3f;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #8b9eb5;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --error: #f85149;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: "JetBrains Mono", monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-main {
  flex: 1 1 auto;
}

.header-user {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user .btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.header-user .header-admin-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.header-user .header-admin-link:hover {
  text-decoration: underline;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.main {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  min-height: 400px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.section h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1rem;
}

.tabs.hidden {
  display: none;
}

.tab-wrapper {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tab-wrapper.tab-dragging {
  opacity: 0.5;
}

.tab-wrapper.tab-drag-over {
  border-top: 2px solid var(--accent);
  margin-top: -2px;
}

.tab-drag-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  font-size: 0.85rem;
  user-select: none;
  cursor: grab;
}

.tab-drag-handle:active {
  cursor: grabbing;
}

.tab-drag-handle:hover {
  color: var(--accent);
}

.tab {
  flex: 1;
  padding: 0.5rem 0.85rem;
  text-align: left;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tab.active {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.upload-area {
  margin-top: 1rem;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.upload-icon {
  display: block;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.upload-text {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
}

.upload-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.template-list {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
}

.template-list::-webkit-scrollbar {
  width: 6px;
}

.template-list::-webkit-scrollbar-track {
  background: var(--surface);
  border-radius: 3px;
}

.template-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.35rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.template-item:hover {
  background: var(--surface-hover);
}

.template-item.active {
  background: rgba(88, 166, 255, 0.15);
  border-left: 3px solid var(--accent);
}

.template-item .name {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-item-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.template-item .template-replace,
.template-item .template-refresh,
.template-item .delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.template-item .template-refresh svg {
  display: block;
  flex-shrink: 0;
}

.template-item:hover .template-replace,
.template-item:hover .template-refresh,
.template-item:hover .delete {
  opacity: 1;
}

.template-item .template-replace:hover,
.template-item .template-refresh:hover {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
}

.template-item .delete:hover {
  color: var(--error);
  background: rgba(248, 81, 73, 0.1);
}

.content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  text-align: center;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.empty-state h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 360px;
}

.form-panel {
  display: flex;
  flex-direction: column;
}

.form-panel.hidden {
  display: none;
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.form-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  display: none;
}

.form-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.form-header-actions #generateBtn {
  margin-left: auto;
}

.layout-edit-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.layout-edit-toggle {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  line-height: 1;
}

.layout-edit-toggle.active {
  background: rgba(88, 166, 255, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

/* В режиме редактирования расположения поля формы недоступны для ввода, видны только ручки перетаскивания */
.form-panel.layout-edit-mode .fields-form input,
.form-panel.layout-edit-mode .fields-form select,
.form-panel.layout-edit-mode .fields-form textarea,
.form-panel.layout-edit-mode .fields-form .multiselect-trigger,
.form-panel.layout-edit-mode .fields-form .btn-remove-route,
.form-panel.layout-edit-mode .fields-form .btn-add-route,
.form-panel.layout-edit-mode .form-bottom-actions .btn {
  pointer-events: none;
  opacity: 0.8;
}

.form-panel.layout-edit-mode .form-header-actions .btn:not(.layout-save-btn):not(.layout-edit-toggle) {
  pointer-events: none;
  opacity: 0.7;
}

.form-panel.layout-edit-mode .drag-handle,
.form-panel.layout-edit-mode .merge-zone,
.form-panel.layout-edit-mode .split-btn {
  pointer-events: auto;
  opacity: 1;
}

.btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

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

.btn-outline,
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover,
.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.btn-block {
  display: block;
  width: 100%;
}

.actualize-area {
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}

.fields-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-bottom-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-org-actions {
  flex-shrink: 0;
}

.form-nav-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.form-nav-actions.hidden {
  display: none;
}

.form-nav-actions button.hidden {
  display: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 0.5rem 1rem;
}

.field-row.paired {
  grid-template-columns: 1fr 1fr;
}

.field-row.paired-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.field-row.paired .field-cell:first-child {
  grid-column: 1;
}

.field-row.paired .field-cell:last-child {
  grid-column: 2;
}

.ord-table-wrap {
  margin-bottom: 1rem;
}

.ord-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ord-table th,
.ord-table td {
  padding: 0.6rem 0.85rem;
  text-align: left;
  border: 1px solid var(--border);
}

.ord-table th:nth-child(1),
.ord-table td:nth-child(1),
.ord-table th:nth-child(2),
.ord-table td:nth-child(2) {
  width: 1%;
  white-space: nowrap;
}

.ord-table th {
  background: var(--surface-hover);
  color: var(--text-muted);
  font-weight: 500;
}

.ord-table td input {
  width: 100%;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.ord-table td input:focus {
  outline: none;
  border-color: var(--accent);
}

.ord-table .ord-table-number {
  width: 14ch;
  min-width: 14ch;
  max-width: 14ch;
}

.ord-table .date-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.ord-table .date-input-wrap .date-input {
  width: 14ch;
  min-width: 14ch;
}

.ord-table .date-picker-btn {
  flex-shrink: 0;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
}

.ord-table .date-picker-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ord-table .ord-name-readonly {
  background: var(--surface);
  color: var(--text-muted);
  cursor: default;
}

/* Таблица должностей по транспортной безопасности */
.tb-table-block-wrap {
  flex: 1;
  min-width: 0;
}

.tb-table-block {
  margin-top: 0;
}

.tb-table-row .tb-table-block {
  margin-top: 0;
}

.tb-table-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

/* Вторая таблица ТБ: перечень должностей работников СТИ */
.tb-sti-table-block-wrap {
  flex: 1;
  min-width: 0;
}

.tb-sti-table-block {
  margin-top: 0;
}

.tb-sti-table-row .tb-sti-table-block {
  margin-top: 0;
}

.tb-sti-table-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.tb-sti-table-actions {
  margin-top: 0.5rem;
}

.tb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tb-table th,
.tb-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

/* Ширина колонок: 2/3 для «Должность», 1/3 для «Кол-во чел.» */
.tb-table th:nth-child(1),
.tb-table td:nth-child(1) {
  width: 66.666%;
}

.tb-table th:nth-child(2),
.tb-table td:nth-child(2) {
  width: 33.333%;
}

.tb-table th {
  background: var(--surface-hover);
  color: var(--text-muted);
  font-weight: 500;
}

.tb-role-input,
.tb-count-input,
.tb-sti-role-input,
.tb-sti-count-input {
  width: 100%;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

/* Убираем стрелки добавления/убавления у полей «Кол-во чел.» в обеих таблицах ТБ */
.tb-count-input::-webkit-inner-spin-button,
.tb-count-input::-webkit-outer-spin-button,
.tb-sti-count-input::-webkit-inner-spin-button,
.tb-sti-count-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.tb-count-input,
.tb-sti-count-input {
  -moz-appearance: textfield;
}

.tb-count-wrap,
.tb-sti-count-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tb-row-remove,
.tb-sti-row-remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  font-size: 1.2rem;
}

.tb-row-remove:hover,
.tb-sti-row-remove:hover {
  border-color: var(--error);
  color: var(--error);
}

.tb-table-actions {
  margin-top: 0.5rem;
}

/* Уполномоченные органы — три раздельных блока */
.uv-sections-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-left: calc(36px + 0.5rem);
  margin-right: 1.5rem;
}

.uv-section {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
}

.uv-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.uv-section-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.uv-section-fields .field-cell {
  margin-bottom: 0;
}

.uv-section-fields .uv-cell-full {
  width: 100%;
}

.uv-contacts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.uv-dds-subsection {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.tsotb-schema-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.tsotb-schema-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.tsotb-schema-fields .field-cell {
  margin-bottom: 0;
}

.tsotb-schema-images-area {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.tsotb-schema-images-title {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.tsotb-schema-images-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tsotb-schema-image-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tsotb-schema-thumb {
  max-width: 120px;
  max-height: 90px;
  object-fit: contain;
  display: block;
}

.tsotb-schema-thumb-placeholder {
  width: 120px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.tsotb-schema-img-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tsotb-schema-img-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.tsotb-schema-img-remove:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.tsotb-schema-add-btn,
.tsotb-schema-add-url-btn {
  flex-shrink: 0;
}

.tsotb-schema-add-url-btn {
  margin-left: 0.5rem;
}

.uv-dds-title {
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.uv-dds-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0 1rem;
}

.uv-dds-fields .field-cell {
  margin-bottom: 0;
}

.uv-section-fields input {
  width: 100%;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.uv-section-fields input:focus {
  outline: none;
  border-color: var(--accent);
}

.uv-section-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.uv-section-actions .uv-add-to-db,
.uv-section-actions .uv-edit-in-db {
  flex-shrink: 0;
}

.uv-section-actions .uv-edit-in-db:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.uv-lookup-wrap {
  position: relative;
}

.uv-lookup-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 100;
  box-shadow: var(--shadow);
}

.uv-lookup-suggestions.visible {
  display: block;
}

.uv-lookup-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.1s;
}

.uv-lookup-item:hover {
  background: var(--surface-hover);
}

.uv-extra-wrap {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.uv-extra-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.uv-extra-entry {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.uv-extra-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.uv-extra-entry-num {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.uv-extra-remove {
  padding: 0.2rem 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.uv-extra-remove:hover {
  border-color: var(--error);
  color: var(--error);
}

.uv-add-extra {
  margin-top: 0;
}

/* Таблица технических характеристик ТС */
.tkh-table-block-wrap {
  flex: 1;
  min-width: 0;
}

.tkh-table-block {
  margin-top: 0;
}

.tkh-table-loading {
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tkh-table-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.tkh-file-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tkh-file-select-wrap label {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.tkh-file-select,
.tkh-file-input {
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.tkh-file-input-wrap {
  flex: 1;
  min-width: 0;
  max-width: 280px;
  position: relative;
}

.tkh-file-input-wrap .tkh-file-input {
  width: 100%;
  box-sizing: border-box;
}

.tkh-file-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  margin-top: 2px;
}

.tkh-file-suggestions.visible {
  display: block;
}

.tkh-file-suggestion-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.tkh-file-suggestion-item:hover {
  background: var(--bg-hover);
}

.tkh-file-select-wrap .tkh-btn-save,
.tkh-file-select-wrap .tkh-btn-save-as {
  flex-shrink: 0;
}

.tkh-tabs-wrap {
  margin-top: 0.5rem;
}

.tkh-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.tkh-tab-btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.tkh-tab-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--accent);
}

.tkh-tab-btn.active {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.tkh-tab-panels {
  position: relative;
}

.tkh-tab-panel {
  display: none;
}

.tkh-tab-panel.active {
  display: block;
}

.tkh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tkh-table th,
.tkh-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

.tkh-table th:nth-child(1),
.tkh-table td:nth-child(1) {
  width: 45%;
}

.tkh-table th:nth-child(2),
.tkh-table td:nth-child(2) {
  width: 55%;
}

.tkh-table th {
  background: var(--surface-hover);
  color: var(--text-muted);
  font-weight: 500;
}

.tkh-section-row td {
  font-weight: 500;
  background: var(--surface-hover);
}

.tkh-value-input {
  width: 100%;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

/* Таблица «Номер и дата решения ФДА Росавтодор о внесении в реестр» */
.tc-reestr-table-block-wrap {
  flex: 1;
  min-width: 0;
}

.tc-reestr-table-block {
  margin-top: 0;
}

.tc-reestr-table-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.tc-reestr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tc-reestr-table th,
.tc-reestr-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

.tc-reestr-table th:nth-child(1),
.tc-reestr-table td:nth-child(1) {
  width: 35%;
}

.tc-reestr-table th:nth-child(2),
.tc-reestr-table td:nth-child(2) {
  width: 40%;
}

.tc-reestr-table th:nth-child(3),
.tc-reestr-table td:nth-child(3) {
  width: 40px;
}

.tc-reestr-table th {
  background: var(--surface-hover);
  color: var(--text-muted);
  font-weight: 500;
}

.tc-reestr-nomer,
.tc-reestr-data {
  width: 100%;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.tc-reestr-row-remove {
  padding: 0.25rem 0.5rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.tc-reestr-row-remove:hover {
  border-color: var(--error);
  color: var(--error);
}

.tc-reestr-table-actions {
  margin-top: 0.5rem;
}

/* Таблица «Описание результатов изучения паспорта ТС» */
.pts-table-block-wrap {
  flex: 1;
  min-width: 0;
}

.pts-table-block {
  margin-top: 0;
}

.pts-table-loading {
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pts-table-title {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.pts-file-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.pts-file-select-wrap label {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.pts-file-select {
  flex: 1;
  min-width: 0;
  max-width: 280px;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.pts-file-select-wrap .pts-save-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1.25;
  min-height: 2.05rem;
  box-sizing: border-box;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.pts-file-select-wrap .pts-save-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.pts-tabs-wrap {
  margin-top: 0.5rem;
}

.pts-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.pts-tab-btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pts-tab-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--accent);
}

.pts-tab-btn.active {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.pts-tab-panels {
  position: relative;
}

.pts-tab-panel {
  display: none;
}

.pts-tab-panel.active {
  display: block;
}

.pts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.pts-table th,
.pts-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

.pts-table th:nth-child(1),
.pts-table td:nth-child(1) {
  width: 45%;
}

.pts-table th:nth-child(2),
.pts-table td:nth-child(2) {
  width: 55%;
}

.pts-table th {
  background: var(--surface-hover);
  color: var(--text-muted);
  font-weight: 500;
}

.pts-value-input {
  width: 100%;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.pts-value-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pts-table .date-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pts-table .date-input-wrap .date-input {
  width: 14ch;
  min-width: 14ch;
  flex: none;
}

.field-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-input-row > input:not(.date-input) {
  flex: 1;
  min-width: 0;
}

.field-input-row > .date-input-wrap {
  flex: 1;
  min-width: 0;
}

.merge-zone {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: default;
  transition: all 0.15s;
}

.merge-zone:hover,
.merge-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
}

.split-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.split-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.field-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

/* Подсказки ТСОТБ (марка/модель) */
.tsotb-input-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}

.tsotb-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 100;
  box-shadow: var(--shadow);
}

.tsotb-suggestions.visible {
  display: block;
}

.tsotb-suggestion-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.1s;
}

.tsotb-suggestion-item:hover {
  background: var(--surface-hover);
}

.field-cell label {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: left;
}

.field-cell input {
  width: 100%;
}

.field-row.draggable {
  cursor: grab;
}

.field-row.draggable:active {
  cursor: grabbing;
}

.field-row.dragging {
  opacity: 0.5;
}

.field-row.drag-over {
  border-top: 2px solid var(--accent);
}

.drag-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: grab;
  user-select: none;
}

.drag-handle:hover {
  color: var(--accent);
}


.field-row input,
.field-row textarea {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s;
  text-align: left;
}

.field-row select.field-select {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  padding-right: 2rem;
  appearance: none;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b9eb5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s;
  text-align: left;
}

.field-row .multiselect-trigger {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  padding-right: 2rem;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b9eb5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s;
  text-align: left;
}

.field-row input:focus,
.field-row select.field-select:focus,
.field-row textarea:focus,
.field-row .multiselect-trigger:hover,
.field-row .multiselect-trigger:focus {
  outline: none;
  border-color: var(--accent);
}

.field-row input[readonly] {
  background: var(--surface);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Вкладка «Сведения о ТС и перевозках»: поле не растягивается, обрезка длинного текста, подсказка при наведении */
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row .field-cell {
  min-width: 0;
}

#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row input.tc-truncate-input,
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row select.tc-truncate-input,
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row .date-input-wrap .date-input.tc-truncate-input,
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .route-entry-field input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row input.tc-truncate-input::-webkit-scrollbar,
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row select.tc-truncate-input::-webkit-scrollbar,
#formPanel[data-active-tab="Сведения о ТС и перевозках"] .field-row .date-input-wrap .date-input.tc-truncate-input::-webkit-scrollbar {
  display: none;
}

/* Маршруты при регулярной перевозке */
.route-regular-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.btn-add-route {
  align-self: flex-start;
}

.route-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.route-entries-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.route-entry-block {
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.route-entry-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 0.5rem;
}

.btn-remove-route {
  padding: 0.2rem 0.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  border-radius: var(--radius-sm);
}

.btn-remove-route:hover {
  color: var(--error);
}

.route-entry-field {
  margin-bottom: 0.5rem;
}

.route-entry-field:last-child {
  margin-bottom: 0;
}

.route-entry-field label {
  padding-left: 0;
  text-align: left;
  display: block;
}

.route-entry-field input {
  width: 100%;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.route-entry-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-input-row > select.field-select,
.field-input-row > .field-multiselect {
  flex: 1;
  min-width: 0;
}

.field-row textarea {
  min-height: 80px;
  resize: vertical;
}

.date-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.date-input-wrap .date-input {
  width: 14ch;
  min-width: 14ch;
  max-width: 14ch;
  flex: none;
}

.date-picker-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.date-picker-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.date-picker-popup {
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.date-picker-popup .cal-body {
  min-width: 220px;
}

.date-picker-popup .cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.25rem;
}

.date-picker-popup .cal-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.date-picker-popup .cal-nav {
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.15s;
}

.date-picker-popup .cal-nav:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.date-picker-popup .cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 0.5rem;
}

.date-picker-popup .cal-wd {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

.date-picker-popup .cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.date-picker-popup .cal-day {
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.date-picker-popup .cal-day:hover:not(.cal-other) {
  background: var(--surface-hover);
  color: var(--accent);
}

.date-picker-popup .cal-day.cal-today {
  background: rgba(88, 166, 255, 0.2);
  color: var(--accent);
}

.date-picker-popup .cal-day.cal-other {
  cursor: default;
  visibility: hidden;
}

/* Multiselect dropdown */
.field-multiselect {
  position: relative;
  flex: 1;
  min-width: 0;
}

.multiselect-trigger {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  cursor: pointer;
  appearance: none;
}

.multiselect-trigger-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.multiselect-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

.multiselect-dropdown.visible {
  display: block;
}

.multiselect-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.multiselect-option:hover {
  background: var(--surface-hover);
}

.multiselect-option input[type="checkbox"] {
  width: auto;
  flex-shrink: 0;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 10000;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--error);
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
  }

  .field-row.paired,
  .field-row.paired-3 {
    grid-template-columns: 1fr;
  }

  .field-row.paired .field-cell:first-child {
    grid-column: 1;
  }

  .field-row.paired .field-cell:last-child {
    grid-column: 1;
    grid-row: 2;
  }

  .field-row.paired-3 .field-cell {
    grid-column: 1;
  }

  .field-row.paired-3 .field-cell:nth-child(2) {
    grid-row: 2;
  }

  .field-row.paired-3 .field-cell:nth-child(3) {
    grid-row: 3;
  }
}

/* Модальное окно актуализации */
.actualize-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.actualize-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.actualize-title {
  font-weight: 600;
  margin-bottom: 1rem;
}
.actualize-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  margin-bottom: 1rem;
}
.actualize-item {
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
}
.actualize-item:hover {
  background: var(--surface-hover);
}
.actualize-name {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}
.actualize-date {
  display: block;
  font-size: 0.9rem;
  opacity: 0.8;
}
.actualize-close {
  align-self: flex-start;
}

/* Кнопки в демо-режиме: визуально неактивны, при клике показывают сообщение */
.guest-inactive {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: auto;
}
