/* ============================================================
   Telegram 云控 · SwiftAdmin 风格视觉系统
   ------------------------------------------------------------
   深色侧边导航 + 浅色内容区 + 蓝色主色，卡片化面板与表格。
   ============================================================ */

/* ---------- 设计令牌 ---------- */

:root {
  color-scheme: light;

  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f5f5f5;

  --line: #f0f0f0;
  --line-strong: #e5e7eb;
  --line-hover: #bfbfbf;

  --text: #1f1f1f;
  --muted: #8c8c8c;
  --faint: #bfbfbf;

  --primary: #1890ff;
  --primary-hover: #40a9ff;
  --primary-active: #096dd9;
  --primary-soft: #e6f7ff;
  --primary-border: #91d5ff;
  --primary-ring: rgba(24, 144, 255, 0.12);

  --ok: #52c41a;
  --ok-soft: #f6ffed;
  --ok-border: #b7eb8f;
  --warn: #d48806;
  --warn-soft: #fffbe6;
  --warn-border: #ffe58f;
  --danger: #ff4d4f;
  --danger-soft: #fff1f0;
  --danger-border: #ffa39e;

  /* 侧边栏：固定深色，作为控制台的身份 */
  --sider: #001529;
  --sider-2: #002140;
  --sider-line: rgba(255, 255, 255, 0.08);
  --sider-fg: rgba(255, 255, 255, 0.65);
  --sider-fg-active: #ffffff;

  --overlay: rgba(0, 0, 0, 0.35);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);

  --radius: 6px;

  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0f1318;
  --surface: #171b21;
  --surface-2: #1d222a;
  --surface-3: #232932;

  --line: #242b34;
  --line-strong: #2f3742;
  --line-hover: #46505d;

  --text: #e6edf3;
  --muted: #8b949e;
  --faint: #5d6672;

  --primary: #2f81f7;
  --primary-hover: #58a0ff;
  --primary-active: #1f6feb;
  --primary-soft: rgba(47, 129, 247, 0.16);
  --primary-border: rgba(47, 129, 247, 0.45);
  --primary-ring: rgba(47, 129, 247, 0.22);

  --ok: #3fb950;
  --ok-soft: rgba(63, 185, 80, 0.14);
  --ok-border: rgba(63, 185, 80, 0.4);
  --warn: #d29922;
  --warn-soft: rgba(210, 153, 34, 0.14);
  --warn-border: rgba(210, 153, 34, 0.42);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.14);
  --danger-border: rgba(248, 81, 73, 0.42);

  --sider: #001529;
  --sider-2: #002140;

  --overlay: rgba(0, 0, 0, 0.55);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* ---------- 基础 ---------- */

* {
  box-sizing: border-box;
}

body.tg-login,
body.tg-app {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5715;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--primary-soft);
  color: var(--primary);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ---------- 通用控件 ---------- */

.tg-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

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

.tg-icon-btn svg {
  width: 16px;
  height: 16px;
}

/* 深色主题显示太阳（切到浅色），浅色主题显示月亮 */
:root[data-theme='dark'] .tg-icon-moon {
  display: none;
}

:root[data-theme='light'] .tg-icon-sun {
  display: none;
}

.tg-lamp {
  display: inline-block;
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

/* ============================================================
   登录页
   ============================================================ */

body.tg-login {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #001529;
}

.tg-login-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(1100px 720px at 10% 4%, rgba(24, 144, 255, 0.48), transparent 58%),
    radial-gradient(820px 620px at 92% 10%, rgba(54, 207, 201, 0.2), transparent 62%),
    radial-gradient(1000px 760px at 76% 98%, rgba(24, 144, 255, 0.36), transparent 62%),
    linear-gradient(155deg, #020d1a 0%, #062445 46%, #08386c 100%);
}

.tg-login-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  -webkit-mask-image: radial-gradient(760px 540px at 50% 32%, #000 0%, transparent 80%);
  mask-image: radial-gradient(760px 540px at 50% 32%, #000 0%, transparent 80%);
}

/* 斜向光束，增加空间层次 */
.tg-login-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, 0.05) 49%, transparent 56%),
    linear-gradient(115deg, transparent 62%, rgba(120, 200, 255, 0.07) 69%, transparent 76%);
  pointer-events: none;
}

