/* ==========================================================================
   DSH 掌上遥控 — 移动端深色界面
   ========================================================================== */

:root {
  --bg: #0a0c11;
  --bg-soft: #0e1118;
  --card: #151a24;
  --card-2: #1b2130;
  --line: #232b3d;
  --line-soft: #1c2333;
  --text: #e9edf6;
  --muted: #8b93a7;
  --dim: #5d6680;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --accent-2: #7aa2ff;
  --ok: #3ddc97;
  --warn: #ffb454;
  --err: #ff6b6b;
  --radius: 16px;
  --radius-lg: 22px;
  --app-h: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(76, 141, 255, 0.13), transparent 60%),
    radial-gradient(90% 50% at 100% 0%, rgba(122, 162, 255, 0.07), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  color: inherit;
}

[hidden] { display: none !important; }

code, pre { font-family: var(--mono); }

/* ---------------------------------------------------------------- 登录 */

.login {
  position: relative;
  z-index: 1;
  min-height: var(--app-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(32px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
}

.login-inner {
  width: 100%;
  max-width: 360px;
  text-align: center;
  animation: rise 0.45s ease both;
}

.brand-mark {
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(76, 141, 255, 0.22), rgba(76, 141, 255, 0.04));
  border: 1px solid rgba(122, 162, 255, 0.28);
  box-shadow: 0 18px 40px -22px rgba(76, 141, 255, 0.9);
}

.brand-mark svg { width: 42px; height: 42px; }

.brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.4px;
  font-weight: 700;
}

.brand-sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.login-form {
  margin-top: 34px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form label {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.5px;
}

.pin-input {
  width: 100%;
  height: 62px;
  text-align: center;
  font-size: 26px;
  letter-spacing: 12px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  padding-left: 12px;
}

.pin-input::placeholder { color: var(--dim); letter-spacing: 8px; }
.pin-input:focus {
  border-color: rgba(122, 162, 255, 0.6);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: -4px;
}

.pin-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.15s ease, transform 0.15s ease;
}

.pin-dots i.on { background: var(--accent-2); transform: scale(1.25); }

.btn-primary {
  height: 52px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #5a96ff, #3d7bf0);
  color: #fff;
  font-weight: 650;
  font-size: 16px;
  box-shadow: 0 14px 30px -16px rgba(76, 141, 255, 0.95);
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn-primary:active { transform: scale(0.985); }
.btn-primary[disabled] { opacity: 0.55; }

.login-hint {
  margin: 4px 0 0;
  color: var(--dim);
  font-size: 12.5px;
  line-height: 1.7;
}

.login-hint code {
  background: var(--card-2);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}

.login-hint.error { color: var(--err); }

.login-foot {
  margin: 40px 0 0;
  color: #3f4860;
  font-size: 12px;
  letter-spacing: 0.6px;
}

/* ---------------------------------------------------------------- 主体 */

.app {
  position: relative;
  z-index: 1;
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 10px 10px;
  background: rgba(10, 12, 17, 0.82);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  z-index: 6;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--card-2); color: var(--text); }

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}

.topbar-title strong {
  max-width: 100%;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--dim);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(255, 180, 84, 0.12);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.conn.online .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.14); }
.conn.offline .dot { background: var(--err); box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.14); }
.conn.online #connText { color: #6c7897; }

/* ---------------------------------------------------------------- 消息区 */

.scroller {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #2b3448 transparent;
  padding: 0 14px;
}

.scroller::-webkit-scrollbar { width: 4px; }
.scroller::-webkit-scrollbar-thumb { background: #2b3448; border-radius: 4px; }

.scroller-pad { height: 18px; }

.thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 16px;
}

/* 空状态 */
.empty {
  padding: 26px 4px 6px;
  animation: rise 0.5s ease both;
}

.empty-mark {
  width: 56px;
  height: 56px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-2);
  background: linear-gradient(160deg, rgba(76, 141, 255, 0.2), rgba(76, 141, 255, 0.03));
  border: 1px solid rgba(122, 162, 255, 0.22);
}

.empty-mark svg { width: 30px; height: 30px; }

.empty h2 {
  margin: 16px 0 6px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.empty > p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.75;
}

.quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 13px 13px 14px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.quick-card:active {
  transform: scale(0.975);
  border-color: rgba(122, 162, 255, 0.35);
  background: var(--card-2);
}

.q-ico { font-size: 17px; line-height: 1.2; }
.q-title { font-size: 13.5px; font-weight: 600; margin-top: 3px; }
.q-desc { font-size: 11.5px; color: var(--dim); line-height: 1.5; }

