/* ============================================================
   Tavern — iOS 风格设计系统
   ============================================================ */
:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --text: #1c1c1e;
  --text-2: #8e8e93;
  --text-3: #c7c7cc;
  --line: rgba(60, 60, 67, 0.09);
  --line-strong: rgba(60, 60, 67, 0.16);
  --blue: #007aff;
  --blue-soft: rgba(0, 122, 255, 0.1);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --bubble-ai: #ffffff;
  --bubble-user: linear-gradient(180deg, #0a84ff 0%, #0071e3 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --r-card: 16px;
  --r-btn: 12px;
  --r-bub: 18px;
  --nav-h: 44px;
  --tab-h: 54px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --app-h: 100dvh;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --glass: rgba(249, 249, 249, 0.97);
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --text: #ffffff;
  --text-2: #8e8e93;
  --text-3: #48484a;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --blue: #0a84ff;
  --blue-soft: rgba(10, 132, 255, 0.16);
  --bubble-ai: #26262a;
  --bubble-user: linear-gradient(180deg, #0a84ff 0%, #0066d6 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  --glass: rgba(28, 28, 30, 0.97);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, "SF Pro Text", "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

button { cursor: pointer; }
img { display: block; }

/* ---------------- 布局骨架 ---------------- */
#app {
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.nav {
  height: calc(var(--nav-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 12px;
  padding-right: 12px;
  background: var(--glass);
  border-bottom: 0.5px solid var(--line);
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--blue);
  font-size: 16px;
  padding: 6px 4px;
  border-radius: 8px;
  transition: opacity 0.15s;
}
.nav-btn:active { opacity: 0.5; }
.nav-btn.strong { font-weight: 600; }
.nav-btn.icon { padding: 6px; }

.views {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
}

.view { display: none; }
.view.active { display: block; }



/* ---------------- 底部 Tab ---------------- */
.tabbar {
  flex: 0 0 auto;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--glass);
  border-top: 0.5px solid var(--line);
  position: relative;
  z-index: 30;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-2);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1px;
  transition: color 0.18s;
}
.tab svg { width: 24px; height: 24px; stroke-width: 1.8; }
.tab.active { color: var(--blue); }
.tab:active { opacity: 0.6; }

/* ---------------- 列表 ---------------- */
.group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  padding: 18px 20px 7px;
  letter-spacing: 0.2px;
}

.list {
  margin: 0 12px;
  background: var(--card);
  border-radius: var(--r-card);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  min-height: 64px;
  position: relative;
  background: var(--card);
  transition: background 0.12s;
  text-align: left;
  width: 100%;
}
.row:active { background: var(--card-2); }
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 62px;
  right: 0;
  height: 0.5px;
  background: var(--line);
}
.row.no-sep::before { display: none; }

.ava {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  flex: 0 0 50px;
  object-fit: cover;
  background: var(--card-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  user-select: none;
}
.ava.sm { width: 34px; height: 34px; flex-basis: 34px; font-size: 14px; }
.ava.lg { width: 72px; height: 72px; flex-basis: 72px; font-size: 26px; }

.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 16px;
  font-weight: 590;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-sub {
  font-size: 13.5px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chev { color: var(--text-3); font-size: 17px; flex: 0 0 auto; margin-left: 2px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--blue-soft);
  color: var(--blue);
  flex: 0 0 auto;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.16);
}

.empty {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.7;
}
.empty svg { width: 44px; height: 44px; opacity: 0.28; margin: 0 auto 14px; }