.tg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
  pointer-events: none;
}

.tg-blob-1 {
  top: -160px;
  left: -120px;
  width: 460px;
  height: 460px;
  background: radial-gradient(circle, rgba(24, 144, 255, 0.4), transparent 68%);
  animation: tg-float 16s ease-in-out infinite;
}

.tg-blob-2 {
  right: -180px;
  bottom: -200px;
  width: 560px;
  height: 560px;
  background: radial-gradient(circle, rgba(64, 169, 255, 0.32), transparent 68%);
  animation: tg-float 20s ease-in-out infinite reverse;
}

.tg-blob-3 {
  top: 42%;
  right: 12%;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1), transparent 70%);
  animation: tg-float 24s ease-in-out infinite;
}

.tg-login-theme {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 5;
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
}

.tg-login-theme:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.tg-login-main {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px 32px;
}

.tg-login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 40px 30px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow:
    0 24px 64px rgba(0, 14, 32, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: tg-card-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.tg-login-head {
  text-align: center;
}

.tg-login-logo {
  display: block;
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
}

.tg-login-logo svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tg-login-head h1 {
  margin: 16px 0 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.tg-login-head p {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.tg-auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 28px;
}

.tg-input {
  position: relative;
  display: block;
}

.tg-auth-form .layui-input {
  display: block;
  width: 100%;
  height: 46px;
  padding: 0 42px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tg-auth-form .layui-input:hover {
  border-color: var(--line-hover);
}

.tg-auth-form .layui-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  outline: none;
}

.tg-auth-form .layui-input::placeholder {
  color: var(--faint);
}

.tg-auth-form .layui-input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
  caret-color: var(--text);
}

.tg-input-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--faint);
  transform: translateY(-50%);
  pointer-events: none;
  transition: color 0.2s;
}

.tg-input-icon svg {
  width: 18px;
  height: 18px;
}

.tg-input:focus-within .tg-input-icon {
  color: var(--primary);
}

.tg-pwd-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 0.2s, background 0.2s;
}

.tg-pwd-toggle:hover {
  color: var(--primary);
  background: var(--surface-3);
}

.tg-pwd-toggle svg {
  width: 17px;
  height: 17px;
}

.tg-pwd-toggle .tg-eye-off,
.tg-pwd-toggle.is-on .tg-eye {
  display: none;
}

.tg-pwd-toggle.is-on .tg-eye-off {
  display: block;
}

.tg-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  margin-top: 4px;
  padding: 0 18px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--primary);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.tg-submit:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.tg-submit:active:not(:disabled) {
  background: var(--primary-active);
  border-color: var(--primary-active);
}

.tg-submit:disabled {
  cursor: wait;
  opacity: 0.6;
}

.tg-auth-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--faint);
}

.tg-auth-foot svg {
  flex: none;
  width: 13px;
  height: 13px;
}

.tg-login-copy {
  position: relative;
  z-index: 2;
  margin: 20px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}

/* ============================================================
   控制台
   ============================================================ */

.tg-app {
  display: flex;
  background: var(--bg);
}

/* ---------- 左侧导航 ---------- */

.tg-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  width: 232px;
  background:
    radial-gradient(380px 240px at 100% 0%, rgba(22, 119, 255, 0.3), transparent 72%),
    radial-gradient(260px 220px at 0% 100%, rgba(54, 207, 201, 0.12), transparent 70%),
    linear-gradient(180deg, #04182e 0%, #001529 46%, #000d1a 100%);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.05);
  color: var(--sider-fg);
}

.tg-logo {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: 72px;
  padding: 0 20px;
  background: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tg-logo strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #ffffff;
  line-height: 1.3;
}

.tg-nav-title {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  margin: 22px 22px 10px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.35);
}

.tg-nav-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent);
}

.tg-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 0 12px 12px;
  overflow-y: auto;
}

.tg-nav button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sider-fg);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}

