:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f8f8fb;
  --text: #1c1c1e;
  --text-2: #6e6e73;
  --text-3: #8e8e93;
  --sep: rgba(60, 60, 67, 0.12);
  --blue: #007aff;
  --blue-soft: rgba(0, 122, 255, 0.12);
  --green: #34c759;
  --green-soft: rgba(52, 199, 89, 0.14);
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.16);
  --red: #ff3b30;
  --red-soft: rgba(255, 59, 48, 0.12);
  --purple: #af52de;
  --purple-soft: rgba(175, 82, 222, 0.14);
  --teal: #30b0c7;
  --teal-soft: rgba(48, 176, 199, 0.16);
  --gray-soft: rgba(120, 120, 128, 0.12);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #f2f2f7;
    --text-2: #aeaeb2;
    --text-3: #8e8e93;
    --sep: rgba(84, 84, 88, 0.65);
    --blue: #0a84ff;
    --blue-soft: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --green-soft: rgba(48, 209, 88, 0.18);
    --orange: #ffd60a;
    --orange-soft: rgba(255, 214, 10, 0.16);
    --red: #ff453a;
    --red-soft: rgba(255, 69, 58, 0.18);
    --purple: #bf5af2;
    --purple-soft: rgba(191, 90, 242, 0.18);
    --teal: #40c8e0;
    --teal-soft: rgba(64, 200, 224, 0.18);
    --gray-soft: rgba(120, 120, 128, 0.24);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

svg { display: block; }

