/* =========================================================
   LEGACY / BASE STYLESHEET
   ---------------------------------------------------------
   This file still contains historical/base styles.
   The active UI override layer now lives in:
     public/styles.final.css
   New UI fixes should be added there first.
   ========================================================= */

:root {
  --bg: #0b1220;
  --bg-soft: #121b2d;
  --panel: #ffffff;
  --panel-soft: #f3f6fb;
  --border: #dbe3ee;
  --text: #111827;
  --muted: #6b7280;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --sidebar-text: #e5e7eb;
  --sidebar-muted: #9ca3af;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: Inter, Arial, sans-serif;
  background: #eef3f8;
  color: var(--text);
  height: 100%;
}

body {
  min-height: 100vh;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 76px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #0d1527 0%, #17253d 100%);
  color: var(--sidebar-text);
  border-right: 1px solid rgba(255,255,255,0.08);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  min-width: 0;
}

.brand-title {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.brand-subtitle {
  color: var(--sidebar-muted);
  font-size: 13px;
  margin-top: 6px;
}

.burger-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: inherit;
  cursor: pointer;
  flex: 0 0 auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nav-btn {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.03);
  color: var(--sidebar-text);
  min-height: 54px;
  border-radius: 16px;
  padding: 0 16px;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.nav-btn.active {
  background: rgba(59,130,246,0.25);
  border-color: rgba(96,165,250,0.65);
  color: #ffffff;
}

.app-shell.sidebar-collapsed .brand-subtitle,
.app-shell.sidebar-collapsed .nav-btn {
  font-size: 0;
}

.app-shell.sidebar-collapsed .brand-title {
  font-size: 0;
}

.app-shell.sidebar-collapsed .nav-btn::before {
  font-size: 14px;
  display: block;
}

.app-shell.sidebar-collapsed .nav-btn[data-section="dialogs"]::before { content: "D"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="clients"]::before { content: "C"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="orders"]::before { content: "O"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="templates"]::before { content: "T"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="calculator"]::before { content: "K"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="channels"]::before { content: "CH"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="settings"]::before { content: "S"; }
.app-shell.sidebar-collapsed .nav-btn[data-section="users"]::before { content: "U"; }

.main-shell {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 72px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: #4ade80;
  border-radius: 999px;
  display: inline-block;
}

.mobile-only {
  display: none;
}

.section {
  display: none;
  padding: 20px;
  min-height: calc(100vh - 72px);
}

.section.active {
  display: block;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dialogs-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 320px;
  gap: 20px;
  min-height: calc(100vh - 112px);
}

.dialogs-list-panel,
.chat-panel,
.dialogs-side-panel {
  min-height: 0;
}

.dialogs-list-panel,
.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.panel-header.no-border {
  border-bottom: 0;
  padding-bottom: 8px;
}

.panel-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.toolbar-row {
  padding: 14px 18px;
  display: flex;
  gap: 10px;
}

.input,
.textarea,
select.input {
  width: 100%;
  border: 1px solid #cfd8e3;
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
}

.input:focus,
.textarea:focus,
select.input:focus {
  outline: none;
  border-color: #7fb0ff;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.textarea {
  resize: vertical;
  min-height: 110px;
}

.large-textarea {
  min-height: 220px;
}

.entity-list {
  padding: 0 12px 12px;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entity-item {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fbff;
  padding: 14px;
  cursor: pointer;
}

.entity-item.active {
  border-color: #7fb0ff;
  background: #eaf3ff;
}

.entity-title {
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 6px;
}

.entity-subtitle,
.entity-meta,
.muted {
  color: var(--muted);
  font-size: 14px;
}

.messages-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: var(--panel-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 76%;
  padding: 14px 16px;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(15,23,42,0.05);
}

.message.out {
  align-self: flex-end;
  background: #dceaff;
  border-color: #bdd5ff;
}

.message-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
}

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

.composer {
  border-top: 1px solid var(--border);
  padding: 14px 18px 18px;
  background: #fff;
}

.composer-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 12px;
  align-items: end;
}

.composer-textarea {
  min-height: 72px;
  max-height: 180px;
}

.composer-send {
  min-height: 72px;
  font-size: 28px;
}

.dialogs-side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  min-height: 0;
}

.accordion {
  overflow: hidden;
}

.accordion-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 800;
  font-size: 18px;
  border-bottom: 1px solid var(--border);
}

.accordion-body {
  padding: 16px 18px;
  display: block;
}

.accordion.collapsed .accordion-body {
  display: none;
}

.grid-2,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.full-btn {
  width: 100%;
}

.stack-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.settings-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.primary-btn,
.secondary-btn,
.small-btn,
.status-btn {
  border: 1px solid #c9d8ee;
  background: #fff;
  color: var(--text);
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  padding: 12px 16px;
}

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

.secondary-btn {
  padding: 11px 14px;
  background: #f7fbff;
}

.small-btn {
  padding: 10px 14px;
  min-width: 44px;
}

.status-btn {
  padding: 10px 12px;
  background: #f8fbff;
}

.status-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.kv,
.kv-notes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.kv span,
.kv-notes span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 700;
}

.kv strong,
.kv-notes div {
  font-size: 15px;
  word-break: break-word;
}

.mini-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #f8fbff;
}

.mini-item-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.mini-item-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.mini-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-result,
.preview-box,
.divider {
  margin-top: 14px;
}

.preview-box {
  border: 1px solid var(--border);
  background: #f8fbff;
  border-radius: 14px;
  padding: 14px;
  white-space: pre-wrap;
  min-height: 100px;
}

.divider {
  border-top: 1px solid var(--border);
}

.section-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  min-height: calc(100vh - 112px);
}

.single-card-layout {
  display: block;
}

.list-column,
.editor-column {
  overflow: hidden;
  min-height: 0;
}

.list-column {
  display: flex;
  flex-direction: column;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 14px;
}

@media (max-width: 1400px) {
  .dialogs-layout {
    grid-template-columns: 300px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 1180px) {
  .dialogs-layout,
  .section-layout {
    grid-template-columns: 1fr;
  }

  .dialogs-side-panel {
    order: 3;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar {
    padding: 0 14px;
  }

  .section {
    padding: 14px;
  }

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

  .span-2 {
    grid-column: span 1;
  }

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

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 14, 25, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: #ffffff;
  border: 1px solid #dbe3ee;
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
  padding: 24px;
}

.login-card h2 {
  margin: 0 0 16px;
  font-size: 24px;
  font-weight: 800;
}

.login-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

/* dialogs layout stabilization */
.section#section-dialogs {
  min-height: calc(100vh - 72px);
  height: calc(100vh - 72px);
  overflow: hidden;
}

.dialogs-layout {
  height: 100%;
  min-height: 0;
  align-items: stretch;
}

.dialogs-list-panel,
.chat-panel,
.dialogs-side-panel {
  height: 100%;
  min-height: 0;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.messages-list {
  min-height: 0;
  overflow: auto;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #fff;
}

.dialogs-list-panel .entity-list,
.dialogs-side-panel {
  min-height: 0;
  overflow: auto;
}

/* better spacing for compact cards */
.entity-item {
  padding: 12px 13px;
}

.entity-title {
  font-size: 16px;
}

.entity-subtitle,
.entity-meta,
.muted {
  font-size: 13px;
}

@media (max-width: 1180px) {
  .section#section-dialogs {
    height: auto;
    overflow: visible;
  }

  .dialogs-layout {
    height: auto;
  }

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

  .composer {
    position: static;
  }
}


.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  margin-bottom: 8px;
}

.quick-reply-btn {
  border: 1px solid #c9d8ee;
  background: #f7fbff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.quick-reply-btn:hover {
  background: #eef6ff;
}

.preview-box {
  max-height: 260px;
  overflow: auto;
}

.preview-box pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}

/* ===== dialogs adaptive fix ===== */

.dialogs-layout {
  grid-template-columns: 340px minmax(620px, 1fr) 290px;
  gap: 18px;
}

.chat-panel {
  min-width: 0;
}

.messages-list {
  min-width: 0;
}

.message {
  max-width: 88%;
}

.dialogs-side-panel {
  width: 100%;
  min-width: 0;
  max-width: 290px;
  overflow-y: auto;
  overflow-x: hidden;
}

.accordion {
  min-width: 0;
}

.accordion-body {
  overflow-x: hidden;
}

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

.input,
.textarea,
select.input,
.secondary-btn,
.primary-btn,
.small-btn,
.status-btn {
  min-width: 0;
}

.composer {
  padding: 12px 16px 14px;
}

.composer-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-file-row input[type="file"] {
  max-width: 100%;
}

.composer-row {
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 10px;
}

.composer-textarea {
  min-width: 0;
  min-height: 70px;
  max-height: 140px;
}

.quick-replies {
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.quick-replies::-webkit-scrollbar {
  height: 8px;
}

.quick-reply-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* slightly more compact right column cards */
.dialogs-side-panel .accordion-toggle {
  padding: 14px 16px;
  font-size: 16px;
}

.dialogs-side-panel .accordion-body {
  padding: 14px 16px;
}

.dialogs-side-panel .secondary-btn.full-btn {
  padding: 10px 12px;
}

.dialogs-side-panel .label {
  font-size: 12px;
  margin-bottom: 4px;
}

/* medium screens: give chat priority */
@media (max-width: 1500px) {
  .dialogs-layout {
    grid-template-columns: 300px minmax(560px, 1fr) 270px;
  }

  .dialogs-side-panel {
    max-width: 270px;
  }
}

@media (max-width: 1320px) {
  .dialogs-layout {
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-areas:
      "list chat"
      "side side";
  }

  .dialogs-list-panel {
    grid-area: list;
  }

  .chat-panel {
    grid-area: chat;
  }

  .dialogs-side-panel {
    grid-area: side;
    max-width: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 14px;
    overflow: visible;
  }

  .message {
    max-width: 80%;
  }
}

@media (max-width: 980px) {
  .dialogs-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "list"
      "chat"
      "side";
  }

  .dialogs-side-panel {
    grid-template-columns: 1fr;
  }

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

  .composer-send {
    min-height: 56px;
    font-size: 24px;
  }

  .message {
    max-width: 94%;
  }
}


/* =========================================================
   GLOBAL POLISH + STABLE DIALOGS LAYOUT
   ========================================================= */

body.theme-light {
  --page-bg: #eef3f8;
  --page-bg-2: #f6f9fc;
  --shell-top: rgba(255,255,255,0.94);
  --card-bg: #ffffff;
  --card-bg-soft: #f4f7fb;
  --card-border: #d7e1ee;
  --text-main: #142033;
  --text-muted-2: #6b7280;
  --sidebar-grad-1: #0c1630;
  --sidebar-grad-2: #132347;
  --sidebar-border: rgba(255,255,255,0.10);
  --sidebar-card: rgba(255,255,255,0.03);
  --sidebar-card-active: rgba(59,130,246,0.24);
  --shadow-soft: 0 10px 28px rgba(15, 23, 42, 0.08);
  --message-in: #ffffff;
  --message-out: #dceaff;
  --composer-bg: #ffffff;
}

body.theme-dark {
  --page-bg: #0b1220;
  --page-bg-2: #10192b;
  --shell-top: rgba(15,23,42,0.88);
  --card-bg: #121c2f;
  --card-bg-soft: #162238;
  --card-border: #26344b;
  --text-main: #e8eefc;
  --text-muted-2: #9aa7bf;
  --sidebar-grad-1: #08101f;
  --sidebar-grad-2: #0d1830;
  --sidebar-border: rgba(255,255,255,0.08);
  --sidebar-card: rgba(255,255,255,0.025);
  --sidebar-card-active: rgba(59,130,246,0.30);
  --shadow-soft: 0 14px 34px rgba(0, 0, 0, 0.30);
  --message-in: #17243a;
  --message-out: #213d73;
  --composer-bg: #121c2f;
}

body {
  background:
    radial-gradient(circle at top left, rgba(59,130,246,0.08), transparent 24%),
    linear-gradient(180deg, var(--page-bg), var(--page-bg-2));
  color: var(--text-main);
  transition: background 0.18s ease, color 0.18s ease;
}

.topbar {
  background: var(--shell-top);
  border-bottom: 1px solid var(--card-border);
  color: var(--text-main);
}

.topbar-right,
.entity-subtitle,
.entity-meta,
.muted,
.message-meta,
.brand-subtitle,
.kv span,
.kv-notes span,
.label {
  color: var(--text-muted-2);
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar-grad-1) 0%, var(--sidebar-grad-2) 100%);
  border-right: 1px solid var(--sidebar-border);
}