.tg-nav button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 0;
  border-radius: 0 2px 2px 0;
  background: #ffffff;
  transform: translateY(-50%);
  transition: height 0.2s ease;
}

.tg-nav button svg {
  flex: none;
  width: 17px;
  height: 17px;
  opacity: 0.85;
}

.tg-nav button:hover {
  color: var(--sider-fg-active);
  background: rgba(255, 255, 255, 0.07);
}

.tg-nav button.is-active {
  color: #ffffff;
  background: linear-gradient(90deg, #1677ff 0%, #3d9bff 100%);
  box-shadow: 0 8px 20px rgba(22, 119, 255, 0.35);
}

.tg-nav button.is-active::before {
  left: 0;
  height: 18px;
}

.tg-nav button.is-active svg {
  opacity: 1;
}

.tg-nav-label {
  min-width: 0;
  white-space: nowrap;
}

.tg-sidebar-foot {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 20px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.tg-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.45);
}

.tg-status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(82, 196, 26, 0.18);
  animation: tg-pulse 2.4s ease-in-out infinite;
}

.tg-theme-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.tg-theme-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.tg-theme-btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- 主区域与顶栏 ---------- */

.tg-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  margin-left: 232px;
}

.tg-header {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.tg-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.tg-header p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.tg-header-right {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
}

.tg-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.tg-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.tg-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.tg-ghost svg {
  width: 15px;
  height: 15px;
}

.tg-ghost:hover {
  color: var(--primary);
  background: var(--surface-3);
}

.tg-content {
  flex: 1;
  padding: 16px 24px 40px;
}

.tg-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--muted);
}

.tg-crumb i {
  font-style: normal;
  color: var(--faint);
}

.tg-crumb em {
  font-style: normal;
  color: var(--text);
}

/* ---------- 统计卡片 ---------- */

