/* ============================================================================
   应用外壳：侧栏 / 舞台 / 移动端抽屉 + 底部标签栏 · 桌面 & iOS 横竖屏适配
   ============================================================================ */
.shell {
  display: flex; min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r))
           calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  gap: 16px;
}

/* ------------------------------------------------------------ 侧栏 */
.rail {
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  border-radius: var(--r-lg); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 3px;
  position: sticky; top: calc(14px + var(--safe-t));
  height: calc(100dvh - 30px - var(--safe-t) - var(--safe-b));
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  z-index: 60;
}
.rail::-webkit-scrollbar { width: 6px; }

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 15px; }
.brand .mark {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-2) 58%, var(--accent-3));
  box-shadow: 0 9px 20px -9px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.42);
}
.brand .name { font-weight: 680; font-size: 15.5px; letter-spacing: -.028em; line-height: 1.2; }
.brand .sub { font-size: 10px; color: var(--muted); letter-spacing: .09em; font-weight: 600; text-transform: uppercase; }

.nav-label {
  font-size: 10.5px; font-weight: 660; color: var(--faint);
  padding: 13px 12px 6px; letter-spacing: .07em; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 12px; min-height: 40px;
  color: var(--ink-2); font-size: 14px; font-weight: 520;
  cursor: pointer; user-select: none; position: relative;
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--spring);
}
.nav-item:hover { background: var(--fill); color: var(--ink); text-decoration: none; }
.nav-item:active { transform: scale(.985); }
.nav-item.active {
  background: rgba(255,255,255,.92); color: var(--ink); font-weight: 600;
  box-shadow: var(--shadow-sm), inset 0 1px 0 #fff;
}
.nav-item.active .ico { color: var(--accent); }
.nav-item .ico { color: var(--ink-3); }
.nav-item .pill {
  margin-left: auto; font-size: 11px; font-weight: 640; color: var(--accent-ink);
  background: var(--accent-soft); padding: 1.5px 8px; border-radius: 999px;
}
.nav-item .pill.dot { width: 7px; height: 7px; padding: 0; border-radius: 50%; background: var(--red); }

.rail-foot { margin-top: auto; padding-top: 12px; }
.user-card {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 15px;
  background: var(--fill); cursor: pointer; transition: background .18s var(--ease);
}
.user-card:hover { background: var(--fill-2); }

/* ------------------------------------------------------------ 舞台 */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.stage {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  padding-bottom: 6px;
}
.stage-scroll { flex: 1; min-height: 0; }
.page { max-width: 1280px; margin: 0 auto; width: 100%; }
.page.wide { max-width: none; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { font-size: clamp(22px, 2.4vw, 27px); font-weight: 700; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ------------------------------------------------------------ 移动端顶栏 / 抽屉 / 标签栏 */
.topbar {
  display: none; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 16px; margin-bottom: 14px;
  position: sticky; top: calc(8px + var(--safe-t)); z-index: 55;
}
.topbar .title { font-weight: 660; font-size: 15px; }

.scrim {
  position: fixed; inset: 0; z-index: 59; background: rgba(24,28,40,.34);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity .28s var(--ease);
}
.scrim.on { opacity: 1; pointer-events: auto; }

.tabbar {
  display: none; position: fixed; z-index: 70;
  left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  padding: 6px; border-radius: 22px;
  /* minmax(0,1fr) 必须显式写：否则列最小宽度为 min-content，窄屏会撑破视口 */
  grid-template-columns: repeat(var(--tabs, 4), minmax(0, 1fr));
}
.tabbar .tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 7px 3px; border-radius: 16px; cursor: pointer; user-select: none;
  color: var(--ink-3); font-size: 10.5px; font-weight: 560;
  transition: background .2s var(--ease), color .2s;
  min-height: 48px; min-width: 0; overflow: hidden;
}
.tabbar .tab > span:not(.ico) {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabbar .tab.active { background: rgba(255,255,255,.92); color: var(--accent-ink); box-shadow: var(--shadow-xs); }

/* 平板：侧栏收窄为图标栏 */
@media (max-width: 1100px) {
  :root { --rail-w: 76px; }
  .rail { padding: 14px 10px; }
  .rail .brand .name, .rail .brand .sub, .rail .nav-label,
  .rail .nav-item span:not(.ico):not(.pill), .rail-foot .user-card > div:not(.avatar),
  .rail-foot .btn span:not(.ico) { display: none; }
  .rail .nav-item { justify-content: center; padding: 11px 0; }
  .rail .nav-item .pill { position: absolute; top: 4px; right: 10px; }
  .rail .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .rail-foot .user-card { justify-content: center; padding: 7px; }
  .rail-foot .btn { padding: 9px 0; }
}

/* 手机：侧栏变抽屉 + 底部标签栏 */
@media (max-width: 860px) {
  .shell { padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r))
                    calc(var(--tabbar-h) + 24px + var(--safe-b)) calc(10px + var(--safe-l)); gap: 0; }
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; height: 100dvh;
    width: min(300px, 84vw); flex: none; border-radius: 0 var(--r-lg) var(--r-lg) 0;
    padding: calc(18px + var(--safe-t)) 14px calc(18px + var(--safe-b)) calc(14px + var(--safe-l));
    transform: translateX(-104%); transition: transform .38s var(--spring);
    z-index: 60; overflow-y: auto;
  }
  .rail.open { transform: translateX(0); }
  .rail .brand .name, .rail .brand .sub, .rail .nav-label,
  .rail .nav-item span:not(.ico):not(.pill), .rail-foot .user-card > div:not(.avatar),
  .rail-foot .btn span:not(.ico) { display: block; }
  .rail .nav-item { justify-content: flex-start; padding: 10px 12px; }
  .rail-foot .user-card, .rail-foot .btn { justify-content: flex-start; padding: 9px 10px; }
  .topbar { display: flex; }
  .tabbar { display: grid; }
  .page-head h1 { font-size: 21px; }
  .stat .v { font-size: 23px; }
  th, td { padding: 10px 11px; font-size: 12.6px; }
}

