/* Claude.ai 风格：米白暖底 + 陶土橙点缀，衬线标题 */
:root {
  --bg: #faf9f5;
  --bg-sidebar: #f0eee6;
  --surface: #ffffff;
  --surface-2: #f5f4ee;
  --text: #29261b;
  --muted: #73726c;
  --accent: #c96442;
  --accent-hover: #b55534;
  --border: #e3e1d7;
  --user-bubble: #f0eee6;
  --error: #ab2b1e;
  --ok: #4a7c59;
  --radius: 14px;
  --serif: "Tiempos Text", Georgia, "Songti SC", SimSun, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --bg-sidebar: #1f1f1d;
    --surface: #30302e;
    --surface-2: #383836;
    --text: #e5e4df;
    --muted: #a6a39a;
    --accent: #d97757;
    --accent-hover: #e08b6e;
    --border: #3e3e3a;
    --user-bubble: #393937;
    --error: #e0806c;
    --ok: #8fbf9c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 system-ui, "Segoe UI", "Microsoft YaHei", sans-serif;
}

body { display: flex; }

/* ---------- 侧栏 ---------- */

#sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
}

.brand {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

#convo-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }

.convo-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 13.5px;
}
.convo-item:hover { background: var(--surface-2); }
.convo-item.active { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.convo-item .t {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-item .del {
  visibility: hidden;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}
.convo-item:hover .del { visibility: visible; }
.convo-item .del:hover { color: var(--error); }

#sidebar-mask { display: none; }

/* ---------- 主区 ---------- */

#app {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  display: flex;
  align-items: center;
  gap: 6px;
  /* PWA 全屏时避开刘海/状态栏 */
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}

#btn-sidebar { display: none; }

#conn-dot {
  color: var(--error);
  font-size: 11px;
  cursor: pointer;
  animation: conn-pulse 1.6s infinite;
}
@keyframes conn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#model-badge {
  flex: 1;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0 24px;
  overscroll-behavior: contain;
}

.msg, .error-msg, .usage-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
}

.msg.user { display: flex; justify-content: flex-end; margin: 18px auto 14px; }
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: var(--radius);
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant { margin: 6px auto; }

.md { font-size: 15px; }
.md :first-child { margin-top: 0; }
.md :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-family: var(--serif); }
.md pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
}
.md code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.md pre code { background: none; padding: 0; border: none; }
.md blockquote { border-left: 3px solid var(--accent); margin-left: 0; padding-left: 14px; color: var(--muted); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 10px; }
.md a { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  font: 12px/1.6 inherit;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.running { border-color: var(--accent); color: var(--accent); }

.tool-detail {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 4px 0 10px;
}
.tool-detail pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--text);
}
.tool-detail .td-args { color: var(--muted); padding-bottom: 6px; border-bottom: 1px dashed var(--border); margin-bottom: 6px; }
.tool-detail .td-result { max-height: 320px; overflow-y: auto; }

.thinking { color: var(--muted); font-style: italic; }
.thinking i {
  font-style: normal;
  animation: think-blink 1.2s infinite both;
}
.thinking i:nth-child(2) { animation-delay: 0.2s; }
.thinking i:nth-child(3) { animation-delay: 0.4s; }
@keyframes think-blink {
  0%, 80%, 100% { opacity: 0.15; }
  40% { opacity: 1; }
}

.usage { font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.usage .hit { color: var(--ok); }

.error-msg {
  color: var(--error);
  font-size: 13px;
  margin: 10px auto;
}
.error-msg .inner {
  background: color-mix(in srgb, var(--error) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
  border-radius: 10px;
  padding: 8px 14px;
}

/* ---------- 输入区 ---------- */

footer { padding: 0 20px calc(16px + env(safe-area-inset-bottom)); }

.input-shell {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 10px 10px 18px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
.input-shell:focus-within { border-color: var(--accent); }

#input {
  flex: 1;
  resize: none;
  max-height: 40vh;
  background: none;
  color: var(--text);
  border: none;
  font: inherit;
  outline: none;
  padding: 3px 0;
}

#btn-send, #btn-stop {
  border: none;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-stop { background: var(--error); font-size: 12px; }

/* ---------- 设置 ---------- */

dialog {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(640px, 94vw);
  max-height: 88vh;
  padding: 24px 26px;
}
dialog::backdrop { background: rgba(41, 38, 27, 0.45); }
dialog h2 { margin: 0 0 16px; font-family: var(--serif); font-size: 19px; }
dialog h3 {
  margin: 22px 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}
dialog section:first-of-type h3 { margin-top: 0; }

dialog label { display: block; margin-bottom: 10px; font-size: 12.5px; color: var(--muted); }
dialog input, dialog textarea, dialog select {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font: 13.5px/1.5 inherit;
}
dialog input:focus, dialog textarea:focus, dialog select:focus { outline: none; border-color: var(--accent); }

.inline-label { margin-top: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px 10px;
  margin-bottom: 10px;
}
.card input { background: var(--surface-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.card-actions button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.card-actions button:hover { border-color: var(--accent); color: var(--accent); }
.card-actions .danger { margin-left: auto; }
.card-actions .danger:hover { border-color: var(--error); color: var(--error); }
.card-status { font-size: 12px; color: var(--muted); flex-shrink: 1; }
.card-status.ok { color: var(--ok); }
.card-status.err { color: var(--error); }

.headers-label { font-size: 12.5px; color: var(--muted); margin: 2px 0 6px; }
.header-row { display: flex; gap: 6px; margin-bottom: 6px; }
.header-row input { margin-top: 0; }
.header-row .icon-btn { font-size: 13px; }

.add-btn {
  border: 1px dashed var(--border);
  background: none;
  color: var(--muted);
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
}
.add-btn:hover { border-color: var(--accent); color: var(--accent); }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions button {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 20px;
  font: inherit;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}
.dialog-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dialog-actions .primary:hover { background: var(--accent-hover); }

.error { color: var(--error); font-size: 12.5px; min-height: 1em; margin: 8px 0 0; }

/* ---------- 移动端 ---------- */

@media (max-width: 768px) {
  /* iOS：输入框字号 <16px 会在聚焦时自动放大页面，全部提到 16px 根治 */
  #input,
  dialog input,
  dialog textarea,
  dialog select {
    font-size: 16px;
  }

  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }
  #sidebar.open { transform: none; }
  #sidebar-mask.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(0, 0, 0, 0.3);
  }
  #btn-sidebar { display: block; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
}
