:root {
  --shell-bg: #e4e8ef;
  --panel-bg: #f6f8fc;
  --paper: #ffffff;
  --line: #c7ced9;
  --line-strong: #9fa9b7;
  --text: #1f2530;
  --muted: #566073;
  --accent: #a82031;
  --accent-dark: #7e1624;
  --select: #d8e9ff;
  --ok: #1f7d46;
  --bad: #a42a2a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--shell-bg);
  color: var(--text);
  font-family: "Segoe UI", "Tahoma", sans-serif;
  font-size: 14px;
}

.app-shell {
  height: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: 44px 36px minmax(0, 1fr);
}

.title-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(90deg, var(--accent), #b32333 54%, #c12639);
  color: #fff;
}

.title-ribbon__left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.api-state {
  font-size: 14px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.api-state.ok {
  background: rgba(38, 155, 86, 0.18);
  border-color: rgba(192, 255, 215, 0.5);
}

.api-state.bad {
  background: rgba(205, 58, 58, 0.25);
  border-color: rgba(255, 213, 213, 0.5);
}

.current-user-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
  padding: 0 4px;
}

.organization-switcher {
  max-width: 260px;
  min-width: 150px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 14px;
  padding: 4px 26px 4px 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 13px;
}

.organization-switcher option {
  color: #1f2937;
  background: #fff;
}

.logout-btn {
  font-size: 14px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.menu-strip {
  background: #eceef3;
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  display: flex;
  align-items: stretch;
}

.menu-tab {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 0 18px;
  font-size: 14px;
  cursor: pointer;
  color: #313947;
}

.menu-tab.active {
  background: #fff;
  font-weight: 600;
}

.ribbon-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f7f8fb;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
}

.tool-btn {
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #ffffff, #f1f4fa);
  border-radius: 3px;
  padding: 7px 12px;
  cursor: pointer;
  color: #2d3340;
}

.tool-btn:hover {
  border-color: #6f7b8b;
}

.tool-btn-primary {
  background: linear-gradient(180deg, #fff2f4, #ffd7dc);
  border-color: #b44a58;
  color: #7a1f2c;
  font-weight: 600;
}

.hqs-quarter-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 8px;
  padding: 10px 12px;
  background: #edf2f9;
  border-top: 1px solid #ccd7e6;
  border-bottom: 1px solid #ccd7e6;
}

.hqs-quarter-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 14px;
  color: #344258;
  background: #fff;
  border: 1px solid #aebed2;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
}

.hqs-quarter-tab strong {
  font-size: 14px;
}

.hqs-quarter-tab span {
  color: #6a778a;
  font-size: 11px;
}

.hqs-quarter-tab:hover {
  border-color: #8b2034;
}

.hqs-quarter-tab.active {
  color: #fff;
  background: #7c1d30;
  border-color: #7c1d30;
}

.hqs-quarter-tab.active span {
  color: #f4dce1;
}

