* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0e1621;
  --rail: #17212b;
  --surface: #17212b;
  --surface2: #232e3c;
  --hover: #202b36;
  --active: #2b5278;
  --border: #0e1621;
  --text: #f5f5f5;
  --text-muted: #6d7f8f;
  --primary: #5288c1;
  --primary-hover: #6ab3f3;
  --success: #4fae4e;
  --warning: #e5a04b;
  --danger: #e53935;
  --customer-bg: #182533;
  --agent-bg: #2b5278;
  --system-bg: #17212b;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
}

html {
  height: 100%;
  height: var(--app-height, 100dvh);
}

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.page {
  height: 100%;
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
}

.login-apply {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 50;
  color: rgba(232, 226, 214, 0.72);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: none;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 2px;
  border: 1px solid rgba(201, 169, 110, 0.28);
  background: rgba(12, 14, 18, 0.45);
  backdrop-filter: blur(10px);
  cursor: pointer;
  font-family: 'Manrope', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-weight: 500;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s;
}
.login-apply:hover {
  color: #f3eee3;
  border-color: rgba(201, 169, 110, 0.55);
  background: rgba(201, 169, 110, 0.12);
  transform: translateY(-1px);
}

#apply-page {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(61, 139, 253, 0.22), transparent 45%),
    radial-gradient(ellipse at 90% 10%, rgba(62, 207, 142, 0.1), transparent 40%),
    var(--bg);
  overflow: auto;
}

.apply-shell {
  max-width: 440px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.apply-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.apply-top h1 { font-size: 20px; }
.apply-back {
  border: 1px solid #2a3b4d;
  background: rgba(23, 33, 43, 0.9);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.apply-back:hover { border-color: var(--primary); }

.apply-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.apply-user-name { font-size: 17px; font-weight: 600; }
.apply-user-id { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.apply-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.apply-hint { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin-bottom: 8px; }
#apply-note {
  width: 100%;
  border: 1px solid #2a3b4d;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  resize: vertical;
  font: inherit;
  margin-bottom: 12px;
}
.apply-kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 14px;
}
.apply-kv span { color: var(--text-muted); }
.apply-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.apply-badge.pending { background: rgba(240, 180, 41, 0.18); color: var(--warning); }
.apply-badge.approved { background: rgba(62, 207, 142, 0.18); color: var(--success); }
.apply-badge.rejected { background: rgba(240, 113, 120, 0.18); color: var(--danger); }

/* Login */
#login-page {
  --login-ink: #0b0d10;
  --login-fog: #e8e2d6;
  --login-gold: #c9a96e;
  --login-gold-soft: rgba(201, 169, 110, 0.18);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--login-ink);
  font-family: 'Manrope', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}

body.in-telegram #login-page {
  align-items: flex-start;
}
body.in-telegram #login-page .login-stage {
  margin: auto 0;
  width: min(400px, 100%);
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.login-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: loginDrift 14s ease-in-out infinite alternate;
}
.login-orb-a {
  width: 48vw;
  height: 48vw;
  max-width: 520px;
  max-height: 520px;
  left: -12%;
  top: -18%;
  background: radial-gradient(circle, rgba(201, 169, 110, 0.35), transparent 68%);
}
.login-orb-b {
  width: 42vw;
  height: 42vw;
  max-width: 460px;
  max-height: 460px;
  right: -10%;
  bottom: -16%;
  background: radial-gradient(circle, rgba(90, 120, 140, 0.28), transparent 70%);
  animation-delay: -4s;
}

.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(232, 226, 214, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 226, 214, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  animation: loginGrid 18s linear infinite;
}