.burger-btn,
.nav-btn {
  background: var(--sidebar-card);
  border-color: rgba(255,255,255,0.12);
}

.nav-btn.active {
  background: var(--sidebar-card-active);
}

.card,
.login-card {
  background: var(--card-bg);
  border-color: var(--card-border);
  box-shadow: var(--shadow-soft);
}

.messages-list {
  background: var(--card-bg-soft);
}

.message {
  background: var(--message-in);
  border-color: var(--card-border);
}

.message.out {
  background: var(--message-out);
  border-color: rgba(96,165,250,0.35);
}

.composer {
  background: var(--composer-bg);
  border-top: 1px solid var(--card-border);
}

.input,
.textarea,
select.input,
.preview-box {
  background: color-mix(in srgb, var(--card-bg) 86%, transparent);
  border-color: var(--card-border);
  color: var(--text-main);
}

.entity-item,
.mini-item {
  background: color-mix(in srgb, var(--card-bg-soft) 88%, transparent);
  border-color: var(--card-border);
}

.entity-item.active {
  background: color-mix(in srgb, rgba(59,130,246,0.18) 40%, var(--card-bg-soft));
  border-color: rgba(96,165,250,0.65);
}

.accordion-toggle {
  color: var(--text-main);
  border-bottom-color: var(--card-border);
}

.secondary-btn,
.small-btn,
.status-btn,
.quick-reply-btn {
  background: color-mix(in srgb, var(--card-bg-soft) 85%, transparent);
  border-color: var(--card-border);
  color: var(--text-main);
}

.primary-btn {
  box-shadow: 0 8px 22px rgba(59,130,246,0.18);
}

.primary-btn:hover {
  transform: translateY(-1px);
}

.secondary-btn:hover,
.small-btn:hover,
.status-btn:hover,
.quick-reply-btn:hover,
.nav-btn:hover,
.entity-item:hover {
  filter: brightness(1.02);
}

.app-shell {
  grid-template-columns: 262px 1fr;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 82px 1fr;
}

.sidebar {
  padding: 16px 12px;
}

.sidebar-top {
  margin-bottom: 8px;
}

.brand-title {
  font-size: 28px;
  font-weight: 900;
}

.nav-btn {
  min-height: 56px;
  border-radius: 18px;
  font-size: 15px;
  font-weight: 800;
}

.section {
  padding: 18px;
}

.section#section-dialogs {
  height: calc(100vh - 72px);
  min-height: calc(100vh - 72px);
  overflow: hidden;
}

/* LEFT / CENTER / RIGHT balance */
.dialogs-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(260px, 22vw, 340px) minmax(0, 1fr) clamp(250px, 19vw, 290px);
  gap: 16px;
  align-items: stretch;
}

.dialogs-list-panel,
.chat-panel,
.dialogs-side-panel {
  min-height: 0;
  height: 100%;
}

.dialogs-list-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  min-width: 0;
}

.messages-list {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  gap: 10px;
}

.message {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 20px;
}

.dialogs-side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding-right: 4px;
}

.dialogs-side-panel::-webkit-scrollbar,
.messages-list::-webkit-scrollbar,
.entity-list::-webkit-scrollbar,
.preview-box::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.dialogs-side-panel::-webkit-scrollbar-thumb,
.messages-list::-webkit-scrollbar-thumb,
.entity-list::-webkit-scrollbar-thumb,
.preview-box::-webkit-scrollbar-thumb {
  background: rgba(148,163,184,0.45);
  border-radius: 999px;
}

.accordion {
  min-width: 0;
  overflow: hidden;
}

.accordion-body {
  overflow-x: hidden;
}

.panel-header {
  padding: 16px 18px 14px;
}

.panel-header h2 {
  font-size: 18px;
}

.toolbar-row {
  padding: 12px 18px;
}

.entity-list {
  padding: 0 12px 12px;
  overflow: auto;
}

.entity-item {
  padding: 12px 13px;
  border-radius: 18px;
}

.entity-title {
  font-size: 15px;
  line-height: 1.25;
}

.entity-subtitle,
.entity-meta,
.muted {
  font-size: 13px;
  line-height: 1.35;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 12px 14px 14px;
}

.composer-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.composer-row {
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 10px;
}

.composer-textarea {
  min-height: 72px;
  max-height: 130px;
}

.composer-send {
  min-height: 72px;
  font-size: 28px;
  border-radius: 18px;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 4px;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.quick-reply-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.dialogs-side-panel .accordion-toggle {
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 900;
}

.dialogs-side-panel .accordion-body {
  padding: 12px 16px 14px;
}

.dialogs-side-panel .grid-2 {
  gap: 10px;
}

.dialogs-side-panel .secondary-btn.full-btn {
  padding: 10px 12px;
}

.dialogs-side-panel .kv,
.dialogs-side-panel .kv-notes {
  margin-bottom: 10px;
}

.preview-box {
  border-radius: 14px;
}

/* other sections */
.section-layout {
  grid-template-columns: clamp(280px, 25vw, 360px) minmax(0, 1fr);
}

.form-grid {
  gap: 12px;
}

/* responsive */
@media (max-width: 1500px) {
  .dialogs-layout {
    grid-template-columns: clamp(245px, 21vw, 310px) minmax(0, 1fr) clamp(235px, 18vw, 270px);
  }
}

@media (max-width: 1280px) {
  .dialogs-layout {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    grid-template-areas:
      "list chat"
      "side side";
  }

  .dialogs-list-panel { grid-area: list; }
  .chat-panel { grid-area: chat; }
  .dialogs-side-panel {
    grid-area: side;
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 12px;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

@media (max-width: 980px) {
  .dialogs-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "list"
      "chat"
      "side";
  }

  .dialogs-side-panel {
    grid-template-columns: 1fr;
  }

  .section#section-dialogs {
    height: auto;
    min-height: calc(100vh - 72px);
    overflow: visible;
  }

  .dialogs-layout {
    height: auto;
  }

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

  .composer {
    position: static;
  }
}

/* ===== right column full-height / scroll / content visibility fix ===== */

.dialogs-side-panel {
  height: 100%;
  min-height: 0;
  align-self: stretch;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-right: 6px;
  padding-bottom: 24px;
  scroll-padding-bottom: 24px;
}

.dialogs-side-panel .accordion {
  overflow: visible;
  flex: 0 0 auto;
}

.dialogs-side-panel .accordion-body {
  display: block;
  overflow: visible !important;
  max-height: none !important;
  white-space: normal;
  word-break: break-word;
}

.dialogs-side-panel .mini-item,
.dialogs-side-panel .kv,
.dialogs-side-panel .kv-notes,
.dialogs-side-panel .preview-box,
.dialogs-side-panel .label,
.dialogs-side-panel .secondary-btn,
.dialogs-side-panel .small-btn,
.dialogs-side-panel .status-btn {
  white-space: normal;
  word-break: break-word;
}

.dialogs-side-panel .mini-item-meta,
.dialogs-side-panel .entity-meta,
.dialogs-side-panel .muted,
.dialogs-side-panel .kv strong,
.dialogs-side-panel .kv-notes div {
  white-space: normal;
  word-break: break-word;
}

.dialogs-side-panel .grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.dialogs-side-panel .input,
.dialogs-side-panel .textarea,
.dialogs-side-panel select.input {
  min-width: 0;
  width: 100%;
}

.dialogs-side-panel .stack-btns {
  margin-top: 12px;
}

.dialogs-side-panel .stack-btns .secondary-btn {
  min-height: 44px;
}

.dialogs-side-panel::-webkit-scrollbar {
  width: 10px;
}

.dialogs-side-panel::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.42);
  border-radius: 999px;
}

@media (max-width: 1280px) {
  .dialogs-side-panel {
    overflow: visible !important;
    height: auto;
    padding-bottom: 8px;
  }
}

/* ===== full workflow polish ===== */

.message-attachments {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-attachment {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(148,163,184,0.28);
}

body.theme-dark .message-attachment {
  background: rgba(255,255,255,0.04);
  border-color: rgba(148,163,184,0.18);
}

.message-attachment-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  opacity: .8;
  margin-bottom: 4px;
}

.message-attachment-name {
  font-size: 13px;
  line-height: 1.35;
}

.mini-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.stack-btns .secondary-btn,
.mini-item-actions .small-btn {
  min-height: 40px;
}

.preview-box pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
}


/* ===== multi-file upload ui ===== */

.composer-upload-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.composer-upload-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: color-mix(in srgb, var(--card-bg-soft) 85%, transparent);
}

.composer-upload-main {
  min-width: 0;
}

.composer-upload-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

.composer-upload-meta {
  font-size: 12px;
  color: var(--text-muted-2);
  margin-top: 4px;
}

#composer-upload-progress {
  margin-bottom: 10px;
  min-height: 18px;
}

body.theme-dark input[type="file"] {
  color: var(--text-main);
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}


/* ===== compact dialogs ui ===== */

.panel-header {
  padding: 14px 16px 12px;
}

.panel-header h2,
.chat-header h2,
#chat-title {
  font-size: 16px;
}

.toolbar-row {
  padding: 10px 12px;
}

.dialogs-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.compact-input {
  min-height: 38px;
  padding: 8px 12px;
}

.entity-list {
  padding: 0 10px 10px;
  gap: 8px;
}

.entity-item.dialog-compact-card {
  padding: 10px 12px;
  border-radius: 16px;
}

.dialog-compact-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  margin-bottom: 4px;
}

.dialog-compact-date {
  font-size: 12px;
  color: var(--text-muted-2);
  white-space: nowrap;
}

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

.entity-title {
  font-size: 14px;
  line-height: 1.2;
}

.entity-subtitle {
  font-size: 12px;
  line-height: 1.28;
}

.entity-meta,
.muted {
  font-size: 11px;
  line-height: 1.25;
}

.messages-list {
  padding: 10px 12px;
  gap: 8px;
}

.message.message-compact {
  padding: 9px 11px;
  border-radius: 16px;
  max-width: 78%;
}

.message-text {
  font-size: 13px;
  line-height: 1.3;
}

.message-meta {
  font-size: 11px;
  margin-top: 6px;
}

.message-attachments {
  margin-top: 7px;
  gap: 6px;
}

.message-attachment {
  padding: 8px 10px;
  border-radius: 12px;
}

.composer {
  padding: 8px 12px 10px;
}

.chat-bottom-tools {
  margin-bottom: 8px;
}

.chat-template-toggle {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.chat-templates-drawer {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: color-mix(in srgb, var(--card-bg-soft) 88%, transparent);
}

.chat-templates-drawer.hidden {
  display: none;
}

.chat-templates-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.chat-templates-title {
  font-size: 13px;
  font-weight: 800;
}

.chat-templates-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-template-chip {
  padding: 7px 10px;
  font-size: 12px;
}

.composer-upload-list {
  gap: 6px;
  margin-bottom: 8px;
}

.composer-upload-item {
  padding: 8px 10px;
  border-radius: 12px;
}

.composer-upload-name {
  font-size: 13px;
}

.composer-upload-meta {
  font-size: 11px;
}

#composer-upload-progress {
  margin-bottom: 8px;
  font-size: 11px;
}

.composer-file-row {
  margin-bottom: 6px;
}

.composer-row {
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 8px;
}

.composer-textarea {
  min-height: 58px;
  max-height: 110px;
  padding: 10px 12px;
  font-size: 13px;
}

.composer-send {
  min-height: 58px;
  font-size: 24px;
  border-radius: 16px;
}

.quick-replies {
  margin-top: 6px;
  gap: 6px;
}

.quick-reply-btn {
  padding: 6px 10px;
  font-size: 12px;
}

.dialogs-side-panel .accordion-toggle {
  padding: 11px 14px;
  font-size: 14px;
}

.dialogs-side-panel .accordion-body {
  padding: 10px 14px 12px;
}

.dialogs-side-panel .grid-2 {
  gap: 8px;
}

.dialogs-side-panel .input,
.dialogs-side-panel select.input {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
}

.dialogs-side-panel .secondary-btn.full-btn,
.dialogs-side-panel .status-btn,
.dialogs-side-panel .small-btn {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 12px;
}

.dialogs-side-panel .mini-item {
  padding: 8px 10px;
  border-radius: 12px;
}

.dialogs-side-panel .mini-item-title {
  font-size: 13px;
}

.dialogs-side-panel .mini-item-meta {
  font-size: 11px;
}