.tg-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.tg-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.tg-stat-info span {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.tg-stat-info strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tg-stat-info strong.is-ok {
  color: var(--ok);
}

.tg-stat-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

.tg-stat-icon svg {
  width: 22px;
  height: 22px;
}

.tg-stat-icon.is-blue {
  background: #e6f7ff;
  color: #1890ff;
}

.tg-stat-icon.is-green {
  background: #f6ffed;
  color: #52c41a;
}

.tg-stat-icon.is-orange {
  background: #fff7e6;
  color: #fa8c16;
}

.tg-stat-icon.is-purple {
  background: #f9f0ff;
  color: #722ed1;
}

/* ---------- 面板与表格 ---------- */

.tg-section {
  display: none;
}

.tg-section.is-active {
  display: block;
  animation: tg-rise 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.tg-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.tg-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.tg-panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.tg-panel-head p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

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

.tg-btn {
  height: 32px;
  padding: 0 15px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--primary);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

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

.tg-btn-soft {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.tg-btn-soft:hover {
  border-color: var(--primary);
  background: var(--surface);
  color: var(--primary);
}

.tg-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.layui-table.tg-table {
  width: 100%;
  min-width: 100%;
  margin: 0;
  border-collapse: collapse;
  background: transparent;
  color: var(--text);
}

.tg-table th {
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.tg-table td {
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}

.tg-table tbody tr {
  transition: background 0.15s;
}

.tg-table tbody tr:hover {
  background: var(--surface-2);
}

.tg-table tbody tr:last-child td {
  border-bottom: 0;
}

#accountTable td:nth-child(1),
#proxyTable td:nth-child(1),
#deviceTable td:nth-child(1) {
  font-size: 12.5px;
  color: var(--muted);
}

.tg-table .tg-empty {
  padding: 48px 16px;
  font-size: 13px;
  text-align: center;
  color: var(--faint);
  white-space: normal;
}

/* 状态标签 */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.pill::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill.is-ok {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.is-warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.is-danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.is-muted {
  border-color: var(--line-strong);
  background: var(--surface-3);
  color: var(--muted);
}

.tag {
  display: inline-block;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 12px;
  line-height: 20px;
  color: var(--muted);
}

.tg-link {
  display: inline-block;
  margin-right: 14px;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.2s;
}

.tg-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tg-link.is-danger {
  margin-right: 0;
  color: var(--danger);
}

.tg-link.is-danger:hover {
  color: var(--danger);
  opacity: 0.8;
}

.tg-err {
  display: inline-block;
  max-width: 190px;
  overflow: hidden;
  color: var(--danger);
  font-size: 12px;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.tg-actions-cell {
  white-space: nowrap;
}

.tg-action-head,
.tg-actions-cell {
  width: 150px;
  padding-right: 16px;
  text-align: left;
}

/* ============================================================
   Layui 弹窗与表单
   ============================================================ */

.layui-layer {
  background: var(--surface) !important;
  border: 1px solid var(--line-strong) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow-lg) !important;
  color: var(--text);
}

.layui-layer-title {
  height: 52px;
  line-height: 52px;
  padding-left: 20px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
}

.layui-layer-content {
  color: var(--text);
}

.layui-layer-dialog .layui-layer-content {
  padding: 20px 22px;
  font-size: 13px;
  color: var(--muted);
}

.layui-layer-dialog .layui-layer-padding {
  padding: 20px 22px 20px 60px;
  text-align: left;
}

.layui-layer-dialog .layui-layer-content .layui-layer-face {
  left: 20px;
  font-size: 28px;
}

.layui-layer-btn {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 18px 16px;
}

.layui-layer-btn a {
  height: 32px;
  line-height: 30px;
  margin: 0;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.layui-layer-btn a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.layui-layer-btn .layui-layer-btn0 {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.layui-layer-btn .layui-layer-btn0:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
  color: #ffffff;
}

.layui-layer-msg {
  border: 1px solid var(--line-strong) !important;
  border-radius: 6px !important;
  box-shadow: var(--shadow-md) !important;
}

.layui-layer-setwin span {
  color: var(--muted) !important;
}

.layui-layer-setwin span:hover {
  color: var(--text) !important;
}

.tg-form {
  padding: 20px 24px 8px 0;
}

.tg-form .layui-form-label {
  width: 78px;
  padding: 9px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--muted);
}

.tg-form .layui-input-block {
  margin-left: 98px;
}

.tg-form .layui-input,
.tg-form select {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tg-form .layui-input:hover,
.tg-form select:hover {
  border-color: var(--line-hover);
}

.tg-form .layui-input:focus,
.tg-form select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  outline: none;
}

.tg-form select {
  padding: 0 9px;
}

.tg-form .layui-textarea {
  width: 100%;
  min-height: 86px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
}

.tg-form .layui-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  outline: none;
}

.layui-form-select dl {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.layui-form-select dl dd {
  color: var(--text);
  font-size: 13px;
}

.layui-form-select dl dd:hover {
  background: var(--surface-2);
}

.layui-form-select dl dd.layui-this {
  background: var(--primary-soft);
  color: var(--primary);
}

.tg-form .layui-btn {
  height: 34px;
  line-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--primary);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 13px;
}

.tg-form .layui-btn:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.tg-form .layui-btn-primary {
  height: 34px;
  line-height: 32px;
  margin-left: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.tg-form .layui-btn-primary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tg-step-tip {
  margin: 0;
  padding: 16px 24px 0;
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted);
}

.tg-step .tg-form {
  padding-top: 10px;
}

/* ============================================================
   全屏加载
   ============================================================ */

.tg-loading {
  position: fixed;
  inset: 0;
  z-index: 9999999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}

.tg-loading.is-visible {
  opacity: 1;
  visibility: visible;
}

.tg-loading-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: tg-spin 0.75s linear infinite;
}

/* ============================================================
   暗色主题细节
   ============================================================ */

:root[data-theme='dark'] .tg-stat-icon.is-blue {
  background: rgba(47, 129, 247, 0.16);
  color: #79b8ff;
}

:root[data-theme='dark'] .tg-stat-icon.is-green {
  background: rgba(63, 185, 80, 0.16);
  color: #56d364;
}

:root[data-theme='dark'] .tg-stat-icon.is-orange {
  background: rgba(210, 153, 34, 0.16);
  color: #e3b341;
}

:root[data-theme='dark'] .tg-stat-icon.is-purple {
  background: rgba(163, 113, 247, 0.18);
  color: #c297ff;
}

:root[data-theme='dark'] body.tg-app {
  background-image: radial-gradient(760px 420px at 90% -10%, rgba(47, 129, 247, 0.12), transparent 62%);
  background-repeat: no-repeat;
}

:root[data-theme='dark'] .tg-header {
  border-bottom: 1px solid var(--line);
  box-shadow: none;
}

:root[data-theme='dark'] .tg-login-card {
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.62),
    0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* ============================================================
   动画
   ============================================================ */

@keyframes tg-rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tg-card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes tg-pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

@keyframes tg-float {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }

  50% {
    transform: translate3d(24px, -18px, 0) scale(1.06);
  }
}

@keyframes tg-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .tg-loading-spinner {
    animation-duration: 1.8s;
  }
}