/* 横屏矮屏（手机横过来）：标签栏让位，侧栏抽屉更宽 */
@media (max-height: 560px) and (orientation: landscape) {
  .shell { padding-bottom: calc(12px + var(--safe-b)); }
  .tabbar { display: none !important; }
  .rail { width: min(360px, 62vw); }
  .topbar { margin-bottom: 10px; }
  .modal .box { max-height: 92dvh; }
}

/* 超小屏 */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 20px; }
}

/* ============================================================================
   对话工作台
   ============================================================================ */
.chat-wrap {
  display: flex; flex-direction: column; min-height: 0;
  height: calc(100dvh - 30px - var(--safe-t) - var(--safe-b));
}
@media (max-width: 860px) {
  .chat-wrap { height: calc(100dvh - var(--tabbar-h) - 40px - var(--safe-t) - var(--safe-b)); }
}
@media (max-height: 560px) and (orientation: landscape) {
  .chat-wrap { height: calc(100dvh - 26px - var(--safe-t) - var(--safe-b)); }
}
.chat-top {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 18px; margin-bottom: 12px;
}
.picker {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 12px;
  background: rgba(255,255,255,.9); border: 1px solid var(--hairline-soft);
  box-shadow: var(--shadow-xs); cursor: pointer; min-height: 38px;
}
.picker select {
  border: none; background: transparent; padding: 0 18px 0 0; box-shadow: none;
  font-size: 13.5px; font-weight: 580; width: auto; min-width: 110px; max-width: 240px;
}
.picker select:focus { box-shadow: none; background: transparent; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 4px 14px; overscroll-behavior: contain; }
.thread { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.msg { display: flex; gap: 12px; animation: fadeUp .3s var(--ease) both; }
.msg .who {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-size: 12.5px; font-weight: 660;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35); overflow: hidden;
}
.msg .who img { width: 100%; height: 100%; object-fit: cover; }
.msg.user .who { background: linear-gradient(150deg, var(--green), var(--green-ink)); }
.msg.assistant .who { background: linear-gradient(150deg, var(--accent), var(--accent-2)); }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg .content { font-size: 14.8px; line-height: 1.8; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .content {
  background: rgba(255,255,255,.9); border: 1px solid var(--hairline-soft);
  padding: 11px 15px; border-radius: 16px; box-shadow: var(--shadow-xs);
}
.msg .content p { margin: 0 0 10px; } .msg .content p:last-child { margin-bottom: 0; }
.msg .content h1, .msg .content h2, .msg .content h3 { margin: 18px 0 8px; font-size: 16.5px; }
.msg .content ul, .msg .content ol { margin: 8px 0; padding-left: 22px; }
.msg .content li { margin: 4px 0; }
.msg .content code {
  background: rgba(120,120,128,.13); padding: 1.5px 6px; border-radius: 6px;
  font-family: var(--mono); font-size: 12.9px; color: #A3217B;
}
.msg .content pre {
  background: rgba(22,24,32,.96); color: #E6E9F2; padding: 14px 16px; border-radius: 14px;
  overflow-x: auto; margin: 10px 0; font-size: 12.9px; line-height: 1.72; position: relative;
  -webkit-overflow-scrolling: touch;
}
.msg .content pre code { background: none; color: inherit; padding: 0; font-size: 12.9px; }
.msg .content blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--accent-line); color: var(--ink-3); }
.msg .content table { border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.msg .content th, .msg .content td { border: 1px solid var(--hairline); padding: 7px 11px; white-space: normal; }
.code-copy {
  position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity .18s;
  background: rgba(255,255,255,.14); border: 0; color: #DDE3F0; border-radius: 8px;
  padding: 4px 8px; font-size: 11px; cursor: pointer; font-family: var(--font);
}
pre:hover .code-copy, pre:focus-within .code-copy { opacity: 1; }
@media (max-width: 860px) { .code-copy { opacity: 1; } }

.cursor-blink {
  display: inline-block; width: 7px; height: 15px; vertical-align: -2px;
  background: var(--accent); border-radius: 1.5px; animation: cb 1s steps(2) infinite;
}
@keyframes cb { 50% { opacity: 0; } }

.msg-actions { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity .2s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
@media (max-width: 860px) { .msg-actions { opacity: 1; } }

.chat-empty { max-width: 680px; margin: min(7vh, 70px) auto 0; text-align: center; padding: 0 8px; }
.chat-empty .big {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 20px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(150deg, var(--accent), var(--accent-2) 58%, var(--accent-3));
  box-shadow: 0 20px 44px -20px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.42);
}
.chat-empty h2 { font-size: clamp(20px, 3.4vw, 26px); font-weight: 700; }
.chat-empty p { color: var(--muted); margin: 9px 0 26px; font-size: 14.5px; }
.suggests { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 11px; text-align: left; }
.suggests > * { min-width: 0; }
@media (max-width: 640px) { .suggests { grid-template-columns: minmax(0, 1fr); } }
.suggest {
  padding: 14px 16px; border-radius: 16px; cursor: pointer;
  background: var(--glass-strong); border: 1px solid rgba(255,255,255,.75);
  box-shadow: var(--shadow-xs);
  transition: transform .24s var(--spring), box-shadow .24s var(--ease);
}
.suggest:hover { transform: translateY(-3px); box-shadow: var(--shadow-sm); }
.suggest .t { font-size: 13.8px; font-weight: 590; display: flex; align-items: center; gap: 8px; }
.suggest .d { font-size: 12.3px; color: var(--muted); margin-top: 4px; }
.suggest .ico { color: var(--accent); }

.composer { padding: 10px 2px 0; }
.composer-inner {
  max-width: 820px; margin: 0 auto; border-radius: 20px; padding: 9px 9px 9px 16px;
  background: rgba(255,255,255,.92); border: 1px solid var(--hairline);
  box-shadow: 0 12px 34px -16px rgba(16,24,40,.34), inset 0 1px 0 #fff;
  display: flex; align-items: flex-end; gap: 9px;
  transition: border-color .2s, box-shadow .2s;
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft), 0 12px 34px -16px rgba(16,24,40,.34);
}
.composer textarea {
  flex: 1; min-width: 0; border: none; background: transparent; box-shadow: none; padding: 7px 0;
  min-height: 26px; max-height: 33vh; resize: none; font-family: inherit; font-size: 15px; line-height: 1.6;
}
.composer textarea:focus { box-shadow: none; background: transparent; }
.composer .send {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer; flex: 0 0 auto;
  background: linear-gradient(180deg, var(--accent), var(--accent-ink)); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 8px 18px -8px var(--accent-glow); transition: transform .14s var(--spring), opacity .18s;
}
.composer .send:active:not(:disabled) { transform: scale(.93); }
.composer .send:disabled { opacity: .4; cursor: not-allowed; }
.composer .send.stop { background: linear-gradient(180deg, var(--red), var(--red-ink)); }
.composer-hint {
  max-width: 820px; margin: 8px auto 0; display: flex; justify-content: space-between;
  gap: 12px; font-size: 11.5px; color: var(--faint); flex-wrap: wrap;
}
@media (max-width: 860px) { .composer-hint { display: none; } }

