/* X-TG Bot 样式：简洁客服后台 / IM 布局，桌面端优先 */

:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #e4e9f1;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2f6fed;
  --primary-dark: #1d4ed8;
  --primary-soft: #e8f0ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font-family: inherit;
  font-size: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ----------------------------- 按钮 ----------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  background: #eef2f7;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: #e3e9f2;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

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

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  background: var(--panel-soft);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}

.btn.danger:hover {
  background: #fee2e2;
}

.btn.small {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 7px;
}

.btn.block {
  width: 100%;
  padding: 11px 14px;
}

.btn.danger-text {
  color: var(--danger);
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--panel-soft);
}

/* ----------------------------- 登录页 ----------------------------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #e5efff 0, transparent 45%),
    radial-gradient(circle at 80% 80%, #e8f7ef 0, transparent 40%), #f4f7fb;
}

.login-card {
  width: 360px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 34px 30px 24px;
  border: 1px solid var(--border);
}

.login-brand {
  text-align: center;
  margin-bottom: 26px;
}

.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4f8cff, #2f6fed);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(47, 111, 237, 0.35);
}

.login-brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-foot {
  margin-top: 18px;
  text-align: center;
  color: #9aa4b2;
  font-size: 12px;
}

.form-error {
  margin-top: 12px;
  padding: 8px 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
}

/* ----------------------------- 顶栏 ----------------------------- */
.app-body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  height: 62px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand .logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f8cff, #2f6fed);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bot-chip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
}

