[hidden] { display: none !important; }

:root {
  --bg: #0b1120;
  --panel: #111a2e;
  --panel2: #182338;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #4f8cff;
  --user: #1f4fd8;
  --border: #243049;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button:not(:disabled):active { transform: scale(.96); }

/* ---------- 侧边栏 ---------- */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 60;
}
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(82vw, 300px);
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 61;
  display: flex; flex-direction: column;
  transform: translateX(-102%);
  transition: transform .22s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px;
  padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.sidebar-head strong { font-size: 16px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 10px 20px; }
.sidebar-foot {
  display: flex; gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sidebar-foot button {
  flex: 1; padding: 9px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 12px 2px 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .05em;
}
.mini {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  font-size: 15px; line-height: 1;
}
.conv-list, .item-list { list-style: none; }
.conv-list li, .item-list li { margin-bottom: 2px; }
.conv-list .row, .item-list .row {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
}
.conv-list .row:hover, .item-list .row:hover { background: var(--panel2); }
.conv-list li.active .row, .item-list li.active .row { background: rgba(79,140,255,.18); color: #bcd3ff; }
.conv-list .title, .item-list .title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-list .del {
  color: var(--muted); padding: 4px 6px; font-size: 13px;
}
.conv-list .del:hover { color: var(--err); }
.item-list .check { color: var(--ok); font-size: 13px; }
.projects-root { padding: 0 4px 4px; color: var(--muted); font-size: 11px; word-break: break-all; }
.sidebar.locked .row, .sidebar.locked .mini { pointer-events: none; opacity: .5; }

/* ---------- 主区域 ---------- */
.main { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  font-size: 17px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.titles strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model { font-size: 11px; color: var(--muted); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

#chat {
  flex: 1; overflow-y: auto;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.welcome { margin: auto; text-align: center; color: var(--muted); max-width: 340px; line-height: 1.7; }
.welcome-icon { font-size: 42px; margin-bottom: 10px; }
.welcome .sub { font-size: 13px; }
.welcome em { color: var(--text); font-style: normal; }

.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; font-size: 15px; line-height: 1.65; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant.streaming { border-color: var(--accent); }
.msg.error { align-self: flex-start; background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.35); color: #fecaca; }
.msg pre { background: #0a101f; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; margin: 8px 0; font-size: 13px; }
.msg code { background: #0a101f; border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.msg pre code { background: none; padding: 0; }
.msg p { margin: 4px 0; }
.msg ul, .msg ol { margin: 4px 0 4px 20px; }
.msg a { color: #7fb0ff; }

.syscard {
  align-self: center; max-width: 96%;
  font-size: 12px; color: var(--muted);
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px;
  word-break: break-all; line-height: 1.5;
}
.syscard .cmd { font-family: Consolas, monospace; color: var(--text); }
.syscard.err { border-color: rgba(248,113,113,.4); color: #fca5a5; }
.syscard.ok { border-color: rgba(52,211,153,.35); color: #6ee7b7; }
.usage { font-size: 11px; color: var(--muted); text-align: center; }

.composer {
  display: flex; gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#input {
  flex: 1; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; resize: none; max-height: 120px; outline: none;
}
#input:focus { border-color: var(--accent); }
#sendBtn { width: 44px; border-radius: 12px; font-size: 17px; background: var(--panel2); border: 1px solid var(--border); }

.busybar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 5px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
}
.spinner { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 70; padding: 20px;
}
.panel {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel h2 { font-size: 17px; margin-bottom: 4px; }
.panel label { font-size: 12px; color: var(--muted); }
.panel input {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; outline: none;
}
.panel-actions { display: flex; gap: 8px; margin-top: 4px; }
.panel-actions button { flex: 1; padding: 10px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--border); }
.panel-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

.toast {
  position: fixed; left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1f2937; color: #f3f4f6;
  border-radius: 10px; padding: 9px 14px;
  font-size: 13px; z-index: 100; max-width: 90%;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}

@media (min-width: 720px) {
  .sidebar { transform: translateX(-102%); }
  .sidebar.open { transform: translateX(0); }
}