@media (max-width: 1280px) {
  .dialogs-filters {
    grid-template-columns: 1fr;
  }

  .message.message-compact {
    max-width: 88%;
  }
}


/* ===== precision polish ===== */

.toolbar-row .input {
  min-height: 38px;
}

.entity-item.dialog-compact-card {
  padding: 8px 10px;
  border-radius: 14px;
}

.entity-title {
  font-size: 13px;
  font-weight: 800;
}

.entity-subtitle {
  font-size: 11.5px;
  line-height: 1.22;
}

.entity-meta,
.muted {
  font-size: 10.5px;
}

.messages-list {
  padding: 8px 10px;
  gap: 7px;
}

.message.message-compact {
  padding: 8px 10px;
  border-radius: 14px;
  max-width: 76%;
}

.message-text {
  font-size: 12.5px;
  line-height: 1.26;
}

.message-meta {
  font-size: 10.5px;
  margin-top: 5px;
}

.composer {
  padding: 7px 10px 9px;
}

.chat-template-toggle {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 12px;
}

.chat-templates-drawer {
  padding: 8px 10px;
  border-radius: 12px;
}

.quick-reply-btn,
.chat-template-chip {
  padding: 5px 9px;
  font-size: 11.5px;
}

.composer-upload-item {
  padding: 7px 9px;
  border-radius: 10px;
}

.composer-upload-name {
  font-size: 12px;
}

.composer-upload-meta {
  font-size: 10.5px;
}

.composer-textarea {
  min-height: 52px;
  max-height: 96px;
  font-size: 12.5px;
  line-height: 1.25;
}

.composer-send {
  min-height: 52px;
  border-radius: 14px;
}

.dialogs-side-panel .accordion-toggle {
  padding: 10px 12px;
  font-size: 13px;
}

.dialogs-side-panel .accordion-body {
  padding: 8px 12px 10px;
}

.dialogs-side-panel .secondary-btn.full-btn,
.dialogs-side-panel .status-btn,
.dialogs-side-panel .small-btn {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 11.5px;
}


/* ===== compact navigation + compact chat polish ===== */

.app-shell {
  grid-template-columns: 236px 1fr;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 72px 1fr;
}

.sidebar {
  padding: 10px 10px;
}

.sidebar-top {
  margin-bottom: 6px;
}

.brand-title {
  font-size: 22px;
}

.brand-subtitle {
  font-size: 13px;
}

.nav-btn {
  min-height: 46px;
  border-radius: 16px;
  font-size: 14px;
  padding: 10px 12px;
}

.burger-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
}

.section {
  padding: 10px;
}

.dialogs-layout {
  gap: 10px;
  grid-template-columns: clamp(250px, 22vw, 320px) minmax(0, 1fr) clamp(220px, 18vw, 270px);
}

.card,
.login-card {
  border-radius: 18px;
}

.panel-header {
  padding: 11px 14px 9px;
}

.panel-header h2,
.chat-header h2,
#chat-title {
  font-size: 15px;
}

.toolbar-row {
  padding: 8px 10px;
}

.dialogs-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 6px;
}

.dialog-filter-single {
  width: 100%;
}

.toolbar-row .input,
.compact-input {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 13px;
}

.entity-list {
  padding: 0 8px 8px;
  gap: 6px;
}

.entity-item.dialog-compact-card {
  padding: 8px 9px;
  border-radius: 14px;
}

.dialog-compact-top {
  margin-bottom: 3px;
}

.entity-title {
  font-size: 13px;
  font-weight: 800;
}

.entity-subtitle {
  font-size: 11px;
  line-height: 1.18;
}

.entity-meta,
.muted {
  font-size: 10px;
  line-height: 1.2;
}

.messages-list {
  padding: 8px;
  gap: 6px;
}

.message.message-compact {
  padding: 7px 9px;
  border-radius: 14px;
  max-width: 74%;
}

.message-text {
  font-size: 12px;
  line-height: 1.22;
}

.message-meta {
  font-size: 10px;
  margin-top: 4px;
}

.composer {
  padding: 6px 8px 8px;
}

.composer-main-row {
  grid-template-columns: 38px 38px minmax(0, 1fr) 92px 54px;
  align-items: center;
}

.composer-icon-btn {
  height: 38px;
  min-width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: color-mix(in srgb, var(--card-bg-soft) 85%, transparent);
  color: var(--text-main);
  cursor: pointer;
  font-size: 17px;
  user-select: none;
}

.composer-clear-btn {
  min-height: 38px;
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 12px;
}

.composer-textarea {
  min-height: 48px;
  max-height: 92px;
  padding: 9px 11px;
  font-size: 12px;
  line-height: 1.22;
  border-radius: 14px;
}

.composer-send {
  min-height: 48px;
  border-radius: 14px;
  font-size: 22px;
}

.chat-bottom-tools {
  margin-bottom: 6px;
}

.chat-templates-drawer {
  margin-top: 0;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: 12px;
}

.chat-templates-header {
  margin-bottom: 6px;
}

.chat-templates-title {
  font-size: 12px;
}

.chat-template-chip,
.quick-reply-btn {
  padding: 5px 8px;
  font-size: 11px;
}

.composer-upload-list {
  gap: 5px;
  margin-bottom: 6px;
}

.composer-upload-item {
  padding: 6px 8px;
  border-radius: 10px;
}

.composer-upload-name {
  font-size: 11.5px;
}

.composer-upload-meta {
  font-size: 10px;
}

#composer-upload-progress {
  margin-bottom: 6px;
  font-size: 10px;
}

.dialogs-side-panel .accordion-toggle {
  padding: 9px 11px;
  font-size: 12px;
}

.dialogs-side-panel .accordion-body {
  padding: 8px 11px 9px;
}

.dialogs-side-panel .secondary-btn.full-btn,
.dialogs-side-panel .status-btn,
.dialogs-side-panel .small-btn {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 11px;
}

.dialogs-side-panel .input,
.dialogs-side-panel select.input {
  min-height: 34px;
  padding: 7px 8px;
  font-size: 12px;
}

.dialogs-side-panel .mini-item {
  padding: 7px 8px;
  border-radius: 10px;
}

.dialogs-side-panel .mini-item-title {
  font-size: 12px;
}

.dialogs-side-panel .mini-item-meta {
  font-size: 10px;
}

@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: 78px 1fr;
  }

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

  .dialogs-layout {
    grid-template-columns: minmax(220px, 290px) minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .composer-main-row {
    grid-template-columns: 36px 36px minmax(0, 1fr) 48px;
  }

  .composer-clear-btn {
    display: none;
  }

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


/* ===== stable upload / statuses / filters ===== */

.dialog-search-full {
  width: 100%;
  display: block;
  margin-bottom: 6px;
}

.dialogs-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 6px;
}

.dialog-filter-single {
  width: 100%;
}

.message-attachment-link,
.message-attachment-name a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.composer-icon-btn {
  height: 34px;
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: color-mix(in srgb, var(--card-bg-soft) 85%, transparent);
  color: var(--text-main);
  cursor: pointer;
  font-size: 15px;
  user-select: none;
}

.composer-main-row,
.composer-row {
  grid-template-columns: 34px 34px minmax(0, 1fr) 88px 48px !important;
}

.composer-clear-btn {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 11px;
  border-radius: 10px;
}

.composer-upload-item {
  padding: 6px 8px;
  border-radius: 10px;
}

.composer-upload-name {
  font-size: 11px;
}

.composer-upload-meta {
  font-size: 10px;
}

#composer-upload-progress {
  font-size: 10px;
}

@media (max-width: 980px) {
  .composer-main-row,
  .composer-row {
    grid-template-columns: 34px 34px minmax(0, 1fr) 48px !important;
  }

  .composer-clear-btn {
    display: none;
  }
}


/* ===== outbound/file stability polish ===== */

.message-attachment-link,
.message-attachment-name a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#composer-upload-progress {
  white-space: pre-wrap;
}


/* ===== dialog/message flow stabilization ===== */

.message-attachment-link,
.message-attachment-name a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-attachment-name {
  word-break: break-word;
}

#composer-upload-progress {
  white-space: pre-wrap;
}


/* ===== vk/file follow-up fixes ===== */

#composer-clear-file,
.composer-clear-btn {
  display: none !important;
}

.dialog-compact-date {
  font-size: 11px;
  color: var(--text-muted-2);
  white-space: nowrap;
}

.message-attachment-link,
.message-attachment-name a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}


/* ===== peer id / file name stabilization ===== */

.message-attachment-link,
.message-attachment-name a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-attachment-name {
  word-break: break-word;
}


.dialog-admin-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}


.mini-input {
  min-width: 110px;
}

.entity-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}


.picker-results {
  position: relative;
  z-index: 5;
  display: none;
  margin-top: 6px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--card-bg);
  overflow: hidden;
}

.picker-results.open {
  display: block;
}

.picker-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--card-border);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.picker-item:last-child {
  border-bottom: 0;
}

.picker-item:hover {
  background: color-mix(in srgb, var(--card-bg-soft) 85%, transparent);
}

.template-item .entity-subtitle {
  white-space: normal;
}

#calc-total {
  font-weight: 700;
}


/* ===== safe row for dialog filters ===== */
.dialogs-filters-safe-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.dialogs-filters-safe-row #dialogs-source-filter,
.dialogs-filters-safe-row #dialogs-status-filter {
  width: 100%;
}

@media (max-width: 980px) {
  .dialogs-filters-safe-row {
    grid-template-columns: 1fr;
  }
}

/* ===== final fix: dialogs search on first row, filters on second row ===== */
.dialogs-list-panel .toolbar-row {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 8px !important;
}

.dialogs-list-panel .toolbar-row > #dialogs-search {
  width: 100% !important;
  flex: 0 0 auto !important;
  margin: 0 !important;
}

.dialogs-list-panel .toolbar-row > .dialogs-filters-safe-row {
  width: 100% !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
  margin: 0 !important;
}

.dialogs-list-panel .toolbar-row > .dialogs-filters-safe-row > #dialogs-source-filter,
.dialogs-list-panel .toolbar-row > .dialogs-filters-safe-row > #dialogs-status-filter {
  width: 100% !important;
  min-width: 0 !important;
}

@media (max-width: 980px) {
  .dialogs-list-panel .toolbar-row > .dialogs-filters-safe-row {
    grid-template-columns: 1fr !important;
  }
}


/* ===== small avatar in dialog cards ===== */
.dialog-card-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.dialog-card-content {
  min-width: 0;
}

.dialog-avatar-wrap {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dialog-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: inherit;
}


/* ===== real avatar layout in dialog compact cards ===== */
.dialog-card-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.dialog-card-content {
  min-width: 0;
}

.dialog-avatar-wrap {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dialog-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: inherit;
}


/* ===== source badge in dialog cards ===== */
.source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid color-mix(in srgb, var(--badge-color) 62%, white 38%);
  background: color-mix(in srgb, var(--badge-color) 18%, transparent);
  color: color-mix(in srgb, var(--badge-color) 78%, white 22%);
}


/* ===== status badge ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid color-mix(in srgb, var(--badge-color) 62%, white 38%);
  background: color-mix(in srgb, var(--badge-color) 18%, transparent);
  color: color-mix(in srgb, var(--badge-color) 78%, white 22%);
}


/* ===== unread dialog highlight ===== */
.dialog-unread {
  border-color: rgba(96, 165, 250, 0.85) !important;
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.35);
}

.dialog-unread .entity-title {
  color: #dbeafe;
}

.unread-pill,
.dialog-read-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.unread-pill {
  border: 1px solid rgba(96, 165, 250, 0.7);
  background: rgba(96, 165, 250, 0.16);
  color: #bfdbfe;
}

.dialog-read-marker {
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.10);
  color: #94a3b8;
}


/* ===== status color polish for orders/panels/selects ===== */
.entity-subtitle .status-badge,
.mini-item-meta .status-badge {
  vertical-align: middle;
}

#order-status,
#orders-status-filter,
#dialogs-status-filter {
  transition: border-color .15s ease, box-shadow .15s ease;
}

#order-status option[value="open"],
#orders-status-filter option[value="open"] { color: #22c55e; }

#order-status option[value="pending"],
#order-status option[value="waiting"],
#order-status option[value="payment"],
#orders-status-filter option[value="pending"],
#orders-status-filter option[value="waiting"],
#orders-status-filter option[value="payment"],
#dialogs-status-filter option[value="pending"] { color: #f59e0b; }

#order-status option[value="closed"],
#order-status option[value="cancelled"],
#orders-status-filter option[value="closed"],
#orders-status-filter option[value="cancelled"] { color: #ef4444; }

