:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e1ec;
  --text: #172033;
  --muted: #65748b;
  --accent: #1876d1;
  --accent-strong: #0e5fab;
  --good: #12805c;
  --warn: #a45b00;
  --danger: #c93434;
  --ink-blue: #183c64;
  --teal: #0b7285;
  --rose: #b4235a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}

.app-shell.sidebar-open {
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 240px;
  padding: 22px 16px;
  color: #eaf5ff;
  background: #16344f;
  transition: width 0.18s ease, box-shadow 0.18s ease;
  z-index: 4;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar {
  width: 72px;
  padding-inline: 12px;
  overflow: hidden;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover {
  width: 240px;
  box-shadow: 10px 0 28px rgba(17, 39, 61, 0.22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.sidebar-toggle {
  display: grid;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 7px;
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: #eaf5ff;
  border-radius: 999px;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .brand {
  padding-inline: 0;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .brand-mark,
.app-shell.sidebar-collapsed:not(.sidebar-open) .brand-title,
.app-shell.sidebar-collapsed:not(.sidebar-open) .brand-subtitle,
.app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item span:not(.nav-icon),
.app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item strong,
.app-shell.sidebar-collapsed:not(.sidebar-open) .sync-card > div {
  display: none;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .brand-mark,
.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .brand-title,
.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .brand-subtitle,
.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .nav-item span:not(.nav-icon),
.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .nav-item strong,
.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .sync-card > div {
  display: block;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #12314e;
  background: #72d4ff;
  border-radius: 8px;
  font-weight: 800;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle,
.sync-text,
.crumb {
  color: var(--muted);
  font-size: 13px;
}

.brand-subtitle {
  color: #b7c7d9;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 7px 10px;
  color: #dfeeff;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item {
  grid-template-columns: 28px;
  justify-content: center;
  padding-inline: 10px;
}

.app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar:hover .nav-item {
  grid-template-columns: 28px 1fr auto;
  justify-content: stretch;
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
}

.nav-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.nav-item strong {
  min-width: 24px;
  padding: 3px 6px;
  text-align: center;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: 12px;
}

.sync-card,
.filter-sync-state {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-card {
  align-items: flex-start;
  margin-top: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.sync-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  background: #63d79b;
  border-radius: 50%;
}

.sync-dot-running {
  background: #ffd166;
}

.sync-dot-error {
  background: #ff6b6b;
}

.sync-title {
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 22px 24px 28px;
}

.topbar,
.topbar-actions,
.filters,
.role-switch,
.quick-actions,
.thread-head,
.message-meta {
  display: flex;
  align-items: center;
}

.topbar {
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.crumb {
  margin: 0 0 6px;
}

h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar-actions {
  gap: 12px;
}

.role-switch {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.role-button {
  min-width: 100px;
  padding: 9px 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}

.role-button.active {
  color: #fff;
  background: var(--accent);
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}

.primary-button {
  padding: 10px 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.quick-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.quick-filter {
  min-height: 40px;
  padding: 8px 16px;
  color: #52627a;
  background: #eef2f6;
  border: 2px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}

.quick-filter strong {
  color: inherit;
}

.quick-filter.active {
  color: #4c5a6f;
  background: #fff;
  border-color: #6e7785;
}

.quick-filter.blue {
  color: #2368df;
  background: #eaf2ff;
}

.quick-filter.amber {
  color: #b36a00;
  background: #fff0d7;
}

.quick-filter.red {
  color: #c93434;
  background: #ffe5e5;
}

.quick-filter.green {
  color: #12805c;
  background: #def6eb;
}

.quick-filter.blue.active,
.quick-filter.amber.active,
.quick-filter.red.active,
.quick-filter.green.active {
  border-color: currentColor;
}

.filters {
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.filter-sync-state {
  margin-left: auto;
  min-height: 34px;
  padding: 0 8px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  white-space: nowrap;
}

.filter-sync-state .sync-dot {
  flex: 0 0 auto;
  margin-top: 0;
}

.search-box {
  display: flex;
  flex: 0 1 260px;
  align-items: center;
  gap: 6px;
  min-width: 220px;
  padding: 0 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.search-box input {
  width: 100%;
  height: 32px;
  background: transparent;
  border: 0;
  outline: none;
}

select,
.check-filter,
.settings-block input,
.settings-block select,
.template-editor input,
.template-editor textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

select {
  height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

.filters select {
  max-width: 170px;
}

.check-filter {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  font-size: 13px;
  padding: 0 8px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 13px;
}

.content-grid {
  display: block;
}

.table-shell,
.thread-panel,
.report-view,
.templates-view,
.settings-view {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-shell {
  overflow-x: hidden;
}

.mail-list {
  width: 100%;
}

.mail-list-head,
.mail-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.mail-list-head {
  padding: 10px 12px;
  color: var(--muted);
  background: #eef3f8;
  font-size: 12px;
  text-transform: uppercase;
}

.mail-row {
  position: relative;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.mail-row:hover,
.mail-row.selected {
  background: #f2f8ff;
}

.zone-indicators {
  display: flex;
  flex: 0 0 26px;
  align-items: center;
  gap: 4px;
}

.zone-avatar {
  display: flex;
  flex: 0 0 32px;
  align-items: center;
  justify-content: center;
}

.zone-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.zone-sla {
  display: flex;
  flex: 0 0 96px;
  justify-content: center;
  min-width: 0;
  padding: 0 4px;
}

.zone-crm {
  display: flex;
  flex: 0 0 78px;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding-right: 4px;
}

.zone-manager {
  display: flex;
  flex: 0 0 28px;
  align-items: center;
  gap: 4px;
}

.zone-time {
  flex: 0 0 44px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.mail-list-head .zone-main,
.mail-list-head .zone-sla,
.mail-list-head .zone-crm,
.mail-list-head .zone-time {
  font-weight: 700;
}

th {
  padding: 12px 12px;
  color: var(--muted);
  background: #eef3f8;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  padding: 12px 12px;
  border-top: 1px solid var(--line);
  vertical-align: top;
  overflow: hidden;
  min-width: 0;
}

th {
  min-width: 0;
  overflow: hidden;
}

tr {
  cursor: pointer;
}

tr:hover,
tr.selected {
  background: #f2f8ff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 4px 8px;
  overflow: hidden;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-unopened {
  color: #0d5481;
  background: #dff2ff;
}

.status-waiting_reply {
  color: var(--warn);
  background: #fff0d6;
}

.status-overdue {
  color: var(--danger);
  background: #ffe1e1;
}

.status-processed_by_email,
.status-processed_by_call {
  color: var(--good);
  background: #dcf6eb;
}

.status-no_reply_required {
  color: #665100;
  background: #f7ecc0;
}

.status-unassigned {
  color: var(--rose);
  background: #ffe3ee;
}

.status-demo {
  color: #4a5568;
  background: #edf2f7;
}

.status-configured,
.status-ready {
  color: var(--good);
  background: #dcf6eb;
}

.status-blocked {
  color: var(--danger);
  background: #ffe1e1;
}

.status-passed {
  color: var(--good);
  background: #dcf6eb;
}

.status-needs_real_check {
  color: var(--warn);
  background: #fff0d6;
}

.subject-main {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.client-sub {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.summary-item a {
  color: var(--accent);
  text-decoration: none;
}

.summary-item a:hover {
  text-decoration: underline;
}

/* Строка письма (редизайн триажа) */

.unread-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  background: transparent;
  border-radius: 50%;
}

.unread-dot.is-unread {
  background: var(--accent);
}

.priority-flag {
  flex: 0 0 auto;
  padding: 0;
  color: #c7cbd4;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.priority-flag.is-active {
  color: var(--warn);
}

.avatar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}

.avatar-sm {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

.main-line1 {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.main-line1 .line1-client {
  font-weight: 500;
}

.main-line2 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.main-preview {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.main-meta {
  flex: 0 0 auto;
  white-space: nowrap;
}

.sla-pill {
  max-width: 100%;
  overflow: hidden;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  text-align: center;
  text-overflow: ellipsis;
}

.sla-overdue {
  color: var(--danger);
  background: #ffe1e1;
}

.sla-warning {
  color: var(--warn);
  background: #fff0d6;
}

.sla-success {
  color: var(--good);
  background: #dcf6eb;
}

.sla-muted {
  color: var(--muted);
  background: transparent;
}

.sla-unassigned {
  color: var(--rose);
  background: #ffe3ee;
}

.crm-chip {
  overflow: hidden;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 700;
  font-size: 12px;
}

a.crm-chip:hover {
  text-decoration: underline;
}

span.crm-chip {
  color: var(--muted);
}

.crm-sync-icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: var(--good);
  font-size: 11px;
}

.crm-sync-icon.is-unsynced {
  color: var(--warn);
}

.channel-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: #fff;
  background: #93a2b8;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 800;
}

.row-actions {
  position: absolute;
  top: 50%;
  right: 12px;
  display: none;
  align-items: center;
  gap: 4px;
  padding-left: 10px;
  background: linear-gradient(to right, transparent, #f2f8ff 18%);
  transform: translateY(-50%);
}

.mail-row:hover .row-actions {
  display: flex;
}

.row-action-btn {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.row-action-btn:hover {
  color: var(--accent-strong);
  border-color: #b9c7d8;
}

@media (max-width: 1280px) {
  th,
  td {
    padding-inline: 10px;
  }

  .status-pill,
  .client-sub {
    font-size: 11px;
  }

  .subject-main {
    font-size: 14px;
  }

  .zone-sla {
    flex-basis: 84px;
  }

  .zone-crm {
    flex-basis: 68px;
  }
}

@media (max-width: 980px) {
  .thread-topline {
    display: grid;
  }

  .thread-files {
    justify-content: flex-start;
    max-width: none;
  }
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.thread-head {
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.thread-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.summary-item {
  padding: 10px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  display: block;
  margin-top: 5px;
}

.thread-head h2 {
  margin: 0 0 5px;
  font-size: 18px;
}

.quick-actions {
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.thread-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.thread-topline .quick-actions {
  margin: 0;
}

.thread-files {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 360px;
}

.thread-file {
  display: grid;
  gap: 5px;
  max-width: 150px;
  min-height: 54px;
  padding: 8px 10px;
  color: #111827;
  background: #e8e8ea;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.2;
  text-decoration: none;
}

.thread-file span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.thread-file strong {
  width: max-content;
  padding: 2px 5px;
  color: #fff;
  background: var(--accent-strong);
  border-radius: 3px;
  font-size: 12px;
}

.thread-file[href]:hover {
  background: #dcecff;
}

.thread-file-disabled {
  cursor: default;
  opacity: 0.72;
}

.thread-file small {
  color: var(--muted);
  font-size: 11px;
}

.secondary-button,
.icon-button {
  padding: 8px 10px;
  color: var(--accent-strong);
  background: #eef7ff;
  border-color: #cce5fb;
  font-weight: 700;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
}

.message {
  margin-top: 12px;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.message.outgoing {
  background: #eefaf6;
}

.message img {
  display: block;
  max-width: min(100%, 720px);
  height: auto;
  margin-top: 8px;
  border: 1px solid var(--line);
}

.message-meta {
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.attachment {
  display: inline-flex;
  margin-top: 10px;
  padding: 6px 8px;
  color: var(--accent-strong);
  background: #e6f2ff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

a.attachment:hover {
  text-decoration: underline;
}

.composer-box {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  padding: 14px;
  background: #f6fbff;
  border: 1px solid #cce5fb;
  border-radius: 8px;
}

.composer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.composer-head span,
.action-note {
  color: var(--muted);
  font-size: 12px;
}

.composer-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
}

.composer-box textarea {
  width: 100%;
  min-height: 112px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: vertical;
}

.audit-box {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  padding: 12px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.audit-line {
  color: var(--muted);
  font-size: 13px;
}

.report-view,
.templates-view,
.settings-view,
.audit-view,
.checks-view {
  padding: 16px;
}

.audit-view,
.checks-view {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.audit-toolbar {
  margin-bottom: 12px;
}

.report-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.report-card,
.settings-block {
  padding: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-card span {
  display: block;
  color: var(--muted);
}

.report-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.report-slices {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.slice-card {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.slice-card h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.slice-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.slice-row strong {
  color: var(--text);
}

.template-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

.template-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.template-item {
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.template-item.active {
  border-color: var(--accent);
  background: #eef7ff;
}

.template-editor {
  display: grid;
  gap: 10px;
}

.section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.template-editor input {
  height: 40px;
  padding: 0 10px;
}

.template-editor textarea {
  min-height: 170px;
  padding: 12px;
  resize: vertical;
}

.variable-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 8px;
}

.variable {
  padding: 8px;
  background: #f3f7fb;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
}

.variable code {
  display: block;
  color: var(--text);
  font-weight: 700;
}

.warning-line {
  min-height: 22px;
  color: var(--warn);
  font-weight: 700;
}

.input-error {
  border-color: var(--danger) !important;
}

.settings-block h2 {
  margin: 0 0 12px;
  font-size: 17px;
}

.settings-block label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.settings-block .inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-block .inline-check input {
  width: auto;
}

.settings-block input,
.settings-block select,
.settings-block textarea {
  width: 100%;
  padding: 0 10px;
  color: var(--text);
}

.settings-block input,
.settings-block select {
  height: 38px;
}

.settings-block textarea {
  min-height: 138px;
  padding: 10px;
  resize: vertical;
}

.settings-note,
.settings-status {
  margin-top: 10px;
  padding: 9px 10px;
  color: var(--muted);
  background: #eef3f8;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.35;
}

.settings-status {
  grid-column: 1 / -1;
  color: #10456f;
  background: #e8f4ff;
  border-color: #b9daf8;
}

.settings-note-ok {
  color: var(--good);
  background: #e9f8f2;
  border-color: #b9e8d6;
}

.settings-note-warn {
  color: var(--warn);
  background: #fff5e8;
  border-color: #efd3aa;
}

.settings-save {
  margin-top: 14px;
}

.reason-list {
  line-height: 1.8;
  color: var(--muted);
}

.hidden {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 10px;
  background: rgba(15, 29, 45, 0.48);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(1480px, calc(100vw - 20px));
  height: calc(100vh - 20px);
  max-height: calc(100vh - 20px);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(15, 29, 45, 0.24);
}

.modal-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #f7fafc;
}

.modal-toolbar h2 {
  margin: 0;
  font-size: 22px;
}

.modal-toolbar h2 span {
  display: block;
}

.modal-client-line {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.modal-status-slot {
  margin-left: auto;
  padding-top: 3px;
  white-space: nowrap;
}

.close-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.close-button:hover {
  color: var(--text);
  border-color: #b9c7d8;
}

#modalContent {
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 18px 20px 20px;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .template-layout {
    grid-template-columns: 1fr;
  }

  .report-grid,
  .settings-grid,
  .variable-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell,
  .app-shell.sidebar-collapsed,
  .app-shell.sidebar-open {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .app-shell.sidebar-collapsed:not(.sidebar-open) .sidebar {
    position: static;
    width: 100%;
    padding: 16px;
    overflow: visible;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell.sidebar-collapsed:not(.sidebar-open) .brand-mark,
  .app-shell.sidebar-collapsed:not(.sidebar-open) .brand-title,
  .app-shell.sidebar-collapsed:not(.sidebar-open) .brand-subtitle,
  .app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item span:not(.nav-icon),
  .app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item strong,
  .app-shell.sidebar-collapsed:not(.sidebar-open) .sync-card > div {
    display: block;
  }

  .app-shell.sidebar-collapsed:not(.sidebar-open) .nav-item {
    grid-template-columns: 28px 1fr auto;
    justify-content: stretch;
  }

  .sync-card {
    margin-top: 0;
  }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .thread-summary {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

/* ---- Режим сделки: блок «Коммуникации» ---- */
body.deal-mode {
  background: transparent;
}
body.deal-mode .app-shell {
  display: none;
}
.deal-view {
  padding: 12px;
}
.deal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.deal-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}
.deal-tab-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 10px;
}
.deal-tab-ico {
  font-size: 12px;
}
.deal-tab-spacer {
  flex: 1;
}
.deal-refresh {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 15px;
}
.deal-refresh:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.deal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
}
.deal-col {
  padding: 14px;
  min-width: 0;
}
.deal-col-mail {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.deal-col-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.deal-col-title {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.deal-thread {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.deal-thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-soft);
  border: 0;
  cursor: pointer;
  text-align: left;
}
.deal-thread.open .deal-thread-head {
  border-bottom: 1px solid var(--line);
}
.deal-thread-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eaf2ff;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.deal-thread-main {
  flex: 1;
  min-width: 0;
}
.deal-thread-subject {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deal-thread-meta {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
.deal-thread-status {
  flex: 0 0 auto;
  font-size: 10px;
  border-radius: 20px;
  padding: 2px 8px;
}
.deal-thread-caret {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}
.deal-thread-body {
  padding: 6px 11px 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deal-msg {
  border-left: 2px solid var(--line);
  padding: 6px 0 6px 10px;
}
.deal-msg.incoming {
  border-left-color: var(--accent);
}
.deal-msg-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}
.deal-msg-meta strong {
  color: var(--text);
  font-size: 12px;
}
.deal-msg-text {
  font-size: 12px;
  color: var(--text);
  overflow-wrap: anywhere;
}
.deal-msg-text img {
  max-width: 100%;
  height: auto;
}
.deal-inline-file {
  display: inline-block;
  margin-top: 6px;
  margin-right: 6px;
  font-size: 11px;
  color: var(--accent-strong);
  text-decoration: none;
}
.deal-side-block {
  min-width: 0;
}
.deal-files,
.deal-calls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.deal-file,
.deal-call {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  text-decoration: none;
  color: var(--text);
}
a.deal-file:hover,
a.deal-inline-file:hover {
  border-color: var(--accent);
}
.deal-file-ico {
  flex: 0 0 auto;
  min-width: 34px;
  height: 24px;
  padding: 0 4px;
  border-radius: 6px;
  background: #eef3f8;
  color: var(--ink-blue);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.deal-file-main,
.deal-call-main {
  flex: 1;
  min-width: 0;
}
.deal-file-name,
.deal-call-title {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deal-file-sub,
.deal-call-sub {
  display: block;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deal-call-ico {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #dcf6eb;
  color: var(--good);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.deal-call.call-missed .deal-call-ico,
.deal-call.call-failed .deal-call-ico {
  background: #ffe1e1;
  color: var(--danger);
}
.deal-call-badge {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--danger);
  background: #ffe1e1;
  border-radius: 20px;
  padding: 2px 7px;
}
.deal-call-play {
  flex: 0 0 auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}
.deal-call-play:hover {
  color: var(--accent);
}
.deal-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 12px;
  text-align: center;
}
.deal-error {
  color: var(--danger);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
@media (max-width: 720px) {
  .deal-grid {
    grid-template-columns: 1fr;
  }
  .deal-col-mail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