.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: -0.01em; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(160deg, #0a84ff, #5e5ce6); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3); }
.brand .logo svg { width: 18px; height: 18px; stroke: #fff; }

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

.wrap { max-width: 1080px; margin: 0 auto; padding: 22px 24px 64px; }

/* 侧边栏布局 */
.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 248px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  background: var(--bg-elev);
  border-right: 1px solid var(--sep);
}

.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.side-brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(160deg, #0a84ff, #5e5ce6); display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(10, 132, 255, 0.28); flex-shrink: 0; }
.side-brand .logo svg { width: 20px; height: 20px; stroke: #fff; }
.side-brand .side-brand-text { min-width: 0; }
.side-brand b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.side-brand span { display: block; font-size: 11px; color: var(--text-3); margin-top: 1px; }

.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-group { font-size: 11px; font-weight: 600; color: var(--text-3); letter-spacing: 0.05em; padding: 14px 12px 5px; }
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.12s;
}
.side-item:hover { background: var(--gray-soft); color: var(--text); }
.side-item:active { transform: scale(0.985); }
.side-item.active { background: var(--blue); color: #fff; box-shadow: 0 8px 18px rgba(0, 122, 255, 0.26); }
.side-item .icon-slot { width: 20px; height: 20px; display: inline-flex; flex-shrink: 0; }
.side-item .icon-slot svg { width: 20px; height: 20px; }
.side-item .side-count { margin-left: auto; font-size: 11px; color: var(--text-3); font-weight: 600; }
.side-item.active .side-count { color: rgba(255, 255, 255, 0.75); }

.side-user { margin-top: auto; display: flex; align-items: center; gap: 9px; padding: 12px 8px 4px; border-top: 1px solid var(--sep); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #0a84ff, #5e5ce6); color: #fff; font-size: 14px; font-weight: 700; flex-shrink: 0; }
.side-user-info { flex: 1; min-width: 0; }
.side-user-info b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-info span { display: block; font-size: 11px; color: var(--text-3); }

.main-shell { margin-left: 248px; min-height: 100vh; display: flex; flex-direction: column; }
.page-title { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.menu-btn { display: none; }
.drawer-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.42); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.22s ease; }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
body.drawer-open { overflow: hidden; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 4px 0 18px; flex-wrap: wrap; }
.hero h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; font-weight: 700; }
.hero .sub { color: var(--text-2); font-size: 13px; margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--sep); box-shadow: var(--shadow); }
.stat .label { color: var(--text-2); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 12px; font-weight: 500; color: var(--text-3); margin-left: 4px; }

.segmented { display: inline-flex; background: var(--gray-soft); padding: 3px; border-radius: 11px; gap: 2px; margin-bottom: 14px; max-width: 100%; overflow-x: auto; }
.segmented button { border: 0; background: transparent; color: var(--text-2); padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap; transition: background 0.18s, color 0.18s; }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.segmented .count { color: var(--text-3); font-size: 11px; margin-left: 3px; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--sep); background: var(--card); color: var(--text); padding: 9px 15px; border-radius: 12px; font-size: 14px; font-weight: 550; cursor: pointer; transition: transform 0.12s, background 0.16s, opacity 0.16s; }
.btn:active { transform: scale(0.975); }
.btn.primary { background: var(--blue); border-color: transparent; color: #fff; }
.btn.primary:hover { background: color-mix(in srgb, var(--blue) 88%, #000); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn .icon { width: 16px; height: 16px; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 11px; border: 1px solid var(--sep); background: var(--card); color: var(--text-2); cursor: pointer; transition: background 0.15s, color 0.15s; }
.icon-btn:hover { color: var(--text); }
.icon-btn .icon { width: 18px; height: 18px; }

.acct-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.card { background: var(--card); border: 1px solid var(--sep); border-radius: var(--radius); box-shadow: var(--shadow); }

.acc { padding: 16px; display: flex; flex-direction: column; gap: 10px; transition: transform 0.15s; }
.acc:hover { transform: translateY(-1px); }
.acc-head { display: flex; align-items: center; gap: 8px; }
.acc-label { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 7px; letter-spacing: 0.01em; }
.badge.trae { background: var(--blue-soft); color: var(--blue); }
.badge.workbuddy { background: var(--green-soft); color: var(--green); }
.badge.qoder { background: var(--purple-soft); color: var(--purple); }
.badge.codebuddy { background: var(--orange-soft); color: var(--orange); }
.badge.doubao { background: var(--teal-soft); color: var(--teal); }

.pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.pill.gray { background: var(--gray-soft); color: var(--text-2); }

.acc-msg { color: var(--text-2); font-size: 13px; min-height: 19px; overflow-wrap: anywhere; }
.acc-info { color: var(--text-3); font-size: 12px; }
.acc-metrics { display: flex; gap: 18px; padding: 10px 0 2px; border-top: 1px solid var(--sep); }
.acc-metrics .m { display: flex; flex-direction: column; gap: 2px; }
.acc-metrics .m span { color: var(--text-3); font-size: 11px; }
.acc-metrics .m b { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.acc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.muted { color: var(--text-3); font-size: 12px; }
.row-actions { display: flex; gap: 4px; }
.row-actions .icon-btn { width: 32px; height: 32px; border-radius: 9px; border-color: transparent; background: transparent; }
.row-actions .icon-btn:hover { background: var(--gray-soft); }
.row-actions .icon-btn.danger:hover { color: var(--red); background: var(--red-soft); }

.empty { text-align: center; padding: 56px 20px; color: var(--text-3); }
.empty .icon { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--text-3); opacity: 0.6; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; font-weight: 650; }
.empty p { margin: 0; font-size: 13px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.36); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade 0.18s ease; }
.modal { width: 100%; max-width: 520px; max-height: min(86vh, 760px); overflow-y: auto; background: var(--bg-elev); border-radius: 22px; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28); animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.modal-body { padding: 8px 20px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 550; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--sep); background: var(--card-2); color: var(--text);
  border-radius: 12px; padding: 11px 13px; font-size: 14px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.field .hint { font-size: 12px; color: var(--text-3); }

.option-list { display: flex; flex-direction: column; gap: 8px; }
.option { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 1px solid var(--sep); border-radius: 14px; background: var(--card); cursor: pointer; transition: background 0.15s, border-color 0.15s; text-align: left; }
.option:hover { border-color: color-mix(in srgb, var(--blue) 40%, var(--sep)); background: var(--card-2); }
.option .opt-icon { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.option .opt-icon.trae { background: var(--blue-soft); color: var(--blue); }
.option .opt-icon.workbuddy { background: var(--green-soft); color: var(--green); }
.option .opt-icon.qoder { background: var(--purple-soft); color: var(--purple); }
.option .opt-icon.codebuddy { background: var(--orange-soft); color: var(--orange); }
.option .opt-icon.doubao { background: var(--teal-soft); color: var(--teal); }
.option .opt-text { flex: 1; min-width: 0; }
.option .opt-text b { display: block; font-size: 15px; font-weight: 600; }
.option .opt-text span { font-size: 12px; color: var(--text-3); }
.option .chev { color: var(--text-3); }

.steps { margin: 0 0 16px; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding: 0 0 12px 32px; color: var(--text-2); font-size: 13px; counter-increment: s; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -1px; width: 21px; height: 21px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.steps li:last-child { padding-bottom: 0; }

.callout { padding: 12px 14px; border-radius: 13px; background: var(--blue-soft); color: var(--blue); font-size: 13px; margin-bottom: 14px; }
.callout.warn { background: var(--orange-soft); color: var(--orange); }
.callout.error { background: var(--red-soft); color: var(--red); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--gray-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; padding: 12px 0; }

.log-list { display: flex; flex-direction: column; }
.log-item { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--sep); }
.log-item:last-child { border-bottom: 0; }
.log-item .lg-main { flex: 1; min-width: 0; }
.log-item .lg-msg { font-size: 13px; overflow-wrap: anywhere; }
.log-item .lg-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.log-item .lg-credit { font-size: 13px; font-weight: 650; color: var(--green); white-space: nowrap; }

.toast-wrap { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(28, 28, 30, 0.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25); animation: toastIn 0.2s ease; max-width: 86vw; }
.toast.error { background: rgba(255, 59, 48, 0.95); }
.toast.ok { background: rgba(28, 28, 30, 0.92); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 登录页 */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--blue) 16%, transparent), transparent 42%), radial-gradient(circle at 90% 100%, color-mix(in srgb, var(--purple) 14%, transparent), transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 390px; background: var(--bg-elev); border-radius: 26px; padding: 30px 26px 26px; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.12); border: 1px solid var(--sep); }
.auth-logo { width: 58px; height: 58px; border-radius: 17px; background: linear-gradient(160deg, #0a84ff, #5e5ce6); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; box-shadow: 0 10px 24px rgba(10, 132, 255, 0.32); }
.auth-logo svg { width: 30px; height: 30px; stroke: #fff; }
.auth-card h1 { margin: 0; text-align: center; font-size: 22px; letter-spacing: -0.02em; }
.auth-card .auth-sub { margin: 6px 0 22px; text-align: center; color: var(--text-3); font-size: 13px; }
.auth-tabs { display: flex; background: var(--gray-soft); border-radius: 11px; padding: 3px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.auth-tabs button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.auth-card .btn { width: 100%; padding: 12px; font-size: 15px; }
.auth-err { min-height: 18px; margin: 10px 0 0; color: var(--red); font-size: 13px; text-align: center; }
.auth-foot { margin-top: 18px; text-align: center; color: var(--text-3); font-size: 12px; }

/* 管理后台 */
.admin-tabs { margin-bottom: 18px; }
.panel { display: none; }
.panel.active { display: block; animation: fade 0.18s ease; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--sep); background: var(--card); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; padding: 11px 14px; border-bottom: 1px solid var(--sep); white-space: nowrap; background: var(--card-2); }
td { padding: 11px 14px; border-bottom: 1px solid var(--sep); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .cell-actions { display: flex; gap: 4px; }
td .cell-actions .icon-btn { width: 30px; height: 30px; border-radius: 8px; }
.tag { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 7px; font-size: 11px; font-weight: 600; background: var(--gray-soft); color: var(--text-2); }
.tag.admin { background: var(--blue-soft); color: var(--blue); }
.tag.disabled { background: var(--red-soft); color: var(--red); }
.tag.on { background: var(--green-soft); color: var(--green); }

.settings-card { padding: 18px; }
.settings-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.settings-card .desc { margin: 0 0 14px; color: var(--text-3); font-size: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--sep); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .sw-text b { display: block; font-size: 14px; font-weight: 550; }
.switch-row .sw-text span { font-size: 12px; color: var(--text-3); }
.switch { position: relative; width: 48px; height: 29px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--gray-soft); transition: background 0.2s; cursor: pointer; }
.switch .track::after { content: ""; position: absolute; width: 25px; height: 25px; border-radius: 50%; background: #fff; top: 2px; left: 2px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(19px); }

.cron-box { display: flex; gap: 8px; align-items: center; }
.cron-box code { flex: 1; padding: 10px 12px; background: var(--card-2); border: 1px solid var(--sep); border-radius: 10px; font-size: 12px; overflow-x: auto; white-space: nowrap; }

@media (max-width: 900px) {
  .acct-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .sidebar {
    width: 272px;
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.22, 0.85, 0.24, 1);
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.18);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  .main-shell { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 14px; }
  .wrap { padding: 18px 14px 56px; }
}

@media (max-width: 560px) {
  .wrap { padding: 16px 14px 56px; }
  .topbar { padding: 12px 14px; }
  .hero h1 { font-size: 22px; }
  .stats { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 21px; }
  .acc-metrics { gap: 14px; }
  .modal { max-height: 92vh; }
  .table-wrap { border-radius: 14px; }
}