.login-stage {
  position: relative;
  z-index: 1;
  width: min(400px, calc(100% - 40px));
  padding: 36px 32px 32px;
  border: 1px solid rgba(232, 226, 214, 0.12);
  background: linear-gradient(165deg, rgba(22, 25, 30, 0.88), rgba(11, 13, 16, 0.92));
  backdrop-filter: blur(18px);
  animation: loginRise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.login-mark {
  width: 42px;
  height: 42px;
  margin: 0 auto 16px;
  border: 1px solid rgba(201, 169, 110, 0.55);
  position: relative;
  transform: rotate(45deg);
  animation: loginMark 1s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
}
.login-mark::after {
  content: '';
  position: absolute;
  inset: 8px;
  background: var(--login-gold);
  opacity: 0.9;
}

.login-title {
  font-family: 'Cormorant Garamond', 'Songti SC', serif;
  font-size: clamp(34px, 7vw, 42px);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--login-fog);
  line-height: 1.1;
  margin: 0;
}

.login-tagline {
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(201, 169, 110, 0.75);
  font-weight: 500;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: left;
}
.login-field span {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(232, 226, 214, 0.5);
  font-weight: 500;
}
.login-field input {
  width: 100%;
  padding: 13px 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(232, 226, 214, 0.12);
  border-radius: 2px;
  color: var(--login-fog);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.login-field input::placeholder { color: rgba(232, 226, 214, 0.28); }
.login-field input:focus {
  border-color: rgba(201, 169, 110, 0.55);
  background: rgba(0, 0, 0, 0.38);
}

.login-submit {
  margin-top: 6px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 2px;
  background: linear-gradient(120deg, #d4b57a, #b8924d);
  color: #1a140c;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.2s, transform 0.2s;
}
.login-submit:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}
.login-submit:active { transform: translateY(0); }

#login-page .error {
  min-height: 18px;
  margin-top: 2px;
  text-align: center;
  color: #e07a72;
  font-size: 13px;
}

.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

@keyframes loginRise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes loginMark {
  from { opacity: 0; transform: rotate(45deg) scale(0.7); }
  to { opacity: 1; transform: rotate(45deg) scale(1); }
}
@keyframes loginDrift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(3%, 4%, 0) scale(1.08); }
}
@keyframes loginGrid {
  from { transform: translateY(0); }
  to { transform: translateY(56px); }
}

@media (max-width: 480px) {
  .login-stage { padding: 28px 20px 24px; width: 100%; }
  .login-apply {
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    padding: 8px 12px;
  }
  .login-title { font-size: 32px; }
}

/* Telegram / 窄屏：聊天两栏改为列表↔对话切换 */
@media (max-width: 700px) {
  .customer-pane { width: 240px; }
  body.in-telegram #chat-page,
  body.tg-narrow #chat-page {
    position: relative;
  }
  body.in-telegram .customer-pane,
  body.tg-narrow .customer-pane {
    width: 100%;
    border-right: none;
  }
  body.in-telegram .chat-main,
  body.tg-narrow .chat-main {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    min-width: 0;
    background: var(--bg);
    z-index: 5;
  }
  body.in-telegram #chat-page.chat-open .customer-pane,
  body.tg-narrow #chat-page.chat-open .customer-pane {
    display: none;
  }
  body.in-telegram #chat-page.chat-open .chat-main,
  body.tg-narrow #chat-page.chat-open .chat-main {
    display: flex;
  }
  body.in-telegram .chat-header,
  body.tg-narrow .chat-header {
    padding-left: 8px;
  }
  body.in-telegram #chat-back-btn,
  body.tg-narrow #chat-back-btn {
    display: inline-flex !important;
  }
  #message-input,
  .search-box input,
  #apply-note {
    font-size: 16px;
  }
}

/* legacy login selectors kept for safety */
.login-card { display: none; }

/* ===== 两栏聊天布局 ===== */
#chat-page {
  display: flex;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* 左栏客户列表 */
.customer-pane {
  width: 360px;
  background: var(--surface);
  border-right: 1px solid #101922;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.customer-pane-header {
  padding: 14px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.customer-pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.agent-name { font-weight: 600; font-size: 15px; }
.status { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.status.online { color: var(--success); }

.search-box { padding: 4px 12px 12px; }

.search-box input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: none;
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder { color: var(--text-muted); }

.session-list {
  flex: 1;
  overflow-y: auto;
}

.session-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.12s;
}
.session-item:hover { background: var(--hover); }
.session-item.active { background: var(--active); }

.session-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def, #3d6bb3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
  color: #fff;
}

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

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

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