/* ============================================================
   滚动条
   ============================================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.18);
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

:root[data-theme='dark'] ::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.16);
}

:root[data-theme='dark'] ::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.28);
}

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 1200px) {
  .tg-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .tg-app {
    display: block;
  }

  .tg-sidebar {
    position: static;
    width: 100%;
    height: auto;
  }

  .tg-logo {
    height: 56px;
    padding: 0 16px;
  }

  .tg-nav-title {
    display: none;
  }

  .tg-sidebar-foot {
    padding: 0 16px 10px;
    border-top: 0;
  }

  .tg-nav {
    flex: none;
    flex-direction: row;
    gap: 4px;
    padding: 0 12px 10px;
    overflow-x: auto;
  }

  .tg-nav button {
    width: auto;
    height: 36px;
    padding: 0 12px;
    white-space: nowrap;
  }

  .tg-main {
    margin-left: 0;
  }

  .tg-header {
    position: static;
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .tg-content {
    padding: 14px 16px 32px;
  }

  .tg-panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .tg-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .tg-stats {
    grid-template-columns: 1fr;
  }

  .tg-user span {
    display: none;
  }

  .tg-header p {
    display: none;
  }

  .tg-login-card {
    padding: 32px 24px 24px;
  }

  .tg-login-theme {
    top: 14px;
    right: 14px;
  }

  .tg-action-head,
  .tg-actions-cell {
    width: auto;
  }
}

/* ============================================================
   列表筛选、批量操作与分页
   ============================================================ */

.tg-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tg-filter select,
.tg-filter .layui-input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
}

.tg-filter select {
  min-width: 132px;
}

.tg-filter .layui-input {
  flex: 1 1 180px;
  max-width: 280px;
}

.tg-filter select:focus,
.tg-filter .layui-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  outline: none;
}

.tg-batch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.tg-batch-info {
  margin-right: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.tg-batch select {
  height: 32px;
  min-width: 140px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
}

.tg-btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.tg-btn-danger:hover {
  border-color: var(--danger);
  background: var(--danger);
  opacity: 0.88;
}

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

.tg-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.tg-pager span {
  margin-right: auto;
}

/* 选择列：提高选择器优先级，覆盖 .tg-table th 的左对齐 */
.tg-table th.tg-check-head,
.tg-table td.tg-check-cell {
  width: 44px;
  min-width: 44px;
  padding: 0 !important;
  text-align: center;
  vertical-align: middle;
}

.tg-table th.tg-check-head input,
.tg-table td.tg-check-cell input {
  display: block;
  width: 15px;
  height: 15px;
  margin: 0 auto;
  vertical-align: middle;
  cursor: pointer;
  accent-color: var(--primary);
}

.tg-muted-cell {
  max-width: 200px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}

.tg-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
}

.tg-log-detail {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 任务与自动化 ---------- */

.tg-progress {
  display: inline-block;
  width: 90px;
  height: 6px;
  overflow: hidden;
  vertical-align: middle;
  background: var(--surface-3);
  border-radius: 999px;
}

.tg-progress span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.tg-progress-text {
  margin-left: 8px;
  font-size: 12px;
  color: var(--muted);
}

.tg-code {
  color: var(--text);
  font-weight: 600;
  letter-spacing: 1px;
}

.tg-code-card {
  padding: 8px 4px 4px;
}

.tg-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tg-code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--text);
  user-select: all;
}