/* 消息 */
.msg { display: flex; animation: rise 0.28s ease both; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble-user {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(165deg, #2f6bdc, #2a5cc4);
  color: #f4f7ff;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 24px -18px rgba(76, 141, 255, 0.9);
}

.card-assistant {
  width: 100%;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 8px;
  padding: 12px 14px 11px;
  box-shadow: 0 16px 34px -30px rgba(0, 0, 0, 0.9);
}

.card-assistant.running { border-color: rgba(122, 162, 255, 0.3); }
.card-assistant.error { border-color: rgba(255, 107, 107, 0.32); }

/* 思考块 */
.think {
  margin-bottom: 8px;
  border-radius: 12px;
  background: rgba(122, 162, 255, 0.06);
  border: 1px dashed rgba(122, 162, 255, 0.2);
  overflow: hidden;
}

.think-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  font-size: 12.5px;
  color: #8fa6d8;
  text-align: left;
}

.think-toggle .chev { margin-left: auto; transition: transform 0.18s ease; font-size: 10px; color: var(--dim); }
.think.open .think-toggle .chev { transform: rotate(90deg); }

.think-body {
  display: none;
  padding: 0 11px 10px;
  color: #9aa6c4;
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 260px;
  overflow-y: auto;
}

.think.open .think-body { display: block; }

/* 工具卡片 */
.tools { display: flex; flex-direction: column; gap: 7px; margin-bottom: 9px; }

.tool {
  border-radius: 12px;
  background: var(--card-2);
  border: 1px solid var(--line-soft);
  overflow: hidden;
}

.tool-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 11px;
  text-align: left;
}

.tool-ico {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: rgba(76, 141, 255, 0.14);
  color: var(--accent-2);
}

