:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ea;
  --panel: rgba(255, 255, 255, 0.94);
  --blue: #175cd3;
  --blue-dark: #123f91;
  --teal: #087f72;
  --warning: #9a5b00;
  --danger: #b42318;
  --success: #027a48;
  --shadow: 0 18px 45px rgba(28, 48, 75, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #dcecff 0, transparent 35%),
    radial-gradient(circle at 100% 10%, #d8f5ef 0, transparent 30%),
    #f5f8fc;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  align-items: flex-end;
  padding: 42px max(5vw, 28px) 28px;
  border-bottom: 1px solid rgba(217, 225, 234, 0.8);
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(28px, 4vw, 44px); letter-spacing: -0.045em; }
h2 { margin-bottom: 18px; font-size: 22px; letter-spacing: -0.025em; }
.subtitle, .hint { color: var(--muted); }
.auth-hint { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.eyebrow {
  margin-bottom: 7px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

main { width: min(1380px, 92vw); margin: 28px auto 70px; }
.readiness {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.readiness-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid rgba(217, 225, 234, 0.9);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 22px rgba(28, 48, 75, 0.06);
}
.readiness-item span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.readiness-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.readiness-item strong[data-kind="ok"] { color: var(--success); }
.readiness-item strong[data-kind="warning"] { color: var(--warning); }
.readiness-item strong[data-kind="error"] { color: var(--danger); }
.workspace-hidden { display: none !important; }
.grid.workspace-hidden { margin: 0; }
.grid { display: grid; gap: 22px; margin-bottom: 22px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel {
  padding: 24px;
  border: 1px solid rgba(217, 225, 234, 0.9);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.info-box, .advanced-box {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #b8d4fe;
  border-radius: 12px;
  background: #eef6ff;
}
.advanced-box { margin-top: 18px; border-color: var(--line); background: #fbfdff; }
.info-box summary, .advanced-box summary { color: #344054; font-weight: 800; cursor: pointer; }
.info-box p, .advanced-box form { margin: 13px 0 0; }
h3 { margin: 20px 0 7px; font-size: 16px; }
code { padding: 2px 5px; border-radius: 5px; background: #eef2f6; }
.accent-panel { border-top: 4px solid var(--blue); }
.warning-panel { color: #6b4608; background: #fff9e8; border-color: #f3d991; }
.section-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.auth-box { width: min(430px, 100%); }
.compact-button { margin-top: 8px; padding: 7px 10px; font-size: 12px; }
.saved-forms-panel { padding: 18px 24px; }
.saved-forms-settings summary {
  color: #344054;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.saved-forms-settings .hint { margin-top: 12px; max-width: 780px; }
.saved-forms-settings .compact-button { margin-top: 14px; }

label { display: grid; gap: 7px; color: #344054; font-size: 13px; font-weight: 700; }
input, textarea, select, button {
  width: 100%;
  border-radius: 10px;
  font: inherit;
}
input, textarea, select {
  border: 1px solid #cbd5e1;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
  outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #dbeafe; }
button {
  width: auto;
  border: 0;
  padding: 11px 16px;
  color: white;
  background: var(--blue);
  font-weight: 800;
  cursor: pointer;
}
button:hover { background: var(--blue-dark); }
button.secondary { background: #344054; }
button.ghost { color: var(--blue); background: #eff6ff; }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.55; cursor: wait; }
.inline, .suggest-box { display: flex; gap: 9px; }
.inline input, .suggest-box input { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }
.checkbox { display: flex; flex-direction: row; align-items: center; }
.checkbox input { width: auto; }
.hint { margin: 0; font-size: 13px; line-height: 1.45; }

.cards { display: grid; gap: 9px; margin-top: 18px; }
.card, .audit-item {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfdff;
}
.card strong { display: block; margin-bottom: 4px; }
.card small, .audit-item small { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.suggest-box { margin-top: 14px; }

.status { display: inline-block; margin-top: 9px; font-size: 12px; font-weight: 800; }
.status.ok { color: var(--success); }
.status.error { color: var(--danger); }
.status.neutral { color: var(--muted); }
.notice { position: sticky; top: 10px; z-index: 5; padding: 13px 16px; border-radius: 11px; margin-bottom: 16px; box-shadow: var(--shadow); }
.notice.ok { color: #05603a; background: #dff8ea; }
.notice.error { color: #8f1d16; background: #fee4e2; }
.operator-alerts {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding: 15px 17px;
  border: 1px solid #f3d991;
  border-left: 5px solid #f0b429;
  border-radius: 13px;
  background: #fffbeb;
  box-shadow: var(--shadow);
}
#operatorAlertItems { display: grid; gap: 5px; margin-top: 7px; color: #6b4608; font-size: 13px; }
.operator-alert-item { overflow-wrap: anywhere; }
.hidden { display: none !important; }

.confirmation {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  margin: 0 0 18px;
  padding: 18px;
  border: 2px solid #f0b429;
  border-radius: 13px;
  background: #fffbeb;
}
.confirmation p { margin: 3px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.row-actions button { padding: 7px 10px; font-size: 12px; }
th { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.state { font-weight: 800; }
.state.completed { color: var(--success); }
.state.failed, .state.cancelled, .state.expired { color: var(--danger); }
.state.pending_confirmation { color: var(--warning); }
.audit-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 22px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  border: 1px solid rgba(217, 225, 234, 0.7);
}
.workspace-tabs {
  position: sticky;
  top: 10px;
  z-index: 4;
  box-shadow: 0 10px 30px rgba(28, 48, 75, 0.08);
  backdrop-filter: blur(12px);
}
.tab {
  flex: 0 0 auto;
  border: 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { background: rgba(23, 82, 211, 0.06); color: var(--ink); }
.tab.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 2px 8px rgba(23, 82, 211, 0.25);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============ AUTH DIALOG ============ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
}
.dialog {
  width: min(440px, 92vw);
  padding: 28px;
  border-radius: 18px;
  background: white;
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
.dialog h3 { margin-bottom: 18px; }
.dialog button { margin-top: 9px; }

/* ============ ACCOUNT CARDS ============ */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
}
.card-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 9px;
}
.card-body small { display: block; color: var(--muted); font-size: 12px; }
.card-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.card-actions button { font-size: 11px; padding: 6px 10px; width: auto; }
.account-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.status-active { color: var(--success); background: #dff8ea; }
.status-banned { color: var(--danger); background: #fee4e2; }
.status-flood_wait { color: var(--warning); background: #fff3d6; }
.status-pending { color: #6b4608; background: #fff9e8; }
.status-running { color: var(--blue); background: #dbeafe; }
.status-created { color: var(--blue); background: #dbeafe; }
.status-completed { color: var(--success); background: #dff8ea; }
.status-completed_with_errors { color: var(--warning); background: #fff3d6; }
.status-failed { color: var(--danger); background: #fee4e2; }
.status-cancelled { color: var(--muted); background: #f0f2f5; }
.status-paused { color: #6b4608; background: #fff3d6; }
.status-resolved { color: var(--success); background: #dff8ea; }
.status-ignored { color: var(--muted); background: #f0f2f5; }
.success-text { color: var(--success); font-weight: 700; font-size: 15px; }
.template-variable-fields {
  padding: 13px;
  border: 1px dashed #9fb9dc;
  border-radius: 11px;
  background: #f7fbff;
}
.template-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 9px; }
.batch-progress { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 8px 0; color: var(--muted); font-size: 13px; }
.batch-progress strong { display: inline; color: var(--ink); }
.form-step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 -2px;
  padding-top: 8px;
  border-top: 1px solid #edf1f5;
  color: #344054;
  font-size: 13px;
}
.form-step:first-of-type { padding-top: 0; border-top: 0; }
.form-step span {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--blue);
  font-size: 12px;
}
.batch-preview {
  padding: 13px 15px;
  border: 1px solid #b8d4fe;
  border-radius: 11px;
  color: #173b72;
  background: #eef6ff;
  font-size: 13px;
  line-height: 1.5;
}
.batch-preview strong { color: var(--ink); }
.batch-preview[data-kind="warning"] { border-color: #f3d991; color: #6b4608; background: #fffbeb; }
.batch-card { display: grid; gap: 9px; }

#batches {
  /* Batch cards refresh automatically. Do not let the browser select a
     disappearing detail row as the page scroll anchor. */
  overflow-anchor: none;
}
.batch-card-controls, .batch-footer { display: flex; align-items: center; gap: 9px; }
.batch-footer { justify-content: space-between; }
.batch-card-controls .icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
}
.batch-control-button { padding: 7px 10px; font-size: 12px; }
.batch-human-status {
  padding: 10px 12px;
  border: 1px solid #b8d4fe;
  border-radius: 9px;
  color: #173b72;
  background: #eef6ff;
  font-size: 13px;
  line-height: 1.45;
}
.batch-human-status[data-kind="success"] { border-color: #99d9b5; color: #17623a; background: #edf9f2; }
.batch-human-status[data-kind="warning"] { border-color: #f3d991; color: #6b4608; background: #fffbeb; }
.batch-human-status[data-kind="error"] { border-color: #f2b8b5; color: #8a1c17; background: #fff5f4; }
.batch-human-status[data-kind="neutral"] { border-color: var(--line); color: var(--muted); background: #f7f8fa; }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: #e7edf5; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--teal)); }
.batch-detail { padding: 13px; border-top: 1px solid var(--line); background: #f8fbff; }
.batch-detail h4 { margin: 8px 0; }
.batch-actions-list { display: grid; gap: 6px; }
.batch-skipped-list { display: grid; gap: 6px; }
.batch-skipped-target {
  display: grid;
  grid-template-columns: minmax(170px, .8fr) minmax(180px, 2fr);
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  color: #6b4608;
  background: #fffbeb;
}
.batch-skipped-target span { overflow-wrap: anywhere; }
.batch-action-row {
  display: grid;
  grid-template-columns: minmax(170px, .8fr) minmax(100px, .7fr) minmax(160px, 1.3fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-radius: 8px;
  background: white;
}
.batch-action-row small { grid-column: 2 / -1; overflow-wrap: anywhere; }
.state.result-success { color: var(--success); }
.state.result-warning { color: #8a5a00; }
.state.result-error { color: var(--danger); }
.state.result-info { color: var(--blue); }
.state.result-neutral { color: var(--muted); }
.technical-details { grid-column: 2 / -1; font-size: 12px; color: var(--muted); }
.technical-details summary { cursor: pointer; font-weight: 700; }
.technical-details code {
  display: block;
  margin-top: 6px;
  padding: 8px;
  border-radius: 7px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  background: #f1f4f8;
}
.operation-timeline { display: grid; gap: 8px; margin-top: 16px; }
.operation-filters {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(190px, 1.4fr) minmax(120px, .7fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fbff;
}
.timeline-item {
  display: grid;
  grid-template-columns: minmax(190px, .8fr) minmax(120px, .6fr) minmax(160px, 1.4fr);
  gap: 12px;
  padding: 11px 13px;
  border-left: 4px solid #9fb9dc;
  border-radius: 9px;
  background: #f8fbff;
}
.timeline-item strong, .timeline-item small { display: block; }
.timeline-item small { margin-top: 3px; color: var(--muted); }
.timeline-item.level-warning { border-left-color: #f0b429; background: #fffbeb; }
.timeline-item.level-error { border-left-color: var(--danger); background: #fff5f4; }
.timeline-target, .timeline-message { overflow-wrap: anywhere; font-size: 12px; }
.timeline-target { font-weight: 700; }
.alert-card { border-left: 4px solid #f0b429; }
.exclusion-card { border-left: 4px solid var(--danger); }
.account-restriction-card { border-left: 4px solid var(--danger); }
.account-restriction-card .card-header { align-items: flex-start; }
.account-restriction-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.account-restriction-tools button { width: auto; }
.account-restriction-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  padding-right: 5px;
  overflow-y: auto;
}
.account-restriction-row {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border-radius: 8px;
  background: #fff5f4;
}
.account-restriction-row span {
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 700;
}
.account-restriction-row small { color: var(--muted); }
.account-restriction-empty { margin: 9px 0 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

@media (max-width: 900px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .grid.two, .audit-list { grid-template-columns: 1fr; }
  .readiness { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .operation-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  main { width: min(94vw, 100%); }
  .topbar, .panel { padding: 19px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .confirmation { grid-template-columns: 1fr; }
  .inline, .suggest-box { flex-direction: column; }
  .workspace-tabs { position: static; }
  .workspace-tabs .tab { flex: 1 1 45%; }
  .readiness, .template-values { grid-template-columns: 1fr; }
  .batch-action-row, .batch-skipped-target, .timeline-item { grid-template-columns: 1fr; }
  .batch-action-row small { grid-column: auto; }
  .technical-details { grid-column: auto; }
  .operator-alerts { flex-direction: column; }
  .operation-filters { grid-template-columns: 1fr; }
}

/* Drag-and-drop file import zone */
.drop-zone {
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop-zone.dragging {
  border-color: var(--accent, #2e86de) !important;
  background: rgba(46, 134, 222, 0.08);
  outline: 2px dashed var(--accent, #2e86de);
  outline-offset: -4px;
}

/* Full-screen chats */
[data-workspace="chats"] .cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}
.chat-item:hover { background: #f7fbff; }
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #dcecff, #d8f5ef);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--blue);
  flex-shrink: 0;
}
.chat-body { flex: 1; min-width: 0; }
.chat-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-preview {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-operator-attention {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #8a4b08;
  background: #fff1d6;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.chat-account {
  font-size: 11px;
  color: var(--muted);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.chat-time {
  font-size: 12px;
  color: var(--muted);
}
.chat-unread {
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }


/* Consolidated inbox workspace */
body.chat-workspace-active main {
  width: calc(100vw - 32px);
  max-width: none;
  margin-left: 16px;
  margin-right: 16px;
}
body.chat-workspace-active [data-workspace="chats"] {
  min-height: calc(100vh - 210px);
}
body.chat-workspace-active #inbox {
  max-height: calc(100vh - 330px);
  overflow-y: auto;
  padding-right: 4px;
}
.chat-account {
  font-size: 11px;
  color: var(--muted);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Interactive Telegram conversation pane */

.telegram-chat-layout {
  display: grid;
  grid-template-columns:
    minmax(320px, 38%)
    minmax(0, 1fr);
  gap: 16px;
  min-height: calc(100vh - 330px);
}

.telegram-chat-list {
  max-height: calc(100vh - 330px);
  overflow-y: auto;
  padding-right: 4px;
  align-content: start;
}

.telegram-chat-conversation {
  min-width: 0;

  display: grid;

  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto;

  min-height: calc(100vh - 330px);
  max-height: calc(100vh - 330px);

  border: 1px solid var(--line);
  border-radius: 14px;

  background: rgba(
    255,
    255,
    255,
    0.92
  );

  overflow: hidden;
}

.telegram-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 12px;
  padding: 14px 16px;

  border-bottom:
    1px solid var(--line);
}

.telegram-chat-messages {
  min-height: 0;

  overflow-y: auto;

  padding: 18px;

  display: flex;
  flex-direction: column;

  gap: 8px;

  background:
    rgba(
      245,
      248,
      252,
      0.75
    );
}

.telegram-message {
  position: relative;

  width: fit-content;

  max-width:
    min(76%, 720px);

  padding:
    9px 12px 7px;

  border-radius: 14px;

  box-shadow:
    0 1px 3px
    rgba(
      16,
      24,
      40,
      0.08
    );
}

.telegram-message.manageable {
  min-width: 132px;
  padding-right: 42px;
}

.telegram-message-actions {
  position: absolute;
  top: 5px;
  right: 6px;
  z-index: 3;
}

.telegram-message-menu-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  min-width: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: #526174;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: none;
  font-size: 20px;
  line-height: 1;
}

.telegram-message-menu-button:hover,
.telegram-message-menu-button[aria-expanded="true"] {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
}

.telegram-message-menu {
  position: absolute;
  right: 0;
  bottom: 30px;
  z-index: 8;
  width: max-content;
  min-width: 154px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.2);
}

.telegram-message-menu.open-downward {
  top: 30px;
  bottom: auto;
}

.telegram-message-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  background: transparent;
  box-shadow: none;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.telegram-message-menu button:hover {
  background: #f0f4fa;
}

.telegram-message-menu button.danger {
  color: var(--danger);
}

.telegram-message-menu button.danger:hover {
  background: #fff0ef;
}

.telegram-message.in {
  align-self: flex-start;

  background: #fff;

  border-bottom-left-radius:
    5px;
}

.telegram-message.out {
  align-self: flex-end;

  background: #dff6eb;

  border-bottom-right-radius:
    5px;
}

.telegram-message-sender {
  margin-bottom: 3px;

  font-size: 11px;
  font-weight: 800;

  color: var(--teal);
}

.telegram-message-text {
  overflow-wrap: anywhere;
}

.telegram-message-time {
  margin-top: 4px;

  font-size: 10px;

  color: var(--muted);

  text-align: right;
}

.message-edit-dialog {
  width: min(560px, 92vw);
}

.message-edit-dialog .hint {
  margin: -8px 0 16px;
}

.message-edit-dialog label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.message-edit-dialog textarea {
  width: 100%;
  min-height: 140px;
  max-height: 55vh;
  resize: vertical;
}

.message-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 12px;
}

.message-edit-actions button {
  width: auto;
}

.telegram-chat-composer {
  display: grid;

  grid-template-columns:
    minmax(0, 1fr)
    auto;

  gap: 10px;

  align-items: end;

  padding: 12px;

  border-top:
    1px solid var(--line);

  background: #fff;
}

.telegram-chat-composer textarea {
  min-height: 46px;
  max-height: 160px;
}

.chat-item {
  cursor: pointer;
}

.chat-item.active {
  border-color:
    var(--blue);

  box-shadow:
    0 0 0 2px
    rgba(
      23,
      92,
      211,
      0.12
    );
}

@media (max-width: 900px) {

  .telegram-chat-layout {
    grid-template-columns: 1fr;
  }

  .telegram-chat-conversation {
    min-height: 60vh;
    max-height: 70vh;
  }
}

/* Group Search V2 */

.group-search-results {
  display: grid;
  gap: 10px;
}

.group-search-result {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  cursor: pointer;
}

.group-search-result:hover {
  transform: translateY(-1px);
}

.group-search-result > input {
  margin-top: 5px;
  width: 18px;
  height: 18px;
}

.group-search-result-body {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.group-search-result-body a {
  width: fit-content;
  overflow-wrap: anywhere;
}

.group-search-result-body small {
  display: block;
}


/* FAQ learning and operator suggestions */

.faq-learning-panel {
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(245, 248, 252, 0.7);
}

.faq-learning-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.faq-learning-stat {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.faq-learning-stat strong,
.faq-learning-stat small {
  display: block;
}

.faq-learning-stat strong {
  margin-top: 3px;
  font-size: 18px;
}

.faq-answer-variants {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.faq-answer-variant {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
}

.faq-answer-variant.primary {
  border-color: var(--teal);
}

.faq-answer-variant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.faq-answer-variant-badge {
  font-size: 11px;
  font-weight: 800;
  color: var(--teal);
}

.telegram-chat-conversation {
  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto
    auto;
}

.chat-faq-suggestions {
  display: grid;
  gap: 9px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(238, 247, 255, 0.96);
}

.chat-faq-suggestions.hidden {
  display: none;
}

.chat-faq-suggestions-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.chat-faq-suggestions-header small {
  display: block;
  max-width: 720px;
  margin-top: 3px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-faq-suggestion-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

.chat-faq-suggestion {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 10px 12px;
  text-align: left;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.chat-faq-suggestion:hover,
.chat-faq-suggestion:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(23, 92, 211, 0.1);
}

.chat-faq-suggestion-text {
  overflow-wrap: anywhere;
}

.chat-faq-suggestion-meta {
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .chat-faq-suggestion-options {
    grid-template-columns: 1fr;
  }
}

/* Compact operational lists, night mode, and persistent chat videos */

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.section-actions button {
  width: auto;
}

.night-mode-card {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.night-mode-card.active {
  border-color: #5b4bd8;
  background: linear-gradient(135deg, #f6f3ff, #edf4ff);
  box-shadow: 0 0 0 3px rgba(91, 75, 216, 0.08);
}

.night-mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  font-size: 12px;
  font-weight: 800;
}

.night-mode-card.active .night-mode-badge {
  color: #fff;
  background: #5b4bd8;
}

  .telegram-chat-conversation {
  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto
    auto
    auto
    auto;
}

.chat-video-panel {
  max-height: min(62%, 660px);
  padding: 12px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  background: #f8fbff;
}

.chat-video-source-section {
  padding: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.chat-video-source-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.chat-video-source-header small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.chat-video-source-section .chat-video-library {
  margin-top: 0;
}

.chat-saved-video-card .chat-video-thumbnail {
  background: linear-gradient(135deg, #1677b8, #4ca6df);
}

.chat-video-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chat-video-panel-header small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.chat-video-upload-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 9px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}

.chat-video-upload-form label {
  min-width: 0;
}

.chat-video-upload-form input {
  width: 100%;
}

.chat-video-library {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.chat-video-card {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}

.chat-video-thumbnail {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 86px;
  overflow: hidden;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(135deg, #26344b, #536988);
  font-size: 28px;
}

.chat-video-thumbnail img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-video-card-body {
  min-width: 0;
}

.chat-video-card-body > strong,
.chat-video-card-body > small {
  display: block;
  overflow-wrap: anywhere;
}

.chat-video-card-body > small {
  margin: 4px 0 9px;
  color: var(--muted);
}

.selected-chat-video {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid #b9d9cb;
  background: #e9f8f1;
}

.selected-chat-video strong,
.selected-chat-video small {
  display: block;
}

.selected-chat-video small {
  margin-top: 2px;
  color: var(--muted);
}

.telegram-chat-composer {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.chat-attachment-button {
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 0;
  font-size: 21px;
}

@media (max-width: 900px) {
  .chat-video-upload-form {
    grid-template-columns: 1fr;
  }

  .chat-video-card {
    grid-template-columns: 100px minmax(0, 1fr);
  }

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

@media (max-width: 520px) {
  .message-edit-actions {
    flex-direction: column;
  }

  .message-edit-actions button {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .section-title {
    align-items: stretch;
  }

  .section-actions {
    justify-content: flex-start;
  }

  .chat-video-card {
    grid-template-columns: 1fr;
  }

  .chat-video-thumbnail {
    min-height: 150px;
  }

  .selected-chat-video {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-video-source-header {
    flex-direction: column;
  }
}
