:root {
  --ink: #193b31;
  --ink-soft: #355347;
  --muted: #68786f;
  --green: #176c49;
  --green-dark: #105137;
  --green-deep: #1a654c;
  --gold: #d6a62f;
  --gold-hover: #c49a30;
  --soft: #f3f7f4;
  --soft-strong: #e9f1ec;
  --panel: #ffffff;
  --line: #d8e3dc;
  --danger: #a44a42;
  --danger-soft: #fbeeed;
  --shadow: 0 18px 55px rgba(25, 59, 49, .10);
  --shadow-small: 0 7px 24px rgba(25, 59, 49, .07);
  --radius: 20px;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-width: 0; background: var(--soft); line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(214,166,47,.5); outline-offset: 2px; }
a { color: inherit; }

.app-shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; padding: 25px 20px 20px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 10; }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 30px; }
.brand-mark { width: 44px; height: 44px; flex: none; object-fit: contain; }
.brand-copy { min-width: 0; }
.brand-name { display: flex; align-items: baseline; font-family: "Trebuchet MS", Arial, sans-serif; font-size: 23px; font-weight: 950; line-height: .95; letter-spacing: -.065em; transform: skewX(-7deg); transform-origin: left center; }
.brand-name span { color: var(--green-deep); }
.brand-name em { margin-left: .03em; color: #fdcb01; font-size: 1.07em; font-style: normal; letter-spacing: -.08em; }
.brand-copy small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; letter-spacing: .02em; }