.session-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

.session-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.session-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.session-item.active .session-preview,
.session-item.active .session-time { color: rgba(255,255,255,0.75); }

.session-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.bot-tag {
  font-size: 11px;
  color: var(--primary-hover);
  max-width: 72px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-list {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.unread {
  background: #4ea4f6;
  color: #fff;
  font-size: 12px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  font-weight: 600;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.badge.waiting { background: rgba(229, 160, 75, 0.2); color: var(--warning); }
.badge.active { background: rgba(79, 174, 78, 0.2); color: var(--success); }
.badge.bot { background: rgba(82, 136, 193, 0.2); color: var(--primary-hover); }

/* 右栏对话框 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(43, 82, 120, 0.25), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(23, 33, 43, 0.9), transparent 45%),
    #0e1621;
  min-width: 280px;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  min-height: 100%;
}
.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 16px;
}
.empty-state p { font-size: 15px; }
.empty-state .hint { font-size: 13px; margin-top: 8px; opacity: 0.7; }

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  padding: 10px 20px;
  border-bottom: 1px solid #101922;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(23, 33, 43, 0.92);
  backdrop-filter: blur(8px);
}

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

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def, #3d6bb3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.chat-header h2 { font-size: 15px; font-weight: 600; }
.chat-bot-name {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.danger { background: rgba(229, 57, 53, 0.15); color: var(--danger); }
.btn.danger:hover { background: rgba(229, 57, 53, 0.25); }
.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid #2a3b4d;
}
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.small { padding: 6px 12px; font-size: 12px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.msg {
  max-width: 65%;
  padding: 8px 12px 6px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.msg.customer {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}

.msg.agent {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}

.msg.system {
  align-self: center;
  background: rgba(23, 33, 43, 0.8);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  box-shadow: none;
}

.msg.blocked {
  border: 1px dashed var(--warning);
  color: var(--warning);
  font-size: 13px;
}

.msg-time {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-top: 4px;
  text-align: right;
}

.chat-input-area {
  padding: 10px 16px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: rgba(23, 33, 43, 0.95);
  border-top: 1px solid #101922;
}

.attach-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}
.attach-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.attach-btn:not(:disabled):hover { background: var(--hover); color: var(--text); }

#message-input {
  flex: 1;
  padding: 11px 16px;
  background: var(--bg);
  border: none;
  border-radius: 22px;
  color: var(--text);
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 120px;
  line-height: 1.4;
}
#message-input:disabled { opacity: 0.5; }

.send-round {
  height: 42px;
  border-radius: 21px;
  padding: 0 18px;
}

.msg-image {
  max-width: 280px;
  max-height: 280px;
  border-radius: 8px;
  display: block;
}

.msg-sticker {
  max-width: 160px;
  max-height: 160px;
  display: block;
  background: transparent;
}

.msg-video {
  max-width: 320px;
  max-height: 280px;
  border-radius: 8px;
  display: block;
}

.msg-album {
  display: grid;
  gap: 4px;
  max-width: 320px;
  border-radius: 10px;
  overflow: hidden;
}
.msg-album.count-1 { grid-template-columns: 1fr; }
.msg-album.count-2 { grid-template-columns: 1fr 1fr; }
.msg-album.count-3,
.msg-album.count-4 { grid-template-columns: 1fr 1fr; }

.album-item {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  background: #0e1621;
}
.msg-album.count-1 .album-item {
  height: auto;
  max-height: 280px;
  object-fit: contain;
}
.album-video {
  background: #000;
}

.msg-caption { margin-top: 6px; font-size: 13px; white-space: pre-wrap; }

/* Admin page */
#admin-page {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid #101922;
  flex-shrink: 0;
}

.admin-topbar-copy { min-width: 0; flex: 1; }
.admin-topbar h1 {
  font-size: 18px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-topbar-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}
.admin-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.admin-user-name {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-shell {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 16px 28px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#admin-page.is-owner .admin-shell {
  max-width: 720px;
}

#admin-page .admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: 10px;
  padding: 4px;
  position: sticky;
  top: 0;
  z-index: 4;
  border: 1px solid #243447;
}

#admin-page .admin-tab {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#admin-page .admin-tab.active {
  background: var(--surface2);
  color: var(--text);
  font-weight: 600;
}

.admin-body {
  background: var(--surface);
  border-radius: 12px;
  padding: 18px;
  border: 1px solid #243447;
  min-height: 360px;
  display: flex;
  flex-direction: column;
}

.admin-pane {
  flex: 1;
  min-height: 0;
}

.admin-error-slot {
  flex-shrink: 0;
  min-height: 18px;
  margin-top: 12px;
  margin-bottom: 0;
}

.add-agent-form,
.admin-add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  max-width: 100%;
  min-width: 0;
}