@media (max-width: 900px) {
  .hqs-quarter-tabs {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

.tool-btn-danger {
  background: linear-gradient(180deg, #fff0f0, #ffc8c8);
  border-color: #c0392b;
  color: #7a1010;
  font-weight: 600;
}

.tool-btn-danger:hover {
  background: linear-gradient(180deg, #ffe0e0, #ffaaaa);
}

.days-wrap {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.days-wrap input {
  width: 70px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 6px;
}

.ribbon-message {
  color: var(--muted);
  min-height: 20px;
  padding-left: 6px;
}

.ribbon-message.ok {
  color: var(--ok);
}

.ribbon-message.bad {
  color: var(--bad);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.left-nav {
  border-right: 1px solid var(--line);
  background: #f2f4f8;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  min-height: 0;
  overflow: hidden;
}

.left-nav__title {
  padding: 12px 12px 8px;
  font-size: 24px;
  color: #22314a;
}

.left-nav__search {
  margin: 0 12px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 7px 9px;
  background: #fff;
}

.left-nav__list {
  flex: 1 1 auto;
  list-style: none;
  margin: 0;
  padding: 0 0 10px;
  min-height: 0;
  overflow-y: auto;
}

.left-nav__list li {
  padding: 7px 12px 7px 22px;
  border-top: 1px solid transparent;
  border-bottom: 1px solid transparent;
  color: #263242;
  cursor: default;
  position: relative;
}

.left-nav__list li::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 1px;
  background: #6a7f9f;
}

.left-nav__list li.active {
  background: #dde9fc;
  border-color: #b8cbe9;
  font-weight: 600;
}

.main-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) minmax(340px, auto);
  background: var(--panel-bg);
}

.grid-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
}

.grid-head__meta,
.migrant-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.migrant-tools .tool-btn {
  padding: 5px 9px;
}

.migrant-tools .days-wrap input {
  padding: 4px 6px;
}

.grid-head h1 {
  margin: 0;
  font-size: 20px;
}

.grid-head p {
  margin: 2px 0 0;
  color: var(--muted);
}

.grid-wrap {
  overflow: auto;
  background: var(--paper);
}

.table-search {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-width: 100%;
  padding: 6px 8px;
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
  box-sizing: border-box;
}

.table-search__input {
  width: min(380px, 70vw);
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.table-search__input:focus {
  outline: 2px solid rgba(33, 91, 165, 0.18);
  border-color: var(--accent);
}

.table-search__clear {
  white-space: nowrap;
}

.table-search__count {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.table-search-hidden {
  display: none !important;
}

.case-grid {
  width: auto;
  border-collapse: collapse;
  min-width: 0;
  font-size: 14px;
}

.case-grid thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  width: 1%;
  text-align: left;
  font-weight: 600;
  padding: 4px;
  color: #29313d;
  background: #e7edf7;
  border-bottom: 1px solid #b9c7dd;
  border-right: 1px solid #d1d9e7;
  white-space: normal;
  line-height: 1.1;
}

.case-grid tbody td {
  padding: 3px 4px;
  border-bottom: 1px solid #e6ebf3;
  border-right: 1px solid #f0f3f9;
  white-space: nowrap;
}

.case-grid .tool-btn {
  padding: 3px 5px;
  font-size: 14px;
  white-space: nowrap;
}

.case-grid tbody tr {
  background: #fff;
  cursor: pointer;
}

.case-grid tbody tr:nth-child(2n) {
  background: #fbfcff;
}

.case-grid tbody tr:hover {
  background: #eef4ff;
}

.case-grid tbody tr.selected {
  background: var(--select);
}

#contractsTable {
  width: auto;
  min-width: 0;
  font-size: 13px;
}

#contractsTable thead th {
  width: 1%;
  padding: 4px;
}

#contractsTable tbody td {
  padding: 3px 4px;
}

#contractsTable thead th:nth-child(1) {
  min-width: 155px;
}

#contractsTable thead th:nth-child(10) {
  min-width: 245px;
}

#contractsTable thead th:nth-child(11),
#contractsTable thead th:nth-child(12) {
  width: 145px;
  min-width: 145px;
  white-space: normal;
  line-height: 1.1;
}

.contract-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.contract-actions .tool-btn,
#contractsTable tbody td > .tool-btn {
  padding: 3px 5px;
  font-size: 13px;
  white-space: nowrap;
}

