:root {
  --bg: #edf3fb;
  --bg-soft: #f7faff;
  --panel: rgba(255, 255, 255, .92);
  --panel-solid: #ffffff;
  --text: #111827;
  --muted: #738198;
  --primary: #2f6bff;
  --primary-2: #00c2ff;
  --danger: #ef4444;
  --warning: #f59e0b;
  --ok: #12a56f;
  --line: #dfe7f3;
  --line-strong: #cad6e8;
  --side: #0c1424;
  --side-2: #13213a;
  --shadow: 0 18px 48px rgba(17, 24, 39, .08);
  --shadow-lg: 0 26px 80px rgba(17, 24, 39, .14);
  --radius: 22px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at 25% 0%, rgba(47, 107, 255, .14), transparent 34%),
    radial-gradient(circle at 96% 16%, rgba(0, 194, 255, .12), transparent 28%),
    linear-gradient(180deg, #f6f9ff 0%, var(--bg) 100%);
  color: var(--text);
}
body::selection { background: rgba(47, 107, 255, .18); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; }
button { border: 0; }
.hidden { display: none !important; }

.app { min-height: 100vh; display: flex; align-items: stretch; }
.sidebar {
  width: 284px;
  padding: 24px 18px;
  color: #fff;
  background:
    radial-gradient(circle at 20% 0%, rgba(47, 107, 255, .38), transparent 28%),
    linear-gradient(180deg, var(--side) 0%, #0a1020 100%);
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: 18px 0 60px rgba(15, 23, 42, .12);
  overflow: hidden;
}
.sidebar::before {
  content: "";
  position: absolute;
  inset: auto -60px -120px 30px;
  width: 260px;
  height: 260px;
  border-radius: 999px;
  background: rgba(0, 194, 255, .13);
  filter: blur(16px);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; padding: 0 6px; }
.logo {
  width: 48px;
  height: 48px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 24px;
  background: linear-gradient(135deg, #2f6bff 0%, #68e1ff 100%);
  box-shadow: 0 20px 45px rgba(47, 107, 255, .35);
}
.brand h1 { font-size: 17px; letter-spacing: -.02em; }
.brand p { margin-top: 4px; color: #aebbd0; font-size: 12px; }
nav { display: grid; gap: 8px; position: relative; z-index: 1; }
.nav {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 15px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, color .18s ease, box-shadow .18s ease;
  font-size: 15px;
}
.nav::before {
  content: attr(data-icon);
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255,255,255,.07);
  font-size: 15px;
}
.nav:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(2px); }
.nav.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(47,107,255,.95), rgba(0,194,255,.72));
  box-shadow: 0 14px 34px rgba(47, 107, 255, .26);
}
.nav.active::before { background: rgba(255,255,255,.18); }
.status, .logout-btn { position: relative; z-index: 1; }
.status {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.11);
  background: rgba(255,255,255,.06);
  border-radius: 18px;
  padding: 14px 15px;
  color: #c6d2e5;
  font-size: 13px;
  line-height: 1.45;
  backdrop-filter: blur(12px);
}
.logout-btn {
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.09);
  color: #edf5ff;
  box-shadow: none;
}
.logout-btn:hover { background: rgba(255,255,255,.14); }

.main {
  flex: 1;
  min-width: 0;
  padding: 34px clamp(22px, 3.5vw, 46px) 48px;
  overflow: auto;
}
.page { display: grid; gap: 22px; max-width: 1260px; margin: 0 auto; }
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 2px;
}
.header h2 { font-size: clamp(25px, 3vw, 34px); letter-spacing: -.04em; }
.header p, .login-card p { color: var(--muted); margin-top: 6px; line-height: 1.55; }
.header > h2 + p { color: var(--muted); }