.admin-add-form input,
.add-agent-form input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid #2a3b4d;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  box-sizing: border-box;
}

.admin-add-btn,
.admin-add-form .btn,
.add-agent-form .btn,
.bot-add-form .btn,
.notify-add-form .btn,
.password-submit {
  width: 100%;
  min-height: 44px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  box-sizing: border-box;
  border-radius: 8px;
}

.bot-add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  max-width: 100%;
}

.stack-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.stack-field span {
  font-size: 12px;
  color: var(--text-muted);
}
.stack-field input,
.bot-add-form input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid #2a3b4d;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.agent-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface2);
  border-radius: 8px;
  min-width: 0;
}
.agent-row-main {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.agent-row-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-row-user {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.admin-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.owner-renew {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-width: 0;
}

.duration-select {
  min-width: 0;
  flex: 1 1 120px;
  max-width: 180px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid #2a3b4d;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.duration-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.app-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.owner-row,
.app-row {
  align-items: flex-start;
}

.password-panel {
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
  padding: 8px 4px 4px;
}

.password-panel-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

#admin-page.is-admin .admin-shell {
  max-width: 720px;
}

#admin-page.is-admin .admin-body {
  min-height: 280px;
}

.password-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.password-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.password-field span {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.password-field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid #2a3b4d;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.password-field input:focus {
  border-color: var(--primary);
}

.password-submit {
  margin-top: 4px;
}

.password-form-msg {
  min-height: 18px;
  font-size: 13px;
  text-align: center;
  color: var(--success);
}
.password-form-msg.is-error { color: var(--danger); }

.bot-list { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.bot-card {
  padding: 14px;
  background: var(--surface2);
  border-radius: 10px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #2a3b4d;
}

.bot-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  min-width: 0;
}

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

.bot-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.bot-assign {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  min-width: 0;
}

.bot-section-title {
  width: 100%;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.bot-notify {
  border-top: 1px solid #2a3b4d;
  padding-top: 12px;
  min-width: 0;
}

.notify-add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  min-width: 0;
}

.notify-add-form input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid #2a3b4d;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
}

.notify-add-form .btn {
  width: 100%;
}

.notify-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.notify-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border-radius: 8px;
  min-width: 0;
}

.notify-row-main {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.assign-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  min-width: 0;
}
.assign-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.assign-item em {
  font-style: normal;
  color: var(--text-muted);
  font-size: 12px;
}

@media (max-width: 640px) {
  .admin-topbar {
    padding: 12px 14px;
    align-items: flex-start;
  }
  .admin-topbar-right {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
  .admin-shell {
    padding: 12px 12px 24px;
  }
  .admin-body {
    padding: 14px;
    min-height: 300px;
  }
  #admin-page .admin-tab {
    font-size: 12px;
    padding: 10px 6px;
  }
  .bot-card-head {
    flex-direction: column;
  }
  .bot-card-actions {
    width: 100%;
    justify-content: space-between;
  }
}

#chat-back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-right: 4px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  font-family: inherit;
}
#chat-back-btn:hover { background: var(--hover); }
