:root {
  --bg: #0f1116;
  --panel: #161a22;
  --panel-2: #1c2130;
  --panel-3: #232838;
  --text: #e6e8ee;
  --muted: #8a94a6;
  --accent: #f0b429;
  --accent-2: #ffd166;
  --user: #2b3245;
  --bot: #1e2432;
  --warn: #f26d6d;
  --ok: #4ec9b0;
  --danger: #ff6b6b;
  --border: #2a3040;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ================== 顶栏 ================== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid var(--panel-3); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 32px; height: 32px; border-radius: 8px; }
.brand-name { font-size: 18px; font-weight: 700; color: var(--accent); }
.brand-tagline { font-size: 12px; color: var(--muted); margin-top: 2px; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.hint { font-size: 12px; color: var(--muted); }

.settings-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.15s;
}
.settings-btn:hover { border-color: var(--accent); color: var(--accent); }
.settings-btn .gear { font-size: 14px; }

/* ================== 聊天区 ================== */
.chat { display: flex; flex-direction: column; height: calc(100vh - 100px); max-width: 900px; margin: 0 auto; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }

.msg { display: flex; gap: 10px; max-width: 92%; }
.msg .bubble {
  padding: 12px 14px; border-radius: 12px; line-height: 1.55; font-size: 14px; white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--user); color: #fff; border-top-right-radius: 4px; }
.msg.bot { align-self: flex-start; }
.msg.bot .bubble { background: var(--bot); border-top-left-radius: 4px; }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg.bot .role { color: var(--accent); }

.composer {
  display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--panel-3); background: var(--panel);
}
textarea#input {
  flex: 1; resize: none; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; font-family: inherit;
}
textarea#input:focus { outline: none; border-color: var(--accent); }
button#send {
  padding: 10px 20px; border-radius: 10px; border: none; cursor: pointer;
  background: var(--accent); color: #17181d; font-weight: 700; font-size: 14px;
}
button#send:hover { background: var(--accent-2); }
button#send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ================== 底部 ================== */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 24px; font-size: 11px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--panel-3);
}
.footer-warn { color: var(--warn); }

/* ================== Settings Modal ================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fade-in 0.15s ease-out;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(680px, 96vw); max-height: 92vh; overflow: hidden;
  background: var(--panel); border: 1px solid var(--panel-3);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column;
  animation: slide-up 0.2s ease-out;
}

.modal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px; border-bottom: 1px solid var(--panel-3);
}
.modal-header h2 { margin: 0; font-size: 18px; color: var(--accent); font-weight: 700; }
.modal-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.modal-close {
  background: transparent; color: var(--muted); border: none;
  font-size: 18px; cursor: pointer; padding: 4px 10px; border-radius: 6px;
}
.modal-close:hover { color: var(--danger); background: var(--panel-2); }

.modal-body {
  padding: 20px 24px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}

.card {
  background: var(--panel-2); border: 1px solid var(--panel-3);
  border-radius: 12px; padding: 16px 18px;
}
.card-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.card-hint { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }
.card-hint strong { color: var(--warn); }

.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block; font-size: 12px; color: var(--muted);
  margin-bottom: 6px; font-weight: 500;
}
.field-note {
  display: block; font-size: 11px; color: var(--ok); margin-top: 4px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.field-row .field { margin-bottom: 0; }

.field input, .field select {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 13px; font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field select { cursor: pointer; }

/* Toggle */
.toggle-row {
  display: flex; align-items: center; gap: 14px;
  padding-top: 12px; margin-top: 4px;
  border-top: 1px dashed var(--panel-3);
}
.toggle { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0; background: var(--panel-3);
  border-radius: 26px; transition: 0.2s;
}
.toggle-slider::before {
  content: ""; position: absolute; height: 20px; width: 20px;
  left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

.toggle-title { font-size: 13px; font-weight: 600; }
.toggle-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Polymarket 凭据子卡 */
.subcard {
  margin-top: 14px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--panel-3); border-radius: 10px;
}
.subcard-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.subcard-hint {
  font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-bottom: 12px;
}
.subcard-hint code {
  padding: 1px 6px; background: var(--panel-2); border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px;
}
.tag-dry { color: var(--muted); }
.tag-live { color: var(--ok); }
.field-warn { color: var(--warn); font-weight: normal; font-size: 10.5px; margin-left: 4px; }

.creds-status { margin-top: 10px; text-align: center; }
.creds-badge {
  display: inline-block; padding: 5px 12px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.3px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--panel-3);
}
.creds-badge.dry {
  background: rgba(138, 148, 166, 0.1); color: var(--muted); border-color: var(--panel-3);
}
.creds-badge.live {
  background: rgba(78, 201, 176, 0.12); color: var(--ok); border-color: rgba(78, 201, 176, 0.35);
}

.save-status {
  min-height: 20px; font-size: 13px; text-align: center;
  transition: all 0.2s;
}
.save-status.ok { color: var(--ok); }
.save-status.err { color: var(--danger); }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--panel-3);
}
.btn {
  padding: 9px 20px; border-radius: 10px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.15s;
}
.btn.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
}
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.primary { background: var(--accent); color: #17181d; }
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