.primary, .secondary, .ghost, .icon, .nav-item, .side-filter, .segmented button, .contract-tab { border: 0; font: inherit; cursor: pointer; }
.primary { min-height: 42px; padding: 10px 18px; border-radius: 9px; background: var(--green); color: #fff; font-weight: 700; transition: background-color .16s ease, box-shadow .16s ease; }
.primary:hover { background: var(--green-dark); }
.primary:disabled { cursor: not-allowed; opacity: .48; }
.compose { width: 100%; min-height: 50px; margin-bottom: 27px; background: var(--gold); color: var(--ink); box-shadow: 0 7px 20px rgba(154,116,28,.16); }
.compose:hover { background: var(--gold-hover); }
nav { display: grid; gap: 6px; }
.nav-item, .side-filter { width: 100%; text-align: left; border-radius: 9px; background: transparent; color: #53685e; padding: 11px 12px; transition: background-color .15s ease, color .15s ease; }
.nav-item { font-size: 14px; font-weight: 650; }
.nav-item span { display: inline-grid; width: 25px; color: #668075; }
.nav-item.active, .nav-item:hover { background: var(--soft-strong); color: var(--green-dark); }
.nav-item.active { box-shadow: inset 3px 0 var(--gold); }
.nav-item.active span { color: var(--green); }
.nav-count { float: right; min-width: 22px; padding: 2px 6px; border-radius: 99px; background: var(--gold); color: var(--ink); text-align: center; font-size: 11px; font-weight: 800; }
.side-title { margin: 30px 12px 8px; color: #789086; font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.side-filter { padding: 8px 12px; font-size: 14px; }
.side-filter:hover { background: var(--soft); color: var(--green); }
.sidebar-footer { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 12px 10px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #42a879; box-shadow: 0 0 0 4px #e4f3eb; }

main { grid-column: 2; min-width: 0; }
.topbar { height: 80px; padding: 0 38px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 17px; position: sticky; top: 0; z-index: 5; }
.search { flex: 1; max-width: 760px; display: flex; align-items: center; gap: 11px; padding: 10px 15px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); }
.search:focus-within { border-color: #91b29f; box-shadow: 0 0 0 3px rgba(23,108,73,.09); }
.search input { width: 100%; padding: 0; border: 0; outline: 0; background: transparent; }
.ghost { padding: 10px 15px; border-radius: 9px; background: transparent; color: var(--green); font-weight: 650; }
.ghost:hover { background: var(--soft); }
.view { padding: 38px 42px 52px; max-width: 1540px; margin: 0 auto; }
.hidden { display: none !important; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 25px; margin-bottom: 27px; }
.page-head h1 { margin: 0 0 7px; font-size: clamp(28px, 2.6vw, 38px); line-height: 1.08; font-weight: 600; letter-spacing: -.035em; }
.page-head p, .company-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.segmented { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.segmented button { padding: 8px 14px; border-radius: 7px; background: transparent; color: var(--muted); }
.segmented button.active { background: var(--green); color: #fff; box-shadow: 0 3px 9px rgba(23,108,73,.16); }
.filterbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 15px; }
.filterbar select, .filterbar input { min-width: 155px; background: #fff; }

.table-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-small); }
table { width: 100%; border-collapse: collapse; }
th { padding: 0; border-bottom: 1px solid var(--line); background: #f8faf8; color: #6d8177; text-align: left; font-size: 10px; font-weight: 800; letter-spacing: .075em; text-transform: uppercase; }
.sort-button { display: flex; width: 100%; min-height: 43px; align-items: center; justify-content: space-between; gap: 7px; padding: 11px 15px; border: 0; border-radius: 0; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-align: left; text-transform: inherit; cursor: pointer; }
.sort-button:hover, .sort-button.active { background: #edf3ee; color: var(--green); }
.sort-button:focus-visible { position: relative; z-index: 1; outline: 2px solid var(--green); outline-offset: -2px; }
.sort-indicator { font-size: 13px; line-height: 1; }
.mobile-sort-control { display: none; }
td { padding: 15px; border-bottom: 1px solid #e8eee9; font-size: 13px; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background-color .12s ease; }
tbody tr:hover { background: #f6faf7; }
tbody tr:last-child td { border-bottom: 0; }
.reg-number { color: var(--green); font-weight: 800; }
.badge, .source-badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.badge.incoming { background: #e5f2ea; color: #176c49; }
.badge.outgoing { background: #f8eed2; color: #765813; }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.source-badge { background: #edf3ee; color: var(--ink-soft); }
.source-email { background: #e8f1fb; color: #255b85; }
.source-diadoc { background: #fff0e5; color: #98501f; }
.source-paper { background: #e9f5ff; color: #2472a8; }
.source-manual { background: #f1f0ed; color: #615f58; }
.reply-mark { color: var(--gold-hover); font-weight: 900; }
.muted { color: var(--muted); }
.empty { padding: 42px; color: #7a8c83; text-align: center; }
.empty.large { padding: 140px 30px; }

.company-layout { display: grid; grid-template-columns: 285px minmax(0,1fr); min-height: 620px; overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: #fff; box-shadow: var(--shadow-small); }
.company-list { padding: 13px; border-right: 1px solid var(--line); background: #fafcfb; }
.company-card { display: block; width: 100%; padding: 13px; border: 0; border-radius: 11px; background: transparent; text-align: left; cursor: pointer; }
.company-card:hover, .company-card.active { background: var(--soft-strong); }
.company-card.active { box-shadow: inset 3px 0 var(--gold); }
.company-card strong { display: block; margin-bottom: 4px; color: var(--ink); }
.company-card span { color: var(--muted); font-size: 12px; }
.company-workspace { padding: 29px; }
.company-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.company-actions { display: flex; align-items: center; gap: 8px; }
.edit-company { border: 1px solid transparent; }
.company-heading h2 { margin: 0 0 5px; font-size: 26px; font-weight: 600; letter-spacing: -.025em; }
.secondary { padding: 10px 15px; border: 1px solid #b7ccc0; border-radius: 9px; background: #fff; color: var(--green); font-weight: 700; }
.secondary:hover { border-color: var(--green); background: var(--soft); }
.contract-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0; }
.contract-tab { padding: 9px 14px; border: 1px solid transparent; border-radius: 9px; background: var(--soft); color: #53685e; }
.contract-tab:hover { border-color: #b7ccc0; }
.contract-tab.active { border-color: var(--green); background: var(--green); color: #fff; }
.split-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 21px; }
.split-lists section { min-width: 0; }
.split-lists h3 { margin: 0 0 11px; font-size: 14px; }
.split-lists h3 span { color: var(--muted); }
.item-list { min-height: 220px; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; }
.list-item { padding: 14px; border-bottom: 1px solid var(--line); background: #fff; cursor: pointer; }
.list-item:hover { background: #f7faf8; }
.list-item:last-child { border-bottom: 0; }
.list-item strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.list-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.document-row { display: flex; align-items: flex-start; gap: 11px; }
.document-icon { width: 36px; height: 36px; flex: none; border-radius: 9px; background: #e7f1eb; color: var(--green); display: grid; place-items: center; }
.document-info { min-width: 0; flex: 1; }
.ocr-line { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.ocr-badge { display: inline-flex; width: fit-content; padding: 3px 7px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.ocr-pending, .ocr-processing { background: #fff3d6; color: #7a5700; }
.ocr-done { background: var(--green-soft); color: var(--green); }
.ocr-error { background: var(--danger-soft); color: var(--danger); }
.ocr-text { margin: 7px 0; font-size: 12px; }
.ocr-text summary { color: var(--green); cursor: pointer; }
.ocr-text div { max-height: 220px; margin-top: 7px; padding: 9px; overflow: auto; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 8px; background: #fafbf9; color: var(--text); }

.upload-limits { display: flex; gap: 10px; margin: -3px 0 15px; padding: 11px 13px; border: 1px solid #d8c58e; border-radius: 10px; background: #fff9e8; color: #65501b; font-size: 12px; line-height: 1.45; }
.upload-limits strong { flex: none; }
.upload-limits span { color: #65501b; }

.holder-input { width: 100%; margin-top: 8px !important; padding: 7px 9px !important; font-size: 11px !important; }
.inline-link { padding: 0; border: 0; background: transparent; color: var(--green); font: inherit; cursor: pointer; }
.inline-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.queue-section { margin-top: 32px; }
.queue-section:first-of-type { margin-top: 0; }
.queue-section > h2 { margin: 0 0 13px; font-size: 17px; font-weight: 650; }
.queue-section > h2 span { color: var(--muted); font-weight: 500; }
.mail-queue { display: grid; gap: 13px; }
.mail-card { display: grid; grid-template-columns: minmax(0,1fr) 570px; gap: 26px; align-items: center; padding: 20px 22px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: 0 5px 20px rgba(25,59,49,.045); }
.mail-card-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.mail-card h2 { margin: 11px 0 7px; font-size: 17px; font-weight: 650; letter-spacing: -.015em; }
.mail-card-main p { margin: 0; color: var(--muted); font-size: 13px; }
.document-caption { margin-top: 6px !important; font-size: 12px !important; }
.mail-import-error { margin-top: 8px !important; color: var(--danger) !important; font-size: 12px !important; }
.mail-bindings { display: grid; grid-template-columns: minmax(150px,1fr) minmax(150px,1fr) auto; gap: 9px; align-items: end; }
.mail-bindings label { display: grid; gap: 5px; color: #63766c; font-size: 11px; font-weight: 700; }
.mail-bindings select { width: 100%; min-width: 0; }
.mail-bindings .field-with-action { min-width: 0; }
.mail-bindings .field-add { padding-inline: 9px; }
.mail-bindings .primary { height: 42px; white-space: nowrap; }
.mail-error { grid-column: 1/-1; color: var(--danger); font-size: 12px; }
.mail-empty { border: 1px solid var(--line); border-radius: 17px; background: #fff; }

.modal { width: min(520px,calc(100vw - 40px)); padding: 0; border: 0; border-radius: 20px; color: var(--ink); box-shadow: 0 35px 100px rgba(10,35,27,.27); }
.modal.wide { width: min(800px,calc(100vw - 40px)); }
.modal.detail-modal { width: min(740px,calc(100vw - 40px)); }
.modal::backdrop { background: rgba(18,43,34,.55); backdrop-filter: blur(2px); }
.modal form, .detail-body { padding: 27px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 21px; }
.modal-head h2 { margin: 0 0 5px; font-size: 25px; font-weight: 600; letter-spacing: -.025em; }
.modal-head p { margin: 0; color: var(--muted); font-size: 13px; }
.icon { padding: 0; background: transparent; color: #708179; font-size: 27px; line-height: 1; }
.direction-picker { display: flex; gap: 19px; margin-bottom: 17px; padding: 13px; border-radius: 10px; background: var(--soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.modal label { display: grid; gap: 6px; margin-bottom: 13px; color: #53685e; font-size: 12px; font-weight: 700; }
.field-with-action { display: flex; gap: 6px; }
.field-with-action select { min-width: 0; flex: 1; }
.field-add { padding: 0 11px; border: 1px solid #bdd0c3; border-radius: 8px; background: #f4f8f5; color: var(--green); font: inherit; font-size: 11px; font-weight: 750; cursor: pointer; white-space: nowrap; }
.field-add:hover { border-color: var(--green); background: #e8f1eb; }
.field-hint { color: #86958e; font-size: 10px; font-weight: 400; }
input, select, textarea { padding: 10px 11px; border: 1px solid #becfc3; border-radius: 9px; outline: 0; background: #fff; color: var(--ink); }
input::placeholder, textarea::placeholder { color: #85948d; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,108,73,.1); }
textarea { resize: vertical; }
.file-drop { padding: 14px; border: 1px dashed #9fb8a8; border-radius: 11px; background: #fafcfb; }
.file-drop span { color: var(--muted); font-weight: 400; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-error { margin-top: 8px; padding: 11px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

.detail-top { padding: 27px; border-bottom: 1px solid var(--line); background: var(--soft); }
.detail-top h2 { margin: 7px 0 9px; font-size: 28px; font-weight: 600; letter-spacing: -.025em; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 15px; color: var(--muted); font-size: 12px; }
.detail-section { margin-top: 21px; }
.detail-section h3 { font-size: 13px; }
.detail-text { color: #465c51; line-height: 1.6; white-space: pre-wrap; }
.detail-doc { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 10px; }
.detail-doc-main { min-width: 0; flex: 1; }
.detail-doc-main > a { color: var(--green); text-decoration: none; }
.detail-doc a { min-width: 0; flex: 1; color: var(--green); text-decoration: none; }
.detail-doc input { width: 220px; }
.thread-link { display: flex; align-items: center; gap: 8px; margin-bottom: 17px; padding: 12px 13px; border-radius: 10px; background: #e8f1eb; color: #53685e; font-size: 12px; }
.thread-link button, .thread-list button { border: 0; background: transparent; color: var(--green); font: inherit; text-align: left; cursor: pointer; }
.thread-link button:hover, .thread-list button:hover { text-decoration: underline; text-underline-offset: 3px; }
.thread-list { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; }
.thread-list button { display: grid; gap: 4px; padding: 11px 13px; border-bottom: 1px solid var(--line); }
.thread-list button:last-child { border-bottom: 0; }
.thread-list span { color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 26px; bottom: 26px; z-index: 30; padding: 13px 19px; border-radius: 10px; background: var(--green-deep); color: #fff; box-shadow: var(--shadow); }

@media (max-width: 1360px) {
  .mail-card { grid-template-columns: 1fr; }
  .split-lists { grid-template-columns: 1fr; }
  .view { padding-inline: 30px; }
}
@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 240px minmax(0,1fr); }
  .sidebar { width: 240px; padding-inline: 15px; }
  .brand-name { font-size: 21px; }
  .view { padding: 30px 24px 45px; }
  .mail-bindings { grid-template-columns: 1fr 1fr; }
  .mail-bindings > .primary { grid-column: 1/-1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
.current-user { color: var(--muted); font-size: 13px; white-space: nowrap; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.admin-card { padding: 20px; }
.admin-card.full { grid-column: 1 / -1; }
.admin-card h2 { margin: 0 0 16px; }
.inline-form { display: grid; grid-template-columns: 1fr 1.5fr 1.2fr 1fr auto; gap: 8px; margin-bottom: 16px; }
.login-modal { width: min(420px, calc(100vw - 32px)); }
.login-modal .primary { width: 100%; margin-top: 12px; }
@media (max-width: 1000px) {
  .admin-grid { grid-template-columns: 1fr; }
  .admin-card.full { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
  .current-user { display: none; }
}

.sidebar-footer.status-error { color: #ffb4ab; }
.sidebar-footer.status-error .status-dot { background: #e25555; box-shadow: 0 0 0 4px rgba(226,85,85,.15); }

.user-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.user-row > div:first-child { display: flex; flex-direction: column; gap: 4px; }
.user-controls { display: flex; gap: 8px; align-items: center; }
.login-modal form > .ghost { width: 100%; margin-top: 8px; }
@media (max-width: 700px) { .user-row, .user-controls { align-items: stretch; flex-direction: column; } }
.password-field { display: flex; align-items: stretch; gap: 0; }
.password-field input { flex: 1; min-width: 0; border-radius: 8px 0 0 8px; }
.password-icon { border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: #fff; color: var(--green-dark); padding: 0 10px; cursor: pointer; font-size: 12px; }
.password-generate { border: 0; background: transparent; color: var(--brand); padding: 5px 0 0; cursor: pointer; font-size: 12px; text-align: left; }
.password-strength { display: block; color: var(--muted); font-size: 11px; line-height: 1.35; margin-top: 4px; }
.password-strength.weak { color: #b42318; }
.password-strength.medium { color: #a15c00; }
.password-strength.strong { color: #16794b; font-weight: 600; }
.inline-form .password-field { min-width: 190px; }
.inline-form .password-generate, .inline-form .password-strength { align-self: center; }
/* Responsive shell and mobile navigation */
.brand { width: calc(100% - 16px); padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.brand-copy { display: block; }
.mobile-menu, .menu-backdrop { display: none; }
.sidebar-links { display: flex; flex-wrap: wrap; gap: 5px 12px; padding: 10px; font-size: 11px; color: var(--muted); }
.sidebar-links a { text-decoration: none; }
.sidebar-links a:hover { color: var(--green); text-decoration: underline; }

@media (max-width: 1000px) {
  body { min-width: 0; overflow-x: hidden; }
  .app-shell { display: block; min-width: 0; }
  main { width: 100%; min-width: 0; }
  .sidebar { width: min(310px, 86vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 12px 0 35px rgba(25,59,49,.18); }
  body.menu-open .sidebar { transform: translateX(0); }
  .menu-backdrop { position: fixed; inset: 0; z-index: 9; border: 0; background: rgba(18,43,34,.45); }
  body.menu-open .menu-backdrop { display: block; }
  .mobile-menu { display: grid; width: 42px; height: 42px; flex: none; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--green); font-size: 22px; cursor: pointer; }
  .topbar { height: auto; min-height: 70px; padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar .search { order: 3; width: 100%; max-width: none; flex-basis: 100%; }
  .topbar > .ghost { padding-inline: 10px; }
  .view { width: 100%; padding: 24px 16px 40px; overflow: hidden; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 14px; }
  .segmented { width: 100%; overflow: hidden; }
  .segmented button { flex: 1; padding-inline: 8px; }
  .filterbar { display: grid; grid-template-columns: 1fr 1fr; }
  .filterbar select, .filterbar input { width: 100%; min-width: 0; }
  .mobile-sort-control { display: block; }
  .table-card { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .table-card table, .table-card tbody, .table-card tr, .table-card td { display: block; width: 100%; }
  .table-card thead { display: none; }
  .table-card tbody { display: grid; gap: 12px; }
  .table-card tbody tr { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow-small); }
  .table-card td { display: grid; grid-template-columns: minmax(105px, 36%) 1fr; gap: 10px; padding: 9px 13px; border-bottom: 1px solid #edf1ee; overflow-wrap: anywhere; }
  .table-card td::before { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
  .table-card td:nth-child(1)::before { content: "Номер"; }
  .table-card td:nth-child(2)::before { content: "Дата"; }
  .table-card td:nth-child(3)::before { content: "Направление"; }
  .table-card td:nth-child(4)::before { content: "Источник"; }
  .table-card td:nth-child(5)::before { content: "Компания"; }
  .table-card td:nth-child(6)::before { content: "Договор"; }
  .table-card td:nth-child(7)::before { content: "Тема"; }
  .table-card td:nth-child(8)::before { content: "Документы"; }
  .table-card td:nth-child(9)::before { content: "Оригинал"; }
  .company-layout { display: block; min-height: 0; overflow: visible; }
  .company-list { display: flex; gap: 8px; overflow-x: auto; border: 0; border-bottom: 1px solid var(--line); }
  .company-card { min-width: 220px; }
  .company-workspace { padding: 20px 14px; }
  .company-heading, .company-actions { align-items: flex-start; flex-direction: column; }
  .company-actions { width: 100%; }
  .company-actions button { width: 100%; }
  .contract-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 5px; }
  .contract-tab { flex: none; }
  .split-lists { grid-template-columns: 1fr; }
  .mail-card { padding: 16px; }
  .mail-bindings { grid-template-columns: 1fr; }
  .mail-bindings > .primary { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .modal, .modal.wide, .modal.detail-modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); overflow-y: auto; }
  .modal form, .detail-body, .detail-top { padding: 20px 16px; }
  .detail-doc { align-items: stretch; flex-direction: column; }
  .detail-doc input { width: 100%; }
  .toast { right: 12px; bottom: 12px; left: 12px; text-align: center; }
  .admin-card { padding: 14px; }
  .current-user { display: none; }
}
@media (max-width: 520px) {
  .filterbar { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 28px; }
  .topbar #refresh { display: none; }
  .modal-actions { align-items: stretch; flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}
.info-page { min-width: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--soft); }
.info-card { width: min(620px, 100%); padding: clamp(24px, 5vw, 50px); border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.info-card h1 { margin: 22px 0 10px; font-size: clamp(30px, 7vw, 46px); line-height: 1.1; }
.info-card h2 { margin: 24px 0 6px; font-size: 20px; }
.info-card p, .info-card li { color: var(--ink-soft); }
.info-card a:not(.primary):not(.secondary) { color: var(--green); }
.info-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-size: 20px; }
.error-code { margin: 28px 0 -20px !important; color: var(--gold-hover) !important; font-size: 18px; font-weight: 800; }
.info-action { display: inline-block; margin-top: 20px; text-decoration: none; }
.legal-card { width: min(760px, 100%); }
.legal-card ol { padding-left: 22px; }

.toast.error { background: var(--danger); }
.user-identity { min-width: 180px; flex: 1; }
.user-identity input { width: 100%; }
.session-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.session-row > div { min-width: 0; }
.session-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .session-row { align-items: stretch; flex-direction: column; } }

.queue-preview-button { display: inline-block; margin-top: 12px; padding: 8px 11px; font-size: 12px; text-decoration: none; }
.queue-preview { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbf9; color: #253b31; }
.queue-preview-meta { margin-bottom: 10px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.queue-preview-text { max-height: 240px; overflow: auto; padding: 12px; border-radius: 9px; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.queue-preview-files { display: grid; gap: 7px; margin-top: 12px; }
.queue-preview-files a { display: flex; justify-content: space-between; gap: 14px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--green); text-decoration: none; }
.queue-preview-files a:hover { border-color: var(--green); }
.queue-preview-files small { color: var(--muted); white-space: nowrap; }
@media (max-width: 640px) {
  .queue-preview-files a { align-items: flex-start; flex-direction: column; gap: 3px; }
  .queue-preview-files small { white-space: normal; }
}

/* Refined application layout */
.view {
  max-width: 1480px;
  padding: 34px 36px 52px;
}
.page-head {
  align-items: center;
  margin-bottom: 22px;
}
.page-head h1 {
  font-size: clamp(30px, 2.4vw, 38px);
  font-weight: 650;
  letter-spacing: -.04em;
}
.filterbar {
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.8);
}
.filterbar select,
.filterbar input {
  min-width: 150px;
  min-height: 40px;
  border-color: #cad8cf;
  background-color: #fff;
}
.table-card {
  overflow-x: auto;
  border-radius: 14px;
  box-shadow: 0 6px 22px rgba(25,59,49,.055);
}
.table-card table {
  min-width: 1050px;
  table-layout: fixed;
}
.table-card th:nth-child(1) { width: 108px; }
.table-card th:nth-child(2) { width: 120px; }
.table-card th:nth-child(3) { width: 106px; }
.table-card th:nth-child(4) { width: 92px; }
.table-card th:nth-child(5) { width: 142px; }
.table-card th:nth-child(6) { width: 126px; }
.table-card th:nth-child(8) { width: 82px; }
.table-card th:nth-child(9) { width: 132px; }
.sort-button {
  min-height: 46px;
  padding: 12px;
  justify-content: flex-start;
}
.sort-indicator {
  margin-left: 2px;
  color: #91a198;
  font-size: 11px;
}
.sort-button.active .sort-indicator { color: var(--green); }
td {
  padding: 14px 12px;
  color: #29443a;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
td:nth-child(1),
td:nth-child(2),
td:nth-child(3),
td:nth-child(4),
td:nth-child(8) {
  white-space: nowrap;
}
tbody tr:hover { background: #f3f8f5; }
.reg-number { font-size: 12px; letter-spacing: .01em; }

/* Correspondence detail */
.modal.detail-modal {
  width: min(880px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  border-radius: 18px;
}
#detail-content {
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
.detail-top {
  padding: 28px 30px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f6faf7 0%, #f1f6f3 100%);
}
.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.detail-title {
  min-width: 0;
  flex: 1;
}
.detail-kickers {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.detail-top h2 {
  max-width: 690px;
  margin: 12px 0 10px;
  color: #173d31;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.16;
}
.detail-close {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
}
.detail-close:hover { background: #e2ebe5; }
.detail-meta {
  gap: 8px 18px;
  align-items: center;
}
.detail-number {
  color: var(--green-dark);
  font-weight: 800;
}
.detail-body {
  padding: 26px 30px 32px;
}
.detail-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
}
.detail-facts:empty { display: none; }
.detail-facts > div {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid #e1e9e3;
  border-radius: 10px;
  background: #fafcfb;
}
.detail-facts span,
.detail-holder span {
  color: #778a80;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.detail-facts b {
  color: #27463b;
  font-size: 13px;
  font-weight: 650;
}
.detail-section {
  margin-top: 25px;
}
.detail-section h3 {
  margin: 0 0 10px;
  color: #24453a;
  font-size: 14px;
  font-weight: 750;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title h3 { margin: 0; }
.section-title > span {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 99px;
  background: #edf3ef;
  color: #61776c;
  font-size: 11px;
  font-weight: 750;
}
.detail-text {
  padding: 16px 18px;
  border: 1px solid #e3eae5;
  border-radius: 11px;
  background: #fbfcfb;
  color: #425a50;
  font-size: 14px;
  line-height: 1.65;
}
.detail-documents {
  display: grid;
  gap: 9px;
  margin-top: 11px;
}
.detail-doc {
  display: grid;
  grid-template-columns: 38px minmax(0,1fr) 220px;
  gap: 13px;
  align-items: center;
  margin: 0;
  padding: 13px 14px;
  border-color: #dfe8e2;
  border-radius: 11px;
  background: #fff;
}
.detail-file-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 9px;
  background: #edf5f0;
  color: var(--green);
  font-size: 18px;
}
.detail-doc-main > a {
  display: block;
  overflow: hidden;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-doc-main .ocr-line {
  margin: 5px 0 0;
}
.detail-holder {
  display: grid;
  gap: 5px;
  margin: 0 !important;
}
.detail-holder input {
  width: 100%;
  padding: 9px 10px;
  font-size: 12px;
}
.ocr-view-button {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.ocr-view-button:hover { text-decoration: underline; text-underline-offset: 3px; }

/* OCR viewer */
.modal.ocr-modal {
  width: min(900px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  border-radius: 18px;
}
.ocr-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--line);
  background: #f6faf7;
}
.ocr-modal-head h2 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.25;
}
.eyebrow {
  color: #74877d;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.ocr-document-text {
  max-height: calc(100vh - 145px);
  margin: 0;
  padding: 24px 27px 30px;
  overflow: auto;
  background: #fff;
  color: #243f35;
  font: 13px/1.65 "Segoe UI", Arial, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Administration */
.admin-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  gap: 16px;
  align-items: start;
}
.admin-card {
  padding: 22px;
  border-radius: 16px;
}
.admin-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 17px;
}
.admin-card-head h2,
.admin-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.admin-card-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.admin-user-form {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid #e0e9e3;
  border-radius: 12px;
  background: #f8faf9;
}
.admin-form-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1.35fr);
  gap: 12px;
  align-items: end;
}
.admin-form-grid label {
  display: grid;
  gap: 5px;
  margin: 0;
}
.admin-form-grid label > span {
  color: #63776d;
  font-size: 11px;
  font-weight: 700;
}
.admin-form-grid input,
.admin-form-grid select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
}
.admin-password {
  grid-column: 1 / -1;
}
.admin-password .password-generate {
  width: fit-content;
  padding-top: 2px;
}
.admin-password .password-strength {
  min-height: 15px;
  margin: 0;
}
.admin-add-user {
  width: 100%;
  min-height: 42px;
}
.admin-list {
  min-height: 0;
  max-height: 430px;
  overflow-y: auto;
  border-radius: 11px;
}
.sync-list { max-height: 540px; }
.user-row {
  align-items: flex-start;
  padding: 13px;
}
.user-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
}
.user-controls select {
  min-width: 145px;
}
.user-controls .ghost,
.user-controls .secondary {
  padding: 8px 10px;
  font-size: 12px;
}
.user-identity input {
  padding: 8px 9px;
  font-weight: 650;
}
.admin-card.full .item-list {
  min-height: 0;
  max-height: 360px;
  overflow-y: auto;
}
.users-card-head { align-items: center; }
.users-head-actions { display: flex; align-items: center; gap: 12px; }
.users-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.users-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 190px;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #e0e9e3;
  border-radius: 12px;
  background: #f8faf9;
}
.users-toolbar label,
.user-account-fields label { display: grid; gap: 5px; margin: 0; }
.users-toolbar label > span,
.user-account-fields label > span {
  color: #63776d;
  font-size: 11px;
  font-weight: 700;
}
.users-toolbar input,
.users-toolbar select,
.user-account-fields input,
.user-account-fields select { width: 100%; min-width: 0; min-height: 40px; }
.user-account-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.user-account-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #dce6df;
  border-radius: 14px;
  background: #fff;
}
.user-account-head {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid #e7ede9;
  background: #fbfcfb;
}
.user-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: #e4f1ea;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}
.user-account-title { min-width: 0; }
.user-account-title h3 {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-account-title span { color: var(--muted); font-size: 12px; }
.account-status {
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
}
.account-status.active { background: #e4f3ea; color: #167146; }
.account-status.inactive { background: #f0f1f0; color: #6c746f; }
.user-account-meta {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 1px;
  border-bottom: 1px solid #e7ede9;
  background: #e7ede9;
}
.user-account-meta > div { min-width: 0; padding: 10px 12px; background: #fff; }
.user-account-meta span,
.user-account-meta strong { display: block; }
.user-account-meta span { margin-bottom: 2px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.user-account-meta strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.user-account-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(150px, .8fr);
  gap: 10px;
  padding: 14px 15px;
}
.user-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  padding: 0 15px 15px;
}
.user-account-actions button { min-height: 36px; padding: 7px 10px; font-size: 11px; }
.user-account-actions .user-delete { margin-left: auto; }
.own-account-note { margin-left: auto; color: var(--muted); font-size: 11px; }
.users-empty { grid-column: 1 / -1; }

@media (max-width: 1180px) {
  .admin-grid { grid-template-columns: 1fr; }
  .admin-card.full { grid-column: auto; }
  .user-account-list { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) {
  .view { padding: 26px 18px 42px; }
  .table-card table { min-width: 0; table-layout: auto; }
  .detail-doc {
    grid-template-columns: 38px minmax(0,1fr);
  }
  .detail-holder {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .detail-top,
  .detail-body {
    padding: 20px 16px;
  }
  .detail-facts,
  .admin-form-grid {
    grid-template-columns: 1fr;
  }
  .admin-password { grid-column: auto; }
  .users-card-head,
  .users-head-actions { align-items: stretch; flex-direction: column; }
  .users-head-actions { display: flex; }
  .users-toolbar,
  .user-account-fields { grid-template-columns: 1fr; }
  .user-account-head { grid-template-columns: 38px minmax(0, 1fr); }
  .user-avatar { width: 38px; height: 38px; }
  .account-status { grid-column: 2; justify-self: start; }
  .user-account-meta { grid-template-columns: 1fr; }
  .user-account-actions { align-items: stretch; flex-direction: column; }
  .user-account-actions button { width: 100%; }
  .user-account-actions .danger-link,
  .own-account-note { margin-left: 0; text-align: center; }
  .detail-doc {
    grid-template-columns: 34px minmax(0,1fr);
    padding: 12px;
  }
  .ocr-modal-head { padding: 18px 16px 14px; }
  .ocr-document-text { padding: 18px 16px 24px; }
}

.subject-cell {
  display: -webkit-box;
  overflow: hidden;
  line-height: 1.4;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid #e4eae6;
}
.danger-link {
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.danger-link:hover { background: var(--danger-soft); }
.modal.confirm-modal {
  width: min(460px, calc(100vw - 32px));
  border-radius: 18px;
}
.confirm-modal form {
  padding: 28px;
  text-align: center;
}
.confirm-icon {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 21px;
  font-weight: 850;
}
.confirm-modal h2 {
  margin: 0 0 9px;
  font-size: 23px;
}
.confirm-modal p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
#delete-correspondence-summary b,
#delete-correspondence-summary span {
  display: block;
}
#delete-correspondence-summary b {
  color: var(--ink);
  font-size: 14px;
}
#delete-correspondence-summary span {
  margin-top: 3px;
}
.confirm-warning {
  margin-top: 15px !important;
  padding: 11px 12px;
  border-radius: 9px;
  background: #faf6f5;
  color: #76534f !important;
}
.danger-button {
  min-height: 42px;
  padding: 10px 17px;
  border: 0;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
.danger-button:hover { background: #8f3e37; }
.danger-button:disabled { cursor: wait; opacity: .55; }
.confirm-modal .modal-actions {
  justify-content: center;
  margin-top: 20px;
}
