:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-muted: #f5f7fa;
  --surface-strong: #eef2f7;
  --border: #d8e0ea;
  --border-strong: #c5d0de;
  --text: #152033;
  --muted: #5c6b7e;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-border: rgba(37, 99, 235, 0.28);
  --error: #dc2626;
  --error-soft: rgba(220, 38, 38, 0.1);
  --error-border: rgba(220, 38, 38, 0.28);
  --error-text: #b91c1c;
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --success-border: rgba(22, 163, 74, 0.28);
  --success-text: #15803d;
  --warning-text: #b45309;
  --warning-soft: rgba(245, 158, 11, 0.12);
  --radius: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
  --panel-elevated: #ffffff;
  --topbar-glass: rgba(255, 255, 255, 0.92);
  --input-bg: #ffffff;
  --pill-bg: #eef2f7;
  --overlay: rgba(15, 23, 42, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(37, 99, 235, 0.08), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(99, 102, 241, 0.06), transparent 50%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: var(--shadow);
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.brand p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--error-soft);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.auth-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-form button {
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-form button:hover {
  background: var(--accent-hover);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  font-weight: 600;
  font-size: 1.1rem;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
}

.btn-outline {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-decoration: none;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

button.btn-outline,
button.btn-primary,
button.btn-danger {
  appearance: none;
  line-height: 1.3;
}

.btn-outline:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dashboard-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
}

.welcome-card h1 {
  font-size: 1.75rem;
  margin-bottom: 8px;
}

.welcome-card p {
  color: var(--muted);
}

.welcome-lead {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-top: 4px;
}

.welcome-lead strong {
  color: var(--text);
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.tile h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.status-ok {
  color: var(--success);
  font-weight: 600;
}

.topbar-nav {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.nav-link {
  padding: 8px 14px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text);
  background: var(--accent-soft);
}

.nav-soon {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(92, 107, 126, 0.12);
  vertical-align: middle;
}

.alert-success {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.tile-feature {
  grid-column: 1 / -1;
}

.tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tile-value {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.tile-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.feed-status {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.tile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary {
  display: inline-block;
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  display: inline-block;
  padding: 10px 18px;
  background: var(--error-soft);
  color: var(--error-text);
  border: 1px solid var(--error-border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.16);
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-muted {
  background: rgba(139, 156, 179, 0.15);
  color: var(--muted);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.field-textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.field-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.help-list {
  margin: 12px 0 0 20px;
  color: var(--muted);
}

.help-list li {
  margin-bottom: 8px;
}

.help-list code {
  color: var(--accent);
}

.info-card,
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.scope-list {
  margin: 12px 0 0 18px;
  color: var(--muted);
}

.scope-list li {
  margin-bottom: 8px;
}

.scope-list code {
  color: var(--accent);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.5rem;
}

.filter-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-form input[type="date"] {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.list-item {
  display: block;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover:not(.static) {
  background: rgba(59, 130, 246, 0.05);
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}

.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item-preview {
  color: var(--muted);
  font-size: 0.9rem;
}

.list-item-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.list-item-contacts {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--accent);
}

.inline-form {
  display: inline;
}

.chat-layout {
  max-width: 720px;
}

.chat-messages {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 300px;
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: min(85%, 520px);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  position: relative;
}

.chat-bubble-own {
  align-self: flex-end;
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.35);
  border-bottom-right-radius: 4px;
}

.chat-bubble-other {
  align-self: flex-start;
  background: var(--surface-muted);
  border-bottom-left-radius: 4px;
}

.chat-bubble-meta {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-bubble-own .chat-bubble-meta {
  justify-content: flex-end;
}

.chat-bubble-author {
  font-weight: 600;
  color: var(--accent);
}

.list-item-unread {
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.06);
}

.list-item-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unread-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
}

.chat-bubble-unread {
  border-color: rgba(59, 130, 246, 0.5);
}

.chat-bubble-voice .chat-bubble-text,
.chat-bubble-image .chat-bubble-text,
.chat-bubble-call .chat-bubble-text {
  font-style: normal;
}

.chat-bubble-call .chat-bubble-text {
  color: var(--text);
}

.chat-bubble-system {
  align-self: center;
  max-width: min(92%, 520px);
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: none;
}

.chat-bubble-system .chat-bubble-text {
  font-size: 0.86rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.chat-bubble-system .chat-bubble-meta {
  justify-content: center;
  margin-top: 4px;
}

.chat-bubble-system .chat-bubble-time {
  font-size: 0.68rem;
  opacity: 0.85;
}

.chat-bubble-media {
  margin-bottom: 4px;
}

.chat-image {
  display: block;
  max-width: min(100%, 320px);
  max-height: 360px;
  border-radius: 10px;
  object-fit: contain;
  cursor: zoom-in;
}

.chat-voice {
  width: min(100%, 280px);
  height: 36px;
}

.chat-voice-unavailable {
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-bubble-own .chat-image {
  margin-left: auto;
}

.chat-bubble-voice-player {
  min-width: 220px;
}

.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chat-lightbox[hidden] {
  display: none !important;
}

.chat-lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
}

.chat-lightbox-image {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1200px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  cursor: default;
}

.chat-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.chat-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

body.chat-lightbox-open {
  overflow: hidden;
}

.chat-bubble-status {
  font-size: 0.7rem;
  font-weight: 500;
}

.chat-status-read {
  color: var(--accent);
}

.chat-status-delivered {
  color: var(--muted);
}

.chat-status-sent {
  color: var(--muted);
  opacity: 0.85;
}

.chat-status-new {
  color: var(--accent);
  font-weight: 600;
}

.chat-bubble-other .chat-status-new {
  color: var(--accent);
}

.chat-bubble-deleted {
  opacity: 0.65;
}

.chat-bubble-deleted .chat-bubble-text {
  font-style: italic;
}

.chat-delete-btn {
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.chat-bubble-own:hover .chat-delete-btn,
.chat-bubble-own:focus-within .chat-delete-btn {
  opacity: 1;
  visibility: visible;
}

.chat-delete-btn:hover:not(:disabled) {
  color: var(--error-text);
  border-color: var(--error-text);
}

.chat-delete-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.chat-compose textarea {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  margin-bottom: 10px;
}

.compose-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

a {
  color: var(--accent);
}

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.account-mini-list {
  list-style: none;
  margin: 12px 0;
}

.account-mini-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.account-mini-list li:last-child {
  border-bottom: none;
}

.account-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.account-tab {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.account-tab:hover,
.account-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.settings-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 16px 0 6px;
}

.settings-form label:first-child {
  margin-top: 0;
}

.settings-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}

.settings-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
}

.steps-list {
  margin: 12px 0 0 20px;
  color: var(--muted);
}

.steps-list li {
  margin-bottom: 10px;
}

.steps-list code {
  color: var(--accent);
}

.dashboard-wide {
  max-width: min(96vw, 1440px);
  width: 100%;
}

.dashboard-main.dashboard-wide {
  padding-left: 28px;
  padding-right: 28px;
}

.cabinet-table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: visible;
}

.cabinet-table {
  width: 100%;
  overflow: visible;
}

.cabinet-status-cell {
  display: flex;
  align-items: center;
}

.cabinet-status-badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
}

.col-id,
.col-name,
.col-login,
.col-password {
  min-width: 0;
  overflow: hidden;
  display: block;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--pill-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6b7c93;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.status-pill.is-success::before {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.45);
}

.status-pill.is-muted::before {
  background: #6b7c93;
}

.status-pill.is-info::before {
  background: #60a5fa;
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.35);
}

.status-pill.is-ws.is-online::before {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.45);
}

.status-pill.is-ws.is-offline::before {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.35);
}

.status-pill.is-ws.is-checking::before {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.35);
}