.contract-notice-dates {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.empty-row td {
  color: var(--muted);
}

.bottom-panels {
  display: grid;
  grid-template-columns: 33% 34% 33%;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: #f0f3f8;
}

.panel-block {
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.panel-block h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-block h3 {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: #384458;
}

.case-card-panel {
  grid-column: 1 / -1;
}

.case-card-grid {
  display: grid;
  grid-template-columns: minmax(300px, 34%) minmax(420px, 1fr);
  gap: 14px;
  align-items: start;
}

.case-card-documents {
  min-width: 0;
}

.case-card-documents h3 {
  margin-top: 0;
}

.case-card-documents .document-list {
  margin-top: 6px;
}

.case-card-documents .panel-message {
  margin: 6px 0 0;
}

.case-summary {
  margin: 0;
}

.case-summary div {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 8px;
  border-bottom: 1px solid #eff2f7;
  padding: 4px 0;
}

.case-summary dt {
  color: var(--muted);
}

.case-summary dd {
  margin: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  min-width: 0;
}

#passportUploadForm {
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: start;
}

.inline-form input[type="file"],
.inline-form select {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 7px;
  background: #fff;
  min-width: 0;
  width: 100%;
}

.inline-form button {
  border: 1px solid #6c7892;
  border-radius: 3px;
  background: linear-gradient(180deg, #ffffff, #f0f4fb);
  padding: 7px 11px;
  cursor: pointer;
  white-space: normal;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 7px;
  min-width: 0;
}

.form-grid.compact {
  grid-template-columns: 1fr 1fr;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.migration-card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 7px;
  grid-column: 1 / -1;
}

.form-grid label span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

.form-grid label {
  min-width: 0;
}

.form-grid .checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
}

.form-grid .checkbox-line input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

.form-grid .checkbox-line span {
  display: inline;
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 6px 7px;
  font: inherit;
  box-sizing: border-box;
}

.form-grid button {
  border: 1px solid #6d7891;
  border-radius: 3px;
  background: linear-gradient(180deg, #fff, #eef3fb);
  padding: 7px 10px;
  cursor: pointer;
  font-weight: 600;
}

.panel-message {
  margin: 0;
  min-height: 16px;
  color: var(--muted);
}

.panel-message.ok {
  color: var(--ok);
}

.panel-message.bad {
  color: var(--bad);
}

.json-box {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px;
  background: #111821;
  color: #d8e6fb;
  font-size: 12px;
  min-height: 120px;
  height: 100%;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.ocr-preview {
  min-height: 520px;
  height: 520px;
  max-height: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfdff;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}

.ocr-preview * {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ocr-preview__empty {
  padding: 12px;
  color: var(--muted);
}

.ocr-preview__meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid #e0e6ef;
  background: linear-gradient(180deg, #fdfefe, #f2f6fc);
}

.ocr-preview__metric {
  border: 1px solid #dbe3ef;
  border-radius: 4px;
  background: #fff;
  padding: 8px 10px;
}

.ocr-preview__metric-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

.ocr-preview__metric-value {
  display: block;
  font-weight: 600;
}

.ocr-preview__section {
  padding: 10px;
}

.ocr-preview__section + .ocr-preview__section {
  border-top: 1px solid #e7edf6;
}

.ocr-preview__title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #314563;
}

.ocr-preview__table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.ocr-preview__table th,
.ocr-preview__table td {
  border: 1px solid #dde5f0;
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.ocr-preview__table th {
  width: 34%;
  background: #f4f7fc;
  color: #425067;
  font-weight: 600;
}

.ocr-preview--with-viewer {
  height: auto;
  max-height: none;
  overflow: visible;
}

#personModal .ocr-preview--with-viewer {
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.pv-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.pv-btn {
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid #c0cde0;
  border-radius: 3px;
  background: #f4f7fb;
  cursor: pointer;
  color: #2f4262;
  line-height: 1.4;
}

.pv-btn:hover {
  background: #e2eaf6;
  border-color: #3f6bb0;
}

.pv-btn--muted {
  color: #7f91ad;
}

.pv-angle {
  min-width: 30px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #425067;
}

.pv-zoom {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #425067;
}

.pv-sep {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: #d0daea;
  margin: 0 4px;
  vertical-align: middle;
}

.pv-hint {
  margin: 0 0 6px;
  font-size: 11px;
  color: #8fa0ba;
}

.pv-wrap {
  background: #dce4ef;
  border-radius: 4px;
  overflow: auto;
  text-align: center;
  min-height: 0;
  max-height: none;
}

.pv-canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  max-height: calc(100vh - 390px);
  height: auto;
  object-fit: contain;
  cursor: crosshair;
}

.list-box {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fdfefe;
  padding: 6px;
  max-height: 160px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.task-row,
.due-row {
  border: 1px solid #dbe2ec;
  background: #fff;
  border-radius: 2px;
  padding: 6px;
  display: grid;
  gap: 5px;
}

.task-row strong,
.due-row strong {
  font-weight: 600;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.task-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.task-controls select {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 5px 7px;
  font: inherit;
}

.task-controls button {
  border: 1px solid #6f7c95;
  border-radius: 3px;
  background: #f7f9fd;
  padding: 5px 8px;
  cursor: pointer;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 36, 0.45);
}

.modal-dialog {
  position: relative;
  width: min(980px, 96vw);
  max-width: calc(100vw - 16px);
  height: min(820px, calc(100vh - 24px));
  overflow: hidden;
  border: 1px solid #9aa7bc;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(11, 21, 35, 0.4);
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
}

.modal-dialog > * {
  min-width: 0;
  min-height: 0;
}

.modal-content {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(0, 1.05fr);
  gap: 10px;
  overflow: hidden;
  overflow-x: hidden;
}

#personModal .modal-dialog {
  width: min(1280px, 98vw);
}

#personModal .modal-content {
  grid-template-columns: minmax(520px, 1.25fr) minmax(360px, 0.75fr);
}

.modal-content > * {
  min-width: 0;
  min-height: 0;
}

.modal-scan-section.hidden + .modal-form {
  grid-column: 1 / -1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
}

.modal-tabs {
  display: inline-flex;
  gap: 6px;
}

.modal-tab {
  border: 1px solid #8ea0bd;
  border-radius: 3px;
  background: #f0f3f9;
  padding: 6px 10px;
  cursor: pointer;
}

.modal-tab.active {
  background: #dbe8ff;
  border-color: #6f8cbc;
  font-weight: 600;
}

.modal-scan-section {
  border: 1px solid var(--line);
  padding: 10px;
  background: #f9fbff;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  overflow: hidden;
}

.paste-zone {
  border: 1px dashed #7f91ad;
  border-radius: 4px;
  background: #f3f8ff;
  color: #314563;
  padding: 10px;
  cursor: default;
  outline: none;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.paste-zone:focus {
  border-color: #3f6bb0;
  box-shadow: 0 0 0 2px rgba(63, 107, 176, 0.2);
}

.paste-zone--dragover {
  background: #ddeeff;
  border-color: #3f6bb0;
  border-style: solid;
}

.scan-file-label {
  cursor: pointer;
  max-width: 200px;
}

.scan-file-label input[type="file"] {
  display: none;
}

.modal-form {
  border: 1px solid var(--line);
  padding: 10px;
  background: #fff;
  min-width: 0;
  min-height: 0;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

@media (max-width: 1180px) {
  #passportUploadForm {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #passportUploadForm input[type="file"] {
    grid-column: 1 / -1;
  }

  #passportUploadForm button {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .modal-dialog {
    width: min(980px, calc(100vw - 16px));
    height: calc(100vh - 16px);
  }

  .modal-content {
    grid-template-columns: 1fr;
    overflow-y: auto;
    padding-right: 2px;
  }

  .ocr-preview {
    min-height: 460px;
    height: 460px;
    max-height: 460px;
  }

  .ocr-preview--with-viewer {
    max-height: none;
  }

  .pv-wrap {
    min-height: 420px;
    max-height: 70vh;
  }

  .pv-canvas {
    max-height: 68vh;
  }

  .modal-form {
    overflow-y: visible;
    overflow-x: hidden;
  }
}

@media (max-width: 1360px) {
  .bottom-panels {
    grid-template-columns: 1fr;
  }

  .case-card-grid {
    grid-template-columns: 1fr;
  }

  .panel-block {
    min-height: 280px;
  }
}

.authority-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.authority-row select {
  flex: 1;
}

.authority-add-form {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}

.authority-add-form input {
  flex: 1;
}

.authority-label {
  grid-column: 1 / -1;
}

/* Wide modal for arrival notice */
.modal-dialog--wide {
  width: min(1100px, 96vw);
  overflow: visible;
  height: auto;
  max-height: calc(100vh - 24px);
}

/* Scrollable single-column modal content */
.modal-content--scroll {
  display: block !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: auto !important;
  max-height: calc(100vh - 140px);
  padding-right: 8px;
}

/* Section titles inside form-grid */
.form-section-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5a6a82;
  border-bottom: 1px solid #dde3ec;
  padding-bottom: 4px;
  margin-top: 8px;
  margin-bottom: 0;
}

/* Case combo-search */
.case-combo {
  position: relative;
}
.case-combo__list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: #fff;
  border: 1px solid #c5cdd8;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.case-combo__item {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.case-combo__item:hover,
.case-combo__item--active {
  background: #e8f0fb;
}
.case-combo__empty {
  padding: 7px 10px;
  color: #888;
  font-size: 0.875rem;
}

/* Doc buttons */
.doc-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.document-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.document-list__empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 0;
}