#order-status option[value="in_progress"],
#orders-status-filter option[value="in_progress"],
#dialogs-status-filter option[value="in_progress"] { color: #3b82f6; }

#order-status option[value="ready"],
#order-status option[value="done"],
#orders-status-filter option[value="ready"],
#orders-status-filter option[value="done"] { color: #10b981; }

#order-status option[value="new"],
#orders-status-filter option[value="new"],
#dialogs-status-filter option[value="new"] { color: #a78bfa; }


/* ===== dialog status badge in right panel ===== */
#side-dialog-status .status-badge,
.side-dialog-status .status-badge {
  vertical-align: middle;
}

/* ===== incoming message subtle highlight ===== */
.message-incoming {
  position: relative;
}

.message-incoming-fresh {
  border-color: rgba(96, 165, 250, 0.85) !important;
  box-shadow:
    inset 0 0 0 1px rgba(96, 165, 250, 0.28),
    0 0 0 1px rgba(96, 165, 250, 0.08);
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 0.10) 0%,
    rgba(96, 165, 250, 0.04) 100%
  ) !important;
}

.message-incoming-fresh .message-meta {
  color: #bfdbfe !important;
}

.message-incoming-fresh::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.9);
}


/* ===== final polish: right panel / client / orders / chat ===== */

/* right accordion blocks */
.dialogs-side-panel .accordion-item,
.info-panel .accordion-item {
  border-radius: 16px;
  overflow: hidden;
}

.dialogs-side-panel .accordion-toggle,
.info-panel .accordion-toggle {
  min-height: 40px;
  padding: 9px 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.dialogs-side-panel .accordion-body,
.info-panel .accordion-body {
  padding: 10px 12px 12px;
}

/* right panel labels/values */
.side-kv,
.side-meta-grid {
  display: grid;
  gap: 8px;
}

.side-kv-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: start;
}

.side-kv-key {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
}

.side-kv-value {
  min-width: 0;
  font-size: 12px;
  line-height: 1.25;
  word-break: break-word;
}

/* status/source pills inside side panel */
#side-dialog-source,
#side-dialog-status,
#side-dialog-unread {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* client mini card */
.client-brief-card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255,255,255,0.02);
}

.client-brief-name {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 4px;
}

.client-brief-meta {
  font-size: 11px;
  line-height: 1.25;
  color: var(--text-muted, #94a3b8);
}

/* mini order cards in side panel */
.dialogs-side-panel .mini-item,
.info-panel .mini-item {
  border: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.025);
}

.dialogs-side-panel .mini-item + .mini-item,
.info-panel .mini-item + .mini-item {
  margin-top: 6px;
}

.dialogs-side-panel .mini-item-title,
.info-panel .mini-item-title {
  font-weight: 700;
  line-height: 1.2;
}

.dialogs-side-panel .mini-item-meta,
.info-panel .mini-item-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  line-height: 1.2;
}

/* chat readability */
.messages-list {
  scroll-padding-bottom: 16px;
}

.message {
  backdrop-filter: blur(4px);
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* attachments cleaner */
.message-attachments {
  display: grid;
  gap: 6px;
}

.message-attachment {
  background: rgba(255,255,255,0.04);
}

.message-attachment-name a,
.message-attachment-link {
  font-weight: 600;
}

/* composer final polish */
.composer-status,
#composer-status {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  margin-top: 6px;
}

.chat-templates-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* active dialog stronger but clean */
.entity-item.dialog-compact-card.active {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
}

/* selected order/client/template cards */
.entity-item.active {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
}

/* a bit nicer status line spacing */
.entity-meta .source-badge,
.entity-meta .status-badge,
.entity-meta .unread-pill,
.entity-meta .dialog-read-marker,
.mini-item-meta .source-badge,
.mini-item-meta .status-badge,
.mini-item-meta .unread-pill,
.mini-item-meta .dialog-read-marker {
  vertical-align: middle;
}


/* ===== channels safe polish ===== */
.channel-card .entity-title-row {
  align-items: center;
}

.channel-card .entity-subtitle {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
}

.channel-help-card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 10px;
  background: rgba(255,255,255,0.02);
  display: grid;
  gap: 8px;
}

.channel-help-title {
  font-size: 13px;
  font-weight: 800;
}

.channel-help-text {
  font-size: 12px;
  line-height: 1.35;
}

.channel-help-meta {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
}

.channel-help-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#channel-config {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.35;
}


/* ===== channels quick form ===== */
.channel-quick-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.channel-qf-item {
  display: grid;
  gap: 6px;
}

.channel-qf-item-span {
  grid-column: 1 / -1;
}

.channel-qf-label {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
}

.channel-inline-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

@media (max-width: 980px) {
  .channel-quick-form {
    grid-template-columns: 1fr;
  }
}


/* ===== minimal channel connect cards ===== */
.channel-advanced-hidden {
  display: none !important;
}

.channel-connect-card {
  border: 1px solid color-mix(in srgb, var(--channel-accent) 48%, #1f2a44 52%);
  border-radius: 18px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.015) 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
  display: grid;
  gap: 12px;
}

.channel-connect-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.channel-connect-dot {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 999px;
  background: var(--channel-accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--channel-accent) 18%, transparent);
}

.channel-connect-title {
  font-size: 15px;
  font-weight: 800;
}

.channel-connect-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted, #94a3b8);
}

.channel-connect-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.channel-connect-grid-advanced {
  margin-top: 10px;
}

.channel-connect-field {
  display: grid;
  gap: 6px;
}

.channel-connect-field-span {
  grid-column: 1 / -1;
}

.channel-connect-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted, #94a3b8);
}

.channel-connect-advanced {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 10px;
}

.channel-connect-advanced > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  list-style: none;
}

.channel-connect-advanced > summary::-webkit-details-marker {
  display: none;
}

.channel-connect-advanced > summary::after {
  content: " ▾";
}

@media (max-width: 980px) {
  .channel-connect-grid {
    grid-template-columns: 1fr;
  }
}


/* ===== channels studio ===== */
.channel-studio-hidden {
  display: none !important;
}

.channel-studio-root {
  margin-bottom: 14px;
}

.channel-studio-card {
  --channel-studio-accent: #64748b;
  border: 1px solid color-mix(in srgb, var(--channel-studio-accent) 48%, #1f2a44 52%);
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.015) 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
  display: grid;
  gap: 14px;
}

.channel-studio-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.channel-studio-head-left {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.channel-studio-dot {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 999px;
  background: var(--channel-studio-accent);
  margin-top: 3px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--channel-studio-accent) 18%, transparent);
}

.channel-studio-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.channel-studio-help {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted, #94a3b8);
  max-width: 760px;
}

.channel-studio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.channel-studio-grid-advanced {
  margin-top: 10px;
}

.channel-studio-field {
  display: grid;
  gap: 6px;
}

.channel-studio-field-span {
  grid-column: 1 / -1;
}

.channel-studio-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted, #94a3b8);
}

.channel-studio-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.channel-studio-advanced {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 10px;
}

.channel-studio-advanced > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  list-style: none;
}

.channel-studio-advanced > summary::-webkit-details-marker {
  display: none;
}

.channel-studio-advanced > summary::after {
  content: " ▾";
}

/* make channel list cleaner */
#section-channels .entity-item.channel-card {
  padding: 12px 14px;
}

#section-channels .entity-item.channel-card .entity-meta {
  line-height: 1.25;
}

@media (max-width: 980px) {
  .channel-studio-grid {
    grid-template-columns: 1fr;
  }

  .channel-studio-head {
    flex-direction: column;
  }
}


/* ===== TG MTProto QR ===== */
.tgmtproto-qr-box {
  border: 1px solid rgba(56, 189, 248, 0.28);
  background: rgba(56, 189, 248, 0.04);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.tgmtproto-qr-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tgmtproto-qr-title {
  font-size: 14px;
  font-weight: 800;
}

.tgmtproto-qr-status {
  font-size: 12px;
  color: #93c5fd;
}

.tgmtproto-qr-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted, #94a3b8);
}

.tgmtproto-qr-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tgmtproto-qr-image {
  min-height: 296px;
  border-radius: 14px;
  border: 1px dashed rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.02);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.tgmtproto-qr-img {
  width: 280px;
  height: 280px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
}

.tgmtproto-qr-success {
  font-size: 13px;
  font-weight: 700;
  color: #86efac;
}

.tgmtproto-password-wrap {
  display: grid;
  gap: 8px;
}

.tgmtproto-password-hint {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
}

.hidden {
  display: none !important;
}


/* ===== TG/UI FINAL POLISH ===== */
.dialog-source-pill,
.dialog-unread-pill,
.dialog-status-pill,
.chat-status-pill,
.chat-attach-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.dialog-source-pill {
  border: 1px solid rgba(110, 170, 255, 0.35);
  background: rgba(80, 130, 255, 0.12);
  color: #bcd3ff;
}

.dialog-source-pill.is-vk {
  border-color: rgba(91, 148, 255, 0.45);
  background: rgba(91, 148, 255, 0.14);
  color: #c5ddff;
}

.dialog-source-pill.is-tg_mtproto,
.dialog-source-pill.is-tg_mtproto_2 {
  border-color: rgba(89, 201, 255, 0.45);
  background: rgba(89, 201, 255, 0.12);
  color: #c7f2ff;
}

.dialog-source-pill.is-max {
  border-color: rgba(255, 157, 71, 0.45);
  background: rgba(255, 157, 71, 0.12);
  color: #ffd8b2;
}

.dialog-source-pill.is-mail_ru {
  border-color: rgba(171, 129, 255, 0.45);
  background: rgba(171, 129, 255, 0.12);
  color: #e2d4ff;
}

.dialog-unread-pill {
  border: 1px solid rgba(126, 227, 146, 0.40);
  background: rgba(76, 175, 80, 0.14);
  color: #b9f7c3;
  font-weight: 700;
}

.dialog-status-pill {
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.06);
  color: #d7dfef;
}

.dialog-status-pill.is-open {
  border-color: rgba(126, 227, 146, 0.40);
  background: rgba(76, 175, 80, 0.12);
  color: #b9f7c3;
}

.dialog-status-pill.is-closed {
  border-color: rgba(255, 120, 120, 0.40);
  background: rgba(255, 90, 90, 0.12);
  color: #ffc4c4;
}

.dialog-status-pill.is-pending,
.dialog-status-pill.is-waiting {
  border-color: rgba(255, 196, 86, 0.40);
  background: rgba(255, 196, 86, 0.12);
  color: #ffe3a4;
}

.dialog-card-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.dialog-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dialog-card-title-row .entity-title {
  min-width: 0;
}

.dialog-compact-card.has-unread {
  box-shadow: 0 0 0 1px rgba(126, 227, 146, 0.18) inset;
}

.dialog-compact-card.is-tg_mtproto .entity-title::before,
.dialog-compact-card.is-tg_mtproto_2 .entity-title::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 999px;
  background: #63d8ff;
  box-shadow: 0 0 10px rgba(99, 216, 255, 0.55);
  vertical-align: middle;
}

.chat-head-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chat-status-pill.is-pending {
  border: 1px solid rgba(255, 196, 86, 0.40);
  background: rgba(255, 196, 86, 0.12);
  color: #ffe3a4;
}

.chat-status-pill.is-sent {
  border: 1px solid rgba(126, 227, 146, 0.40);
  background: rgba(76, 175, 80, 0.12);
  color: #b9f7c3;
}

.chat-status-pill.is-failed {
  border: 1px solid rgba(255, 120, 120, 0.40);
  background: rgba(255, 90, 90, 0.12);
  color: #ffc4c4;
}

.chat-attach-pill {
  border: 1px dashed rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: #dbe5f7;
  margin-top: 6px;
}

#chat-title-wrap-enhanced {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}


/* ===== TG FINAL UX PATCH ===== */
.dialog-compact-card,
.entity-item,
.messages-list .message,
.messages-list .message-item,
.messages-list .chat-message {
  transition: none !important;
  animation: none !important;
}

.msg-delivery-ticks,
.message-delivery-ticks,
.chat-delivery-ticks {
  position: absolute;
  right: 8px;
  bottom: 4px;
  font-size: 11px;
  letter-spacing: -1px;
  user-select: none;
  pointer-events: none;
}

.msg-delivery-ticks.is-pending,
.message-delivery-ticks.is-pending,
.chat-delivery-ticks.is-pending {
  color: #99a0ad;
}