.status-pill.is-ws.is-na::before {
  background: #4b5563;
}

.status-pill.is-proxy.is-online::before {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.45);
}

.status-pill.is-proxy.is-offline::before {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.35);
}

.status-pill.is-proxy.is-checking::before {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.35);
}

.status-pill.is-proxy.is-na::before {
  background: #4b5563;
}

.status-pill.is-success.is-session-warn::before {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.45);
}

.status-pill.is-security.is-required {
  color: #b91c1c;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(254, 226, 226, 0.65);
}

.status-pill.is-security.is-required::before {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.45);
}

.col-actions .cabinet-check-result {
  flex-basis: 100%;
  max-width: none;
  text-align: right;
  margin: 2px 0 0;
}

.cabinet-check-result {
  margin: 4px 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  max-width: 320px;
}

.cabinet-check-result.is-ok {
  color: var(--success-text);
}

.cabinet-check-result.is-error {
  color: var(--error-text);
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.72rem;
  line-height: 1.2;
}

.cabinet-row {
  display: grid;
  --cabinet-col-login: 170px;
  --cabinet-col-password: 118px;
  grid-template-columns: 40px var(--cabinet-col-login) var(--cabinet-col-password) var(--cabinet-col-login) var(--cabinet-col-password) minmax(200px, 1fr) minmax(280px, 1.15fr);
  gap: 10px;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.cabinet-row:last-child {
  border-bottom: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.cabinet-row-head {
  background: var(--surface-strong);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0;
}

.cabinet-field-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.cabinet-num,
.cabinet-id {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.cabinet-add-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cabinet-add-id-input {
  width: 140px;
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  box-sizing: border-box;
}

.cabinet-add-id-input:focus {
  outline: none;
  border-color: var(--accent);
}

.cabinet-row input.cabinet-id-input {
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.cabinet-row input[type="number"]::-webkit-outer-spin-button,
.cabinet-row input[type="number"]::-webkit-inner-spin-button,
.cabinet-add-id-input::-webkit-outer-spin-button,
.cabinet-add-id-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cabinet-row input[type="number"],
.cabinet-add-id-input {
  -moz-appearance: textfield;
  appearance: textfield;
}

.col-num {
  text-align: center;
}

.col-proxy {
  display: flex;
  justify-content: center;
  align-items: center;
}

.col-actions-icons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 2px;
}

.cabinet-icon-form {
  display: inline-flex;
  margin: 0;
}

.proxy-edit-wrap {
  position: relative;
}

.btn-icon-round {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  box-sizing: border-box;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

a.btn-icon-round {
  text-decoration: none;
}

.btn-icon-round .icon-proxy,
.btn-icon-round .icon-save,
.btn-icon-round .icon-verify,
.btn-icon-round .icon-web-session,
.btn-icon-round .icon-messages,
.btn-icon-round .icon-reset,
.btn-icon-round .icon-trash {
  width: 16px;
  height: 16px;
}

.btn-save-round:not(:disabled) {
  color: var(--success-text);
  border-color: var(--success-border);
}

.btn-save-round:hover:not(:disabled) {
  color: var(--success-text);
  border-color: rgba(22, 163, 74, 0.45);
  background: var(--success-soft);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.08);
}

.btn-icon-round:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-messages-round:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.btn-verify-round:hover:not(:disabled) {
  color: #0e7490;
  border-color: rgba(8, 145, 178, 0.35);
  background: rgba(8, 145, 178, 0.1);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.08);
}

.btn-web-session-round:hover {
  color: #6d28d9;
  border-color: rgba(109, 40, 217, 0.3);
  background: rgba(109, 40, 217, 0.08);
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.08);
}

.btn-reset-round:hover {
  color: var(--warning-text);
  border-color: rgba(245, 158, 11, 0.35);
  background: var(--warning-soft);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.08);
}