.document-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  border: 1px solid #dbe2ec;
  background: #f9fbfe;
  border-radius: 4px;
  padding: 7px;
}

.document-row--blocked {
  background: #fbfbfc;
}

.document-row__main {
  min-width: 0;
}

.document-row__title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.document-row__meta,
.document-row__error {
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.document-row__meta {
  color: var(--muted);
}

.document-row__error {
  color: var(--bad);
}

.document-row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
  max-width: 170px;
}

.document-row__actions .tool-btn {
  min-width: 74px;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.2;
  white-space: normal;
}

.document-parameters-dialog {
  width: min(760px, 96vw);
  height: auto;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.document-parameters-form {
  display: grid;
  gap: 12px;
}

.document-parameters-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.document-parameters-note code {
  color: var(--text);
  font-weight: 600;
}

.document-parameters-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px 12px;
}

.document-parameters-fields .full {
  grid-column: 1 / -1;
}

.document-parameters-fields label {
  display: grid;
  gap: 4px;
}

.document-parameters-fields label span {
  color: var(--muted);
  font-size: 12px;
}

.document-parameters-fields input,
.document-parameters-fields textarea {
  width: 100%;
  border: 1px solid #aeb8ca;
  border-radius: 4px;
  padding: 7px 9px;
  font: inherit;
  box-sizing: border-box;
}