.msg-delivery-ticks.is-sent,
.message-delivery-ticks.is-sent,
.chat-delivery-ticks.is-sent {
  color: #99a0ad;
}

.msg-delivery-ticks.is-read,
.message-delivery-ticks.is-read,
.chat-delivery-ticks.is-read {
  color: #43b96b;
}

.entity-avatar-fallback {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255,255,255,0.08);
  color: #d9e3f2;
}

.dialog-card-row-enhanced {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.dialog-card-main-enhanced {
  min-width: 0;
  flex: 1;
}

.audio-message-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  background: rgba(89, 201, 255, 0.12);
  border: 1px solid rgba(89, 201, 255, 0.35);
  color: #c7f2ff;
  margin-top: 6px;
}


/* ===== TG UI STABLE PATCH ===== */
#dialogs-list,
#messages-list,
.dialog-compact-card,
.message,
.message-compact,
.entity-item {
  animation: none !important;
  transition: none !important;
}

.entity-avatar-fallback {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.08);
  color: #dce7f5;
  font-size: 13px;
  font-weight: 700;
}

.message-meta {
  position: relative;
  padding-right: 28px;
}

.msg-delivery-ticks {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  letter-spacing: -1px;
  vertical-align: middle;
}

.msg-delivery-ticks.is-pending {
  color: #9aa3b2;
}

.msg-delivery-ticks.is-sent {
  color: #9aa3b2;
}

.msg-delivery-ticks.is-read {
  color: #50c878;
}

.message-attachments {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.message-attachment {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
}

.message-attachment-kind {
  font-size: 11px;
  opacity: 0.8;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.message-attachment-link {
  color: #dbe9ff;
  text-decoration: underline;
}

.message-attachment-meta {
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.6;
}


/* ===== DIALOGS NO-PULSE + AVATAR FALLBACK PATCH ===== */
#dialogs-list,
#messages-list,
.dialog-compact-card,
.entity-item,
.message,
.message-compact {
  transition: none !important;
  animation: none !important;
  transform: none !important;
}

.dialog-card-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.dialog-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dialog-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dialog-avatar-fallback {
  background: rgba(255,255,255,0.08);
  color: #dce7f5;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.dialog-card-content {
  min-width: 0;
  flex: 1;
}
\n

/* ===== CHAT POLISH ===== */
.dialogs-layout {
  gap: 16px;
}

.dialogs-list-panel .panel-header,
.chat-panel .panel-header {
  padding: 16px 18px 12px;
}

#chat-title,
.chat-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.entity-list {
  padding: 10px 10px 12px;
  gap: 8px;
}

.dialog-compact-card {
  padding: 12px;
  border-radius: 18px;
  background: #f8fbff;
  transition: background-color .15s ease, border-color .15s ease;
}

.dialog-compact-card:hover {
  background: #f1f7ff;
}

.dialog-compact-card.active {
  background: #eaf3ff;
  border-color: #8db6ff;
}

.dialog-card-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.dialog-card-content {
  min-width: 0;
  flex: 1;
}

.dialog-compact-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}

.dialog-compact-top .entity-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.dialog-compact-date {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  margin-top: 1px;
}

.dialog-avatar {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dialog-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dialog-avatar-fallback {
  background: linear-gradient(180deg, #dceaff 0%, #cfe2ff 100%);
  color: #26415f;
  font-size: 13px;
  font-weight: 800;
}

.messages-list {
  padding: 18px 20px;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.65), rgba(248,251,255,0.95));
}

.message-row {
  display: flex;
}

.message-row.in {
  justify-content: flex-start;
}

.message-row.out {
  justify-content: flex-end;
}

.message {
  max-width: min(720px, 78%);
  padding: 10px 12px 8px;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid rgba(15,23,42,0.08);
  box-shadow: 0 4px 12px rgba(15,23,42,0.05);
}

.message.out {
  background: #dceaff;
  border-color: #bdd5ff;
}

.message-text {
  font-size: 14px;
  line-height: 1.42;
}

.message-attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.message-attachment {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid rgba(15,23,42,0.08);
  border-radius: 14px;
  padding: 10px 11px;
  background: rgba(255,255,255,0.55);
}

.message.out .message-attachment {
  background: rgba(255,255,255,0.4);
}

.message-attachment-icon {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(93,135,214,0.12);
  color: #31558f;
  font-weight: 800;
  font-size: 13px;
}

.message-attachment-body {
  min-width: 0;
  flex: 1;
}

.message-attachment-kind {
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.message-attachment-name {
  font-size: 13px;
  line-height: 1.3;
  word-break: break-word;
}

.message-attachment-link {
  color: #204c8d;
  text-decoration: none;
}

.message-attachment-link:hover {
  text-decoration: underline;
}

.message-attachment-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  word-break: break-word;
}

.message-meta-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  min-height: 16px;
}

.message-time {
  font-size: 11px;
  color: var(--muted);
}

.msg-delivery-ticks {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.msg-delivery-ticks.is-pending {
  color: #8b98aa;
}

.msg-delivery-ticks.is-sent {
  color: #8b98aa;
}

.msg-delivery-ticks.is-read {
  color: #18a957;
}

.msg-delivery-ticks.is-failed {
  color: #d9534f;
}

.entity-meta .source-badge,
.entity-meta .status-badge,
.entity-meta .unread-badge {
  vertical-align: middle;
}

@media (max-width: 1200px) {
  .dialogs-layout {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .dialogs-side-panel {
    display: none;
  }
}

@media (max-width: 860px) {
  .dialogs-layout {
    grid-template-columns: 1fr;
  }

  .dialogs-list-panel,
  .chat-panel {
    min-height: auto;
  }

  .message {
    max-width: 88%;
  }
}
\n
/* ===== CHAT FIX AFTER POLISH ===== */

/* вернуть тёмную читаемость */
.dialog-compact-card,
.dialog-compact-card:hover,
.dialog-compact-card.active {
  color: #eaf2ff;
}

.dialog-compact-card {
  background: rgba(255,255,255,0.03);
  border-color: rgba(140,180,255,0.18);
}

.dialog-compact-card:hover {
  background: rgba(255,255,255,0.05);
}

.dialog-compact-card.active {
  background: rgba(80,130,220,0.16);
  border-color: rgba(120,170,255,0.42);
}

.dialog-compact-top .entity-title {
  color: #edf4ff;
  font-size: 14px;
  font-weight: 750;
}

.entity-subtitle {
  color: rgba(230,238,250,0.78);
  font-size: 13px;
  line-height: 1.3;
}

.dialog-compact-date {
  color: rgba(230,238,250,0.72);
  font-size: 11px;
}

/* компактные бейджи вместо огромных плашек */
.entity-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 0;
}

.entity-meta .source-badge,
.entity-meta .status-badge,
.entity-meta .unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
  white-space: nowrap;
}

.entity-meta .source-badge {
  background: rgba(78,163,255,0.12);
  border: 1px solid rgba(78,163,255,0.35);
  color: #7ec3ff;
}

.entity-meta .status-badge {
  background: rgba(72,187,120,0.10);
  border: 1px solid rgba(72,187,120,0.35);
  color: #7edc98;
}

.entity-meta .unread-badge {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(230,238,250,0.82);
}

/* сами карточки списка диалогов компактнее */
.dialog-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
}

.dialog-avatar-fallback {
  font-size: 12px;
}

.entity-list {
  gap: 7px;
}

.dialog-compact-card {
  padding: 10px 11px;
}

/* чат: вернуть нормальный тёмный фон */
.messages-list {
  background:
    linear-gradient(180deg, rgba(8,18,40,0.55), rgba(10,22,50,0.72));
}

.message {
  color: #eef4ff;
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.08);
  box-shadow: none;
}

.message.out {
  background: rgba(103,153,255,0.20);
  border-color: rgba(137,176,255,0.30);
}

.message-text {
  color: #eef4ff;
  font-size: 14px;
}

.message-time {
  color: rgba(233,241,255,0.72);
  font-size: 11px;
}

/* галочки аккуратнее */
.message-meta-row {
  gap: 4px;
  margin-top: 6px;
}

.msg-delivery-ticks {
  min-width: 14px;
  font-size: 11px;
  letter-spacing: -1px;
  opacity: 0.95;
}

.msg-delivery-ticks.is-pending {
  color: rgba(230,238,250,0.58);
}

.msg-delivery-ticks.is-sent {
  color: rgba(230,238,250,0.78);
}

.msg-delivery-ticks.is-read {
  color: #62d98d;
}

.msg-delivery-ticks.is-failed {
  color: #ff7f7f;
}

/* вложения оставить аккуратными, но в тёмной теме */
.message-attachment {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.08);
}

.message.out .message-attachment {
  background: rgba(255,255,255,0.10);
}

.message-attachment-icon {
  background: rgba(126,163,255,0.16);
  color: #a9cbff;
}

.message-attachment-kind {
  color: rgba(233,241,255,0.62);
}

.message-attachment-name {
  color: #eef4ff;
}

.message-attachment-link {
  color: #eef4ff;
}

.message-attachment-meta {
  color: rgba(233,241,255,0.62);
}

/* composer не такой грузный */
.composer {
  background: rgba(9,19,42,0.92);
}

.composer-send {
  font-size: 22px;
}

/* если где-то старые светлые цвета прилипли */
.entity-title,
.entity-subtitle,
.entity-meta,
.message-text,
.message-meta,
.message-time,
.dialog-compact-date {
  text-shadow: none;
}


/* ===== DIALOGS COMPACT UI ===== */
.dialogs-layout {
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 14px;
}

.entity-list {
  padding: 8px;
  gap: 6px;
}

.dialog-compact-card {
  padding: 9px 10px;
  border-radius: 16px;
}

.dialog-card-row {
  gap: 10px;
}

.dialog-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
}

.dialog-avatar-fallback {
  font-size: 11px;
}

.dialog-card-content {
  min-width: 0;
}

.dialog-compact-top {
  margin-bottom: 3px;
}

.dialog-compact-top .entity-title {
  font-size: 13px;
  font-weight: 760;
  line-height: 1.2;
  margin: 0;
}

.dialog-compact-date {
  font-size: 11px;
  line-height: 1;
}

.entity-subtitle {
  font-size: 12px;
  line-height: 1.28;
  margin-top: 0;
}

.dialog-card-bottom {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dialog-mini-badges {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dialog-mini-badge {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  font-weight: 800;
  border: 1px solid rgba(255,255,255,0.14);
}

.dialog-mini-badge.is-source.is-tg_mtproto,
.dialog-mini-badge.is-source.is-tg_mtproto_2 {
  background: rgba(78,163,255,0.16);
  color: #7ec3ff;
  border-color: rgba(78,163,255,0.42);
}

.dialog-mini-badge.is-source.is-vk {
  background: rgba(102,153,255,0.16);
  color: #93b7ff;
  border-color: rgba(102,153,255,0.42);
}

.dialog-mini-badge.is-source.is-max {
  background: rgba(160,120,255,0.16);
  color: #bea5ff;
  border-color: rgba(160,120,255,0.42);
}

.dialog-mini-badge.is-source.is-mail_ru {
  background: rgba(255,184,76,0.16);
  color: #ffd27a;
  border-color: rgba(255,184,76,0.42);
}

.dialog-mini-badge.is-status.is-open,
.dialog-mini-badge.is-status.is-active {
  background: rgba(72,187,120,0.12);
  color: #7edc98;
  border-color: rgba(72,187,120,0.38);
}

.dialog-mini-badge.is-status.is-pending {
  background: rgba(255,184,76,0.12);
  color: #ffd27a;
  border-color: rgba(255,184,76,0.38);
}

.dialog-mini-badge.is-status.is-closed {
  background: rgba(255,255,255,0.08);
  color: rgba(233,241,255,0.7);
  border-color: rgba(255,255,255,0.16);
}

.dialog-unread-pill {
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(78,163,255,0.14);
  color: #dfeeff;
  border: 1px solid rgba(78,163,255,0.38);
  font-size: 11px;
  line-height: 1;
  font-weight: 800;
}

.entity-meta {
  display: none !important;
}

@media (max-width: 1200px) {
  .dialogs-layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}


/* ===== DIALOGS SKETCH LAYOUT ===== */
.dialogs-layout {
  grid-template-columns: 420px minmax(0, 1fr) 320px;
}

.dialogs-list-panel {
  min-width: 0;
}

.entity-list {
  padding: 8px;
  gap: 8px;
}

.dialog-compact-card {
  padding: 10px 12px;
  border-radius: 20px;
}

.dialog-card-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 34px;
  gap: 12px;
  align-items: center;
}

.dialog-avatar {
  width: 54px;
  height: 54px;
  min-width: 54px;
}

.dialog-avatar-fallback {
  font-size: 15px;
}

.dialog-card-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.dialog-compact-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin: 0;
}

