body[data-page='admin-chat'] .main-content {
  overflow-y: auto;
  padding-bottom: 40px;
}

body[data-page='admin-chat'] .title-stack {
  display: grid;
  gap: 10px;
}

body[data-page='admin-chat'] .title-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.title-copy {
  max-width: 760px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--color-border, #d7e3ff);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 26px rgba(30, 64, 175, 0.08);
}

.mode-switch__button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted, #5f6b89);
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

.mode-switch__button:hover,
.mode-switch__button:focus-visible {
  background: rgba(37, 99, 235, 0.1);
  color: var(--color-primary-dark, #1e3a8a);
  outline: none;
}

.mode-switch__button.is-active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.22);
}

.chat-status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), #ffffff);
  color: var(--color-text, #0f172a);
  font-size: 14px;
  line-height: 1.5;
}

.chat-status-banner::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #2563eb;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.12);
  flex: 0 0 auto;
}

.chat-status-banner[data-tone='success']::before {
  background: #10b981;
  box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.14);
}

.chat-status-banner[data-tone='warning']::before {
  background: #f59e0b;
  box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.16);
}

.chat-status-banner[data-tone='danger']::before {
  background: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.16);
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 1rem;
  flex: 0 0 auto;
  min-height: clamp(860px, calc(100vh - var(--topbar-height) - 180px), 1120px);
  height: auto;
  padding: 14px;
}

.chat-sidebar,
.chat-panel {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 18px;
  background: var(--surface-color, #fff);
  min-height: 0;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-filter {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.chat-filter input,
.chat-filter select,
.reply-form textarea {
  width: 100%;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  font: inherit;
  background: #ffffff;
}

.chat-filter input:focus,
.chat-filter select:focus,
.reply-form textarea:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.thread-item {
  display: grid;
  gap: 0.35rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.thread-item:hover {
  background: rgba(37, 99, 235, 0.05);
}

.thread-item.active {
  background: rgba(29, 78, 216, 0.1);
  box-shadow: inset 4px 0 0 #2563eb;
}

.thread-item__title {
  margin: 0;
  font-weight: 700;
  color: var(--color-text, #0f172a);
}

.thread-item__meta {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--color-muted, #5f6b89);
}

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

.chat-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.chat-panel__title {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.chat-panel__title h2 {
  margin: 0;
}

.chat-meta {
  margin: 0;
  color: var(--color-muted, #5f6b89);
}

.chat-mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  min-width: 110px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.chat-mode-pill[data-mode='demo'] {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.chat-mode-pill[data-mode='live'] {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.message-list {
  flex: 1;
  min-height: 420px;
  overflow: auto;
  padding: 0.9rem 1rem;
  display: grid;
  align-content: start;
  gap: 0.75rem;
  background:
    radial-gradient(
      circle at top right,
      rgba(37, 99, 235, 0.08),
      transparent 32%
    ),
    linear-gradient(
      180deg,
      rgba(248, 250, 255, 0.92),
      rgba(255, 255, 255, 0.98)
    );
}

.message {
  max-width: min(72%, 620px);
  padding: 0.8rem 0.9rem;
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  line-height: 1.5;
}

.message--customer {
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.message--admin {
  margin-left: auto;
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
  border: 1px solid rgba(37, 99, 235, 0.18);
}

.message--ai {
  margin-left: auto;
  background: linear-gradient(135deg, #eefbf3 0%, #f7fffb 100%);
  border: 1px solid rgba(16, 185, 129, 0.28);
  box-shadow: 0 12px 26px rgba(16, 185, 129, 0.1);
}

.message__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0.45rem;
}

.message__sender {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--color-muted, #5f6b89);
}

.message--ai .message__sender {
  color: #047857;
}

.message__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.22);
}

.message__meta {
  margin-top: 0.45rem;
  font-size: 0.76rem;
  color: var(--color-muted, #5f6b89);
}

.message-list__empty {
  height: 100%;
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
  color: var(--color-muted, #5f6b89);
  border: 1px dashed rgba(37, 99, 235, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
}

.reply-form {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem 1rem 1rem;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: #ffffff;
}

.reply-form textarea {
  min-height: 80px;
  resize: vertical;
}

.reply-form button[disabled],
.title-actions button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

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

@media (max-width: 1024px) {
  body[data-page='admin-chat'] .main-content {
    overflow: auto;
  }

  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .chat-sidebar {
    max-height: 360px;
  }
}

@media (max-width: 720px) {
  .chat-header-actions,
  body[data-page='admin-chat'] .title-bar,
  .chat-panel__header {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-switch,
  .title-actions {
    width: 100%;
  }

  .mode-switch__button {
    flex: 1;
  }

  .message {
    max-width: 100%;
  }

  .chat-layout {
    padding: 14px;
  }

  .reply-form textarea {
    min-height: 104px;
  }
}