/* ---------------- 按钮 / 表单 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--r-btn);
  background: var(--card-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 550;
  transition: transform 0.12s var(--ease), opacity 0.12s;
}
.btn:active { transform: scale(0.96); opacity: 0.8; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.danger { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.btn.block { width: 100%; padding: 13px; }

.field {
  background: var(--card);
  border-radius: var(--r-card);
  margin: 0 12px 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.field-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
  position: relative;
  min-height: 50px;
}
.field-row + .field-row::before {
  content: "";
  position: absolute; top: 0; left: 14px; right: 0;
  height: 0.5px; background: var(--line);
}
.field-label { font-size: 15.5px; flex: 0 0 auto; min-width: 78px; }
.field-input {
  flex: 1;
  font-size: 15.5px;
  text-align: right;
  color: var(--text-2);
  min-width: 0;
  background: none;
}
.field-input:focus { color: var(--text); }
textarea.field-input { text-align: left; resize: none; line-height: 1.55; min-height: 84px; color: var(--text); }

.switch {
  width: 50px; height: 30px; border-radius: 30px;
  background: var(--text-3); position: relative;
  transition: background 0.22s var(--ease); flex: 0 0 auto;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.22s var(--ease);
}
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }

/* ---------------- 头像色板 ---------------- */
.c0 { background: linear-gradient(140deg, #ff9a8b, #ff6a88); }
.c1 { background: linear-gradient(140deg, #7f7fd5, #86a8e7); }
.c2 { background: linear-gradient(140deg, #43e97b, #38f9d7); }
.c3 { background: linear-gradient(140deg, #fa709a, #fee140); }
.c4 { background: linear-gradient(140deg, #30cfd0, #330867); }
.c5 { background: linear-gradient(140deg, #a8edea, #fed6e3); color: #333 !important; }
.c6 { background: linear-gradient(140deg, #f6d365, #fda085); }

/* ============================================================
   聊天页
   ============================================================ */
#chatView {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  visibility: hidden;
}
#chatView.open { visibility: visible; }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  padding: 14px 12px 20px;
}

.msg {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: flex-start;
}

.msg.u { flex-direction: row-reverse; }

.msg-ava {
  width: 34px; height: 34px; border-radius: 50%;
  flex: 0 0 34px; object-fit: cover; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff;
  background: var(--card-2);
  margin-top: 2px;
}
.msg-body { max-width: calc(100% - 54px); min-width: 0; }

.bub {
  padding: 10px 14px;
  border-radius: var(--r-bub);
  font-size: 15.5px;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.msg.a .bub {
  background: var(--bubble-ai);
  color: var(--text);
  border-top-left-radius: 6px;
}
.msg.u .bub {
  background: var(--bubble-user);
  color: #fff;
  border-top-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 122, 255, 0.24);
}

.bub em { font-style: italic; opacity: 0.72; }
.bub strong { font-weight: 650; }
.bub code {
  background: rgba(120, 120, 128, 0.14);
  padding: 1px 5px; border-radius: 5px;
  font-size: 0.92em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.bub pre {
  background: rgba(120, 120, 128, 0.12);
  padding: 10px 12px; border-radius: 10px;
  overflow-x: auto; font-size: 13px; margin: 6px 0;
}
.bub pre code { background: none; padding: 0; }
.bub blockquote {
  margin: 6px 0; padding-left: 10px;
  border-left: 3px solid var(--line-strong);
  color: var(--text-2);
}

.msg-meta {
  display: none;
  gap: 6px;
  margin-top: 7px;
  align-items: center;
  flex-wrap: wrap;
}
.msg.act .msg-meta { display: flex; }
.msg-meta button {
  border: 0;
  background: var(--card-2);
  color: var(--text-2);
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 13px;
  font-weight: 500;
}
.msg-meta button:active { background: var(--line); }
.msg-meta span { font-size: 12px; color: var(--text-3); padding: 0 2px; }
.msg.u .msg-meta { justify-content: flex-end; }
.msg.u .msg-meta { justify-content: flex-end; }
.msg-meta button { font-size: 12px; color: var(--text-2); padding: 2px 0; }
.msg-meta button:active { color: var(--blue); }

.thinking { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.thinking i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3); display: block;
  opacity: .45;
}
.thinking i:nth-child(2) { animation-delay: 0.16s; }
.thinking i:nth-child(3) { animation-delay: 0.32s; }


/* 输入栏 */
.composer {
  flex: 0 0 auto;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--glass);
  border-top: 0.5px solid var(--line);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer-input {
  flex: 1;
  background: var(--card);
  border: 0.5px solid var(--line-strong);
  border-radius: 19px;
  padding: 9px 15px;
  font-size: 16px;
  line-height: 1.4;
  max-height: 128px;
  min-height: 38px;
  overflow-y: auto;
  color: var(--text);
  resize: none;
}
.composer-input::placeholder { color: var(--text-3); }

.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 38px;
  transition: transform 0.16s var(--ease), opacity 0.16s;
  box-shadow: 0 2px 10px rgba(0, 122, 255, 0.3);
}
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.32; box-shadow: none; }
.send-btn svg { width: 20px; height: 20px; fill: #fff; }
.send-btn.stop { background: var(--red); }

/* 抽屉 / 弹层 */
.sheet-mask {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0; pointer-events: none;
  transition: opacity 0.26s var(--ease);
}
.sheet-mask.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 86vh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.34s var(--ease);
  padding-bottom: var(--safe-b);
}
.sheet.show { transform: none; }
.sheet-head {
  padding: 10px 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 0.5px solid var(--line);
  flex: 0 0 auto;
}
.sheet-grip {
  width: 36px; height: 5px; border-radius: 3px;
  background: var(--text-3); margin: 6px auto 0; flex: 0 0 auto;
}
.sheet-title { font-size: 16px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 8px 0 16px; }

/* 操作菜单 */
.action-list { padding: 6px 0; }
.action-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 20px;
  font-size: 16px; text-align: left;
}
.action-item:active { background: var(--card-2); }
.action-item.danger { color: var(--red); }
.action-item svg { width: 20px; height: 20px; flex: 0 0 20px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff; font-size: 14px;
  padding: 9px 16px; border-radius: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.24s, transform 0.24s var(--ease);
  z-index: 200; max-width: 80vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 搜索栏 */
.searchbar {
  margin: 10px 12px 2px;
  display: flex; align-items: center; gap: 8px;
  background: var(--card-2);
  border-radius: 11px;
  padding: 8px 12px;
}
.searchbar svg { width: 17px; height: 17px; color: var(--text-2); flex: 0 0 17px; }
.searchbar input { flex: 1; font-size: 16px; background: none; min-width: 0; }

/* 编辑器 */
.editor { padding: 0 0 24px; }
.editor textarea {
  width: 100%; min-height: 130px;
  background: var(--card); border-radius: var(--r-card);
  padding: 14px; font-size: 15px; line-height: 1.6;
  resize: vertical; color: var(--text);
  box-shadow: var(--shadow-sm);
}
.editor-label {
  font-size: 13px; font-weight: 600; color: var(--text-2);
  padding: 16px 16px 7px; letter-spacing: 0.2px;
}
.editor-inner { padding: 0 12px; }

/* 全屏编辑页 */
.page {
  position: absolute; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s var(--ease);
  visibility: hidden;
}
.page.open { transform: none; visibility: visible; }
.page-body { flex: 1; overflow-y: auto; padding-bottom: 32px; }

/* 骨架屏 */
.skel {
  background: linear-gradient(90deg, var(--card-2) 25%, var(--line) 50%, var(--card-2) 75%);
  background-size: 200% 100%;
  border-radius: 8px;
}