/* 会话列表 */
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 2px; }
.conv {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 12px;
  font-size: 13.5px; color: var(--ink-2); cursor: pointer; position: relative;
  transition: background .18s var(--ease);
}
.conv:hover { background: var(--fill); }
.conv.on { background: rgba(255,255,255,.92); box-shadow: var(--shadow-xs); font-weight: 570; color: var(--ink); }
.conv .ttl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .18s; }
.conv:hover .acts, .conv.on .acts { opacity: 1; }
.conv .acts button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 3px; border-radius: 6px;
  display: grid; place-items: center;
}
.conv .acts button:hover { background: var(--fill-2); color: var(--ink); }
.conv .acts button.del:hover { color: var(--red); }

/* 模型选择浮层 */
.palette {
  position: fixed; inset: 0; z-index: 8300; display: none;
  align-items: flex-start; justify-content: center; padding: 12vh 18px 18px;
  background: rgba(24,28,40,.32); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.palette.show { display: flex; }
.palette .panel {
  width: 100%; max-width: 560px; border-radius: var(--r-lg); overflow: hidden;
  background: var(--glass-deep); box-shadow: var(--shadow-lg);
  animation: modalIn .32s var(--spring);
}
.palette input {
  border: 0; border-radius: 0; border-bottom: 1px solid var(--hairline-soft);
  padding: 16px 18px; font-size: 16px; background: transparent;
}
.palette input:focus { box-shadow: none; background: transparent; border-color: var(--accent); }
.palette .list { max-height: 52dvh; overflow-y: auto; padding: 6px; }
.palette .opt {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px; border-radius: 12px;
  cursor: pointer; font-size: 14px;
}
.palette .opt.on { background: var(--accent-soft); }
.palette .opt:hover { background: var(--fill); }
.palette .opt .meta { margin-left: auto; font-size: 11.5px; color: var(--muted); }

/* ============================================================================
   个人资料 / 头像
   ============================================================================ */
.avatar-editor { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.avatar-preview {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-size: 36px; font-weight: 680;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 32px -14px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.4);
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.swatch-row { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid transparent;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 2px 8px -3px rgba(0,0,0,.3);
  transition: transform .2s var(--spring);
}
.swatch:hover { transform: scale(1.1); }
.swatch.on { border-color: #fff; outline: 2px solid var(--accent); }

/* 颜色选择器 */
.color-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.color-field input[type=color] {
  width: 46px; height: 38px; padding: 2px; border-radius: 11px; border: 1px solid var(--hairline);
  background: #fff; cursor: pointer;
}

/* ============================================================================
   其他
   ============================================================================ */
.kv { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 10px 14px; font-size: 13.4px; align-items: center; }
@media (max-width: 560px) { .kv { grid-template-columns: minmax(0, 1fr); gap: 4px 0; } }
.kv dt { color: var(--muted); }

.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 176px; padding: 6px 2px 0; }
.bar-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bar-chart .bar {
  width: 100%; max-width: 40px; border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-ink));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
  transition: height .5s var(--ease);
}

.sticky-actions {
  position: sticky; bottom: 0; padding: 12px 0 4px;
  background: linear-gradient(180deg, transparent, rgba(238,241,248,.9) 40%);
}

/* 推理过程的折叠块 */
.think {
  margin: 0 0 12px; border-radius: 12px; overflow: hidden;
  background: var(--fill); border: 1px solid var(--hairline-soft);
}
.think > summary {
  display: flex; align-items: center; gap: 7px; cursor: pointer; list-style: none;
  padding: 8px 13px; font-size: 12.5px; font-weight: 560; color: var(--ink-3);
}
.think > summary::-webkit-details-marker { display: none; }
.think > summary .ico { color: var(--accent); }
.think .think-body {
  padding: 0 13px 11px; font-size: 12.8px; line-height: 1.75; color: var(--muted);
  border-left: 2px solid var(--accent-line); margin: 0 13px 11px; padding-left: 11px;
  max-height: 40vh; overflow-y: auto;
}