.dialog-compact-top .entity-title {
  font-size: 13px;
  line-height: 1.15;
  margin: 0;
}

.dialog-compact-date {
  font-size: 11px;
  line-height: 1;
  margin-top: 1px;
}

.entity-subtitle {
  font-size: 12px;
  line-height: 1.22;
}

.dialog-card-bottom,
.dialog-mini-badges,
.dialog-unread-pill {
  display: none !important;
}

.dialog-side-dots {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dialog-dot {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  font-weight: 800;
  border: 1px solid rgba(255,255,255,0.14);
  flex: 0 0 auto;
}

.dialog-dot.is-source.is-tg_mtproto,
.dialog-dot.is-source.is-tg_mtproto_2 {
  background: rgba(78,163,255,0.18);
  color: #7ec3ff;
  border-color: rgba(78,163,255,0.48);
}

.dialog-dot.is-source.is-vk {
  background: rgba(102,153,255,0.18);
  color: #93b7ff;
  border-color: rgba(102,153,255,0.48);
}

.dialog-dot.is-source.is-max {
  background: rgba(160,120,255,0.18);
  color: #bea5ff;
  border-color: rgba(160,120,255,0.48);
}

.dialog-dot.is-source.is-mail_ru {
  background: rgba(255,184,76,0.18);
  color: #ffd27a;
  border-color: rgba(255,184,76,0.48);
}

.dialog-dot.is-status.is-open,
.dialog-dot.is-status.is-active {
  background: rgba(72,187,120,0.16);
  color: #7edc98;
  border-color: rgba(72,187,120,0.44);
}

.dialog-dot.is-status.is-pending {
  background: rgba(255,184,76,0.16);
  color: #ffd27a;
  border-color: rgba(255,184,76,0.44);
}

.dialog-dot.is-status.is-closed {
  background: rgba(255,255,255,0.08);
  color: rgba(233,241,255,0.72);
  border-color: rgba(255,255,255,0.16);
}

.dialog-dot.is-unread {
  background: rgba(255,255,255,0.05);
  color: rgba(233,241,255,0.65);
  border-color: rgba(255,255,255,0.12);
  font-size: 9px;
}

.dialog-dot.is-unread.has-unread {
  background: rgba(255,255,255,0.92);
  color: #23344f;
  border-color: rgba(255,255,255,0.95);
}

.dialog-dot.is-unread.no-unread {
  background: rgba(255,255,255,0.08);
  color: transparent;
  border-color: rgba(255,255,255,0.12);
}

@media (max-width: 1380px) {
  .dialogs-layout {
    grid-template-columns: 360px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 1200px) {
  .dialogs-layout {
    grid-template-columns: 340px minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .dialogs-layout {
    grid-template-columns: 1fr;
  }
}

/* ===== DIALOGS DENSITY TUNE ===== */
.dialogs-layout {
  grid-template-columns: 360px minmax(0, 1fr) 320px;
  gap: 12px;
}

.entity-list {
  padding: 6px;
  gap: 5px;
}

.dialog-compact-card {
  padding: 7px 8px;
  border-radius: 16px;
}

.dialog-card-row {
  grid-template-columns: 40px minmax(0, 1fr) 26px;
  gap: 8px;
  align-items: center;
}

.dialog-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
}

.dialog-avatar-fallback {
  font-size: 12px;
}

.dialog-card-content {
  gap: 2px;
}

.dialog-compact-top {
  gap: 6px;
  margin: 0;
}

.dialog-compact-top .entity-title {
  font-size: 11px;
  line-height: 1.08;
  font-weight: 760;
  margin: 0;
}

.dialog-compact-date {
  font-size: 10px;
  line-height: 1;
  margin-top: 0;
}

.entity-subtitle {
  font-size: 10px;
  line-height: 1.14;
  margin: 0;
  color: rgba(230,238,250,0.78);
}

.dialog-side-dots {
  gap: 4px;
}

.dialog-dot {
  width: 18px;
  height: 18px;
  font-size: 8px;
  border-width: 1px;
}

.dialog-dot.is-unread {
  font-size: 7px;
}

.dialogs-list-panel .panel-header {
  padding: 12px 14px 10px;
}

.dialogs-list-panel .panel-header h2 {
  font-size: 16px;
}

.toolbar-row {
  padding: 10px 12px;
  gap: 8px;
}

.input,
.textarea,
select.input {
  padding: 10px 12px;
  border-radius: 12px;
}

@media (max-width: 1380px) {
  .dialogs-layout {
    grid-template-columns: 330px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 1200px) {
  .dialogs-layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }
}

/* ===== FINAL DENSITY PASS ===== */

/* верхняя шапка ниже */
.topbar {
  height: 58px;
  min-height: 58px;
  padding: 0 16px;
}

.topbar-title {
  font-size: 18px;
  line-height: 1;
}

.topbar-right {
  font-size: 13px;
}

/* секции ближе кверху */
.section {
  padding: 10px;
  min-height: calc(100vh - 58px);
}

/* внутренняя шапка списка диалогов — убрать */
.dialogs-list-panel .panel-header {
  display: none !important;
}

/* после скрытия шапки не оставлять щели */
.dialogs-list-panel .toolbar-row {
  padding-top: 10px;
}

/* чуть уже общая сетка */
.dialogs-layout {
  grid-template-columns: 355px minmax(0, 1fr) 300px;
  gap: 10px;
  min-height: calc(100vh - 72px);
}

/* ещё плотнее список */
.entity-list {
  padding: 5px;
  gap: 4px;
}

.dialog-compact-card {
  padding: 6px 7px;
  border-radius: 14px;
}

.dialog-card-row {
  grid-template-columns: 38px minmax(0, 1fr) 18px;
  gap: 7px;
}

.dialog-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
}

.dialog-avatar-fallback {
  font-size: 11px;
}

.dialog-card-content {
  gap: 1px;
}

.dialog-compact-top {
  gap: 6px;
}

.dialog-compact-top .entity-title {
  font-size: 10.5px;
  line-height: 1.06;
  font-weight: 760;
}

.dialog-compact-date {
  font-size: 9px;
}

.entity-subtitle {
  font-size: 9.5px;
  line-height: 1.08;
}

/* правая колонка точек = по высоте около аватарки */
.dialog-side-dots {
  gap: 3px;
  justify-content: center;
}

.dialog-dot {
  width: 14px;
  height: 14px;
  font-size: 6px;
  border-width: 1px;
}

.dialog-dot.is-unread {
  font-size: 5.5px;
}

/* поля поиска и фильтров компактнее */
.toolbar-row {
  padding: 8px 10px;
  gap: 6px;
}

.input,
.textarea,
select.input {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
}

/* чат и боковая панель тоже чуть плотнее */
.chat-panel .panel-header,
.dialogs-side-panel .accordion-toggle {
  padding-top: 10px;
  padding-bottom: 10px;
}

.chat-panel .panel-header h2,
.accordion-toggle {
  font-size: 16px;
}

.composer {
  padding: 10px 12px 12px;
}

.composer-row {
  grid-template-columns: 1fr 64px;
  gap: 8px;
}

.composer-textarea {
  min-height: 56px;
}

.composer-send {
  min-height: 56px;
}

@media (max-width: 1380px) {
  .dialogs-layout {
    grid-template-columns: 330px minmax(0, 1fr) 280px;
  }
}

@media (max-width: 1200px) {
  .dialogs-layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }
}

/* ===== FINAL ATTACHMENTS OVERRIDE ===== */
.message-attachments {
  margin-top: 8px !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
}

.message-attachments-download-all {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: #eef4ff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  align-self: flex-start;
  margin-bottom: 2px;
}

.message-attachments-download-all:hover {
  background: rgba(255,255,255,0.10);
}

.message-attachments-download-all:disabled {
  opacity: 0.72;
  cursor: default;
}

.message-attachment {
  padding: 8px 10px !important;
}

.message-attachment-body.only-file-name {
  display: block !important;
  min-width: 0;
}

.message-attachment-kind,
.message-attachment-meta,
.message-attachment-icon {
  display: none !important;
}

.message-attachment-name {
  font-size: 13px !important;
  line-height: 1.25 !important;
  word-break: break-word;
}

.message-attachment-link {
  font-weight: 700;
}

/* ===== INBOUND TG GROUPED FILES ===== */
.message-grouped-inbound-files {
  max-width: 76%;
}

.message-grouped-inbound-files .message-attachments-download-all {
  margin-bottom: 6px;
}


/* ===== dialogs polish 1 ===== */

.entity-item.dialog-compact-card {
  padding: 6px 8px;
  border-radius: 13px;
  background: #f8fbff;
  border: 1px solid rgba(148,163,184,0.20);
}

.entity-item.dialog-compact-card.active {
  background: #edf5ff;
  border-color: rgba(96,165,250,0.55);
  box-shadow: inset 0 0 0 1px rgba(96,165,250,0.14);
}

.dialog-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  margin-top: 0;
}

.dialog-card-content {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding-top: 0;
}

.dialog-compact-top {
  display: block;
  margin: 0;
}