.document-parameters-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.document-parameters-message.bad {
  color: var(--bad);
}

.access-pass-dialog {
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

.access-pass-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.access-pass-search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #aeb8ca;
  border-radius: 4px;
  font-size: 14px;
}

.access-pass-parameters {
  border: 1px solid #dbe2ec;
  border-radius: 4px;
  background: #fbfdff;
  padding: 8px;
  display: grid;
  gap: 8px;
}

.access-pass-parameters h3 {
  margin: 0;
  color: #5b6a84;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.access-pass-list {
  min-height: 0;
  overflow: auto;
  border: 1px solid #d7deea;
  border-radius: 4px;
  background: #f8fbff;
  padding: 6px;
}

.access-pass-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.access-pass-row:hover {
  background: #eef4ff;
}

.access-pass-row + .access-pass-row {
  border-top: 1px solid #e5ebf4;
}

.access-pass-row__main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.access-pass-row__main strong,
.access-pass-row__main small {
  overflow-wrap: anywhere;
}

.access-pass-row__main small {
  color: var(--muted);
  font-size: 12px;
}

.access-pass-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.access-pass-message.bad {
  color: var(--bad);
}

.border-pass-dialog {
  grid-template-rows: auto minmax(0, 1fr);
}

.border-pass-form {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px 12px;
}

.border-pass-form h3,
.border-pass-form .full {
  grid-column: 1 / -1;
}

.border-pass-form h3 {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid #e1e7f0;
  color: #5b6a84;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.border-pass-form label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.border-pass-form label span {
  color: var(--muted);
  font-size: 12px;
}

.border-pass-form input,
.border-pass-form select,
.border-pass-form textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #aeb8ca;
  border-radius: 4px;
  font: inherit;
}

.border-pass-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.border-pass-message.bad {
  color: var(--bad);
}

@media (max-width: 720px) {
  .access-pass-toolbar {
    grid-template-columns: 1fr;
  }

  .access-pass-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .border-pass-form {
    grid-template-columns: 1fr;
  }

  .document-parameters-fields {
    grid-template-columns: 1fr;
  }

  .document-parameters-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .border-pass-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

/* ── Settings tabs ─────────────────────────────────────────────────────────── */
.settings-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 22px;
  font-size: 14px;
  cursor: pointer;
  color: #666;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.settings-tab:hover { color: #222; }
.settings-tab--active {
  color: #b71c1c;
  border-bottom-color: #b71c1c;
  font-weight: 600;
}

/* ── Settings cards ────────────────────────────────────────────────────────── */
.settings-card {
  background: #fff;
  border: 1px solid #e4e8ee;
  border-radius: 8px;
  margin-bottom: 16px;
  max-width: 860px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  overflow: hidden;
}
.settings-card__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #b71c1c;
  padding: 10px 20px;
  background: #fafafa;
  border-bottom: 1px solid #e4e8ee;
}
.settings-card__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
  padding: 18px 20px;
}

.settings-card__body--single {
  grid-template-columns: 1fr;
}

#settingsAdminPanel .settings-card {
  max-width: none;
}

#settingsAdminPanel .settings-card__body--single {
  min-width: 0;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.local-folder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.local-file-list {
  display: grid;
  gap: 6px;
  max-width: 720px;
}

.local-file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #dbe2ec;
  border-radius: 4px;
  background: #fbfdff;
  padding: 8px 10px;
}