.tg-code-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.tg-code-meta.is-stale {
  color: var(--danger);
}

.tg-code-details {
  padding-top: 12px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.tg-code-details summary {
  color: var(--primary);
  cursor: pointer;
  user-select: none;
}

.tg-code-details p {
  max-height: 180px;
  margin: 8px 0 0;
  overflow: auto;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.tg-inline {
  display: inline-block;
  margin-right: 16px;
  cursor: pointer;
}

.tg-checkbox-list {
  max-height: 200px;
  padding: 8px 10px;
  margin-top: 6px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.tg-checkbox-list label {
  display: block;
  padding: 3px 0;
  cursor: pointer;
}

#section-keywords .tg-panel + .tg-panel {
  margin-top: 16px;
}

.tg-keyword-config {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
  padding: 16px 20px 12px;
}

.tg-keyword-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

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

.tg-keyword-config .layui-input {
  box-sizing: border-box;
  width: 100%;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tg-keyword-config .layui-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.tg-keyword-config .layui-input:hover {
  border-color: var(--line-hover);
}

.tg-keyword-config .layui-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  outline: none;
}

.tg-keyword-status {
  padding: 10px 20px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.tg-multi {
  width: 100%;
  min-height: 120px;
  padding: 6px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.tg-task-summary {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tg-task-detail-actions {
  margin-bottom: 10px;
}

@media (max-width: 900px) {
  .tg-filter,
  .tg-batch {
    padding: 10px 16px;
  }

  .tg-filter select,
  .tg-filter .layui-input,
  .tg-batch select {
    flex: 1 1 140px;
    max-width: none;
  }

  .tg-pager {
    padding: 10px 16px;
  }
}

/* ---------- 会话列表 ---------- */

.tg-conversation {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 560px;
  border-top: 1px solid var(--line);
}

.tg-conversation .tg-empty {
  padding: 40px 16px;
  font-size: 13px;
  text-align: center;
  color: var(--faint);
}

.tg-conversation-list {
  max-height: 640px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.tg-conv-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  font-family: var(--font-ui);
  text-align: left;
  cursor: pointer;
}

.tg-conv-item:hover {
  background: var(--surface-3);
}

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

.tg-conv-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.tg-conv-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.tg-conv-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--faint);
}

.tg-conv-unread {
  flex: none;
  min-width: 18px;
  height: 18px;
  margin-left: auto;
  padding: 0 5px;
  font-size: 11px;
  line-height: 18px;
  color: #ffffff;
  text-align: center;
  background: var(--danger);
  border-radius: 9px;
}

.tg-conversation-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tg-conversation-head {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--line);
}

.tg-conversation-messages {
  flex: 1;
  max-height: 480px;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--surface-2);
}

.tg-msg {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  margin-bottom: 14px;
}

.tg-msg.is-out {
  align-items: flex-end;
  margin-left: auto;
}

.tg-msg-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--faint);
}

.tg-msg-bubble {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tg-msg.is-out .tg-msg-bubble {
  background: var(--primary-soft);
  border-color: var(--primary-border);
}

.tg-msg-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.tg-msg-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tg-msg-button {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

button.tg-msg-button {
  font-family: inherit;
  cursor: pointer;
}

.tg-msg-button.is-link,
.tg-msg-button.is-callback {
  color: var(--primary);
  text-decoration: none;
  border-color: var(--primary-border);
}

.tg-msg-button.is-link:hover,
.tg-msg-button.is-callback:hover:not(:disabled) {
  background: var(--primary-soft);
}

.tg-msg-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.tg-conversation-reply {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}

.tg-conversation-reply textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: vertical;
}

.tg-conversation-reply .tg-btn {
  height: 38px;
}

@media (max-width: 900px) {
  .tg-conversation {
    grid-template-columns: 1fr;
  }

  .tg-conversation-list {
    max-height: 240px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
