/* =====================================================================
 * Pages：登录 / 对话 / 生图 / 声音 / 画廊 / 文档 / 后台
 * ===================================================================== */

/* ---------- 登录 ---------- */
.auth {
  min-height: 100%; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  overflow-y: auto; position: relative;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(var(--accent-rgb), 0.16), transparent 70%),
    radial-gradient(50% 45% at 90% 95%, rgba(var(--accent-rgb), 0.10), transparent 70%),
    var(--bg-page);
}
.auth-card { width: min(420px, 100%); padding: clamp(24px, 4vw, 40px); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-brand h1 { font-size: var(--fs-xl); }
.auth-sub { color: var(--text-2); font-size: var(--fs-sm); margin-bottom: 26px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.auth .switch-mode { margin-top: 18px; text-align: center; font-size: var(--fs-sm); color: var(--text-2); }
.auth .switch-mode button { color: var(--accent); font-weight: 600; }
.auth-theme { position: absolute; top: calc(14px + var(--safe-t)); right: 14px; }

/* ---------- 对话 ---------- */
.chat { flex: 1; min-height: 0; display: flex; gap: var(--sp-4); padding: 0 var(--sp-5) var(--sp-4); }
.chat-side {
  width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; min-height: 0;
  background: var(--bg-card); border-radius: var(--r-card); box-shadow: var(--specular); padding: 14px;
}
.chat-side .list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.session {
  display: flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 6px 0 12px; border-radius: var(--r-ctl);
  color: var(--text-2); cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast);
}
.session:hover { background: var(--bg-hover); color: var(--text-1); }
.session[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.session .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
.session .icon-btn { opacity: 0; width: 28px; height: 28px; }
.session:hover .icon-btn, .session:focus-within .icon-btn, .session[aria-current="true"] .icon-btn { opacity: 1; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 4px 20px; }
.thread-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.hero { text-align: center; padding: clamp(32px, 9vh, 96px) 12px 20px; }
.hero h2 { font-size: var(--fs-2xl); margin-bottom: 8px; }
.hero p { color: var(--text-2); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 10px; margin-top: 28px; text-align: left; }
.quick button { background: var(--bg-card); box-shadow: var(--specular); border-radius: var(--r-sub); padding: 14px 16px; text-align: left; transition: transform var(--dur-fast) var(--ease-out); }
.quick button:hover { transform: translateY(-2px); }
.quick b { display: block; font-size: var(--fs-sm); margin-bottom: 4px; }
.quick span { color: var(--text-2); font-size: var(--fs-xs); }
.msg { display: flex; gap: 10px; padding: 8px 0; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { width: 32px; height: 32px; border-radius: 11px; font-size: 13px; }
.msg.ai .avatar { background: var(--accent); color: var(--on-accent); }
.msg .bubble { max-width: min(78%, 720px); min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.msg.user .bubble { align-items: flex-end; }
.msg .content {
  padding: 10px 15px; border-radius: 20px; line-height: 1.75; word-break: break-word; overflow-wrap: anywhere;
  background: var(--bg-card); box-shadow: var(--specular);
}
.msg.ai .content { border-top-left-radius: 8px; }
.msg.user .content { background: var(--accent); color: var(--on-accent); border-top-right-radius: 8px; box-shadow: 0 10px 24px -14px rgba(var(--accent-rgb), 0.9); white-space: pre-wrap; }
.msg .content.streaming::after { content: '▍'; color: var(--accent); animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.msg .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.think { border-radius: var(--r-sub); background: var(--bg-sub); font-size: var(--fs-sm); }
.think > summary { cursor: pointer; padding: 8px 14px; color: var(--text-2); list-style: none; display: flex; align-items: center; gap: 8px; user-select: none; }
.think > summary::-webkit-details-marker { display: none; }
.think > summary .ico { width: 16px; height: 16px; color: var(--warn); }
.think .well { margin: 0 10px 10px; color: var(--text-2); white-space: pre-wrap; max-height: 280px; overflow-y: auto; font-size: var(--fs-sm); }
.tool-trace { display: flex; flex-wrap: wrap; gap: 6px; }

/* Markdown 内容 */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0.6em 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md h1, .md h2, .md h3, .md h4 { margin: 0.9em 0 0.4em; font-size: 1.05em; }
.md a { word-break: break-all; }
.md blockquote { padding: 2px 12px; color: var(--text-2); box-shadow: inset 3px 0 0 var(--accent); }
.md pre { background: var(--bg-well); box-shadow: var(--well-shadow); border-radius: var(--r-well); padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.6; position: relative; }
.md code { font-size: 0.9em; }
.md :not(pre) > code { background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 6px; }
.msg.user .md :not(pre) > code { background: rgba(255, 255, 255, 0.2); color: inherit; }
.md table { border-collapse: collapse; display: block; max-width: 100%; overflow-x: auto; font-size: var(--fs-sm); }
.md th, .md td { padding: 6px 12px; box-shadow: inset 0 -1px 0 var(--hairline); text-align: left; }
.md img { border-radius: var(--r-sub); }
.md hr { border: 0; height: 1px; background: var(--hairline); margin: 1em 0; }

.composer { flex-shrink: 0; max-width: 860px; width: 100%; margin: 0 auto; }
.composer-box { background: var(--bg-card); box-shadow: var(--specular); border-radius: var(--r-card); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.composer-box textarea { background: transparent; box-shadow: none; resize: none; min-height: 48px; max-height: 200px; padding: 8px 10px; }
.composer-box textarea:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer-bar select { width: auto; max-width: 230px; min-height: 36px; padding-top: 6px; padding-bottom: 6px; border-radius: var(--r-pill); font-size: var(--fs-sm); }
.composer-bar .spacer { flex: 1; }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); background: var(--bg-pill); color: var(--text-2); font-size: var(--fs-sm); font-weight: 560; }
.chip-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.composer-hint { text-align: center; color: var(--text-3); font-size: var(--fs-xs); margin-top: 8px; }

/* ---------- 生图 ---------- */
.studio { display: flex; gap: var(--sp-4); padding: 0 var(--sp-5) var(--sp-4); flex: 1; min-height: 0; }
.studio-panel {
  width: 340px; flex-shrink: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
  background: var(--bg-card); border-radius: var(--r-card); box-shadow: var(--specular); padding: var(--sp-5);
}
.studio-panel textarea { min-height: 120px; }
.studio-result { flex: 1; min-width: 0; overflow-y: auto; padding: 2px 2px 20px; }
.drop {
  border-radius: var(--r-sub); background: var(--bg-well); box-shadow: var(--well-shadow);
  padding: 18px; text-align: center; color: var(--text-3); font-size: var(--fs-sm); cursor: pointer;
  transition: box-shadow var(--dur-fast), background-color var(--dur-fast);
}
.drop.drag, .drop:hover { box-shadow: var(--well-shadow), 0 0 0 2px rgba(var(--accent-rgb), 0.5); color: var(--text-2); }
.drop .ico { margin: 0 auto 8px; width: 28px; height: 28px; }
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--bg-sub); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); color: #fff; }
.thumb button .ico { width: 14px; height: 14px; }
.cost-line { display: flex; justify-content: space-between; align-items: center; font-size: var(--fs-sm); color: var(--text-2); }
.placeholder {
  min-height: 320px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: var(--text-3); text-align: center; border-radius: var(--r-card); background: var(--bg-sub); padding: 24px;
}
.placeholder .ico { width: 48px; height: 48px; stroke-width: 1.3; opacity: 0.6; }

/* ---------- 画廊卡片 ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 22vw, 260px), 1fr)); gap: var(--sp-3); }
.gcard { position: relative; background: var(--bg-card); border-radius: 20px; box-shadow: var(--specular); overflow: hidden; animation: pageIn var(--dur-slow) var(--ease-out); }
.gcard .media { position: relative; aspect-ratio: 1; background: var(--bg-sub); overflow: hidden; cursor: zoom-in; }
.gcard .media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out); }
.gcard .media img.bg { object-fit: cover; filter: blur(22px) saturate(1.3); transform: scale(1.2); }
.gcard .media img.loaded { opacity: 1; }
.gcard .media img.bg.loaded { opacity: 0.45; }
.gcard:hover .media img:not(.bg) { transform: scale(1.02); }
.gcard .media.loading { background: linear-gradient(100deg, var(--bg-sub) 30%, var(--bg-pill) 50%, var(--bg-sub) 70%); background-size: 300% 100%; animation: shimmer 1.6s linear infinite; }
.gcard .info { padding: 10px 12px 12px; }
.gcard .prompt { font-size: var(--fs-sm); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gcard .tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.gcard .tags .time { margin-left: auto; font-size: 11px; color: var(--text-3); font-family: var(--font-mono); }
.gcard .ops { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity var(--dur-fast); }
.gcard:hover .ops, .gcard:focus-within .ops { opacity: 1; }
.gcard .ops button, .gcard .pick {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(10, 12, 16, 0.62); color: #fff;
}
@supports (backdrop-filter: blur(4px)) { .gcard .ops button, .gcard .pick { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); } }
.gcard .ops button .ico { width: 16px; height: 16px; }
.gcard .ops button.del:hover { background: var(--err); }
.gcard .pick { position: absolute; top: 8px; left: 8px; z-index: 2; cursor: pointer; }
.gcard .pick input { width: 16px; height: 16px; }
.gcard.picked { box-shadow: var(--specular), 0 0 0 2px var(--accent); }
@media (hover: none) { .gcard .ops { opacity: 1; } }

/* ---------- 声音 ---------- */
.voice-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.voice-out { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 260px; text-align: center; }
.voice-out audio { width: 100%; max-width: 420px; }
.wave { display: flex; align-items: center; gap: 4px; height: 44px; }
.wave i { width: 4px; border-radius: 4px; background: var(--accent); opacity: 0.75; height: 30%; animation: wave 1.1s var(--ease-out) infinite; }
.wave i:nth-child(2) { animation-delay: 0.1s; } .wave i:nth-child(3) { animation-delay: 0.2s; } .wave i:nth-child(4) { animation-delay: 0.3s; } .wave i:nth-child(5) { animation-delay: 0.4s; }
.wave.idle i { animation: none; height: 18%; opacity: 0.35; }
@keyframes wave { 0%, 100% { height: 25%; } 50% { height: 100%; } }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); animation: pulse 1.2s infinite; }