.dialog-title-single-line {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.1;
  margin: 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dialog-preview {
  font-size: 12.5px;
  line-height: 1.16;
  color: #516072;
  margin: 0;
  word-break: break-word;
}

.dialog-compact-date {
  font-size: 10.5px;
  line-height: 1.05;
  color: #8a97a8;
  white-space: nowrap;
  margin-top: 1px;
}

.dialog-compact-date-bottom {
  align-self: flex-end;
}

.dialog-date-right {
  text-align: right;
}

.dialog-side-dots {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  min-width: 18px;
  padding-top: 0;
}

.dialog-dot {
  width: 16px;
  height: 16px;
  min-width: 16px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  box-shadow: none;
}

.dialog-dot.is-unread.has-unread {
  width: auto;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 9px;
}

.entity-subtitle.line-clamp-2,
.dialog-preview.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entity-list {
  padding: 0 8px 8px;
  gap: 6px;
}

body.theme-dark .entity-item.dialog-compact-card {
  background: rgba(255,255,255,0.04);
  border-color: rgba(148,163,184,0.16);
}

body.theme-dark .entity-item.dialog-compact-card.active {
  background: rgba(59,130,246,0.14);
  border-color: rgba(96,165,250,0.50);
}

body.theme-dark .dialog-preview {
  color: #b6c1ce;
}

body.theme-dark .dialog-compact-date {
  color: #8c98a8;
}


/* ===== chat polish 1 ===== */

.messages-list {
  padding: 8px 10px;
  gap: 7px;
}

.message-row {
  display: flex;
}

.message-row.in {
  justify-content: flex-start;
}

.message-row.out {
  justify-content: flex-end;
}

.message.message-compact {
  max-width: 72%;
  padding: 8px 10px;
  border-radius: 14px;
  box-shadow: none;
}

.message.message-compact.out {
  background: #dceaff;
  border-color: #bdd5ff;
}

.message-text {
  font-size: 13px;
  line-height: 1.28;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-attachments {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.message-attachment {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(255,255,255,0.42);
  border: 1px solid rgba(148,163,184,0.18);
}

.message-attachment-icon {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  background: rgba(59,130,246,0.12);
  color: #3b82f6;
  margin-top: 1px;
}

.message-attachment-body {
  min-width: 0;
  flex: 1 1 auto;
}

.message-attachment-kind {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
  opacity: .68;
  margin-bottom: 2px;
  line-height: 1.1;
}

.message-attachment-name {
  font-size: 12px;
  line-height: 1.2;
  word-break: break-word;
}

.message-attachment-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.message-attachment-meta {
  margin-top: 2px;
  font-size: 10px;
  opacity: .55;
  line-height: 1.15;
}

.message-meta-row {
  margin-top: 5px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.message-time {
  font-size: 10.5px;
  color: #7b8797;
  line-height: 1;
}

.msg-delivery-ticks {
  font-size: 12px;
  line-height: 1;
  letter-spacing: -1px;
}

.msg-delivery-ticks.is-sent,
.msg-delivery-ticks.is-read {
  color: #4ea0ff;
}

.msg-delivery-ticks.is-pending {
  color: #93a0b1;
}

.msg-delivery-ticks.is-failed {
  color: #ef4444;
}

body.theme-dark .message.message-compact {
  background: rgba(255,255,255,0.05);
  border-color: rgba(148,163,184,0.16);
}

body.theme-dark .message.message-compact.out {
  background: rgba(79,140,255,0.18);
  border-color: rgba(96,165,250,0.32);
}

body.theme-dark .message-attachment {
  background: rgba(255,255,255,0.04);
  border-color: rgba(148,163,184,0.12);
}

body.theme-dark .message-attachment-icon {
  background: rgba(96,165,250,0.15);
  color: #93c5fd;
}

body.theme-dark .message-time {
  color: #8c98a8;
}

@media (max-width: 1180px) {
  .message.message-compact {
    max-width: 84%;
  }
}


/* ===== chat polish 2 ===== */

.message.message-compact {
  max-width: 68%;
  padding: 8px 10px;
  border-radius: 16px;
}

.message-text {
  font-size: 14px;
  line-height: 1.32;
}

.message-attachments {
  margin-top: 6px;
  gap: 6px;
}

.message-attachments-download-all {
  align-self: flex-start;
  border: 1px solid rgba(148,163,184,0.22);
  background: rgba(255,255,255,0.07);
  color: inherit;
  border-radius: 12px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.message-attachment {
  display: block;
  padding: 0;
  background: transparent;
  border: 0;
}

.message-attachment-body {
  min-width: 0;
}

.message-attachment-name {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(148,163,184,0.16);
  font-size: 12px;
  line-height: 1.2;
  word-break: break-word;
}

.message-attachment-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 700;
}

.message-attachment-icon,
.message-attachment-kind,
.message-attachment-meta {
  display: none !important;
}

.message-meta-row {
  margin-top: 6px;
  gap: 4px;
}

.message-time {
  font-size: 11px;
}

.msg-delivery-ticks {
  font-size: 13px;
}

body.theme-dark .message-attachments-download-all {
  background: rgba(255,255,255,0.05);
  border-color: rgba(148,163,184,0.14);
}

body.theme-dark .message-attachment-name {
  background: rgba(255,255,255,0.05);
  border-color: rgba(148,163,184,0.12);
}

@media (max-width: 1180px) {
  .message.message-compact {
    max-width: 82%;
  }
}


/* ===== chat polish 3 ===== */

.messages-list {
  padding: 10px 14px;
  gap: 14px;
}

.message-row {
  display: flex;
}

.message-row.in {
  justify-content: flex-start;
}

.message-row.out {
  justify-content: flex-end;
}

.message.message-compact {
  max-width: 66%;
  padding: 10px 14px;
  border-radius: 18px;
  box-shadow: none;
}

.message.message-compact.out {
  background: rgba(79,140,255,0.18);
  border-color: rgba(96,165,250,0.34);
}

.message-text {
  font-size: 14px;
  line-height: 1.36;
  margin: 0;
}

.message-attachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-attachments-download-all {
  align-self: flex-start;
  border: 1px solid rgba(148,163,184,0.18);
  background: rgba(255,255,255,0.05);
  color: inherit;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.message-attachment {
  display: block;
}

.message-attachment-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(148,163,184,0.14);
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

.message-meta-row {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.message-time {
  font-size: 11px;
  color: #8c98a8;
  line-height: 1;
}

.msg-delivery-ticks {
  font-size: 13px;
  line-height: 1;
  letter-spacing: -1px;
}

@media (max-width: 1180px) {
  .message.message-compact {
    max-width: 82%;
  }
}


/* ===== reply / emoji / composer v1 ===== */

.message-bottom-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.message-meta-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.message-quote-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 0;
}

.message-quote-btn:hover {
  color: var(--text);
}

.composer {
  padding: 12px 14px 14px;
}

.composer-file-row {
  justify-content: flex-end;
  margin-bottom: 8px;
}

.composer-reply-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fbff;
  padding: 10px 12px;
}

.composer-reply-bar.hidden {
  display: none;
}

.composer-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  border-radius: 999px;
  background: var(--primary);
}

.composer-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.composer-reply-title {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.composer-reply-text {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-reply-cancel {
  border: 0;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
}

.composer-reply-cancel:hover {
  background: rgba(15,23,42,0.06);
  color: var(--text);
}

.composer-row {
  grid-template-columns: 44px 44px 44px minmax(0, 1fr) 60px;
  gap: 10px;
}

.composer-textarea {
  min-height: 108px;
  max-height: 240px;
  resize: none;
  border-radius: 18px;
  padding: 14px 16px;
}

.composer-send {
  min-height: 46px;
  height: 46px;
  border-radius: 16px;
  padding: 0;
  font-size: 24px;
}

.composer-emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fbff;
}

.composer-emoji-panel.hidden {
  display: none;
}

.composer-emoji-item {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  min-width: 40px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
}

.quick-replies {
  margin-top: 10px;
}

body.theme-dark .composer-reply-bar,
body.theme-dark .composer-emoji-panel,
body.theme-dark .composer-emoji-item {
  background: rgba(255,255,255,0.04);
}


/* ===== reply fix v2 ===== */

.message-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.message-quote-btn {
  border: 1px solid var(--border);
  background: #f3f7ff;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.message-quote-btn:hover {
  background: #e6f0ff;
}

.composer-reply-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f5f8ff;
  padding: 10px 12px;
}

.composer-reply-title {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 3px;
}

.composer-reply-text {
  font-size: 13px;
  line-height: 1.25;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-emoji-panel {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8fbff;
}

.composer-emoji-item {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  min-width: 0;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
}

@media (max-width: 760px) {
  .composer-emoji-panel {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

body.theme-dark .message-quote-btn {
  background: rgba(255,255,255,0.06);
}

body.theme-dark .message-quote-btn:hover {
  background: rgba(255,255,255,0.12);
}


/* ===== composer layout v2 ===== */

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
  background: rgba(8, 20, 58, 0.96);
}

.composer-layout-v2 {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 78px;
  gap: 14px;
  align-items: stretch;
}

.composer-side {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.composer-side-btn {
  width: 100%;
  height: 58px;
  min-height: 58px;
  border-radius: 18px;
  font-size: 22px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(130,160,220,0.22);
  color: #dce7ff;
}

.composer-center {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer-textarea-v2 {
  min-height: 138px;
  max-height: 260px;
  resize: none;
  border-radius: 22px;
  padding: 18px 20px;
  font-size: 18px;
  line-height: 1.4;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(130,160,220,0.22);
  color: #eef4ff;
}

.composer-textarea-v2::placeholder {
  color: rgba(220,231,255,0.58);
}

.composer-send-v2 {
  width: 100%;
  height: 82px;
  min-height: 82px;
  border-radius: 24px;
  font-size: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.composer-reply-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid rgba(130,160,220,0.22);
  border-radius: 18px;
  background: rgba(255,255,255,0.05);
  padding: 12px 14px;
}

.composer-reply-bar.hidden {
  display: none;
}

.composer-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  border-radius: 999px;
  background: #6ea8ff;
}

.composer-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.composer-reply-title {
  font-size: 13px;
  font-weight: 800;
  color: #dce7ff;
  margin-bottom: 4px;
}

.composer-reply-text {
  font-size: 14px;
  line-height: 1.3;
  color: rgba(220,231,255,0.68);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-reply-cancel {
  border: 0;
  background: transparent;
  color: rgba(220,231,255,0.8);
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
}

.composer-reply-cancel:hover {
  background: rgba(255,255,255,0.08);
}

.composer-emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(130,160,220,0.22);
  border-radius: 18px;
  background: rgba(255,255,255,0.05);
}

.composer-emoji-panel.hidden {
  display: none;
}

.composer-emoji-item {
  border: 1px solid rgba(130,160,220,0.18);
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  height: 40px;
  cursor: pointer;
  font-size: 20px;
  color: #fff;
}

.composer-emoji-item:hover {
  background: rgba(255,255,255,0.12);
}

.quick-replies {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.quick-reply-btn {
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(130,160,220,0.18);
  color: #e8efff;
}

#composer-status {
  margin-top: 10px;
  color: rgba(220,231,255,0.62);
}

.message-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.message-quote-btn {
  border: 1px solid rgba(130,160,220,0.18);
  background: rgba(255,255,255,0.04);
  color: #dce7ff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 7px 11px;
  border-radius: 12px;
  white-space: nowrap;
}

.message-quote-btn:hover {
  background: rgba(255,255,255,0.1);
}

@media (max-width: 980px) {
  .composer-layout-v2 {
    grid-template-columns: 56px minmax(0, 1fr) 62px;
    gap: 10px;
  }

  .composer-side-btn {
    height: 48px;
    min-height: 48px;
    border-radius: 14px;
    font-size: 18px;
  }

  .composer-send-v2 {
    height: 72px;
    min-height: 72px;
    font-size: 32px;
    border-radius: 18px;
  }

  .composer-textarea-v2 {
    min-height: 110px;
    font-size: 16px;
    padding: 14px 16px;
  }

  .composer-emoji-panel {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}


/* ===== reply ui fix ===== */

.message {
  position: relative;
}

.message-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.message-quote-btn {
  border: 1px solid rgba(130,160,220,0.22);
  background: rgba(255,255,255,0.06);
  color: #dce7ff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: nowrap;
  opacity: 1;
  visibility: visible;
}

.message-quote-btn:hover {
  background: rgba(255,255,255,0.14);
}

.message[data-message-id] {
  cursor: default;
}

.message[data-message-id]:hover {
  box-shadow: 0 0 0 1px rgba(110,168,255,0.18) inset;
}


/* ===== reply select force visible ===== */

.composer-reply-bar {
  display: none;
}

.composer-reply-bar:not(.hidden) {
  display: flex !important;
}

.message.is-reply-selected {
  box-shadow:
    0 0 0 2px rgba(110,168,255,0.45) inset,
    0 0 0 1px rgba(110,168,255,0.25);
}

.message[data-message-id] {
  cursor: pointer;
}

.message-quote-btn {
  display: none !important;
}


/* ===== reply by index ===== */

.messages-list .message {
  cursor: pointer;
}

.messages-list .message.is-reply-selected {
  box-shadow:
    0 0 0 2px rgba(110,168,255,0.45) inset,
    0 0 0 1px rgba(110,168,255,0.22);
}

.messages-list .message-attachment,
.messages-list .message-attachment-link {
  cursor: pointer;
}


/* ===== composer compact polish ===== */

.composer {
  padding: 10px 14px 12px;
}

.composer-layout-v2 {
  grid-template-columns: 60px minmax(0, 1fr) 68px;
  gap: 12px;
  align-items: stretch;
}

.composer-side {
  gap: 10px;
}

.composer-side-btn {
  width: 100%;
  height: 48px;
  min-height: 48px;
  border-radius: 16px;
  font-size: 18px;
}

.composer-center {
  gap: 8px;
}

.composer-textarea-v2 {
  min-height: 82px;
  max-height: 150px;
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.32;
}

.composer-textarea-v2::placeholder {
  font-size: 16px;
}

.composer-send-v2 {
  width: 100%;
  height: 68px;
  min-height: 68px;
  border-radius: 20px;
  font-size: 30px;
}

.composer-reply-bar {
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 16px;
}

.composer-reply-accent {
  width: 4px;
  flex: 0 0 4px;
}

.composer-reply-title {
  font-size: 12px;
  margin-bottom: 2px;
}

.composer-reply-text {
  font-size: 13px;
  line-height: 1.22;
}

.composer-reply-cancel {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.composer-emoji-panel {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
}

.composer-emoji-item {
  height: 34px;
  border-radius: 10px;
  font-size: 18px;
}

.quick-replies {
  margin-top: 10px;
  gap: 8px;
}

.quick-reply-btn {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.15;
}

#composer-status {
  margin-top: 8px;
  font-size: 13px;
}

.messages-list {
  padding: 14px;
  gap: 10px;
}

.message.message-compact {
  max-width: 74%;
  padding: 12px 14px;
  border-radius: 16px;
}

.message-text {
  font-size: 14px;
  line-height: 1.34;
}

.message-meta-row {
  margin-top: 8px;
}

.message-time {
  font-size: 12px;
}

.msg-delivery-ticks {
  font-size: 12px;
}

.message-attachment {
  padding: 8px 10px;
  border-radius: 12px;
}

.message-attachment-name {
  font-size: 13px;
}

.message-attachment-meta {
  font-size: 11px;
}

@media (max-width: 980px) {
  .composer-layout-v2 {
    grid-template-columns: 52px minmax(0, 1fr) 58px;
    gap: 10px;
  }

  .composer-side-btn {
    height: 42px;
    min-height: 42px;
    border-radius: 14px;
    font-size: 16px;
  }

  .composer-textarea-v2 {
    min-height: 74px;
    max-height: 130px;
    padding: 12px 14px;
    font-size: 15px;
  }

  .composer-send-v2 {
    height: 60px;
    min-height: 60px;
    border-radius: 18px;
    font-size: 26px;
  }

  .composer-emoji-panel {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .message.message-compact {
    max-width: 82%;
  }
}


/* ===== composer geometry balance ===== */

.composer {
  padding: 8px 14px 10px;
}

/* сетка всей панели */
.composer-layout-v2 {
  grid-template-columns: 54px minmax(0, 1fr) 60px;
  gap: 10px;
  align-items: center;
}

/* левая колонка */
.composer-side {
  gap: 8px;
  justify-content: center;
}

/* кнопки слева */
.composer-side-btn {
  height: 44px;
  min-height: 44px;
  border-radius: 14px;
  font-size: 17px;
}

/* центральная колонка */
.composer-center {
  gap: 6px;
}

/* поле ввода */
.composer-textarea-v2 {
  min-height: 64px;
  max-height: 110px;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 16px;
  line-height: 1.3;
}

/* кнопка отправки */
.composer-send-v2 {
  height: 58px;
  min-height: 58px;
  border-radius: 18px;
  font-size: 24px;
}

/* блок ответа */
.composer-reply-bar {
  padding: 8px 10px;
  margin-bottom: 6px;
  border-radius: 14px;
}

/* текст ответа */
.composer-reply-title {
  font-size: 11px;
}

.composer-reply-text {
  font-size: 13px;
}

/* быстрые шаблоны */
.quick-replies {
  margin-top: 6px;
  gap: 6px;
}

/* кнопки шаблонов */
.quick-reply-btn {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 14px;
}

/* уменьшаем вертикальный отступ перед статусом */
#composer-status {
  margin-top: 6px;
  font-size: 12px;
}

/* ===== FORCE composer side buttons smaller ===== */

.composer-layout-v2 {
  grid-template-columns: 44px minmax(0, 1fr) 50px !important;
  gap: 8px !important;
  align-items: center !important;
}

.composer-side {
  gap: 6px !important;
  justify-content: center !important;
}

.composer-side-btn,
.composer-icon-btn.composer-side-btn {
  width: 100% !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border-radius: 12px !important;
  font-size: 14px !important;
  line-height: 1 !important;
}

.composer-send-v2,
#composer-send.composer-send-v2,
.composer-send.composer-send-v2 {
  width: 100% !important;
  height: 44px !important;
  min-height: 44px !important;
  padding: 0 !important;
  border-radius: 14px !important;
  font-size: 20px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#composer-emoji-toggle.composer-side-btn,
label[for="composer-file"].composer-side-btn,
#chat-templates-toggle.composer-side-btn {
  height: 36px !important;
  min-height: 36px !important;
  font-size: 14px !important;
}

@media (max-width: 980px) {
  .composer-layout-v2 {
    grid-template-columns: 40px minmax(0, 1fr) 46px !important;
    gap: 7px !important;
  }

  .composer-side-btn,
  .composer-icon-btn.composer-side-btn {
    height: 32px !important;
    min-height: 32px !important;
    border-radius: 10px !important;
    font-size: 13px !important;
  }

  .composer-send-v2,
  #composer-send.composer-send-v2,
  .composer-send.composer-send-v2 {
    height: 40px !important;
    min-height: 40px !important;
    border-radius: 12px !important;
    font-size: 18px !important;
  }
}


/* ===== inline reply in message bubble ===== */

.message-inline-reply {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(130,160,220,0.14);
}

.message-inline-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  border-radius: 999px;
  background: #6ea8ff;
}

.message-inline-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.message-inline-reply-author {
  font-size: 11px;
  font-weight: 800;
  color: #dce7ff;
  margin-bottom: 2px;
}

.message-inline-reply-text {
  font-size: 12px;
  line-height: 1.25;
  color: rgba(220,231,255,0.74);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message.out .message-inline-reply {
  background: rgba(255,255,255,0.08);
}

.message-quote-btn {
  display: none;
}

/* ===== reply ui polish ===== */

.message.is-reply-selected {
  box-shadow:
    0 0 0 2px rgba(110,168,255,0.38) inset,
    0 0 18px rgba(110,168,255,0.08);
  border-color: rgba(110,168,255,0.45) !important;
}

.composer-reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px !important;
  margin-bottom: 6px !important;
  border-radius: 14px !important;
  background: rgba(255,255,255,0.045) !important;
  border: 1px solid rgba(130,160,220,0.18) !important;
}

.composer-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  align-self: stretch;
  border-radius: 999px;
  background: #6ea8ff;
}

.composer-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.composer-reply-title {
  font-size: 11px !important;
  font-weight: 800;
  line-height: 1.15;
  color: #dce7ff;
  margin-bottom: 2px !important;
}

.composer-reply-text {
  font-size: 12px !important;
  line-height: 1.2;
  color: rgba(220,231,255,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-reply-cancel {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  padding: 0 !important;
  border-radius: 10px !important;
  font-size: 16px !important;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid rgba(130,160,220,0.14);
  color: rgba(220,231,255,0.82);
}

.composer-reply-cancel:hover {
  background: rgba(255,255,255,0.06);
}

body.theme-light .composer-reply-bar {
  background: rgba(0,0,0,0.03) !important;
  border-color: rgba(80,110,170,0.16) !important;
}

body.theme-light .composer-reply-title {
  color: #20304d !important;
}

body.theme-light .composer-reply-text {
  color: rgba(32,48,77,0.72) !important;
}


/* ===== inline reply bubble ===== */

.message-inline-reply {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 8px;
  padding: 7px 9px;
  border-radius: 12px;
  background: rgba(255,255,255,0.055);
  border: 1px solid rgba(130,160,220,0.14);
}

.message-inline-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  border-radius: 999px;
  background: #6ea8ff;
}

.message-inline-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.message-inline-reply-author {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  color: #dce7ff;
  margin-bottom: 2px;
}

.message-inline-reply-text {
  font-size: 12px;
  line-height: 1.2;
  color: rgba(220,231,255,0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message.out .message-inline-reply {
  background: rgba(255,255,255,0.08);
}

body.theme-light .message-inline-reply {
  background: rgba(0,0,0,0.03);
  border-color: rgba(80,110,170,0.14);
}

body.theme-light .message-inline-reply-author {
  color: #20304d;
}

body.theme-light .message-inline-reply-text {
  color: rgba(32,48,77,0.72);
}


/* ===== inline reply bubble local ===== */

.message-inline-reply {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 8px;
  padding: 7px 9px;
  border-radius: 12px;
  background: rgba(255,255,255,0.055);
  border: 1px solid rgba(130,160,220,0.14);
}

.message-inline-reply-accent {
  width: 4px;
  flex: 0 0 4px;
  border-radius: 999px;
  background: #6ea8ff;
}

.message-inline-reply-body {
  min-width: 0;
  flex: 1 1 auto;
}

.message-inline-reply-author {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  color: #dce7ff;
  margin-bottom: 2px;
}

.message-inline-reply-text {
  font-size: 12px;
  line-height: 1.2;
  color: rgba(220,231,255,0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message.out .message-inline-reply {
  background: rgba(255,255,255,0.08);
}

body.theme-light .message-inline-reply {
  background: rgba(0,0,0,0.03);
  border-color: rgba(80,110,170,0.14);
}

body.theme-light .message-inline-reply-author {
  color: #20304d;
}

body.theme-light .message-inline-reply-text {
  color: rgba(32,48,77,0.72);
}

/* ===== composer tighten next ===== */

.composer {
  padding: 7px 12px 8px !important;
}

.composer-center {
  gap: 5px !important;
}

.composer-textarea-v2 {
  min-height: 56px !important;
  max-height: 96px !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
  line-height: 1.28 !important;
  border-radius: 15px !important;
}

.composer-textarea-v2::placeholder {
  font-size: 14px !important;
}

.quick-replies {
  margin-top: 4px !important;
  gap: 5px !important;
}

.quick-reply-btn {
  padding: 5px 9px !important;
  font-size: 11.5px !important;
  border-radius: 12px !important;
}

#composer-status {
  margin-top: 4px !important;
  font-size: 11px !important;
  opacity: 0.82;
}

.composer-reply-bar {
  margin-bottom: 5px !important;
}

.composer-upload-list {
  margin-bottom: 5px !important;
}

.composer-file-row {
  margin-bottom: 5px !important;
}

.template-attachments-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.template-attachments-list {
  min-height: 36px;
}

@media (max-width: 980px) {
  .composer-textarea-v2 {
    min-height: 52px !important;
    max-height: 88px !important;
    padding: 9px 11px !important;
    font-size: 13px !important;
  }

  .quick-reply-btn {
    font-size: 11px !important;
    padding: 5px 8px !important;
  }
}

/* ===== reduce top gap above composer input ===== */

.composer {
  padding-top: 4px !important;
}

.composer-reply-bar {
  margin-bottom: 3px !important;
}

.composer-file-row {
  margin-bottom: 2px !important;
}

.composer-upload-list {
  margin-bottom: 2px !important;
}

.composer-center {
  gap: 3px !important;
}

/* ===== reply bar tighter + one-line clamp ===== */

.composer {
  padding-top: 2px !important;
}

.composer-reply-bar {
  margin-bottom: 2px !important;
  padding: 6px 10px !important;
  min-height: 0 !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

.composer-reply-body {
  min-width: 0 !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

.composer-reply-title {
  margin-bottom: 0 !important;
  font-size: 11px !important;
  line-height: 1.1 !important;
}

.composer-reply-text {
  display: block !important;
  max-width: 100% !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  font-size: 12px !important;
  line-height: 1.1 !important;
}

.composer-reply-cancel {
  flex: 0 0 auto !important;
}

.composer-layout-v2 {
  margin-top: 0 !important;
}

.composer-center {
  gap: 2px !important;
}

/* ===== reply bar tighter + one-line clamp ===== */

.composer {
  padding-top: 2px !important;
}

.composer-reply-bar {
  margin-bottom: 2px !important;
  padding: 6px 10px !important;
  min-height: 0 !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

.composer-reply-body {
  min-width: 0 !important;
  max-width: 100% !important;
  overflow: hidden !important;
}

.composer-reply-title {
  margin-bottom: 0 !important;
  font-size: 11px !important;
  line-height: 1.1 !important;
}

.composer-reply-text {
  display: block !important;
  max-width: 100% !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  font-size: 12px !important;
  line-height: 1.1 !important;
}

.composer-reply-cancel {
  flex: 0 0 auto !important;
}

.composer-layout-v2 {
  margin-top: 0 !important;
}

.composer-center {
  gap: 2px !important;
}

/* ===== HARD override: compact one-line reply bar ===== */

.composer {
  padding-top: 0 !important;
}

.composer-reply-bar,
#composer-reply-bar {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  margin: 0 0 2px 0 !important;
  padding: 5px 8px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.composer-reply-accent {
  width: 4px !important;
  flex: 0 0 4px !important;
  align-self: stretch !important;
}

.composer-reply-body {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
  overflow: hidden !important;
  white-space: nowrap !important;
}

.composer-reply-title {
  flex: 0 0 auto !important;
  margin: 0 !important;
  font-size: 11px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

.composer-reply-text {
  display: block !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
  margin: 0 !important;
  font-size: 12px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.composer-reply-cancel,
#composer-reply-cancel {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px !important;
  min-height: 22px !important;
  padding: 0 !important;
  margin: 0 !important;
  flex: 0 0 22px !important;
  font-size: 14px !important;
  line-height: 1 !important;
}

.composer-center {
  gap: 1px !important;
}

.composer-layout-v2 {
  margin-top: 0 !important;
}

/* ===== cap reply preview width ===== */

.composer-reply-body {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
  overflow: hidden !important;
}

.composer-reply-title {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
  max-width: none !important;
}

.composer-reply-text {
  flex: 0 1 auto !important;
  min-width: 0 !important;
  width: auto !important;
  max-width: clamp(180px, 42vw, 520px) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

@media (max-width: 980px) {
  .composer-reply-text {
    max-width: clamp(140px, 36vw, 320px) !important;
  }
}

/* =========================================================
   LEGACY TAIL NOTICE
   ---------------------------------------------------------
   The extracted active UI layer was removed from this file.
   Active UI overrides now live in:
     public/styles.final.css

   public/styles.css should now be treated as base/legacy only.
   ========================================================= */