.tool-name {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 12px;
  color: #a9b6d4;
  font-weight: 600;
  max-width: 34%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-sum {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-state {
  flex: 0 0 auto;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  color: var(--dim);
  background: rgba(139, 147, 167, 0.1);
}

.tool-state.running { color: var(--accent-2); background: var(--accent-soft); }
.tool-state.completed { color: var(--ok); background: rgba(61, 220, 151, 0.11); }
.tool-state.failed { color: var(--err); background: rgba(255, 107, 107, 0.12); }
.tool-state.stopped { color: var(--warn); background: rgba(255, 180, 84, 0.12); }

.tool-body { display: none; padding: 0 11px 10px; }
.tool.open .tool-body { display: block; }

.tool-label {
  margin: 0 0 4px;
  font-size: 10.5px;
  letter-spacing: 0.5px;
  color: var(--dim);
  text-transform: uppercase;
}

.tool-pre {
  margin: 0 0 8px;
  padding: 9px 10px;
  background: #10141d;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.65;
  color: #b8c3dc;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow: auto;
}

/* 正文 Markdown */
.md { font-size: 15px; line-height: 1.72; overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 9px; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 14px 0 7px;
  font-size: 15.5px;
  font-weight: 650;
  color: #f2f5ff;
}
.md h1 { font-size: 17px; }
.md ul, .md ol { margin: 0 0 9px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md code {
  padding: 1.5px 5px;
  border-radius: 5px;
  background: #1e2534;
  color: #a9c4ff;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}
.md pre {
  margin: 9px 0;
  padding: 11px 12px;
  border-radius: 11px;
  background: #0d1119;
  border: 1px solid var(--line-soft);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.md pre code {
  background: none;
  padding: 0;
  color: #c2cee8;
  font-size: 12.5px;
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.md a { color: var(--accent-2); text-decoration: none; border-bottom: 1px solid rgba(122, 162, 255, 0.35); }
.md .table-wrap { margin: 9px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; width: 100%; font-size: 12.5px; table-layout: auto; }
.md th, .md td {
  border: 1px solid var(--line-soft);
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.md th { background: #1b2130; color: #cfd8ee; font-weight: 600; white-space: nowrap; }
.md td:last-child { white-space: nowrap; }
.md tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.015); }
.md strong { color: #fff; font-weight: 650; }
.md blockquote {
  margin: 9px 0;
  padding: 2px 12px;
  border-left: 2px solid rgba(122, 162, 255, 0.45);
  color: var(--muted);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--dim);
}

.msg-meta .spacer { flex: 1 1 auto; }

.copy-btn {
  font-size: 11px;
  color: var(--dim);
  padding: 2px 8px;
  border-radius: 7px;
  background: rgba(139, 147, 167, 0.08);
}

.copy-btn:active { color: var(--text); background: rgba(139, 147, 167, 0.18); }

.err-box {
  margin-top: 9px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.09);
  border: 1px solid rgba(255, 107, 107, 0.22);
  color: #ffb0b0;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.stopped-note { color: var(--warn); font-size: 12px; margin-top: 8px; }

/* 运行中的呼吸点 */
.pulse { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.pulse i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2);
  animation: blink 1.15s infinite ease-in-out;
}
.pulse i:nth-child(2) { animation-delay: 0.16s; }
.pulse i:nth-child(3) { animation-delay: 0.32s; }

/* ---------------------------------------------------------------- 状态条 / 输入 */

.jump {
  position: absolute;
  left: 50%;
  bottom: calc(150px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  color: #cfe0ff;
  background: rgba(30, 38, 56, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px -18px #000;
  z-index: 7;
  animation: rise 0.2s ease both;
}

.composer {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: rgba(10, 12, 17, 0.9);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-top: 1px solid var(--line-soft);
  z-index: 6;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 11px;
  background: var(--accent-soft);
  border: 1px solid rgba(122, 162, 255, 0.22);
  font-size: 12px;
  color: #b9caf0;
}

.spinner {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.6px solid rgba(185, 202, 240, 0.28);
  border-top-color: var(--accent-2);
  animation: spin 0.75s linear infinite;
}

.status-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-timer {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #93a6ce;
}

.stop-btn {
  flex: 0 0 auto;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 12px;
  color: #ffd9d9;
  background: rgba(255, 107, 107, 0.18);
  border: 1px solid rgba(255, 107, 107, 0.3);
}

.stop-btn:active { background: rgba(255, 107, 107, 0.3); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-row:focus-within {
  border-color: rgba(122, 162, 255, 0.45);
  box-shadow: 0 0 0 4px rgba(76, 141, 255, 0.1);
}

.input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 132px;
  padding: 7px 0;
  border: 0;
  outline: none;
  resize: none;
  background: none;
  color: var(--text);
  font-size: 16px; /* ≥16px 防止 iOS 聚焦时自动缩放 */
  line-height: 1.55;
  scrollbar-width: none;
}

.input::-webkit-scrollbar { display: none; }
.input::placeholder { color: var(--dim); }

.send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #5a96ff, #3d7bf0);
  color: #fff;
  box-shadow: 0 10px 22px -14px rgba(76, 141, 255, 0.95);
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.send-btn svg { width: 20px; height: 20px; }
.send-btn:active { transform: scale(0.94); }
.send-btn[disabled] { opacity: 0.35; box-shadow: none; }

.composer-hint {
  margin: 7px 4px 0;
  text-align: center;
  font-size: 10.5px;
  color: #3f4860;
  letter-spacing: 0.3px;
}

/* ---------------------------------------------------------------- 附件 */

.attach-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin-bottom: 2px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: rgba(139, 147, 167, 0.1);
  transition: background 0.15s ease, color 0.15s ease;
}

.attach-btn svg { width: 19px; height: 19px; }
.attach-btn:active { background: rgba(139, 147, 167, 0.22); color: var(--text); }

.attach-strip {
  display: flex;
  gap: 8px;
  padding: 2px 2px 9px;
  overflow-x: auto;
  scrollbar-width: none;
}
.attach-strip::-webkit-scrollbar { display: none; }

.attach-item {
  position: relative;
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card-2);
  border: 1px solid var(--line);
}

.attach-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attach-item .attach-file {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px;
  text-align: center;
}

.attach-item .af-ico { font-size: 17px; line-height: 1; }
.attach-item .af-name {
  font-size: 9px;
  line-height: 1.25;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}

.attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(6, 8, 12, 0.78);
  color: #dfe7f8;
  font-size: 11px;
  line-height: 19px;
  text-align: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.attach-progress {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 12, 0.62);
  color: #cfe0ff;
  font-size: 11px;
  font-family: var(--mono);
}

.attach-item.error { border-color: rgba(255, 107, 107, 0.5); }
.attach-item.error .attach-progress { background: rgba(60, 10, 14, 0.7); color: #ffc4c4; font-size: 9.5px; }

/* 消息里的附件 */
.msg-atts { display: flex; flex-direction: column; gap: 7px; margin-top: 9px; }
.msg-atts .att-grid { display: flex; flex-wrap: wrap; gap: 6px; }

.att-thumb {
  width: 124px;
  height: 124px;
  border-radius: 11px;
  overflow: hidden;
  background: #0d1119;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0;
}

.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.msg-video {
  width: 100%;
  max-width: 260px;
  border-radius: 11px;
  background: #000;
  display: block;
}

.att-file {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.09);
  max-width: 260px;
  text-decoration: none;
  color: inherit;
}

.att-file:active { background: rgba(0, 0, 0, 0.34); }
.att-file .af-ico { font-size: 18px; }
.att-file .af-meta { min-width: 0; display: flex; flex-direction: column; }
.att-file .af-title {
  font-size: 12.5px;
  color: #e3e9f7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-file .af-sub { font-size: 10.5px; color: var(--dim); }

/* 底部选择面板 */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.6);
  z-index: 30;
  animation: fade 0.18s ease both;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  padding: 8px 12px calc(12px + var(--safe-bottom));
  background: #12161f;
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  animation: sheetUp 0.24s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 2px auto 10px;
  border-radius: 4px;
  background: #2b3448;
}

.sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 12px;
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  text-align: left;
}
.sheet-item:active { background: var(--card-2); }
.sheet-ico { font-size: 18px; }

.sheet-cancel {
  width: 100%;
  margin-top: 6px;
  padding: 13px;
  border-radius: 12px;
  font-size: 15px;
  color: var(--muted);
  background: var(--card);
}

/* 图片查看器 */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

/* ---------------------------------------------------------------- 抽屉 */

.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.62);
  backdrop-filter: blur(2px);
  z-index: 20;
  animation: fade 0.2s ease both;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(84vw, 330px);
  display: flex;
  flex-direction: column;
  background: #0f131b;
  border-right: 1px solid var(--line);
  box-shadow: 30px 0 60px -40px #000;
  z-index: 21;
  padding-top: var(--safe-top);
  animation: slideIn 0.24s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 10px 18px;
}