button {
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #5291ff);
  color: #fff;
  padding: 12px 17px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: -.01em;
  box-shadow: 0 14px 30px rgba(47, 107, 255, .20);
  transition: transform .18s ease, filter .18s ease, box-shadow .18s ease;
}
button:hover { filter: brightness(.98); transform: translateY(-1px); box-shadow: 0 18px 36px rgba(47, 107, 255, .25); }
button:active { transform: translateY(0); }
button.danger { background: linear-gradient(135deg, var(--danger), #fb7185); box-shadow: 0 14px 30px rgba(239, 68, 68, .18); }

.hero-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 28px;
  padding: 26px;
  background:
    radial-gradient(circle at 82% 18%, rgba(0,194,255,.24), transparent 30%),
    linear-gradient(135deg, #102040 0%, #2546a5 52%, #3478ff 100%);
  color: #fff;
  box-shadow: var(--shadow-lg);
}
.hero-panel::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -90px;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  border: 34px solid rgba(255,255,255,.08);
}
.hero-kicker {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  color: #d9efff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.hero-panel h3 { margin-top: 12px; font-size: 27px; letter-spacing: -.03em; }
.hero-panel p { margin-top: 8px; color: #dbeafe; line-height: 1.65; max-width: 670px; }
.hero-metrics { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; min-width: 260px; position: relative; z-index: 1; }
.hero-metrics span {
  border: 1px solid rgba(255,255,255,.20);
  background: rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 9px 12px;
  color: #f8fbff;
  font-size: 13px;
  font-weight: 800;
}

.cards { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 16px; }
.card, .panel {
  background: var(--panel);
  border: 1px solid rgba(210, 220, 235, .86);
  border-radius: var(--radius);
  padding: 21px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.card { min-height: 136px; position: relative; overflow: hidden; }
.card::before {
  content: "";
  position: absolute;
  right: 18px;
  top: 18px;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(47,107,255,.16), rgba(0,194,255,.18));
}
.card:nth-child(1)::after { content: "🛡️"; }
.card:nth-child(2)::after { content: "🧩"; }
.card:nth-child(3)::after { content: "✅"; }
.card:nth-child(4)::after { content: "🧾"; }
.card::after {
  position: absolute;
  right: 27px;
  top: 27px;
  font-size: 19px;
}
.card span { color: var(--muted); font-size: 14px; font-weight: 700; }
.card strong { display: block; font-size: 34px; margin-top: 14px; letter-spacing: -.04em; }
.card small { display: block; margin-top: 8px; color: #95a3b8; font-size: 12px; }
.panel h3 { font-size: 18px; letter-spacing: -.02em; }

.grid.two { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 18px; }
.small-gap { gap: 12px !important; }
.action-form, .compact-form { display: grid; gap: 13px; }
.compact-form { grid-template-columns: 1.2fr .7fr 2fr .9fr .7fr auto; align-items: center; }
.settings-form { grid-template-columns: repeat(3, 1fr); align-items: end; }
label { color: var(--muted); font-size: 13px; display: grid; gap: 8px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(248, 251, 255, .92);
  color: var(--text);
  border-radius: 15px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
textarea { min-height: 130px; resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #a2aec0; }
input:focus, select:focus, textarea:focus { border-color: rgba(47,107,255,.72); background: #fff; box-shadow: 0 0 0 4px rgba(47,107,255,.10); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7c8da8 50%), linear-gradient(135deg, #7c8da8 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.result {
  background: #09111f;
  color: #e4eeff;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.06);
  overflow: auto;
  max-height: 420px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.result.mini { max-height: 240px; min-height: 110px; }
.result.tall { max-height: 360px; min-height: 170px; }

.table, .log-list { display: grid; gap: 13px; }
.rule-row, .log-item {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 9px;
  box-shadow: 0 12px 26px rgba(17, 24, 39, .04);
}
.rule-row:hover, .log-item:hover { border-color: var(--line-strong); box-shadow: 0 16px 34px rgba(17,24,39,.07); }
.rule-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  background: #edf4ff;
  color: #2864e5;
}
.badge.off { background: #f1f3f6; color: #7e8796; }
.badge.danger { background: #fff0f0; color: var(--danger); }
.meta { color: var(--muted); font-size: 13px; word-break: break-all; line-height: 1.55; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions button { padding: 8px 11px; font-size: 13px; border-radius: 11px; box-shadow: none; }
.log-item { grid-template-columns: 150px 1fr auto; align-items: start; }
.log-time { color: var(--muted); font-size: 12px; margin-top: 7px; }
.log-main strong { display: block; margin-bottom: 5px; }
.log-main pre { white-space: pre-wrap; word-break: break-word; background: #f5f8fd; border-radius: 14px; padding: 12px; color: #41506a; border: 1px solid #e7edf7; }

.env-group { display: grid; gap: 16px; }
.env-grid { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 14px; }
.env-grid label { color: var(--muted); font-size: 13px; display: grid; gap: 8px; }
.env-grid label span { color: #9aa5b7; font-size: 12px; line-height: 1.45; }
.env-grid textarea { min-height: 118px; }
.env-save-btn { justify-self: start; min-width: 180px; }
.tip-panel p { color: var(--muted); line-height: 1.7; }
.tip-panel code, .login-panel code { background: #edf4ff; color: #2864e5; padding: 2px 7px; border-radius: 8px; }
.env-help { color: var(--muted); line-height: 1.65; font-size: 13px; }
.env-custom-field { display: grid; gap: 8px; }
.env-delete-custom { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px !important; color: var(--danger) !important; font-size: 12px !important; }
.env-delete-custom input { width: auto; box-shadow: none; }

.provider-panel { display: grid; gap: 16px; }
.provider-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.provider-head p { color: var(--muted); margin-top: 6px; }
.provider-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.provider-card {
  text-align: left;
  display: grid;
  gap: 8px;
  padding: 15px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fbfdff;
  color: var(--text);
  cursor: pointer;
  box-shadow: none;
}
.provider-card:hover { border-color: rgba(47,107,255,.45); transform: translateY(-1px); box-shadow: 0 14px 28px rgba(47,107,255,.10); }
.provider-card.active { border-color: var(--primary); background: linear-gradient(180deg, #f3f7ff, #fff); box-shadow: 0 14px 30px rgba(47,107,255,.14); }
.provider-card b { font-size: 15px; }
.provider-card span { justify-self: start; border-radius: 999px; background: #edf4ff; color: #2864e5; padding: 3px 8px; font-size: 12px; font-weight: 800; }
.provider-card code { font-size: 12px; color: #526078; overflow-wrap: anywhere; }
.provider-card em { font-style: normal; font-size: 12px; color: #2b3a55; font-weight: 800; }
.provider-card small { color: var(--muted); line-height: 1.45; }
.model-field { grid-column: span 1; }
.model-select-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.model-tip { color: #7f8da6; font-size: 12px; line-height: 1.45; }

#pageReply label, #pageAiTools label, .settings-form label, .password-form label { color: var(--muted); font-size: 13px; display: grid; gap: 8px; }
#pageReply textarea[name="reply"] { min-height: 110px; }
#pageReply .panel h3, #pageAiTools .panel h3 { margin-bottom: 5px; }
#pageAiTools textarea { min-height: 120px; }

.boot-panel, .login-card {
  max-width: 560px;
  margin: 110px auto;
  background: var(--panel);
  padding: 32px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  color: var(--muted);
}
.boot-panel::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 0 6px rgba(47,107,255,.12);
}
.password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto;
  gap: 14px;
  align-items: end;
}
.password-form > div { grid-column: 1 / -1; }
.password-form h3 { margin-bottom: 6px; }
.password-form p { color: var(--muted); line-height: 1.65; }


.form-head { grid-column: 1 / -1; display: grid; gap: 6px; margin-bottom: 2px; }
.form-head p { color: var(--muted); line-height: 1.6; font-size: 13px; }
.settings-split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 18px; align-items: start; }
.settings-split .settings-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
.settings-split .settings-form button { justify-self: start; }
.settings-split .password-form { grid-template-columns: 1fr; }
.settings-split .password-form button { justify-self: start; }
.env-group h3::after { content: ''; display: block; width: 44px; height: 3px; margin-top: 10px; border-radius: 999px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); }

/* 独立登录页 */
.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 12%, rgba(47,107,255,.30), transparent 30%),
    radial-gradient(circle at 78% 14%, rgba(0,194,255,.18), transparent 28%),
    linear-gradient(135deg, #081222 0%, #13213a 48%, #eef4ff 48%, #f8fbff 100%);
}
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 520px);
  gap: 48px;
  align-items: center;
  padding: 48px clamp(20px, 6vw, 90px);
}
.login-hero { color: white; max-width: 640px; }
.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2f6bff, #68e1ff);
  font-size: 34px;
  font-weight: 900;
  box-shadow: 0 24px 60px rgba(47,107,255,.34);
  margin-bottom: 25px;
}
.eyebrow { color: #a7d3ff; letter-spacing: .14em; text-transform: uppercase; font-weight: 900; font-size: 13px; }
.login-hero h1 { margin-top: 10px; font-size: clamp(38px, 5vw, 62px); line-height: 1.02; letter-spacing: -.05em; }
.login-hero p:not(.eyebrow) { margin-top: 18px; color: #c9d7ee; font-size: 17px; line-height: 1.85; }
.login-feature-list { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
.login-feature-list span { border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #eef6ff; border-radius: 999px; padding: 10px 14px; font-size: 13px; font-weight: 800; backdrop-filter: blur(10px); }
.login-panel {
  position: relative;
  overflow: hidden;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(255,255,255,.74);
  border-radius: 30px;
  padding: 36px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .20);
  backdrop-filter: blur(18px);
}
.login-panel::before {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -60px;
  top: -80px;
  border-radius: 999px;
  background: rgba(47,107,255,.10);
}
.login-panel-head { position: relative; z-index: 1; }
.login-panel-head > span { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: #eef4ff; color: #2864e5; font-size: 12px; font-weight: 900; }
.login-panel h2 { font-size: 30px; margin-top: 14px; letter-spacing: -.03em; }
.login-panel p { color: var(--muted); margin-top: 8px; line-height: 1.65; }
.login-form { display: grid; gap: 16px; margin-top: 24px; position: relative; z-index: 1; }
.login-form label { color: var(--muted); font-size: 13px; display: grid; gap: 8px; }
.login-form button { width: 100%; padding: 14px 18px; }
.login-message { min-height: 22px; margin-top: 14px; font-size: 13px; color: var(--muted); position: relative; z-index: 1; }
.login-message.ok { color: var(--ok); }
.login-message.error { color: var(--danger); }

@media (max-width: 1180px) {
  .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .compact-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form button { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .app { display: block; }
  .sidebar { width: 100%; height: auto; position: static; padding: 18px; border-radius: 0 0 28px 28px; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .nav { justify-content: center; }
  .nav span { display: none; }
  .status { margin-top: 0; }
  .main { padding: 22px 16px 36px; }
  .header { align-items: flex-start; flex-direction: column; }
  .hero-panel { flex-direction: column; align-items: flex-start; }
  .hero-metrics { justify-content: flex-start; min-width: 0; }
  .grid.two, .settings-form, .password-form, .env-grid, .settings-split .settings-form { grid-template-columns: 1fr; }
  .log-item { grid-template-columns: 1fr; }
  .login-shell { grid-template-columns: 1fr; padding: 30px 18px; }
  .login-hero h1 { font-size: 40px; }
}
@media (max-width: 720px) {
  .cards, .provider-grid, .model-select-wrap { grid-template-columns: 1fr; }
  nav { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .nav { padding: 9px; min-height: 42px; }
  .nav::before { width: 26px; height: 26px; }
  .card, .panel { border-radius: 18px; padding: 18px; }
}

.section-title-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.section-title-row h3 { margin: 0 0 6px; }
.section-title-row p { margin: 0; color: var(--muted); line-height: 1.7; }
.config-pill {
  display: inline-flex;
  white-space: nowrap;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 900;
  color: #245ddd;
  background: #edf4ff;
  border: 1px solid #dbe8ff;
}
.bot-config-form {
  display: grid;
  gap: 16px;
  border: 1px solid rgba(47,107,255,.16);
  background: linear-gradient(180deg, rgba(244,248,255,.92), rgba(255,255,255,.98));
}
.bot-config-form button { justify-self: start; }
@media (max-width: 920px) {
  .settings-split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .section-title-row { flex-direction: column; }
  .bot-config-form button { width: 100%; }
}