.btn-proxy-edit:hover,
.btn-proxy-edit.is-open {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.btn-proxy-edit.has-value {
  color: var(--accent);
  border-color: var(--accent-border);
}

.btn-proxy-edit.has-value::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

.btn-delete-round:hover {
  color: var(--error-text);
  border-color: var(--error-border);
  background: var(--error-soft);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.08);
}

.proxy-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  top: auto;
  right: 0;
  z-index: 60;
  width: min(340px, 85vw);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.proxy-popover-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.proxy-popover input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  box-sizing: border-box;
}

.proxy-popover input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.proxy-popover-hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.proxy-popover-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.proxy-popover-actions .btn-proxy-save {
  min-width: 96px;
}

.proxy-popover-actions .btn-proxy-save:not(:disabled) {
  color: var(--success-text);
  border-color: var(--success-border);
  background: var(--success-soft);
}

.proxy-popover-actions .btn-proxy-save:not(:disabled):hover {
  color: var(--success-text);
  border-color: rgba(22, 163, 74, 0.45);
  background: rgba(22, 163, 74, 0.16);
}

.cabinet-row input[type="text"],
.cabinet-row input[type="password"],
.cabinet-row input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  box-sizing: border-box;
}

.cabinet-row input.cabinet-input-password {
  font-size: 0.76rem;
  padding: 6px 8px;
  color: var(--text);
  background: var(--surface-muted);
}

