:root {
  --bg: #0b0d12;
  --bg-soft: #12151d;
  --panel: #171b26;
  --line: #232838;
  --text: #e6e9f0;
  --muted: #9aa3b8;
  --accent: #5b8cff;
  --ok: #37d399;
  --warn: #f5a623;
  --bad: #f2545b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .3px;
  white-space: nowrap;
}

.brand .logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #5b8cff, #8b5cf6);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #fff;
}

.search {
  flex: 1;
  max-width: 340px;
  position: relative;
}

.search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  outline: none;
}

.search input:focus { border-color: var(--accent); }
.search::before {
  content: "";
  position: absolute;
  left: 12px; top: 50%;
  width: 12px; height: 12px;
  margin-top: -7px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  border-bottom-color: transparent;
}

.btn {
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: .15s;
}

.btn:hover { border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- 主体 ---------- */
.layout {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 0;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px 8px 24px;
}

.group-title {
  padding: 12px 12px 6px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}

.site {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}

.site:hover { background: var(--panel); }

.site.active {
  background: linear-gradient(90deg, rgba(91,140,255,.18), transparent);
  border-color: rgba(91,140,255,.45);
}

.site .icon {
  width: 24px; height: 24px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  color: #fff;
  background: #2a3145;
  flex: none;
}

.site .meta { min-width: 0; flex: 1; }
.site .name { font-weight: 600; font-size: 13px; }
.site .host {
  font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex: none;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- 预览区 ---------- */
.main { display: grid; grid-template-rows: auto 1fr; min-width: 0; }

.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}

.toolbar .title { font-weight: 600; }
.toolbar .spacer { flex: 1; }

.switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.switch button {
  padding: 6px 14px;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.switch button.active { background: var(--accent); color: #fff; }

.stage { position: relative; background: var(--bg); }
.stage iframe { width: 100%; height: 100%; border: 0; display: block; }

.placeholder {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center;
  gap: 14px; text-align: center; padding: 40px;
  background: var(--bg);
}

.placeholder h2 { margin: 0; font-size: 18px; }
.placeholder p { margin: 0; color: var(--muted); max-width: 460px; }
.placeholder .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.notice {
  position: absolute; left: 50%; bottom: 18px;
  transform: translateX(-50%);
  background: rgba(23,27,38,.95);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12px; color: var(--muted);
}

/* ---------- 标签页 ---------- */
.tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.tabs button {
  padding: 7px 16px;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.tabs button.active { background: var(--accent); color: #fff; }

body[data-view="chat"] .toolbar,
body[data-view="chat"] .stage,
body[data-view="chat"] .search,
body[data-view="nav"] .chat { display: none; }

/* ---------- 对话 ---------- */
.chat {
  display: grid;
  grid-template-columns: 288px 1fr;
  min-height: 0;
}

.chat-config {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-config label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.chat-config select,
.chat-config input {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.chat-config select:focus,
.chat-config input:focus { border-color: var(--accent); }

.row-inline { display: flex; gap: 6px; }
.row-inline input { flex: 1; min-width: 0; }
.btn.tiny { padding: 6px 10px; font-size: 12px; }

.cfg-link { margin-top: -8px; }
.cfg-link a { color: var(--accent); font-size: 12px; text-decoration: none; }
.cfg-note { font-size: 11px; color: var(--muted); line-height: 1.6; }

.chat-main { display: grid; grid-template-rows: 1fr auto; min-width: 0; }

.messages { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }

.messages .empty {
  margin: auto; color: var(--muted); font-size: 13px;
  text-align: center; line-height: 1.8;
}

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.error { align-self: flex-start; background: rgba(242,84,91,.12); border: 1px solid rgba(242,84,91,.4); color: #ffb4b8; font-size: 13px; }

.composer { border-top: 1px solid var(--line); padding: 12px 16px; background: var(--bg-soft); }

.composer textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  font: inherit;
}

.composer textarea:focus { border-color: var(--accent); }
.composer-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 860px) {
  .chat { grid-template-columns: 1fr; }
  .chat-config { display: none; }
}

/* ---------- 抽屉 ---------- */
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 380px; max-width: 92vw;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .22s ease;
  display: grid; grid-template-rows: auto 1fr;
  z-index: 20;
}
.drawer.open { transform: none; }

.drawer header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer header .spacer { flex: 1; }
.drawer .body { overflow-y: auto; padding: 8px 12px 24px; }

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-bottom: 1px solid rgba(35,40,56,.6);
}
.row .name { flex: 1; font-size: 13px; }
.row .note { font-size: 11px; color: var(--muted); }
.row .code {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  min-width: 46px; text-align: center;
}
.row .code.ok { color: var(--ok); border-color: rgba(55,211,153,.4); }
.row .code.warn { color: var(--warn); border-color: rgba(245,166,35,.4); }
.row .code.bad { color: var(--bad); border-color: rgba(242,84,91,.4); }

.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 19;
}
.scrim.show { opacity: 1; pointer-events: auto; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.show { display: block; position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 30; }
}