.drawer-head strong { font-size: 15px; letter-spacing: 0.4px; }

.drawer-sub {
  margin-left: 6px;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--dim);
  letter-spacing: 0;
}

.drawer-tip {
  margin: 0 16px 10px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--dim);
}

.drawer-actions {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}

.btn-ghost {
  flex: 1 1 0;
  padding: 9px 10px;
  border-radius: 11px;
  font-size: 12.5px;
  color: #cdd6ea;
  background: var(--card-2);
  border: 1px solid var(--line-soft);
}

.btn-ghost:active { background: #232b3d; }
.btn-ghost.danger { color: #ffb3b3; border-color: rgba(255, 107, 107, 0.22); }

.session-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 12px;
  transition: background 0.15s ease;
}

.session-item.active { background: var(--accent-soft); }
.session-item:active { background: var(--card-2); }

.session-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 8px 10px 11px;
  text-align: left;
}

.session-title {
  display: block;
  font-size: 13.5px;
  color: #dbe3f4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-time {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--dim);
}

.session-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 10px;
  color: #9dc0ff;
  background: rgba(76, 141, 255, 0.16);
  vertical-align: 1px;
}

.session-del {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin-right: 4px;
  border-radius: 9px;
  color: var(--dim);
  font-size: 15px;
  opacity: 0.7;
}

.session-del:active { color: var(--err); background: rgba(255, 107, 107, 0.1); }

.drawer-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--line-soft);
  padding: 12px 18px calc(14px + var(--safe-bottom));
  max-height: 42%;
  overflow-y: auto;
}

.drawer-foot dl { margin: 0; display: grid; grid-template-columns: 62px 1fr; gap: 5px 10px; }
.drawer-foot dt { font-size: 11px; color: var(--dim); }
.drawer-foot dd {
  margin: 0;
  font-size: 11px;
  color: #9aa5bf;
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- 提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 84vw;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(28, 35, 51, 0.97);
  border: 1px solid var(--line);
  color: #dfe7f8;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 18px 40px -24px #000;
  z-index: 40;
  animation: rise 0.22s ease both;
}

.toast.err { border-color: rgba(255, 107, 107, 0.4); color: #ffc4c4; }

/* ---------------------------------------------------------------- 动画 */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn {
  from { transform: translateX(-16px); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* 平板 / 桌面预览时不至于拉得太宽 */
@media (min-width: 720px) {
  .app { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); }
  .topbar { padding-top: 14px; }
  .jump { bottom: 160px; }
}

/* ---------------------------------------------------------------- 初梦账单 */

.drawer-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 32px);
  margin: 0 16px 10px;
  padding: 11px 13px;
  border-radius: 13px;
  background: linear-gradient(135deg, rgba(255, 192, 0, 0.16), rgba(255, 192, 0, 0.05));
  border: 1px solid rgba(255, 192, 0, 0.32);
  text-align: left;
}