.cabinet-row input.cabinet-input-password::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.cabinet-row input.cabinet-input-password.is-saved {
  border-color: var(--success-border);
}

.cabinet-row input.cabinet-input-password.is-saved::placeholder {
  color: var(--success-text);
}

.cabinet-row .col-id input,
.cabinet-row .col-name input,
.cabinet-row .col-login input,
.cabinet-row .col-password input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 0.78rem;
  padding: 6px 8px;
}

.cabinet-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.col-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  overflow: visible;
}

.col-actions .col-actions-icons {
  flex-shrink: 0;
}

.col-actions .btn-outline.btn-sm,
.col-actions a.btn-outline.btn-sm,
.col-actions button.btn-outline.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  line-height: 1.3;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.cabinet-row-empty {
  grid-template-columns: 1fr;
  color: var(--muted);
  justify-content: center;
  text-align: center;
}

@media (max-width: 900px) {
  .cabinet-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .cabinet-row-head {
    display: none;
  }

  .col-num::before {
    content: "№: ";
    color: var(--muted);
  }

  .col-id::before {
    content: "ID: ";
    color: var(--muted);
  }

  .col-login::before {
    content: "Логин: ";
    color: var(--muted);
  }

  .col-password::before {
    content: "Пароль: ";
    color: var(--muted);
  }

  .col-name::before {
    content: "Название: ";
    color: var(--muted);
  }

  .col-actions {
    justify-content: flex-start;
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.modal-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.modal-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.modal-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}

.modal-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.modal-status {
  min-height: 1.2em;
  font-size: 0.85rem;
  margin-top: 12px;
}

.modal-status.error {
  color: var(--error-text);
}

.modal-status.success {
  color: var(--success-text);
}

.sync-modal-card {
  width: min(480px, 100%);
}

.sync-progress-track {
  height: 10px;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
  margin: 16px 0 12px;
  border: 1px solid var(--border);
}

.sync-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.sync-progress-stats {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 6px;
}

.sync-progress-current {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 8px;
  min-height: 1.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-progress-messages {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* ── Messenger split view (2026) ── */

.messenger-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 50% at 0% 0%, rgba(37, 99, 235, 0.06), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(99, 102, 241, 0.05), transparent 50%),
    var(--bg);
}

.messenger-topbar {
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  background: var(--topbar-glass);
  border-bottom: 1px solid var(--border);
}

.messenger-topbar .topbar-start {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.messenger-topbar .topbar-nav {
  flex: 0 0 auto;
  justify-content: flex-start;
}

.messenger-topbar .topbar-brand {
  padding-right: 12px;
  border-right: 1px solid var(--border);
}

.messenger-account-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-right: 0;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.messenger-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.messenger-topbar-actions .inline-form {
  margin: 0;
}

.messenger-topbar-actions .messenger-icon-btn {
  margin-left: 0;
}

.bitrix-subnav {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: fit-content;
  box-shadow: var(--shadow);
}

.bitrix-subnav .nav-link {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.bitrix-subnav .nav-link:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.bitrix-subnav .nav-link.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.bitrix-app-page .dashboard-main {
  max-width: 1080px;
}

.bitrix-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 32px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-muted) 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.bitrix-hero h1 {
  margin-bottom: 6px;
}

.bitrix-hero-status {
  flex-shrink: 0;
  padding-top: 4px;
}

.bitrix-stats {
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.85;
}

.stat-card-in::before { background: #2563eb; }
.stat-card-out::before { background: #16a34a; }
.stat-card-map::before { background: #7c3aed; }
.stat-card-err::before { background: #94a3b8; }
.stat-card-err.has-errors::before { background: #dc2626; }

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-meta {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.85;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-card-err.has-errors .stat-value {
  color: var(--error-text);
}

.stats-page .dashboard-main {
  max-width: 1360px;
  padding: 20px 20px 32px;
}

.stats-page .welcome-card {
  padding: 14px 18px;
  margin-bottom: 12px;
}

.stats-page .welcome-card h1 {
  font-size: 1.25rem;
  margin-bottom: 2px;
}

.stats-page .welcome-card .welcome-lead,
.stats-page .welcome-card p {
  font-size: 0.88rem;
  margin: 0;
  color: var(--muted);
}

.stats-page .stats-filters {
  padding: 10px 14px;
  margin-bottom: 12px;
}

.stats-filters-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
}

.stats-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.stats-field input[type="date"],
.stats-field select {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  min-width: 0;
}

.stats-field select {
  min-width: 200px;
  max-width: 280px;
}

.stats-field input[type="date"] {
  width: 138px;
}

.stats-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stats-preset-row .btn-outline {
  height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.stats-actions .btn-primary {
  height: 32px;
  min-width: 88px;
  padding: 0 14px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.stats-period-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.stats-status {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1.1em;
}

.stats-status.is-error {
  color: var(--error-text);
}

.stats-block {
  margin-bottom: 16px;
}

.stats-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

.stats-page .bitrix-stats,
.stats-page .dashboard-grid.bitrix-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.stats-page .stat-card {
  padding: 12px 12px 14px;
  border-radius: 10px;
  box-shadow: none;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 1 / 0.92;
}

.stats-page .stat-card:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border-strong);
}

.stats-page .stat-label {
  font-size: 0.68rem;
  margin-bottom: 0;
  line-height: 1.25;
}

.stats-page .stat-meta {
  font-size: 0.68rem;
  margin-bottom: 0;
  margin-top: 2px;
  opacity: 0.75;
  line-height: 1.2;
}

.stats-page .stat-value {
  font-size: 1.55rem;
  margin-top: auto;
  padding-top: 10px;
}

.stats-table-card {
  margin-top: 8px;
}

.stats-page .stats-table-card .bitrix-section-head {
  padding: 10px 14px 8px;
}

.stats-page .stats-table-card .bitrix-section-head h2 {
  font-size: 0.88rem;
  margin: 0;
}

.stats-kv-row {
  grid-template-columns: 1fr 88px;
  padding: 6px 14px;
  font-size: 0.88rem;
}

.stats-daily-row {
  grid-template-columns: 1.1fr 1fr 1fr 1fr;
  padding: 6px 14px;
  font-size: 0.88rem;
}

.bitrix-cabinets-card {
  padding-top: 22px;
}

.bitrix-section-head {
  padding: 0 24px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.bitrix-section-head h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.bitrix-section-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.bitrix-app-page .dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.bitrix-cabinet-row {
  grid-template-columns: 100px 1fr 120px 140px;
  padding: 12px 24px;
}

.bitrix-cabinet-row.cabinet-row-head {
  padding-top: 12px;
  padding-bottom: 12px;
}

.bitrix-cell-id {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
}

.bitrix-cell-name {
  font-weight: 500;
}

.bitrix-cell-status {
  display: flex;
  align-items: center;
}

.bitrix-line-id {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--accent);
}

.bitrix-line-empty {
  color: var(--muted);
}

.bitrix-cabinets-card .cabinet-row:not(.cabinet-row-head):hover {
  background: var(--accent-soft);
}

.bitrix-log-row {
  grid-template-columns: 120px 120px 100px 1fr;
  font-size: 0.82rem;
}

.bitrix-log-row.is-error span:last-child {
  color: var(--error-text);
}

.bitrix-action-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin: 16px 0;
}

.bitrix-action-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.bitrix-action-form select {
  min-width: 220px;
  padding: 8px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.bitrix-bindings-list {
  margin: 12px 0 0;
  padding-left: 0;
  list-style: none;
  color: var(--muted);
}

.bitrix-binding-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.bitrix-binding-item:last-child {
  border-bottom: none;
}

.bitrix-inline-form {
  margin: 0;
  flex-shrink: 0;
}

.bitrix-reconnect-steps,
.bitrix-connect-steps {
  margin: 0 0 16px;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
}

.bitrix-connect-steps h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.bitrix-iframe .dashboard-main {
  padding-top: 16px;
}

.bitrix-logs-table .cabinet-table {
  max-height: 70vh;
  overflow: auto;
}

.messenger-account-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
  flex-shrink: 0;
  overflow-x: auto;
}

.messenger-account-tab {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.messenger-account-tab.active,
.messenger-account-tab:hover {
  border-color: rgba(59, 130, 246, 0.5);
  color: var(--text);
  background: rgba(59, 130, 246, 0.1);
}

.messenger-error-wrap {
  padding: 24px;
}

.messenger-shell {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: 0;
  margin: 12px;
  gap: 0;
  border-radius: 20px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}

.messenger-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.messenger-sidebar-head {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-muted);
}

.messenger-sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.messenger-sidebar-head h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.messenger-live-status {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

.messenger-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.messenger-filter {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.messenger-filter.active,
.messenger-filter:hover {
  color: var(--text);
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
}

.messenger-icon-btn {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  transition: border-color 0.15s, color 0.15s;
}

.messenger-icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.messenger-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.messenger-ws-pill {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(139, 156, 179, 0.08);
}

.messenger-ws-pill.is-online {
  color: var(--success-text);
  border-color: var(--success-border);
  background: var(--success-soft);
}

.messenger-ws-pill.is-offline {
  color: var(--error-text);
  border-color: var(--error-border);
  background: var(--error-soft);
}

.messenger-ws-pill.is-checking {
  color: var(--warning-text);
  border-color: rgba(245, 158, 11, 0.3);
  background: var(--warning-soft);
}

.messenger-search {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.messenger-search:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.messenger-search::placeholder {
  color: var(--muted);
}

.messenger-chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
}

.messenger-chat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
}

.messenger-chat-item:hover {
  background: var(--accent-soft);
}

.messenger-chat-item.is-active {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
}

.messenger-chat-item.is-unread .messenger-chat-name {
  color: var(--text);
  font-weight: 700;
}

.messenger-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.16), rgba(99, 102, 241, 0.16));
  border: 1px solid var(--accent-border);
  color: var(--accent);
}

.messenger-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
}

.messenger-bitrix-badge {
  position: absolute;
  left: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: var(--success, #15803d);
  border: 2px solid var(--surface, #fff);
  box-shadow: 0 1px 3px rgba(21, 128, 61, 0.35);
  pointer-events: none;
}

.messenger-avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1.1rem;
}

.messenger-chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.messenger-chat-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.messenger-chat-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.messenger-chat-name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messenger-chat-client-id {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messenger-chat-time {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.messenger-chat-preview {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messenger-chat-item-title {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messenger-unread-dot {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.messenger-thread-empty[hidden],
.messenger-thread-active[hidden],
.messenger-compose[hidden] {
  display: none !important;
}

.messenger-empty-list,
.messenger-messages-empty,
.messenger-loading {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.messenger-messages-error {
  color: var(--error-text);
}

.messenger-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface-muted);
}

.messenger-thread-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.messenger-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.messenger-thread-empty h3 {
  font-size: 1.2rem;
  color: var(--text);
  margin-bottom: 8px;
}

.messenger-thread-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messenger-thread-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.messenger-back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.messenger-thread-header-text h3 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.messenger-thread-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.messenger-thread-chat-id {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.messenger-thread-chat-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.messenger-thread-bitrix-status.is-sent {
  color: var(--success, #15803d);
  font-weight: 600;
}

.messenger-thread-bitrix-link {
  color: inherit;
  font-weight: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.messenger-thread-bitrix-link:hover {
  opacity: 0.85;
}

.messenger-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.messenger-compose {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.messenger-compose textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.messenger-compose textarea:focus {
  outline: none;
  border-color: var(--accent-border);
}

.messenger-send-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, opacity 0.12s;
}

.messenger-send-btn:hover:not(:disabled) {
  transform: scale(1.04);
}

.messenger-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.messenger-compose.is-sending .messenger-send-btn {
  opacity: 0.6;
}

.messenger-messages .chat-bubble {
  max-width: min(78%, 480px);
}

.messenger-messages .chat-bubble-own {
  background: rgba(59, 130, 246, 0.2);
}

.messenger-messages .chat-bubble-system {
  max-width: min(88%, 440px);
}

@media (max-width: 860px) {
  .messenger-shell {
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    grid-template-columns: 1fr;
  }

  .messenger-sidebar {
    display: flex;
  }

  .messenger-thread {
    display: none;
  }

  .messenger-chat-open .messenger-sidebar {
    display: none;
  }

  .messenger-chat-open .messenger-thread {
    display: flex;
  }

  .messenger-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .messenger-thread-header::before {
    content: none;
  }
}