/* ---------- 文档 ---------- */
.doc h2 { font-size: var(--fs-lg); margin: 28px 0 10px; }
.doc p, .doc li { color: var(--text-2); line-height: 1.8; }
.doc pre { position: relative; background: var(--bg-well); box-shadow: var(--well-shadow); border-radius: var(--r-well); padding: 14px 16px; overflow-x: auto; font-size: 12.8px; line-height: 1.65; margin: 10px 0 16px; }
.doc pre .copy { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity var(--dur-fast); }
.doc pre:hover .copy, .doc pre:focus-within .copy { opacity: 1; }
@media (hover: none) { .doc pre .copy { opacity: 1; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); }
.kv dd { min-width: 0; word-break: break-all; }

/* ---------- 后台：趋势图 ---------- */
.bars { display: flex; align-items: flex-end; gap: clamp(3px, 0.6vw, 8px); height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .bar i { display: block; width: 100%; max-width: 34px; border-radius: 8px 8px 4px 4px; background: linear-gradient(to top, rgba(var(--accent-rgb), 0.55), var(--accent)); min-height: 3px; transition: height var(--dur-slow) var(--ease-spring); }
.bars .bar span { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); white-space: nowrap; }
.bars .bar:hover i { filter: brightness(1.12); }
.menu-row .order { display: flex; gap: 2px; }
.menu-row input.title-input { width: 150px; min-height: 36px; padding: 6px 12px; }
.gen-codes { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.menu-row .modal-icon { width: 36px; height: 36px; border-radius: 12px; transition: opacity var(--dur-fast); }
.menu-row .row-main { gap: 4px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1023px) {
  .chat-side { width: 220px; }
  .studio-panel { width: 300px; }
  .voice-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .chat { padding: 0 10px 8px; }
  .chat-side {
    position: absolute; z-index: 15; top: 0; bottom: 0; right: 0; width: min(300px, 84vw);
    border-radius: var(--r-card) 0 0 var(--r-card); transform: translateX(105%);
    transition: transform var(--dur-slow) var(--ease-spring); box-shadow: var(--float-shadow);
  }
  .chat-side.open { transform: none; }
  .chat-main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  .msg .bubble { max-width: 86%; }
  .composer-box { border-radius: 22px; }
  .composer-bar select { max-width: 150px; }
  .composer-hint { display: none; }
  .studio { flex-direction: column; overflow-y: auto; padding: 0 14px calc(var(--tabbar-h) + var(--safe-b) + 20px); }
  .studio-panel { width: 100%; overflow: visible; }
  .studio-result { overflow: visible; }
  .placeholder { min-height: 220px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .menu-row input.title-input { width: 100%; max-width: 160px; }
  .menu-row .modal-icon { display: none; }
}
@media (max-width: 359px) {
  .grid { grid-template-columns: 1fr; }
}