.local-file-row__name {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.local-file-row__meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.organization-template-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.organization-template-form .tool-btn {
  min-height: 34px;
}

.organization-template-placeholders {
  max-width: 980px;
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid #dbe2ec;
  border-radius: 4px;
  background: #f8fbff;
}

.organization-template-placeholders:empty {
  display: none;
}

.organization-template-placeholders__title {
  font-weight: 700;
  color: var(--ink);
}

.organization-template-placeholders__note {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.organization-template-placeholder-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.organization-template-placeholder {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8d4e3;
  border-radius: 999px;
  background: #fff;
  color: #15243a;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  user-select: all;
}

.organization-template-placeholder:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.organization-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid #dbe2ec;
  border-radius: 4px;
  background: #fbfdff;
  padding: 8px 10px;
}

.organization-template-row__title {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.organization-template-row__meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .organization-template-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .organization-template-form,
  .organization-template-row {
    grid-template-columns: 1fr;
  }
}
.sf-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: #777;
  font-weight: 500;
}
.sf-full { grid-column: 1 / -1; }
.sf-label input, .sf-label select {
  padding: 8px 11px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 14px;
  color: #111;
  outline: none;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.sf-label input:focus, .sf-label select:focus {
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74,144,217,.12);
}

.admin-inline-form,
.admin-membership-form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-inline-form {
  grid-template-columns: minmax(220px, 1.4fr) minmax(140px, 0.8fr) repeat(3, minmax(150px, 1fr)) max-content;
  align-items: end;
}

.admin-membership-form {
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr) minmax(260px, 1fr) max-content;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f7f9fd;
}

.admin-membership-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #64748b;
}

.admin-org-checks {
  display: grid;
  gap: 6px;
  max-height: 128px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
}

.admin-org-check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 7px;
  color: #1f2530;
  line-height: 1.25;
}

.admin-org-check input {
  margin-top: 2px;
}

.admin-org-check span {
  overflow-wrap: anywhere;
}

.admin-inline-form input,
.admin-inline-form select,
.admin-membership-form select,
.admin-table input,
.admin-table select {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font: inherit;
  background: #fff;
}

.admin-table-wrap {
  width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.admin-table {
  width: 100%;
  min-width: 1040px;
  table-layout: fixed;
}

.admin-table--organizations {
  min-width: 1060px;
}

.admin-table--users {
  min-width: 1280px;
}

.admin-table th,
.admin-table td {
  vertical-align: middle;
}

.admin-table--organizations th:nth-child(1),
.admin-table--organizations td:nth-child(1) { width: 230px; }
.admin-table--organizations th:nth-child(2),
.admin-table--organizations td:nth-child(2) { width: 150px; }
.admin-table--organizations th:nth-child(3),
.admin-table--organizations td:nth-child(3) { width: 82px; text-align: center; }
.admin-table--organizations th:nth-child(4),
.admin-table--organizations td:nth-child(4) { width: 135px; }
.admin-table--organizations th:nth-child(5),
.admin-table--organizations td:nth-child(5) { width: 160px; }
.admin-table--organizations th:nth-child(6),
.admin-table--organizations td:nth-child(6) { width: 170px; }
.admin-table--organizations th:nth-child(7),
.admin-table--organizations td:nth-child(7) { width: 125px; }

.admin-table--users th:nth-child(1),
.admin-table--users td:nth-child(1) { width: 230px; }
.admin-table--users th:nth-child(2),
.admin-table--users td:nth-child(2) { width: 160px; }
.admin-table--users th:nth-child(3),
.admin-table--users td:nth-child(3) { width: 130px; }
.admin-table--users th:nth-child(4),
.admin-table--users td:nth-child(4) { width: 80px; text-align: center; }
.admin-table--users th:nth-child(5),
.admin-table--users td:nth-child(5) { width: 320px; }
.admin-table--users th:nth-child(6),
.admin-table--users td:nth-child(6) { width: 245px; }
.admin-table--users th:nth-child(7),
.admin-table--users td:nth-child(7) { width: 170px; }

.admin-table .contract-actions {
  flex-wrap: nowrap;
  gap: 6px;
}

.admin-password-cell {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) max-content;
  gap: 6px;
  align-items: center;
}

.admin-table .tool-btn {
  padding: 4px 7px;
  white-space: nowrap;
}

@media (max-width: 1280px) {
  .admin-inline-form,
  .admin-membership-form {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}
