/* 聊天规则与记忆云同步系统 - 样式 */
:root {
  --bg: #0b0f17;
  --bg-soft: #101624;
  --card: #141c2e;
  --card-hover: #1a2440;
  --border: #233049;
  --text: #e7ecf5;
  --text-dim: #8b96ad;
  --text-faint: #5b677f;
  --accent: #6366f1;
  --accent2: #22d3ee;
  --green: #34d399;
  --orange: #fbbf24;
  --red: #f87171;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
}
body.light {
  --bg: #f3f5fa;
  --bg-soft: #e9edf6;
  --card: #ffffff;
  --card-hover: #f4f6fc;
  --border: #dbe2f0;
  --text: #1a2233;
  --text-dim: #5b677f;
  --text-faint: #97a2b8;
  --shadow: 0 8px 30px rgba(30, 40, 80, .12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: background .3s, color .3s;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- 登录页 ---------- */
#authScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(800px 400px at 20% 0%, rgba(99, 102, 241, .18), transparent 60%),
    radial-gradient(700px 380px at 85% 90%, rgba(34, 211, 238, .12), transparent 60%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-logo {
  display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px;
}
.auth-logo .logo-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.auth-logo h1 { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.auth-sub { text-align: center; color: var(--text-dim); font-size: 12.5px; margin-bottom: 24px; }
.auth-tabs { display: flex; background: var(--bg-soft); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; padding: 9px 0; border: none; background: transparent; color: var(--text-dim);
  border-radius: 8px; font-size: 13.5px; font-weight: 600; transition: all .2s;
}
.auth-tabs button.active { background: var(--accent); color: #fff; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font-size: 14px; outline: none; transition: border .2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.btn-primary {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff; font-size: 14.5px; font-weight: 700; letter-spacing: 1px;
  transition: opacity .2s, transform .1s;
}
.btn-primary:hover { opacity: .92; }
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.auth-error { color: var(--red); font-size: 12.5px; margin-top: 12px; text-align: center; min-height: 16px; }
.auth-hint { margin-top: 18px; font-size: 11.5px; color: var(--text-faint); text-align: center; line-height: 1.7; }

/* ---------- 主界面 ---------- */
#appScreen { display: none; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px; height: 58px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15.5px; }
.brand .logo-icon {
  width: 30px; height: 30px; border-radius: 8px; font-size: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
}
.sync-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-soft); font-size: 12.5px; color: var(--text-dim);
  cursor: pointer; transition: all .2s; user-select: none;
}
.sync-pill:hover { border-color: var(--accent); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.sync-dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.sync-dot.busy { background: var(--accent2); animation: pulse 1s infinite; }
.sync-dot.dirty { background: var(--orange); box-shadow: 0 0 8px var(--orange); }
.sync-dot.conflict { background: var(--red); box-shadow: 0 0 8px var(--red); }
@keyframes pulse { 50% { opacity: .35; } }
.topbar-spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 13px; }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
}
.btn-logout {
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  padding: 6px 13px; border-radius: 8px; font-size: 12.5px; transition: all .2s;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

.layout { display: flex; max-width: 1180px; margin: 0 auto; gap: 22px; padding: 24px 22px 60px; }
.sidenav { width: 210px; flex-shrink: 0; position: sticky; top: 82px; height: fit-content; }
.sidenav button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 12px 15px; margin-bottom: 6px;
  border: 1px solid transparent; border-radius: 12px;
  background: transparent; color: var(--text-dim); font-size: 14px; font-weight: 600;
  transition: all .2s; text-align: left;
}
.sidenav button:hover { background: var(--card); color: var(--text); }
.sidenav button.active { background: var(--card); border-color: var(--border); color: var(--text); }
.sidenav button .nav-ico { font-size: 17px; width: 22px; text-align: center; }
.sidenav .side-tip { margin-top: 18px; padding: 12px 14px; font-size: 11.5px; color: var(--text-faint); line-height: 1.8; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }

.content { flex: 1; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header .sub { color: var(--text-dim); font-size: 12.5px; margin-top: 4px; }

.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-size: 13px; font-weight: 600; transition: all .2s;
}
.btn:hover { border-color: var(--accent); }
.btn.accent { background: linear-gradient(135deg, var(--accent), #8b5cf6); border: none; color: #fff; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

/* 规则卡片 */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  padding: 7px 15px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.rule-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; transition: all .2s; display: flex; flex-direction: column; gap: 10px;
}
.rule-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.rule-card.disabled { opacity: .55; }
.rule-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.rule-name { font-weight: 700; font-size: 14.5px; word-break: break-all; }
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.badge.history { background: rgba(99, 102, 241, .15); color: #a5b4fc; }
.badge.filter { background: rgba(248, 113, 113, .14); color: #fca5a5; }
.badge.autoreply { background: rgba(52, 211, 153, .14); color: #6ee7b7; }
.badge.custom { background: rgba(34, 211, 238, .13); color: #67e8f9; }
body.light .badge.history { color: #4f46e5; }
body.light .badge.filter { color: #dc2626; }
body.light .badge.autoreply { color: #059669; }
body.light .badge.custom { color: #0891b2; }
.rule-content {
  color: var(--text-dim); font-size: 12.5px; line-height: 1.65;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-wrap; min-height: 40px;
}
.rule-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.rule-time { font-size: 11.5px; color: var(--text-faint); }
.rule-actions { display: flex; gap: 6px; }
.icon-btn {
  border: none; background: var(--bg-soft); color: var(--text-dim);
  width: 30px; height: 30px; border-radius: 8px; font-size: 13px; transition: all .2s;
}
.icon-btn:hover { color: var(--accent); background: var(--card-hover); }
.icon-btn.del:hover { color: var(--red); }

/* 开关 */
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: .25s; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  left: 3px; top: 3px; background: #fff; transition: .25s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-faint);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty-state .big { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

/* 设置卡片 */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.set-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.set-card h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.set-card .desc { font-size: 12px; color: var(--text-faint); margin-bottom: 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.set-row:last-child { margin-bottom: 0; }
.set-row .lbl { font-size: 13px; color: var(--text-dim); }
.set-row .lbl b { color: var(--text); font-weight: 600; display: block; font-size: 13.5px; }
.set-row select, .set-row input[type="number"] {
  padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font-size: 13px; outline: none; width: 130px;
}
.set-row input[type="number"]:focus, .set-row select:focus { border-color: var(--accent); }
.tag-input-wrap {
  display: flex; flex-wrap: wrap; gap: 7px; padding: 9px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg-soft); width: 100%;
}
.tag {
  display: flex; align-items: center; gap: 6px; padding: 3px 9px;
  background: rgba(248, 113, 113, .13); color: #fca5a5; border-radius: 999px; font-size: 12px; font-weight: 600;
}
body.light .tag { color: #dc2626; }
.tag span { cursor: pointer; opacity: .7; }
.tag span:hover { opacity: 1; }
.tag-input {
  border: none; background: transparent; color: var(--text); outline: none;
  font-size: 13px; min-width: 110px; flex: 1; padding: 3px;
}

/* 同步中心 */
.sync-hero {
  background: linear-gradient(135deg, rgba(99, 102, 241, .12), rgba(34, 211, 238, .07));
  border: 1px solid var(--border); border-radius: 18px; padding: 26px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.sync-hero-left { display: flex; align-items: center; gap: 16px; }
.sync-hero .big-dot { width: 46px; height: 46px; border-radius: 50%; background: var(--border); position: relative; flex-shrink: 0; }
.sync-hero .big-dot.ok { background: rgba(52, 211, 153, .18); }
.sync-hero .big-dot.ok::after {
  content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--green); font-size: 20px; font-weight: 700;
}
.sync-hero .big-dot.busy { background: rgba(34, 211, 238, .16); }
.sync-hero .big-dot.busy::after {
  content: "⟳"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--accent2); font-size: 20px; animation: spin 1s linear infinite;
}
.sync-hero .big-dot.dirty { background: rgba(251, 191, 36, .15); }
.sync-hero .big-dot.dirty::after {
  content: "!"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--orange); font-size: 22px; font-weight: 700;
}
.sync-hero .big-dot.conflict { background: rgba(248, 113, 113, .16); }
.sync-hero .big-dot.conflict::after {
  content: "×"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--red); font-size: 22px; font-weight: 700;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sync-hero h3 { font-size: 17px; font-weight: 700; }
.sync-hero .meta { font-size: 12.5px; color: var(--text-dim); margin-top: 5px; }
.sync-hero-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.rev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.rev-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 17px; }
.rev-card .k { font-size: 11.5px; color: var(--text-faint); font-weight: 600; letter-spacing: .5px; }
.rev-card .v { font-size: 21px; font-weight: 800; margin-top: 5px; }
.rev-card .v small { font-size: 11px; color: var(--text-faint); font-weight: 400; margin-left: 4px; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; }
.panel h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 14px; }
.dev-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dev-table th { text-align: left; color: var(--text-faint); font-size: 11.5px; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.dev-table td { padding: 10px; border-bottom: 1px solid var(--border); color: var(--text-dim); }
.dev-table tr:last-child td { border-bottom: none; }
.cur-badge { font-size: 10.5px; background: rgba(52, 211, 153, .15); color: var(--green); padding: 2px 8px; border-radius: 999px; font-weight: 700; margin-left: 7px; }
.log-list { max-height: 320px; overflow-y: auto; }
.log-item { display: flex; align-items: center; gap: 11px; padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.log-item:last-child { border-bottom: none; }
.log-ico { width: 28px; height: 28px; border-radius: 8px; background: var(--bg-soft); display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.log-item .t { color: var(--text-faint); font-size: 11.5px; margin-left: auto; white-space: nowrap; }
.log-item .rev { color: var(--text-faint); font-size: 11.5px; }
.secure-note { font-size: 12.5px; color: var(--text-dim); line-height: 2; }
.secure-note b { color: var(--text); }
.secure-note .lock { margin-right: 6px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(5, 8, 15, .66); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%; max-width: 480px; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; padding: 11px; }
.confirm-text { font-size: 13.5px; color: var(--text-dim); line-height: 1.8; }

/* Toast */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 11px; padding: 12px 16px; min-width: 240px; max-width: 380px;
  box-shadow: var(--shadow); font-size: 13px; animation: slideIn .25s ease;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--orange); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }

@media (max-width: 860px) {
  .layout { flex-direction: column; padding: 16px 14px 50px; }
  .sidenav { width: 100%; position: static; display: flex; gap: 6px; overflow-x: auto; }
  .sidenav button { width: auto; white-space: nowrap; margin-bottom: 0; }
  .sidenav .side-tip { display: none; }
  .sync-hero { flex-direction: column; align-items: flex-start; }
}

/* TRAE 本机配置备份卡片 */
.trae-empty { border: 1.5px dashed var(--border); border-radius: 12px; padding: 20px 22px; color: var(--text-dim); font-size: 13px; line-height: 1.9; background: var(--bg-soft); }
.trae-empty code { background: rgba(99,102,241,.14); color: var(--accent2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.trae-meta { display: flex; flex-direction: column; gap: 14px; }
.trae-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trae-chips .chip { display: inline-flex; align-items: center; gap: 5px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 999px; padding: 6px 13px; font-size: 12.5px; color: var(--text-dim); }
.trae-chips .chip b { color: var(--text); font-weight: 600; }
.trae-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.trae-files { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.trae-files > summary { cursor: pointer; font-size: 13px; color: var(--accent2); user-select: none; }
.trae-files-list { margin: 12px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 6px; }
.trae-file-row { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-dim); background: var(--bg-soft); padding: 7px 11px; border-radius: 8px; word-break: break-all; }
.trae-steps { font-size: 12.5px; color: var(--text-dim); line-height: 1.85; }
.trae-steps ol { margin: 8px 0 0; padding-left: 20px; }
.trae-steps code { background: rgba(99,102,241,.14); color: var(--accent2); padding: 1px 6px; border-radius: 5px; font-size: 11.5px; word-break: break-all; }
