:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-hover: #f1f5f9;
  --surface-selected: #eaf4ff;
  --text: #182235;
  --text-soft: #5f6c7e;
  --text-faint: #8793a4;
  --line: #e2e8f0;
  --line-strong: #d2dbe6;
  --accent: #2786df;
  --accent-hover: #1975c8;
  --accent-soft: #e9f4ff;
  --success: #188b63;
  --warning: #b97713;
  --danger: #c84458;
  --danger-soft: #fff1f3;
  --shadow-xs: 0 1px 3px rgba(28, 44, 68, .05);
  --shadow-sm: 0 7px 24px rgba(31, 48, 73, .07);
  --shadow-md: 0 18px 50px rgba(31, 48, 73, .13);
  --radius-xs: 8px;
  --radius-sm: 11px;
  --radius: 16px;
  --radius-lg: 22px;
  --header-height: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --app-viewport-height: 100dvh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y;
}
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, textarea, select { font: inherit; color: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled, input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; opacity: .58; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img, video, svg { max-width: 100%; }
h1, h2, h3, h4, p { margin-top: 0; }
h1, h2, h3, h4, b, strong { font-weight: 500; }
[hidden] { display: none !important; }

::selection { background: #cfe7ff; color: var(--text); }
:focus-visible { outline: 2px solid rgba(39, 134, 223, .65); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.muted, .hint { color: var(--text-soft); }
.small { font-size: 13px; }
.code, code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}
.ui-icon {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ---------- Header ---------- */
.app-body { min-height: 100dvh; }
.app-header {
  position: relative;
  z-index: 40;
  min-height: var(--header-height);
  padding: 0 max(22px, var(--safe-right)) 0 max(22px, var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(220, 228, 238, .94);
  background: rgba(255, 255, 255, .91);
  box-shadow: 0 1px 0 rgba(255,255,255,.6);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}
.brand { display: inline-flex; align-items: center; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-text { font-size: 19px; font-weight: 500; letter-spacing: -.35px; }
.app-nav { display: flex; align-items: center; gap: 3px; }
.app-nav > a,
.nav-logout button {
  display: block;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 400;
  white-space: nowrap;
}
.app-nav > a:hover,
.app-nav > a[aria-current="page"],
.nav-logout button:hover { background: var(--surface-hover); color: var(--text); }
.nav-logout { margin: 0; }
.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  padding: 9px;
  background: transparent;
}
.nav-toggle:hover { background: var(--surface-hover); }
.nav-toggle span { display: block; height: 1.5px; margin: 5px 0; border-radius: 2px; background: var(--text); }
.impersonation-bar {
  min-height: 38px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 7px 18px;
  border-bottom: 1px solid #ecd799;
  background: #fff6da;
  color: #6e4d08;
  font-size: 13px;
}
.impersonation-bar form { margin: 0; }
.impersonation-bar button { border: 0; padding: 0; background: transparent; color: #765000; text-decoration: underline; }

/* ---------- Notices ---------- */
.notice {
  width: min(1180px, calc(100% - 36px));
  margin: 14px auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  box-shadow: var(--shadow-xs);
}
.notice.soft { background: #f8fbff; }
.notice.success { border-color: #c5e7d8; background: #f0faf5; color: #176b4d; }
.notice.error { border-color: #edc6ce; background: #fff4f6; color: #963246; }
.app-notice, .subscription-notice { flex: none; width: auto; max-width: none; margin: 8px 18px; }
.offline-banner {
  flex: none;
  padding: 7px 16px;
  border-bottom: 1px solid #ead596;
  background: #fff4d5;
  color: #795411;
  text-align: center;
  font-size: 13px;
}

/* ---------- Controls ---------- */
.button, .btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--surface-hover);
  color: var(--text);
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.button:hover, .btn:hover { border-color: var(--line-strong); color: var(--text); }
.button:active, .btn:active { transform: translateY(1px); }
.button.primary, .btn.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover, .btn.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); color: #fff; }
.button.secondary, .btn.secondary, .button.ghost, .btn.ghost, .ghost { border-color: var(--line); background: var(--surface); color: var(--text-soft); }
.button.danger, .btn.danger, button.danger { border-color: #edc4cc; background: var(--danger-soft); color: var(--danger); }
.btn.small, .button.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.icon-button, .composer-button, .send-button, .dialog-close, .client-reference-save {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
}
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-soft);
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.icon-button:hover { border-color: var(--line); background: var(--surface-hover); color: var(--text); }
.icon-button:active { transform: scale(.96); }
.icon-button.is-active { border-color: #c8e1f8; background: var(--accent-soft); color: var(--accent); }
.icon-button.danger-icon.is-active { border-color: #edc4cc; background: var(--danger-soft); color: var(--danger); }
.icon-when-blocked { display: none; }
.is-blocked .icon-when-unblocked { display: none; }
.is-blocked .icon-when-blocked { display: block; }

input, textarea, select {
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  outline: 0;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select { min-height: 42px; padding: 9px 11px; }
textarea { width: 100%; padding: 10px 11px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #8fc0ec; box-shadow: 0 0 0 3px rgba(39, 134, 223, .1); }
input::placeholder, textarea::placeholder { color: #99a4b3; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- Generic pages ---------- */
.page, .admin-page, .settings-page, .channels-page, .operators-page {
  width: min(1180px, calc(100% - 36px));
  margin: 24px auto 52px;
}
.page.wide { width: min(1320px, calc(100% - 36px)); }
.page.narrow { width: min(760px, calc(100% - 36px)); }
.page-head, .admin-head, .compact-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.page-head h1, .admin-head h1, .compact-head h1 { margin: 0; font-size: clamp(22px, 3vw, 27px); line-height: 1.2; letter-spacing: -.45px; }
.page-head p, .admin-head p, .compact-head p { margin: 5px 0 0; color: var(--text-soft); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-heading { margin: 0 0 12px; }
.section-heading h2, .section-heading h3 { margin: 0 0 4px; }
.section-heading p { margin: 0; color: var(--text-soft); }

.card, .form-panel, .list-panel, .channels-list-panel, .operator-create-card, .operators-list-card,
.admin-section, .admin-company, .max-bridge-card, .widget-code-card, .opult-widget-admin-card, .health-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card, .form-panel, .operator-create-card, .max-bridge-card, .widget-code-card, .opult-widget-admin-card, .admin-section { padding: 18px; }
.card > :first-child, .form-panel > :first-child, .admin-section > :first-child { margin-top: 0; }
.card h2, .form-panel h2, .list-panel h2, .admin-section h2 { margin: 0 0 12px; font-size: 18px; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); gap: 18px; align-items: start; }
.form, .form-panel, .admin-form, .operator-edit-form, .channel-widget-form { display: grid; gap: 12px; }
.form-row, .operator-edit-grid, .admin-company-grid, .channel-widget-grid { display: grid; gap: 12px; }
.form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }

:where(.form, .form-panel, .admin-form, .operator-edit-form, .channel-widget-form, .auth-card) label:not(.check-line):not(.switch-row) {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--text-soft);
  font-size: 12px;
}
:where(.form, .form-panel, .admin-form, .operator-edit-form, .channel-widget-form, .auth-card) label:not(.check-line):not(.switch-row) > input:not([type="checkbox"]):not([type="radio"]),
:where(.form, .form-panel, .admin-form, .operator-edit-form, .channel-widget-form, .auth-card) label:not(.check-line):not(.switch-row) > select,
:where(.form, .form-panel, .admin-form, .operator-edit-form, .channel-widget-form, .auth-card) label:not(.check-line):not(.switch-row) > textarea {
  width: 100%;
}
.check-line { display: flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 13px; }
.checklist { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.checklist li { position: relative; padding-left: 24px; color: var(--text-soft); }
.checklist li::before { content: "✓"; position: absolute; left: 0; top: 0; color: var(--success); }
.status-pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--surface-hover);
  color: var(--text-soft);
  font-size: 11px;
  white-space: nowrap;
}
.status-pill.ok, .status-active, .status-trial { background: #eaf8f2; color: #167653; }
.status-pill.error, .status-blocked, .status-locked, .status-past_due { background: #fff0f2; color: #a5394c; }
.status-pill.warning { background: #fff5e3; color: #8e5f10; }
.table-scroll { width: 100%; overflow-x: auto; border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 12px; }
.table th { background: var(--surface-soft); color: var(--text-soft); font-weight: 500; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Messenger ---------- */
body.messenger-mode {
  height: var(--app-viewport-height, 100dvh);
  min-height: var(--app-viewport-height, 100dvh);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
body.messenger-mode .app-header { flex: none; }
.messenger-shell {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  overflow: hidden;
  background: var(--surface);
}
.chat-sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.sidebar-head {
  flex: none;
  padding: 16px 15px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.95);
}
.sidebar-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sidebar-title-row h1 { margin: 0; font-size: 21px; line-height: 1.2; letter-spacing: -.35px; }
.sidebar-title-row p { max-width: 210px; margin: 3px 0 0; overflow: hidden; color: var(--text-soft); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; align-items: center; gap: 6px; }
.connection-state { min-width: 0; display: inline-flex; align-items: center; gap: 6px; color: var(--text-faint); font-size: 11px; white-space: nowrap; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.connection-state.is-online { color: var(--success); }
.connection-state.is-connecting { color: var(--warning); }
.connection-state.is-offline { color: var(--danger); }
.chat-search {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 13px;
  padding: 0 7px 0 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}
.chat-search:focus-within { border-color: #93c4ef; box-shadow: 0 0 0 3px rgba(39,134,223,.09); background: var(--surface); }
.chat-search .ui-icon { width: 18px; height: 18px; color: var(--text-faint); }
.chat-search input { flex: 1; min-height: 0; height: 36px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: 14px; }
.chat-search input:focus { box-shadow: none; }
.chat-search button { border: 0; padding: 5px 4px; background: transparent; color: var(--accent); font-size: 12px; white-space: nowrap; }
.chat-filters { display: flex; gap: 5px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chat-filters::-webkit-scrollbar { display: none; }
.chat-filters button { flex: 0 0 auto; border: 0; border-radius: 9px; padding: 6px 10px; background: transparent; color: var(--text-soft); font-size: 12px; }
.chat-filters button:hover { background: var(--surface-hover); }
.chat-filters button.active { background: var(--accent-soft); color: #176db9; }

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  scrollbar-gutter: stable;
}
.conversation-item {
  position: relative;
  width: 100%;
  min-height: 76px;
  display: block;
  padding: 10px 10px 9px 14px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  text-align: left;
  transition: background .14s ease, transform .14s ease;
}
.conversation-item:hover { background: var(--surface-hover); }
.conversation-item.active { background: var(--surface-selected); }
.conversation-item:active { transform: scale(.994); }
.conversation-item.blocked { opacity: .68; }
.conversation-unread-dot {
  position: absolute;
  left: 5px;
  top: 50%;
  width: 6px;
  height: 6px;
  display: none;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--accent);
}
.conversation-item.unread .conversation-unread-dot { display: block; }
.conversation-content { min-width: 0; display: grid; gap: 4px; }
.conversation-line { min-width: 0; display: flex; align-items: center; gap: 8px; }
.conversation-line-top, .conversation-line-middle, .conversation-line-bottom { justify-content: space-between; }
.conversation-heading { min-width: 0; display: flex; align-items: center; gap: 7px; }
.conversation-heading strong { min-width: 0; overflow: hidden; color: var(--text); font-size: 14.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.platform-label {
  flex: 0 0 auto;
  max-width: 102px;
  overflow: hidden;
  padding: 2px 6px;
  border: 1px solid #d7e1ec;
  border-radius: 6px;
  background: #f5f8fb;
  color: #607286;
  font-size: 10px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-line-top time { flex: 0 0 auto; color: var(--text-faint); font-size: 11px; }
.conversation-preview { min-width: 0; flex: 1; overflow: hidden; color: var(--text-soft); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item.unread .conversation-heading strong { color: #0f1b2e; }
.conversation-item.unread .conversation-preview { color: #33445a; }
.unread-badge { min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 500; }
.conversation-line-bottom { color: var(--text-faint); }
.conversation-line-bottom small { min-width: 0; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-line-bottom em { flex: 0 0 auto; color: #6b7e92; font-size: 10px; font-style: normal; }
.conversation-item.pinned:not(.blocked) .conversation-line-bottom em { color: #4e789e; }
.conversation-list-empty { padding: 42px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }
.conversation-skeleton { padding: 7px 12px; }
.conversation-skeleton span { display: block; height: 64px; margin: 7px 0; border-radius: 13px; background: linear-gradient(90deg, #f0f4f8 20%, #fafbfd 45%, #f0f4f8 70%); background-size: 220% 100%; animation: shimmer 1.35s infinite; }
@keyframes shimmer { to { background-position: -220% 0; } }
.compact-chat-list .conversation-item { min-height: 61px; padding-top: 7px; padding-bottom: 7px; }
.compact-chat-list .conversation-line-bottom { display: none; }

.chat-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: #edf2f7;
}
.chat-empty { margin: auto; padding: 28px; text-align: center; color: var(--text-soft); }
.empty-symbol { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 15px; border-radius: 20px; background: rgba(255,255,255,.76); box-shadow: var(--shadow-sm); color: #4d89bf; font-size: 25px; font-weight: 500; }
.chat-empty h2 { margin: 0 0 6px; font-size: 18px; }
.chat-empty p { margin: 0; font-size: 13px; }
.chat-work { width: 100%; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; overflow: hidden; }
.chat-work.is-loading .message-viewport { opacity: 0; }
.chat-header {
  position: relative;
  z-index: 5;
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
}
.mobile-back { display: none; }
.chat-identity { min-width: 120px; flex: 1; }
.chat-identity h2 { margin: 0; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.chat-identity p { margin: 2px 0 0; overflow: hidden; color: var(--text-faint); font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { min-width: 0; display: flex; align-items: center; gap: 5px; }
.client-reference-control {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 3px 3px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}
.client-reference-control label { color: var(--text-faint); font-size: 11px; }
.client-reference-control input { width: clamp(92px, 13vw, 160px); min-height: 30px; height: 30px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; box-shadow: none; font-size: 12px; }
.client-reference-control input:focus { background: var(--surface); box-shadow: none; }
.client-reference-save { width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--accent); }
.client-reference-save:hover { background: var(--accent-soft); }
.client-reference-save .ui-icon { width: 17px; height: 17px; }

.message-viewport {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px clamp(13px, 4vw, 70px) 20px;
  scrollbar-gutter: stable;
  transition: opacity .12s ease;
  background:
    radial-gradient(ellipse at 10% 15%, rgba(218, 232, 243, .54) 0, rgba(218, 232, 243, 0) 44%),
    radial-gradient(ellipse at 88% 25%, rgba(232, 225, 239, .44) 0, rgba(232, 225, 239, 0) 46%),
    linear-gradient(145deg, #edf3f6 0%, #f4f2f7 48%, #eef5f2 100%);
}
.message-list { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; }
.message-date { align-self: center; margin: 12px 0 7px; padding: 5px 10px; border: 1px solid rgba(206,217,228,.82); border-radius: 12px; background: rgba(255,255,255,.8); color: var(--text-soft); font-size: 11px; backdrop-filter: blur(8px); }
.message-row { width: 100%; display: flex; animation: message-in .15s ease-out; }
.message-row.in { justify-content: flex-start; }
.message-row.out { justify-content: flex-end; }
@keyframes message-in { from { opacity: 0; transform: translateY(3px); } }
.message-bubble { position: relative; max-width: min(680px, 76%); min-width: 76px; overflow: hidden; padding: 8px 10px 6px; border: 1px solid rgba(210,220,231,.92); border-radius: 15px 15px 15px 5px; background: rgba(255,255,255,.96); box-shadow: 0 2px 8px rgba(39,55,78,.045); }
.message-row.out .message-bubble { border-color: #cce1f4; border-radius: 15px 15px 5px 15px; background: #e7f3fd; }
.message-bubble.is-failed { border-color: #e9b6c0; background: #fff2f4; }
.message-text { overflow-wrap: anywhere; white-space: pre-wrap; font-size: 14px; line-height: 1.43; }
.message-meta { min-height: 15px; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; margin-top: 3px; color: #788596; font-size: 9.5px; }
.message-status { color: #537da1; }
.message-retry { align-self: flex-end; border: 0; padding: 2px 0 0; background: transparent; color: #ad3048; font-size: 12px; font-weight: 500; }
.message-retry:hover { text-decoration: underline; }
.message-image-link { display: block; overflow: hidden; margin: -4px -6px 5px; border-radius: 11px; background: #e4e9ef; }
.message-image-link img { display: block; width: auto; max-width: min(520px, 100%); max-height: 480px; object-fit: contain; }
.message-file { display: block; margin-bottom: 4px; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.66); color: var(--accent); overflow-wrap: anywhere; }
.load-older { position: relative; z-index: 2; display: block; margin: 0 auto 12px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.92); color: var(--text-soft); box-shadow: var(--shadow-sm); font-size: 12px; }
.new-messages-button { position: sticky; z-index: 5; bottom: 8px; display: block; margin: 0 auto; padding: 8px 14px; border: 0; border-radius: 18px; background: var(--accent); color: #fff; box-shadow: 0 8px 24px rgba(39,134,223,.27); font-size: 12px; }
.new-messages-button span:not(:empty) { margin-left: 5px; padding: 1px 5px; border-radius: 8px; background: rgba(255,255,255,.2); }

.composer-wrap {
  position: relative;
  z-index: 6;
  padding: 9px clamp(11px, 3vw, 34px) calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}
.blocked-composer-note { max-width: 980px; margin: 0 auto 8px; padding: 8px 11px; border: 1px solid #edc4cc; border-radius: 10px; background: var(--danger-soft); color: #98384a; font-size: 12px; text-align: center; }
.message-composer { max-width: 980px; display: flex; align-items: flex-end; gap: 7px; margin: 0 auto; }
.composer-button, .send-button { width: 42px; height: 42px; border: 0; border-radius: 13px; background: transparent; color: var(--text-soft); }
.composer-button:hover { background: var(--surface-hover); color: var(--text); }
.send-button { background: var(--accent); color: #fff; transition: background .15s ease, transform .15s ease; }
.send-button:hover { background: var(--accent-hover); }
.send-button:active { transform: scale(.95); }
.message-composer.is-sending .send-button { opacity: .6; pointer-events: none; }
.message-composer.is-blocked { opacity: .56; }
.composer-input { min-width: 0; flex: 1; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 15px; background: var(--surface); box-shadow: 0 2px 10px rgba(31,47,73,.04); }
.composer-input:focus-within { border-color: #8fc0ec; box-shadow: 0 0 0 3px rgba(39,134,223,.09); }
.composer-input textarea { display: block; width: 100%; min-height: 42px; max-height: 144px; resize: none; padding: 10px 12px 8px; border: 0; border-radius: 0; background: transparent; box-shadow: none; line-height: 1.45; }
.composer-input textarea:focus { box-shadow: none; }
.file-chip { display: flex; align-items: center; gap: 7px; margin: 0 7px 7px; padding: 6px 7px 6px 10px; border-radius: 9px; background: var(--accent-soft); color: #3677b4; font-size: 12px; }
.file-chip span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 7px; padding: 0; background: rgba(255,255,255,.78); color: var(--text-soft); }
.file-chip .ui-icon { width: 15px; height: 15px; }
.composer-hint { max-width: 980px; margin: 4px auto 0; padding-left: 98px; color: var(--text-faint); font-size: 9.5px; }
.quick-replies-panel { position: absolute; left: clamp(54px, 7vw, 110px); bottom: calc(100% + 8px); width: min(440px, calc(100vw - 40px)); max-height: min(430px, 60dvh); overflow: hidden; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.98); box-shadow: var(--shadow-md); backdrop-filter: blur(20px); }
.quick-replies-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.quick-replies-head strong { font-size: 14px; }
.quick-replies-head button { border: 0; padding: 4px; background: transparent; color: var(--accent); font-size: 12px; }
.quick-replies-panel > input { width: 100%; height: 38px; min-height: 38px; margin: 10px 0 8px; }
.quick-replies-panel > div:last-child { max-height: 300px; overflow-y: auto; }
.quick-reply-item { width: 100%; display: grid; gap: 2px; padding: 9px; border: 0; border-radius: 10px; background: transparent; text-align: left; }
.quick-reply-item:hover { background: var(--surface-hover); }
.quick-reply-item strong { font-size: 12px; }
.quick-reply-item span { overflow: hidden; color: var(--text-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Dialog windows ---------- */
.app-dialog { width: min(560px, calc(100vw - 28px)); max-height: calc(var(--app-viewport-height, 100dvh) - 28px); padding: 0; border: 0; border-radius: 20px; background: transparent; box-shadow: var(--shadow-md); }
.app-dialog::backdrop { background: rgba(20,31,48,.34); backdrop-filter: blur(4px); }
.dialog-card { max-height: calc(var(--app-viewport-height, 100dvh) - 28px); overflow-y: auto; display: grid; gap: 15px; padding: 20px; border: 1px solid rgba(255,255,255,.84); border-radius: 20px; background: rgba(255,255,255,.98); }
.dialog-card header { display: flex; justify-content: space-between; gap: 14px; }
.dialog-card h2 { margin: 0; font-size: 18px; }
.dialog-card header p { margin: 3px 0 0; color: var(--text-soft); font-size: 12px; }
.dialog-close { width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--surface-hover); color: var(--text-soft); }
.dialog-close:hover { color: var(--text); }
.dialog-close .ui-icon { width: 18px; height: 18px; }
.field-label { display: grid; gap: 6px; color: var(--text-soft); font-size: 12px; }
.field-label input, .field-label textarea, .field-label select, .dialog-search-input { width: 100%; }
.switch-row { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row span { display: grid; gap: 2px; }
.switch-row strong { font-size: 13px; }
.switch-row small { color: var(--text-soft); font-size: 11px; }
.switch-row input { width: 42px; height: 23px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.settings-explanation, .settings-note { margin: 0; color: var(--text-soft); font-size: 11px; }
.history-search-results { min-height: 100px; max-height: min(520px, 58dvh); overflow-y: auto; display: grid; gap: 5px; }
.history-result { width: 100%; display: grid; gap: 3px; padding: 10px; border: 0; border-radius: 11px; background: var(--surface-soft); text-align: left; }
.history-result:hover { background: var(--accent-soft); }
.history-result strong { font-size: 12px; }
.history-result span { overflow: hidden; color: var(--text-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.history-result time { color: var(--text-faint); font-size: 10px; }

/* ---------- Channels ---------- */
.channels-page .split { grid-template-columns: minmax(310px, 390px) minmax(0, 1fr); }
.channels-page .form-panel { position: sticky; top: 78px; }
.platform-fields { display: grid; gap: 11px; }
.channels-list-panel { overflow: hidden; padding: 0; }
.channels-bulk-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.channels-bulk-head h2 { margin: 0; }
.channels-bulk-head p { margin: 3px 0 0; font-size: 13px; }
.channel-row { display: grid; grid-template-columns: minmax(210px, .72fr) minmax(320px, 1.28fr) auto; gap: 16px; align-items: start; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.channel-row:last-of-type { border-bottom: 0; }
.channel-main { min-width: 0; display: grid; gap: 5px; }
.channel-main b { color: var(--text); font-size: 14px; }
.channel-main span, .channel-main small { color: var(--text-soft); font-size: 12px; }
.channel-main code { display: block; max-width: 100%; padding: 6px 8px; border-radius: 8px; background: var(--surface-soft); color: #516174; font-size: 10px; }
.channel-widget-form { min-width: 0; }
.channel-widget-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.channel-widget-note { grid-column: 1 / -1; margin: 0; color: var(--text-faint); font-size: 11px; }
.channel-actions { display: grid; gap: 7px; justify-items: stretch; }
.channel-actions form { margin: 0; }
.channel-actions .btn { width: 100%; }
.channels-bulk-bottom { display: flex; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.widget-code-card, .opult-widget-admin-card { margin-top: 18px; }
.widget-code-card textarea, .opult-widget-admin-card textarea { width: 100%; min-height: 96px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }

/* ---------- Operators ---------- */
.operator-admin-grid { display: grid; grid-template-columns: minmax(290px, 350px) minmax(0, 1fr); gap: 18px; align-items: start; }
.operator-create-card { position: sticky; top: 78px; }
.operators-list-card { overflow: hidden; }
.operator-row { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.operator-row:last-child { border-bottom: 0; }
.operator-row-disabled { opacity: .65; }
.operator-main-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.operator-main-line > div { min-width: 0; }
.operator-main-line b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.operator-main-line span { color: var(--text-soft); font-size: 12px; }
.operator-edit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.operator-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.operator-actions form { margin: 0; }
.max-bridge-card { margin-top: 18px; }

/* ---------- Admin ---------- */
.stats-line { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats-line > div { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-xs); }
.stats-line b { display: block; margin-bottom: 3px; font-size: 23px; line-height: 1.15; }
.stats-line span { color: var(--text-soft); font-size: 12px; }
.admin-section { margin-bottom: 18px; }
.admin-company-list { display: grid; gap: 14px; }
.admin-company { overflow: hidden; }
.admin-company-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; background: var(--surface-soft); }
.company-summary-main { min-width: 0; display: flex; align-items: center; gap: 12px; }
.company-avatar { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 13px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.company-title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.company-title-line h3 { margin: 0; }
.company-metrics { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-soft); font-size: 12px; }
.admin-company-body { padding: 16px; }
.admin-company-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.company-plan-summary { padding: 12px; border-radius: 12px; background: var(--surface-soft); }
.company-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.split-admin-tables { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.health-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.health-card { padding: 14px; }
.health-card b { display: block; font-size: 20px; }
.health-card span { color: var(--text-soft); font-size: 12px; }

/* ---------- Devices / Billing ---------- */
.device-list { overflow: hidden; }
.device-row { display: grid; grid-template-columns: 42px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.device-row:last-child { border-bottom: 0; }
.device-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-soft); color: var(--text-soft); }
.device-title { display: flex; align-items: center; gap: 8px; }
.device-agent { overflow-wrap: anywhere; color: var(--text-soft); font-size: 12px; }
.device-meta { color: var(--text-faint); font-size: 11px; }
.tariffs-line { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-top: 22px; }
.tariffs-line > div { display: grid; gap: 10px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.tariffs-line strong { font-size: 24px; }
.tariffs-line a { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--accent); color: white; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, var(--safe-top)) max(18px, var(--safe-right)) max(24px, var(--safe-bottom)) max(18px, var(--safe-left));
  background:
    radial-gradient(circle at 16% 15%, rgba(214,234,252,.8), transparent 32%),
    radial-gradient(circle at 86% 84%, rgba(231,224,242,.55), transparent 35%),
    var(--bg);
}
.auth-shell { width: min(430px, 100%); }
.auth-brand { display: table; margin: 0 auto 17px; }
.auth-card { display: grid; gap: 14px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(255,255,255,.96); box-shadow: var(--shadow-md); backdrop-filter: blur(20px); }
.auth-card > h1 { margin: 0 0 2px; text-align: center; font-size: 24px; }
.auth-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 3px; text-align: left; }
.auth-heading h1 { margin: 0; font-size: 23px; }
.auth-heading p { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; }
.auth-icon { width: 52px; height: 52px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 16px; background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 500; }
.auth-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { min-height: 46px; font-size: 16px; }
.auth-card .button, .auth-card .btn { width: 100%; min-height: 45px; }
.auth-card > p { margin: 1px 0 0; text-align: center; font-size: 13px; }
.remember-line { padding: 2px 0; }

/* ---------- Public ---------- */
.public-body { background: #fbfcfe; }
.topbar { width: min(1180px, calc(100% - 36px)); min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 auto; }
.topbar nav { display: flex; align-items: center; gap: 5px; }
.topbar nav a { padding: 8px 10px; border-radius: 10px; color: var(--text-soft); }
.topbar nav a:hover { background: var(--surface-hover); color: var(--text); }
.topbar .nav-cta { background: var(--accent); color: #fff; }
.topbar .nav-cta:hover { background: var(--accent-hover); color: #fff; }
.landing-page { overflow: hidden; }
.landing-hero { width: min(1180px, calc(100% - 36px)); display: grid; grid-template-columns: 1.05fr .95fr; align-items: center; gap: 54px; margin: 62px auto 80px; }
.landing-copy h1 { max-width: 700px; margin: 10px 0 18px; font-size: clamp(38px, 5vw, 66px); font-weight: 500; line-height: 1.06; letter-spacing: -2.3px; }
.landing-copy > p { max-width: 650px; color: var(--text-soft); font-size: 18px; }
.eyebrow { color: var(--accent); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 26px; }
.landing-card-preview { min-height: 480px; overflow: hidden; border: 1px solid var(--line); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow-md); }
.preview-top { height: 58px; display: flex; align-items: center; gap: 7px; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.preview-top span { width: 9px; height: 9px; border-radius: 50%; background: #d5dde7; }
.preview-body { min-height: 422px; display: grid; grid-template-columns: 42% 58%; }
.preview-list { display: grid; align-content: start; gap: 12px; padding: 22px; border-right: 1px solid var(--line); }
.preview-list i { height: 52px; border-radius: 12px; background: #f1f4f8; }
.preview-list i.active { background: #e6f2fd; }
.preview-chat { padding: 28px 22px; }
.preview-chat p { margin: 18px 0 6px; padding: 12px; border-radius: 14px 14px 14px 4px; background: #f1f4f8; }
.preview-chat em { color: var(--text-faint); font-size: 11px; font-style: normal; }
.preview-answer { margin-top: 20px; padding: 12px; border-radius: 14px 14px 4px 14px; background: #e6f3fd; }
.landing-strip { width: min(1180px, calc(100% - 36px)); display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin: 60px auto; }
.landing-strip span { padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--text-soft); text-align: center; }
.landing-benefits { width: min(1180px, calc(100% - 36px)); display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin: 60px auto; }
.landing-benefits article { padding: 22px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow-xs); }
.landing-benefits b { display: block; margin-bottom: 8px; }
.landing-benefits span { color: var(--text-soft); }
.landing-final { width: min(1180px, calc(100% - 36px)); margin: 60px auto; padding: 40px; border-radius: 26px; background: var(--accent-soft); text-align: center; }
.landing-final h2 { margin-bottom: 8px; }
.landing-final p { max-width: 700px; margin: 0 auto 20px; color: var(--text-soft); }
.footer { padding: 28px; border-top: 1px solid var(--line); color: var(--text-soft); text-align: center; font-size: 12px; }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; z-index: 200; right: max(16px, var(--safe-right)); bottom: calc(16px + var(--safe-bottom)); width: min(380px, calc(100vw - 32px)); display: grid; gap: 8px; pointer-events: none; }
.toast { transform: translateY(8px); opacity: 0; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.97); color: var(--text); box-shadow: var(--shadow-md); backdrop-filter: blur(14px); transition: opacity .18s ease, transform .18s ease; font-size: 13px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast-error { border-color: #ecc1c9; color: #963146; }
.toast-success { border-color: #c3e5d5; color: #176b4d; }
.toast-warning { border-color: #ead59f; color: #795411; }

/* ---------- Responsive ---------- */
@media (max-width: 1120px) {
  .app-nav > a, .nav-logout button { padding-inline: 7px; font-size: 13px; }
  .messenger-shell { grid-template-columns: minmax(275px, 325px) minmax(0,1fr); }
  .channel-row { grid-template-columns: minmax(180px, .58fr) minmax(300px, 1.42fr); }
  .channel-actions { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0,1fr)); }
  .operator-edit-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .health-grid, .stats-line { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .landing-hero { grid-template-columns: 1fr; }
  .landing-card-preview { min-height: 400px; }
}

@media (max-width: 860px) {
  :root { --header-height: 54px; }
  .app-header { padding-inline: max(14px, var(--safe-left)) max(14px, var(--safe-right)); }
  .nav-toggle { display: block; }
  .app-nav { position: absolute; top: calc(100% + 7px); right: max(12px, var(--safe-right)); width: min(280px, calc(100vw - 24px)); display: none; align-items: stretch; flex-direction: column; padding: 8px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.99); box-shadow: var(--shadow-md); }
  .app-nav.is-open { display: flex; }
  .app-nav > a, .nav-logout button { width: 100%; padding: 10px 11px; text-align: left; }

  .messenger-shell { position: relative; display: block; }
  .chat-sidebar, .chat-stage { position: absolute; inset: 0; width: 100%; height: 100%; }
  .chat-sidebar { z-index: 1; border-right: 0; }
  .chat-stage { z-index: 2; transform: translateX(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
  body.mobile-chat-open .chat-stage { transform: translateX(0); }
  body.mobile-chat-open .chat-sidebar { visibility: hidden; }
  .mobile-back { display: inline-grid; }
  .chat-header { min-height: 60px; padding: 7px max(7px, var(--safe-right)) 7px max(7px, var(--safe-left)); }
  .chat-identity { min-width: 0; }
  .chat-actions { gap: 3px; }
  .client-reference-control { max-width: 155px; }
  .client-reference-control input { width: 78px; }
  .chat-actions .icon-button { width: 35px; height: 35px; }
  .message-viewport { padding: 12px max(10px, var(--safe-right)) 14px max(10px, var(--safe-left)); }
  .message-bubble { max-width: 87%; }
  .composer-wrap { padding-left: max(7px, var(--safe-left)); padding-right: max(7px, var(--safe-right)); }

  /* iOS/iPadOS PWA: anchor the composer to the visual viewport instead of
     allowing WebKit to collapse the whole messenger layout above the keyboard. */
  body.mobile-keyboard-open .chat-stage {
    transform: none;
    transition: none;
  }
  body.mobile-keyboard-open .composer-wrap {
    position: fixed;
    z-index: 120;
    left: 0;
    right: 0;
    bottom: var(--keyboard-inset-bottom, 0px);
    width: 100%;
    padding-top: 7px;
    padding-bottom: 7px;
    margin: 0;
    will-change: bottom;
  }
  body.mobile-keyboard-open .message-viewport {
    padding-bottom: calc(var(--composer-height, 62px) + 16px);
  }
  body.mobile-keyboard-open .quick-replies-panel {
    max-height: max(120px, calc(var(--keyboard-visible-height, 50vh) - 96px));
  }

  .composer-hint { display: none; }
  .composer-button { width: 38px; }
  .quick-replies-panel { left: 8px; width: calc(100vw - 16px); }

  .page, .admin-page, .settings-page, .channels-page, .operators-page, .page.wide { width: min(100% - 24px, 760px); margin-top: 16px; }
  .page-head, .admin-head, .compact-head { flex-direction: column; }
  .grid.two, .grid.three, .split, .channels-page .split, .operator-admin-grid, .form-row, .admin-company-grid, .split-admin-tables { grid-template-columns: 1fr; }
  .channels-page .form-panel, .operator-create-card { position: static; }
  .channel-row { grid-template-columns: 1fr; }
  .channel-widget-grid, .operator-edit-grid { grid-template-columns: 1fr; }
  .channel-actions { grid-column: auto; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .admin-company-summary { align-items: flex-start; flex-direction: column; }
  .company-metrics { width: 100%; }
  .landing-benefits, .landing-strip { grid-template-columns: 1fr; }
  .landing-copy h1 { font-size: clamp(35px, 12vw, 52px); letter-spacing: -1.6px; }
  .topbar { min-height: 60px; }
  .topbar nav a:not(.nav-cta) { display: none; }
}

@media (max-width: 560px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), textarea, select { font-size: 16px; }
  .connection-state span { display: none; }
  .sidebar-head { padding: 13px 10px 10px; }
  .sidebar-title-row h1 { font-size: 19px; }
  .conversation-list { padding: 4px; }
  .conversation-item { min-height: 72px; padding: 9px 8px 8px 13px; border-radius: 12px; }
  .platform-label { max-width: 82px; }
  .chat-header { flex-wrap: nowrap; }
  .chat-identity h2 { font-size: 14px; }
  .chat-identity p { max-width: 150px; }
  .client-reference-control { width: 105px; max-width: 105px; padding-left: 6px; }
  .client-reference-control label { display: none; }
  .client-reference-control input { width: 66px; font-size: 12px; }
  .message-bubble { max-width: 92%; }
  .message-image-link img { max-height: 390px; }
  .composer-button:first-child { display: none; }
  .message-composer { gap: 4px; }
  .composer-button, .send-button { border-radius: 11px; }
  .dialog-card { padding: 17px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr; }
  .dialog-actions .button, .dialog-actions .btn { width: 100%; }
  .device-row { grid-template-columns: 42px minmax(0,1fr); }
  .device-row form { grid-column: 1 / -1; }
  .stats-line, .health-grid, .tariffs-line { grid-template-columns: 1fr; }
  .channel-actions { grid-template-columns: 1fr; }
  .auth-card { padding: 20px; }
  .auth-heading { align-items: flex-start; }
  .landing-hero { margin-top: 36px; }
  .landing-final { padding: 28px 18px; }
  .preview-body { grid-template-columns: 1fr; }
  .preview-list { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

/* Small structural corrections for server-rendered sections */
.list-panel:not(.channels-list-panel):not(.operators-list-card):not(.device-list) { padding: 18px; }
.operators-list-card > h2 { margin: 0; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.operators-list-card > p { margin: 0; padding: 18px; }
.operator-row .operator-delete-form { display: flex; justify-content: flex-end; margin-top: 8px; }
.operator-main-line small { display: block; margin-top: 3px; color: var(--text-faint); font-size: 11px; }
.admin-form h4 { grid-column: 1 / -1; margin: 0; font-size: 14px; }
.admin-company-body > .company-actions { margin-top: 14px; }
.admin-section.split-admin-tables > div { min-width: 0; }
.admin-section.split-admin-tables h2 { font-size: 16px; }
.tariffs-line > form { display: grid; gap: 10px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.tariffs-line > form strong { font-size: 24px; }
.page > .table { margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.card .checklist p { margin: 0; padding: 12px 0; border-bottom: 1px solid var(--line); }
.card .checklist p:last-child { border-bottom: 0; }
.health-card small { display: block; margin-top: 4px; color: var(--text-faint); font-size: 11px; }

@media (max-width: 560px) {
  .auth-heading { display: grid; justify-items: center; text-align: center; }
  .operator-main-line { align-items: flex-start; flex-direction: column; }
  .operator-main-line .check-line { width: 100%; }
}

/* v10.6: long client names in the active chat header */
@media (max-width: 700px) {
  .chat-header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: start;
    column-gap: 8px;
  }

  .mobile-back {
    grid-column: 1;
    align-self: start;
    flex: none;
  }

  .chat-identity {
    grid-column: 2;
    width: 100%;
    min-width: 0;
    align-self: center;
    padding-block: 2px;
  }

  .chat-identity h2 {
    display: -webkit-box;
    max-width: 100%;
    max-height: 2.5em;
    margin: 0;
    overflow: hidden;
    color: var(--text);
    line-height: 1.25;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .chat-identity p {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-actions {
    grid-column: 3;
    min-width: 0;
    max-width: 100%;
    align-self: start;
    flex: none;
  }
}

@media (max-width: 380px) {
  .chat-header {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    column-gap: 6px;
  }

  .chat-actions .icon-button {
    width: 33px;
    height: 33px;
  }

  .client-reference-control {
    width: 92px;
    max-width: 92px;
  }

  .client-reference-control input {
    width: 54px;
  }
}