/* ----------------------------- 主布局 ----------------------------- */
.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.bots-panel {
  width: 210px;
  flex: 0 0 210px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conv-panel {
  width: 320px;
  flex: 0 0 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-panel {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #eef2f8;
  min-height: 0;
}

.panel-head {
  height: 46px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.bot-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
}

.bot-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border-radius: 9px;
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
}

.bot-item:hover {
  background: var(--panel-soft);
}

.bot-item.active {
  background: var(--primary-soft);
}

.bot-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: #dbe7ff;
  color: var(--primary-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bot-meta {
  min-width: 0;
  flex: 1;
}

.bot-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-sub {
  font-size: 11px;
  color: var(--muted);
}

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.empty-mini {
  padding: 18px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.7;
}

/* ----------------------------- 会话列表 ----------------------------- */
.conv-head {
  flex: 0 0 auto;
  padding: 10px 12px 0;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--panel-soft);
  padding: 3px;
  border-radius: 9px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 0;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.search-box {
  flex: 0 0 auto;
  padding: 10px 12px;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

.search-box input:focus {
  border-color: #b7ccf7;
  background: #fff;
}

.conv-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 8px 10px;
}

.conv-item {
  display: flex;
  gap: 9px;
  padding: 10px 8px;
  border-radius: 9px;
  cursor: pointer;
  margin-bottom: 2px;
}

.conv-item:hover {
  background: var(--panel-soft);
}

.conv-item.active {
  background: var(--primary-soft);
}

.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: #dbe7ff;
  color: var(--primary-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.conv-main {
  flex: 1;
  min-width: 0;
}

.conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.conv-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: #9aa4b2;
  flex: 0 0 auto;
}

.conv-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.conv-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-note {
  margin-top: 3px;
  font-size: 11px;
  color: var(--warning);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-tags {
  display: flex;
  gap: 4px;
  margin-top: 3px;
}

.tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: #eef2f7;
  color: var(--muted);
}

.tag.blocked {
  background: var(--danger-soft);
  color: var(--danger);
}

.tag.ok {
  background: #e8f7ee;
  color: var(--success);
}

.tag.fail {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ----------------------------- 聊天区 ----------------------------- */
.chat-head {
  flex: 0 0 auto;
  height: 62px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.chat-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-sub {
  font-size: 12px;
  color: var(--muted);
}

.chat-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px;
  min-height: 0;
}

.empty-state {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9aa4b2;
  font-size: 13px;
}

.msg-row {
  display: flex;
  margin-bottom: 12px;
}

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

.msg-bubble {
  max-width: 66%;
  background: var(--panel);
  border-radius: 11px;
  padding: 9px 12px 7px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  word-break: break-word;
}

.msg-row.out .msg-bubble {
  background: #dbe9ff;
}

.msg-text {
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.out .msg-text {
  color: #10264d;
}

.msg-image {
  display: block;
  max-width: 260px;
  max-height: 260px;
  border-radius: 8px;
  margin: 2px 0 4px;
  cursor: zoom-in;
  object-fit: cover;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 2px 0 4px;
  color: inherit;
  max-width: 320px;
}

.msg-file:hover {
  text-decoration: none;
  border-color: #c7d7f5;
}

.msg-file-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 4px;
  max-width: 340px;
}

.msg-file-group .msg-file {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.file-preview {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--primary);
}

.msg-file.pending {
  opacity: 0.75;
}

.file-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}

.file-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.file-info b {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info small {
  font-size: 11px;
  color: var(--muted);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  font-size: 10px;
  color: #94a3b8;
}

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

.load-more {
  text-align: center;
  margin-bottom: 14px;
}

.composer {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
  color: var(--muted);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px dashed #c7d2e4;
  border-radius: 7px;
  cursor: pointer;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
}

.file-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.file-btn input {
  display: none;
}

.file-name {
  color: var(--primary-dark);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-hint {
  margin-left: auto;
  color: #a8b3c2;
  font-size: 11px;
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
}

.composer-row textarea:focus {
  border-color: #b7ccf7;
}

/* ----------------------------- 抽屉（管理设置） ----------------------------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 500px;
  max-width: 94vw;
  height: 100vh;
  background: var(--panel);
  z-index: 50;
  box-shadow: -6px 0 24px rgba(15, 23, 42, 0.14);
  display: flex;
  flex-direction: column;
}

.drawer-head {
  height: 58px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 15px;
  font-weight: 700;
}

.drawer-nav {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.drawer-nav button {
  border: none;
  background: transparent;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.drawer-nav button.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px 30px;
}

/* ----------------------------- 表单 ----------------------------- */
.section-title {
  font-size: 13px;
  font-weight: 700;
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  color: #334155;
}

.section-title:first-child {
  margin-top: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field > span {
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  background: #fff;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #b7ccf7;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.08);
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
}

.hint {
  font-size: 12px;
  color: #94a3b8;
  margin: 4px 0 12px;
  line-height: 1.6;
}

.hint code,
.webhook-box code {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 11px;
  word-break: break-all;
}

.switch {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  margin: 8px 0 12px;
  cursor: pointer;
}

.switch input {
  width: 15px;
  height: 15px;
  margin-top: 2px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.webhook-box {
  border: 1px dashed #cbd7ea;
  background: var(--panel-soft);
  border-radius: 9px;
  padding: 11px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.webhook-box .row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.channel-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fff;
}

.channel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.channel-head strong {
  font-size: 13px;
}

.channel-head .switch {
  margin: 0;
  font-size: 12px;
}

.channel-body {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.channel-body.off {
  display: none;
}

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

.mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
}

.mini-item .meta {
  min-width: 0;
}

.mini-item .name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-item .sub {
  font-size: 11px;
  color: var(--muted);
}

.mini-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-item {
  border: 1px solid var(--border);
  border-left: 3px solid #cbd5e1;
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
}

.log-item.error {
  border-left-color: var(--danger);
}

.log-item.warning {
  border-left-color: var(--warning);
}

.log-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}

.log-message {
  font-size: 13px;
  margin-top: 3px;
}

.log-detail {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
  word-break: break-all;
  white-space: pre-wrap;
}

.log-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.log-filter select {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}

/* ----------------------------- Toast ----------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  z-index: 99;
  max-width: 70vw;
  box-shadow: var(--shadow);
}

.toast.error {
  background: rgba(185, 28, 28, 0.95);
}

.toast.success {
  background: rgba(22, 101, 52, 0.95);
}

/* ----------------------------- 滚动条 ----------------------------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #b2bfd0;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* 中小屏幕：适当收窄侧栏，保证桌面端可用 */
@media (max-width: 1200px) {
  .bots-panel {
    width: 176px;
    flex-basis: 176px;
  }

  .conv-panel {
    width: 280px;
    flex-basis: 280px;
  }

  .msg-bubble {
    max-width: 76%;
  }
}