.drawer-link:active { background: rgba(255, 192, 0, 0.2); }
.drawer-link .dl-ico { font-size: 18px; }
.drawer-link .dl-text {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  color: #f4e6c0;
  font-weight: 600;
}
.drawer-link .dl-text em {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 400;
  color: #a89c7e;
  margin-top: 1px;
}
.drawer-link .dl-arrow { color: #b99f5e; font-size: 16px; }

.bill-panel {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: slideUpPanel 0.22s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

.bill-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 12, 17, 0.92);
}

.bill-head strong { flex: 1 1 auto; text-align: center; font-size: 16px; letter-spacing: 0.4px; }
.bill-head .icon-btn { text-decoration: none; color: var(--muted); }

.bill-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(24px + var(--safe-bottom));
}

.bill-loading { color: var(--dim); font-size: 13px; text-align: center; padding: 20px 0; }

.bill-summary {
  border-radius: 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(255, 192, 0, 0.16), rgba(255, 192, 0, 0.04));
  border: 1px solid rgba(255, 192, 0, 0.3);
  margin-bottom: 16px;
}

.bill-month { font-size: 12px; color: #cbb886; letter-spacing: 0.4px; }
.bill-total { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; }
.bill-total b {
  font-size: 30px;
  font-weight: 700;
  color: #ffd479;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.bill-total span { font-size: 12px; color: #a89c7e; }
.bill-count { font-size: 12px; color: #a89c7e; margin-top: 2px; }

.bill-label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 7px 2px; }

.bill-input {
  width: 100%;
  min-height: 132px;
  max-height: 240px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.66;
  resize: vertical;
  outline: none;
}
.bill-input:focus { border-color: rgba(255, 192, 0, 0.5); box-shadow: 0 0 0 3px rgba(255, 192, 0, 0.1); }
.bill-input::placeholder { color: var(--dim); }

.bill-actions { display: flex; gap: 9px; margin: 12px 0 10px; }
.bill-actions .btn-ghost { flex: 0 0 38%; }
.bill-actions .btn-primary { flex: 1 1 auto; height: 46px; }

.bill-links { text-align: center; margin-bottom: 4px; }

.bill-link {
  font-size: 12px;
  color: var(--dim);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 6px 10px;
}
.bill-link.danger { color: #b06a6a; }
.bill-link:active { color: var(--text); }

.bill-result {
  margin-top: 14px;
  border-radius: 14px;
  border: 1px solid var(--line-soft);
  background: var(--card);
  overflow: hidden;
}

.bill-result-head {
  padding: 10px 13px;
  font-size: 12.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.02);
}
.bill-result-head b { color: #ffd479; font-weight: 600; }

.bill-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 12.5px;
}
.bill-row:last-child { border-bottom: 0; }
.bill-row .br-date { color: var(--muted); width: 56px; flex: 0 0 auto; font-family: var(--mono); font-size: 11.5px; }
.bill-row .br-name { color: #e9edf6; width: 52px; flex: 0 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-row .br-order { flex: 1 1 auto; min-width: 0; color: var(--dim); font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-row .br-amt { color: #ffd479; font-variant-numeric: tabular-nums; font-weight: 600; }
.bill-row .br-note { color: #9aa5bf; font-size: 11px; }
.bill-row.dup { opacity: 0.62; }
.bill-row.err { background: rgba(255, 107, 107, 0.07); }

.bill-badge {
  flex: 0 0 auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(61, 220, 151, 0.14);
  color: #6fe3b0;
}
.bill-badge.dup { background: rgba(139, 147, 167, 0.14); color: var(--dim); }
.bill-badge.err { background: rgba(255, 107, 107, 0.16); color: #ff9d9d; }

.bill-names { margin-top: 18px; }
.bill-names h4 { margin: 0 0 10px 2px; font-size: 12.5px; color: var(--muted); font-weight: 500; letter-spacing: 0.3px; }
.bill-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.bill-name-row .bn-name { width: 64px; flex: 0 0 auto; color: #dfe7f8; }
.bill-name-row .bn-count { color: var(--dim); font-size: 11.5px; width: 46px; flex: 0 0 auto; }
.bill-name-row .bn-total { margin-left: auto; color: #ffd479; font-variant-numeric: tabular-nums; font-weight: 600; }

@keyframes slideUpPanel {
  from { transform: translateY(18px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}
