/* ============================================================
   HY Chat — white & blue, DeepSeek-inspired
   ============================================================ */

:root {
  --brand: #4d6bfe;
  --brand-strong: #3a57ea;
  --brand-soft: #eef2ff;
  --brand-softer: #f6f8ff;
  --brand-border: #d9e2ff;
  --brand-glow: rgba(77, 107, 254, .16);

  --bg: #ffffff;
  --bg-2: #f7f9fe;
  --bg-3: #f0f4fc;
  --sidebar: #f8fafe;
  --sidebar-hover: #eef3ff;
  --sidebar-active: #e8eeff;
  --elevated: #ffffff;

  --text: #1b1f2a;
  --text-2: #5f687d;
  --text-3: #8e96a8;
  --text-4: #aab1c0;

  --border: #e8ecf5;
  --border-2: #dbe1ee;
  --border-3: #cfd7e8;

  --bubble: #eff4ff;
  --bubble-text: #1c2740;
  --code-bg: #f6f8fd;
  --code-head: #edf1f9;

  --danger: #e5484d;
  --danger-soft: #fff2f2;
  --danger-border: #f4cccc;
  --success: #1e9e6a;
  --warning: #d97706;

  --wechat: #07c160;
  --wechat-dark: #059b4d;
  --wechat-soft: #e9f9f0;

  --shadow-sm: 0 1px 2px rgba(20, 35, 80, .05);
  --shadow-md: 0 8px 28px rgba(36, 55, 120, .10);
  --shadow-lg: 0 24px 70px rgba(26, 42, 100, .18);

  --chat-font: 15.5px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --brand: #708cff;
  --brand-strong: #829aff;
  --brand-soft: #1d2642;
  --brand-softer: #181e30;
  --brand-border: #2e3b68;
  --brand-glow: rgba(112, 140, 255, .18);

  --bg: #14161d;
  --bg-2: #191c25;
  --bg-3: #20242f;
  --sidebar: #101218;
  --sidebar-hover: #1b2030;
  --sidebar-active: #222b42;
  --elevated: #191c25;

  --text: #eef1f8;
  --text-2: #a8b0c2;
  --text-3: #7e8699;
  --text-4: #646c7e;

  --border: #262b38;
  --border-2: #303646;
  --border-3: #3a4256;

  --bubble: #1d2a4d;
  --bubble-text: #e8edff;
  --code-bg: #161a23;
  --code-head: #1d222d;

  --danger: #ff6b6f;
  --danger-soft: #2a1a1d;
  --danger-border: #4a2529;
  --success: #43c08a;
  --warning: #f0a33a;

  --wechat: #0acb69;
  --wechat-dark: #07a958;
  --wechat-soft: #10261b;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .5);
}

html[data-font="sm"] { --chat-font: 14.5px; }
html[data-font="md"] { --chat-font: 15.5px; }
html[data-font="lg"] { --chat-font: 17px; }

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

button:disabled { cursor: not-allowed; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

svg.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

::selection {
  background: rgba(77, 107, 254, .22);
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

textarea:focus-visible,
input:focus-visible {
  outline: none;
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-3) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-3);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-4); background-clip: content-box; }

.muted { color: var(--text-3); }

/* ============================================================
   Layout
   ============================================================ */

.app {
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.main {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  background:
    radial-gradient(1100px 460px at 50% -180px, rgba(77, 107, 254, .075), transparent 68%),
    var(--bg);
}

html[data-theme="dark"] .main {
  background:
    radial-gradient(1100px 460px at 50% -180px, rgba(95, 125, 255, .10), transparent 68%),
    var(--bg);
}

.only-mobile { display: none !important; }
.only-desktop { display: inline-flex !important; }

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  z-index: 30;
  display: flex;
  width: 280px;
  min-width: 0;
  flex: 0 0 280px;
  flex-direction: column;
  padding: 10px 10px 12px;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar) 64%, var(--bg-2) 100%);
  border-right: 1px solid var(--border);
  transition: width .24s ease, flex-basis .24s ease, padding .24s ease, opacity .2s ease;
}

.sidebar > * {
  width: 260px;
  flex-shrink: 0;
}

.app.sidebar-collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  padding-right: 0;
  padding-left: 0;
  border-right: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-head {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 0 4px;
  margin-bottom: 7px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 5px 3px 3px;
  border-radius: 12px;
  color: var(--text);
  text-align: left;
}

.brand:hover { background: var(--sidebar-hover); }

.brand-logo {
  display: block;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 5px 14px rgba(77, 107, 254, .26);
}

.brand-logo svg { display: block; width: 100%; height: 100%; }

.brand-name {
  display: flex;
  flex-direction: column;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.05;
}

.brand-sub {
  margin-top: 4px;
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .12em;
}

.icon-btn {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--text-2);
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn:active { transform: scale(.96); }
.icon-btn .icon { width: 19px; height: 19px; }

.sidebar-collapse { width: 32px; height: 32px; color: var(--text-3); }
.sidebar-collapse .icon { width: 17px; height: 17px; }

.new-chat-btn {
  display: flex;
  height: 42px;
  align-items: center;
  gap: 9px;
  padding: 0 11px;
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9ff 100%);
  box-shadow: var(--shadow-sm);
  color: var(--brand);
  font-size: 13.5px;
  font-weight: 600;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
}

html[data-theme="dark"] .new-chat-btn {
  background: linear-gradient(180deg, #1a2033 0%, #161b2a 100%);
}

.new-chat-btn:hover {
  background: var(--brand-softer);
  border-color: #c8d4ff;
  box-shadow: 0 4px 14px rgba(77, 107, 254, .12);
}
.new-chat-btn:active { transform: scale(.99); }
.new-chat-btn .icon { width: 17px; height: 17px; }
.new-chat-btn span { flex: 1; text-align: left; }

.new-chat-kbd {
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .02em;
}

.search-wrap {
  position: relative;
  display: flex;
  height: 36px;
  align-items: center;
  margin: 9px 0 5px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--bg-2);
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.search-wrap:focus-within {
  border-color: var(--brand-border);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.search-icon {
  width: 15px !important;
  height: 15px !important;
  margin: 0 7px 0 10px;
  color: var(--text-3);
}

.search-wrap input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  font-size: 12.5px;
}

.search-wrap input::placeholder { color: var(--text-3); }

.search-clear {
  display: grid;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 7px;
  color: var(--text-3);
}
.search-clear:hover { background: var(--bg-3); color: var(--text); }
.search-clear .icon { width: 13px; height: 13px; }

.conv-scroll {
  flex: 1;
  min-height: 0;
  padding: 5px 3px 12px;
  margin: 0 -3px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conv-group { margin-top: 12px; }
.conv-group:first-child { margin-top: 4px; }

.conv-label {
  padding: 3px 9px 6px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  user-select: none;
}

.conv-item {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 7px;
  padding: 7px 6px 7px 10px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  transition: background .13s, color .13s;
}

.conv-item:hover { background: var(--sidebar-hover); color: var(--text); }

.conv-item.active {
  background: var(--sidebar-active);
  color: var(--text);
  font-weight: 500;
}

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

.conv-pin-icon {
  width: 12px !important;
  height: 12px !important;
  color: var(--brand);
  flex-shrink: 0;
}

.conv-more {
  display: grid;
  width: 25px;
  height: 25px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 7px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity .12s, background .12s;
}

.conv-more:hover { background: var(--bg-3); color: var(--text); }
.conv-more .icon { width: 15px; height: 15px; }
.conv-item:hover .conv-more,
.conv-item.active .conv-more,
.conv-more:focus-visible { opacity: 1; }

.conv-empty {
  display: flex;
  min-height: 150px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 12px;
}
.conv-empty .icon { width: 26px; height: 26px; opacity: .55; }

.sidebar-foot {
  flex-shrink: 0;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.api-status {
  display: flex;
  height: 26px;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: var(--text-3);
  font-size: 10.5px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-4);
  box-shadow: 0 0 0 2px rgba(142, 150, 168, .10);
  flex-shrink: 0;
}

.is-ok .status-dot,
.api-status.is-ok .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(30, 158, 106, .12);
}

.is-error .status-dot,
.api-status.is-error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(229, 72, 77, .12);
}

.api-status.is-loading .status-dot {
  background: var(--brand);
  animation: pulse 1.2s infinite;
}

.user-card {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  padding: 8px 8px;
  border-radius: 12px;
  text-align: left;
  transition: background .15s;
}
.user-card:hover { background: var(--sidebar-hover); }

.avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #6d8bff, #324bdb);
  box-shadow: 0 4px 10px rgba(77, 107, 254, .25);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.user-meta {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}
.user-meta strong { font-size: 12.5px; font-weight: 600; }
.user-meta small { color: var(--text-3); font-size: 10px; }
.user-gear { width: 16px !important; height: 16px !important; color: var(--text-3); }

/* Recharge entry */
.recharge-entry {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
  padding: 7px 8px;
  border: 1px solid var(--brand-border);
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand-softer), var(--bg));
  text-align: left;
  transition: background .15s, border-color .15s, transform .1s;
}

.recharge-entry:hover {
  border-color: var(--brand-border);
  background: var(--brand-soft);
}

.recharge-entry:active { transform: scale(.995); }

.recharge-entry-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
}

.recharge-entry-icon .icon { width: 15px; height: 15px; }

.recharge-entry-text {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 1px;
}

.recharge-entry-text strong { font-size: 11.5px; font-weight: 650; }
.recharge-entry-text small {
  color: var(--text-2);
  font-size: 9px;
  line-height: 1.35;
}

.recharge-entry-arrow {
  width: 13px !important;
  height: 13px !important;
  flex-shrink: 0;
  color: var(--text-3);
}

.recharge-icon-btn { color: var(--brand); }
.recharge-icon-btn:hover { background: var(--brand-soft); color: var(--brand-strong); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(10, 16, 35, .38);
  backdrop-filter: blur(2px);
  animation: fadeIn .2s ease;
}

/* ============================================================
   Topbar
   ============================================================ */

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  height: calc(64px + env(safe-area-inset-top));
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 18px 0 22px;
  transition: background .2s, box-shadow .2s, border-color .2s;
  border-bottom: 1px solid transparent;
}

.topbar.is-scrolled {
  border-bottom-color: var(--border);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
}

.topbar-left {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.topbar-title-wrap {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.topbar-title {
  max-width: min(46vw, 540px);
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-mode {
  flex-shrink: 0;
  padding: 3px 8px;
  border: 1px solid var(--brand-border);
  border-radius: 99px;
  background: var(--brand-softer);
  color: var(--brand-strong);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
}

.topbar-status .status-dot { width: 5px; height: 5px; }
.topbar-status.is-ok .status-dot { background: var(--success); }
.topbar-status.is-error .status-dot { background: var(--danger); }

.theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun { display: none; }
html[data-theme="light"] .theme-icon-moon { display: block; }
html[data-theme="dark"] .theme-icon-sun { display: block; }
html[data-theme="dark"] .theme-icon-moon { display: none; }

.app.sidebar-collapsed #openSidebar { display: inline-flex !important; }

/* ============================================================
   Chat area
   ============================================================ */

.chat-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-inner {
  display: flex;
  width: 100%;
  max-width: 880px;
  min-height: 100%;
  flex-direction: column;
  margin: 0 auto;
  padding: 26px 28px 30px;
}

.msg-list {
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding-top: 8px;
}

/* Welcome */
.welcome {
  width: 100%;
  max-width: 760px;
  margin: auto;
  padding: 3vh 0 7vh;
  text-align: center;
  animation: fadeUp .5s cubic-bezier(.2, .7, .3, 1) both;
}

.welcome-logo {
  position: relative;
  width: 82px;
  height: 82px;
  margin: 0 auto 24px;
}

.welcome-logo::before,
.welcome-logo::after {
  position: absolute;
  inset: -16px;
  border-radius: 34px;
  background: radial-gradient(circle, rgba(77, 107, 254, .20), transparent 68%);
  content: "";
  animation: breathe 4.5s ease-in-out infinite;
}

.welcome-logo::after {
  inset: -32px;
  opacity: .55;
  animation-delay: -2.2s;
}

.welcome-logo .logo {
  position: relative;
  z-index: 1;
  width: 82px;
  height: 82px;
  overflow: hidden;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(55, 82, 220, .28), 0 2px 0 rgba(255, 255, 255, .28) inset;
}

.welcome-logo .logo { display: block; }
.welcome-logo .logo svg { display: block; width: 100%; height: 100%; }

.welcome h1 {
  margin: 0 0 11px;
  color: var(--text);
  font-size: clamp(23px, 3.4vw, 30px);
  font-weight: 750;
  letter-spacing: -.035em;
  line-height: 1.28;
}

.welcome h1 .grad {
  background: linear-gradient(100deg, #4d6bfe 10%, #7b62ff 55%, #4d6bfe 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome > p {
  max-width: 600px;
  margin: 0 auto;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.8;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 11px;
  margin: 30px auto 19px;
  text-align: left;
}

.quick-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--elevated);
  background: color-mix(in srgb, var(--elevated) 82%, transparent);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform .16s, border-color .16s, box-shadow .16s, background .16s;
}

.quick-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-border);
  background: var(--elevated);
  box-shadow: 0 10px 26px rgba(45, 65, 140, .10);
}

.quick-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand);
}

.quick-icon .icon { width: 18px; height: 18px; }

.quick-text {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}
.quick-text strong { font-size: 13px; font-weight: 650; }
.quick-text span { color: var(--text-3); font-size: 11px; line-height: 1.4; }

.samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 4px;
}

.samples > span {
  color: var(--text-3);
  font-size: 11px;
}

.sample-chip {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 11.5px;
  transition: all .15s;
}
.sample-chip:hover {
  border-color: var(--brand-border);
  background: var(--brand-softer);
  color: var(--brand);
}

.welcome-note {
  margin-top: 22px;
  color: var(--text-4);
  font-size: 10.5px;
  letter-spacing: .02em;
}

/* Messages */
.msg-row {
  display: flex;
  width: 100%;
  animation: fadeUp .26s cubic-bezier(.2, .7, .3, 1) both;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-user-wrap {
  display: flex;
  max-width: min(78%, 680px);
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.user-bubble {
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-color: color-mix(in srgb, var(--brand) 8%, transparent);
  border-radius: 19px 19px 5px 19px;
  background: var(--bubble);
  color: var(--bubble-text);
  font-size: calc(var(--chat-font) - .3px);
  line-height: 1.72;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .4) inset;
}

.user-study-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  margin-top: -2px;
}

.user-study-tag {
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
  font-weight: 600;
}

.user-attachments {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.msg-row.assistant {
  align-items: flex-start;
  gap: 13px;
}

.assistant-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(77, 107, 254, .22);
}
.assistant-avatar svg { display: block; width: 100%; height: 100%; }

.assistant-body {
  min-width: 0;
  flex: 1;
  padding-top: 1px;
  font-size: var(--chat-font);
  line-height: 1.78;
}

.study-tag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 11px;
}

.study-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--brand-border);
  border-radius: 99px;
  background: var(--brand-softer);
  color: var(--brand);
  font-size: 10px;
  font-weight: 600;
}
.study-tag .icon { width: 12px; height: 12px; }
.study-tag.sub {
  border-color: var(--border);
  background: var(--bg-2);
  color: var(--text-3);
  font-weight: 500;
}

/* Thinking */
.reasoning-card {
  margin: 1px 0 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-2);
}

.reasoning-head {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: var(--text-2);
  font-size: 12.5px;
  text-align: left;
  transition: background .15s;
}
.reasoning-head:hover { background: var(--bg-3); }

.reasoning-icon {
  display: grid;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
}
.reasoning-icon .icon { width: 13px; height: 13px; }

.reasoning-title { font-weight: 550; }
.reasoning-status { color: var(--text-3); font-size: 10.5px; }
.reasoning-chevron {
  width: 14px !important;
  height: 14px !important;
  margin-left: auto;
  color: var(--text-3);
  transition: transform .2s;
}
.reasoning-card.open .reasoning-chevron { transform: rotate(180deg); }

.reasoning-body {
  display: none;
  max-height: 340px;
  padding: 0 14px 13px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.reasoning-card.open .reasoning-body { display: block; }

.reasoning-text {
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.82;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.thinking-spinner {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  border: 1.6px solid var(--brand-border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.thinking-placeholder {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0 3px;
  color: var(--text-3);
  font-size: 13px;
}

.thinking-orbs {
  display: flex;
  align-items: center;
  gap: 3px;
}
.thinking-orbs i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  animation: bounce 1.2s infinite ease-in-out;
}
.thinking-orbs i:nth-child(2) { animation-delay: .14s; }
.thinking-orbs i:nth-child(3) { animation-delay: .28s; }

/* Search */
.search-card {
  margin: 0 0 14px;
  overflow: hidden;
  border: 1px solid var(--brand-border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--brand-softer), var(--bg));
}

.search-head {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: var(--text-2);
  font-size: 12.5px;
}

.search-icon-badge {
  display: grid;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
}
.search-icon-badge .icon { width: 13px; height: 13px; }
.search-title { font-weight: 550; }
.search-count { color: var(--text-3); font-size: 10.5px; }
.search-chevron {
  width: 14px !important;
  height: 14px !important;
  margin-left: auto;
  color: var(--text-3);
  transition: transform .2s;
}
.search-card.open .search-chevron { transform: rotate(180deg); }

.search-queries {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 12px 10px;
}
.search-query {
  max-width: 100%;
  padding: 3px 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-3);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-steps {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 12px 8px;
}
.search-step {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: 10.5px;
}
.search-step .dot {
  width: 4px;
  height: 4px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
}
.search-step.running .dot { animation: pulse 1s infinite; }

.sources {
  display: none;
  border-top: 1px solid var(--border);
}
.search-card.open .sources { display: block; }

.source-item {
  display: flex;
  gap: 9px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  transition: background .14s;
}
.source-item:first-child { border-top: 0; }
.source-item:hover { background: var(--brand-softer); }

.source-index {
  display: grid;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 9.5px;
  font-weight: 700;
}

.source-body { min-width: 0; flex: 1; }
.source-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 550;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-title:hover { color: var(--brand); text-decoration: none; }
.source-meta {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-snippet {
  display: -webkit-box;
  margin-top: 3px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* ============================================================
   Markdown
   ============================================================ */

.md-body { min-width: 0; overflow-wrap: anywhere; }
.md-body > :first-child { margin-top: 0 !important; }
.md-body > :last-child { margin-bottom: 0 !important; }

.md-body p { margin: .7em 0; }
.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4,
.md-body h5 {
  margin: 1.35em 0 .55em;
  color: var(--text);
  font-weight: 680;
  letter-spacing: -.018em;
  line-height: 1.4;
}
.md-body h1 { font-size: 1.42em; }
.md-body h2 { font-size: 1.23em; }
.md-body h3 { font-size: 1.09em; }
.md-body h4 { font-size: 1em; }
.md-body h5 { font-size: .94em; }

.md-body ul,
.md-body ol {
  margin: .55em 0;
  padding-left: 1.45em;
}
.md-body li { margin: .26em 0; }
.md-body li > p { margin: .2em 0; }
.md-body li::marker { color: var(--brand); }

.md-body strong { font-weight: 680; }
.md-body em { color: var(--text-2); }

.md-body a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px solid var(--brand-border);
  border-bottom-color: color-mix(in srgb, var(--brand) 28%, transparent);
}
.md-body a:hover { border-bottom-color: var(--brand); text-decoration: none; }

.md-body blockquote {
  margin: 1em 0;
  padding: 9px 14px;
  border-left: 3px solid var(--brand);
  border-radius: 0 10px 10px 0;
  background: var(--brand-softer);
  color: var(--text-2);
}
.md-body blockquote > :first-child { margin-top: 0; }
.md-body blockquote > :last-child { margin-bottom: 0; }

.md-body hr {
  height: 1px;
  margin: 1.5em 0;
  border: 0;
  background: var(--border);
}

.md-body code {
  padding: .16em .42em;
  border-radius: 5px;
  background: var(--bg-3);
  color: color-mix(in srgb, var(--brand) 86%, var(--text));
  font-family: var(--mono);
  font-size: .875em;
  overflow-wrap: anywhere;
}

.md-body kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
  font-family: var(--mono);
  font-size: .8em;
}

.md-body mark {
  padding: 0 .15em;
  border-radius: 3px;
  background: #fff1a8;
  color: #534300;
}

.md-body .table-wrap {
  max-width: 100%;
  margin: 1em 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.md-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9em;
  line-height: 1.55;
}
.md-body th,
.md-body td {
  padding: 8px 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.md-body th {
  background: var(--bg-2);
  color: var(--text);
  font-weight: 620;
  white-space: nowrap;
}
.md-body tr:last-child td { border-bottom: 0; }
.md-body th:last-child,
.md-body td:last-child { border-right: 0; }
.md-body tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 40%, transparent); }

.md-body details {
  margin: .8em 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
}
.md-body summary { cursor: pointer; font-weight: 550; }
.md-body details[open] summary { margin-bottom: .55em; }

.md-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: .9em auto;
  border-radius: 12px;
}

.md-body .katex-display {
  max-width: 100%;
  margin: 1em 0;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.md-body .katex { font-size: 1.06em; }

.md-body .code-block {
  margin: 1em 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
}

.md-body .code-head {
  display: flex;
  height: 33px;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 0 13px;
  border-bottom: 1px solid var(--border);
  background: var(--code-head);
}

.md-body .code-lang {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.md-body .code-copy {
  display: inline-flex;
  height: 24px;
  align-items: center;
  gap: 4px;
  padding: 0 7px;
  border-radius: 6px;
  color: var(--text-3);
  font-size: 10px;
}
.md-body .code-copy:hover { background: var(--bg-3); color: var(--text); }
.md-body .code-copy .icon { width: 12px; height: 12px; }

.md-body pre {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  background: transparent;
  font-family: var(--mono);
  font-size: 12.3px;
  line-height: 1.68;
  tab-size: 2;
}
.md-body pre code {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  overflow-wrap: normal;
  white-space: pre;
}
.md-body .hljs {
  padding: 0;
  background: transparent;
}

.md-body .mermaid-diagram {
  max-width: 100%;
  margin: 1em 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  text-align: center;
}
html[data-theme="dark"] .md-body .mermaid-diagram { background: #11151e; }
.md-body .mermaid-diagram svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }

.md-body .mermaid-block {
  margin: 1em 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
html[data-theme="dark"] .md-body .mermaid-block { background: #11151e; }
.md-body .mermaid-block .mermaid-diagram {
  margin: 0;
  padding: 14px;
  border: 0;
  border-radius: 0;
  max-height: 72vh;
  background: #fff;
}
html[data-theme="dark"] .md-body .mermaid-block .mermaid-diagram { background: #11151e; }

.md-body .mermaid-tools {
  display: flex;
  min-height: 31px;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-3);
  font-size: 9.5px;
}
.md-body .mermaid-label {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  font-weight: 600;
}
.md-body .mermaid-label .icon { width: 12px; height: 12px; color: var(--brand); }
.md-body .mermaid-hint {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.md-body .mermaid-actual .mermaid-hint::after { content: " · 可左右滑动"; }
.md-body .mermaid-actions { display: flex; flex-shrink: 0; gap: 2px; }
.md-body .mermaid-actions button {
  height: 22px;
  padding: 0 7px;
  border-radius: 5px;
  color: var(--text-3);
  font-size: 9.5px;
}
.md-body .mermaid-actions button:hover { background: var(--bg-3); color: var(--text); }
.md-body .mermaid-actions button.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.md-body .mermaid-error {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 10.5px;
}

.md-body .task-list-item { list-style: none; }
.md-body input[type="checkbox"] {
  margin: 0 .4em 0 -1.1em;
  accent-color: var(--brand);
}

.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--brand);
  vertical-align: -.16em;
  animation: blink .9s steps(2) infinite;
}

/* Study card deck (generated from 正面/背面 tables) */
.study-card-deck {
  margin: 1em 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-2);
}
.study-card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  font-size: 10.5px;
}
.study-card-toolbar > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.study-card-toolbar .icon { width: 13px; height: 13px; color: var(--brand); }
.study-card-expand {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 600;
}
.study-card-expand:hover { background: var(--brand-soft); }

.study-card-grid { display: flex; flex-direction: column; }

.study-card {
  border-bottom: 1px solid var(--border);
  background: var(--elevated);
}
.study-card:last-child { border-bottom: 0; }
.study-card.open { background: var(--bg-2); }

.study-card-head {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.study-card-head:hover { background: var(--brand-softer); }

.study-card-index {
  display: grid;
  width: 23px;
  height: 23px;
  flex-shrink: 0;
  place-items: center;
  margin-top: 1px;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
}

.study-card-front {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.study-card-front p { margin: 0; }
.study-card-front .katex { font-size: 1em; }

.study-card-chevron {
  flex-shrink: 0;
  width: 14px !important;
  height: 14px !important;
  margin-top: 4px;
  color: var(--text-3);
  transition: transform .18s;
}
.study-card-chevron .icon { width: 14px; height: 14px; }
.study-card .study-card-chevron svg { width: 14px; height: 14px; }
.study-card.open .study-card-chevron { transform: rotate(180deg); }

.study-card-body {
  padding: 0 14px 13px 45px;
  color: var(--text-2);
  font-size: 12.8px;
  line-height: 1.75;
}
.study-card-back { overflow-wrap: anywhere; }
.study-card-back > :first-child { margin-top: 0; }
.study-card-back > :last-child { margin-bottom: 0; }
.study-card-back p { margin: .4em 0; }
.study-card-back .katex { font-size: 1em; }
.study-card-back .katex-display { margin: .55em 0; overflow-x: auto; }
.study-card-back .table-wrap { margin: .5em 0; }

.study-card-hint {
  margin-top: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--brand-softer);
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.6;
}
.study-card-hint strong {
  margin-right: 5px;
  color: var(--brand);
  font-size: 9.5px;
  letter-spacing: .04em;
}

/* Message actions */
.msg-actions {
  display: flex;
  min-height: 29px;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .14s;
}
.msg-row:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; }

.msg-action {
  display: inline-flex;
  height: 28px;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border-radius: 7px;
  color: var(--text-3);
  font-size: 11.5px;
  transition: background .13s, color .13s;
}
.msg-action:hover { background: var(--bg-2); color: var(--text); }
.msg-action .icon { width: 14px; height: 14px; }
.msg-action.primary { color: var(--brand); background: var(--brand-softer); }
.msg-action.primary:hover { background: var(--brand-soft); }

.msg-meta {
  margin-left: auto;
  padding-left: 8px;
  color: var(--text-4);
  font-size: 10px;
  white-space: nowrap;
}

.msg-error {
  margin: 2px 0 10px;
  padding: 12px 14px;
  border: 1px solid var(--danger-border);
  border-radius: 13px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.65;
}
.msg-error strong { display: block; margin-bottom: 3px; font-size: 13px; }
.msg-error .soft-btn { margin-top: 9px; }

.msg-stopped {
  margin: 6px 0 2px;
  color: var(--text-3);
  font-size: 11px;
}

/* ============================================================
   Composer
   ============================================================ */

.composer-area {
  position: relative;
  z-index: 15;
  flex-shrink: 0;
  padding: 8px 24px calc(13px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, var(--bg) 22%, var(--bg) 100%);
}

.study-panel,
.composer,
.composer-hint {
  width: 100%;
  max-width: 840px;
  margin-right: auto;
  margin-left: auto;
}

.study-panel {
  margin-bottom: 8px;
  padding: 11px 13px 12px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: var(--elevated);
  background: color-mix(in srgb, var(--elevated) 92%, transparent);
  box-shadow: 0 8px 26px rgba(38, 58, 130, .07);
  animation: slideUp .22s ease;
}

html[data-theme="dark"] .study-panel {
  box-shadow: 0 8px 26px rgba(0, 0, 0, .25);
}

.study-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.study-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.study-badge {
  display: grid;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
}
.study-badge .icon { width: 16px; height: 16px; }

.study-heading-text {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
}
.study-heading-text strong { font-size: 12.5px; font-weight: 650; }
.study-heading-text small {
  overflow: hidden;
  color: var(--text-3);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-collapse { width: 28px; height: 28px; }
.study-collapse .icon { width: 15px; height: 15px; transition: transform .2s; }
.study-panel.collapsed .study-collapse .icon { transform: rotate(180deg); }
.study-panel.collapsed .study-body { display: none; }

.study-body { margin-top: 10px; }

.study-types {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.study-type {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 5px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 10.5px;
  white-space: nowrap;
  transition: all .14s;
}
.study-type .icon { width: 14px; height: 14px; }
.study-type:hover { border-color: var(--brand-border); color: var(--brand); }
.study-type.active {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.study-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.select-chip {
  position: relative;
  display: inline-flex;
  height: 30px;
  align-items: center;
  gap: 4px;
  padding: 0 5px 0 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-3);
  font-size: 10.5px;
}
.select-chip > span { flex-shrink: 0; }
.select-chip select {
  max-width: 92px;
  height: 100%;
  padding: 0 15px 0 1px;
  border: 0;
  outline: 0;
  appearance: none;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-weight: 550;
  cursor: pointer;
}
.select-chip .icon {
  position: absolute;
  right: 4px;
  width: 12px;
  height: 12px;
  color: var(--text-3);
  pointer-events: none;
}

.composer {
  position: relative;
  padding: 6px 9px 8px 15px;
  border: 1.5px solid var(--border-2);
  border-radius: 24px;
  background: var(--elevated);
  box-shadow: 0 6px 24px rgba(35, 55, 120, .07), 0 1px 0 rgba(255, 255, 255, .5) inset;
  transition: border-color .18s, box-shadow .18s;
}

html[data-theme="dark"] .composer {
  box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}

.composer:focus-within {
  border-color: var(--brand);
  border-color: color-mix(in srgb, var(--brand) 58%, var(--border));
  box-shadow: 0 0 0 4px var(--brand-glow), 0 10px 30px rgba(35, 55, 120, .08);
}

.prompt-input {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 210px;
  padding: 10px 3px 5px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.66;
  resize: none;
  scrollbar-width: thin;
}
.prompt-input::placeholder { color: var(--text-4); }

.composer-bar {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 7px;
}

.composer-tools {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: none;
}
.composer-tools::-webkit-scrollbar { display: none; }

.tool-pill {
  display: inline-flex;
  height: 30px;
  flex-shrink: 0;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  transition: background .13s, color .13s, border-color .13s;
}
.tool-pill:hover { background: var(--bg-2); color: var(--text); }
.tool-pill .icon { width: 15px; height: 15px; }

.tool-pill.active {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
}

.pill-check {
  display: none;
  width: 14px;
  height: 14px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
}
.tool-pill.active .pill-check { display: inline-flex; }
.pill-check .icon { width: 9px; height: 9px; stroke-width: 3.2; }

.mode-pill {
  padding: 0 7px 0 8px;
  border-color: var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-weight: 600;
}
.mode-pill:hover { background: var(--bg-3); }
.mode-pill-icon { color: var(--brand); }
.pill-chevron { width: 12px !important; height: 12px !important; color: var(--text-3); }

.effort-pill {
  padding: 0 6px;
  color: var(--brand);
  font-size: 10.5px;
}

.effort-bars {
  display: inline-flex;
  height: 12px;
  align-items: flex-end;
  gap: 1.5px;
}
.effort-bars i {
  display: block;
  width: 2.5px;
  border-radius: 2px;
  background: var(--brand-border);
}
.effort-bars i:nth-child(1) { height: 4px; }
.effort-bars i:nth-child(2) { height: 7px; }
.effort-bars i:nth-child(3) { height: 10px; }
.effort-pill[data-level="low"] .effort-bars i:nth-child(1),
.effort-pill[data-level="high"] .effort-bars i:nth-child(-n+2),
.effort-pill[data-level="max"] .effort-bars i { background: var(--brand); }

.composer-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
}

.attach-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--text-3);
}
.attach-btn .icon { width: 18px; height: 18px; }

.send-btn {
  display: grid;
  width: 35px;
  height: 35px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #5d7bff, #3b57e8);
  box-shadow: 0 5px 14px rgba(77, 107, 254, .30);
  color: #fff;
  transition: transform .13s, opacity .13s, box-shadow .13s, background .13s;
}
.send-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(77, 107, 254, .38); }
.send-btn:active:not(:disabled) { transform: scale(.95); }
.send-btn:disabled {
  background: var(--bg-3);
  box-shadow: none;
  color: var(--text-4);
}
.send-btn .icon { width: 18px; height: 18px; }
.send-btn .stop-icon { display: none; }
.send-btn.stop-mode { background: linear-gradient(145deg, #334155, #1e293b); box-shadow: 0 5px 14px rgba(30, 41, 59, .24); }
.send-btn.stop-mode .send-icon { display: none; }
.send-btn.stop-mode .stop-icon { display: block; width: 15px; height: 15px; }

.composer-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding-top: 6px;
  color: var(--text-4);
  font-size: 10px;
  letter-spacing: .01em;
}
.hint-dot { opacity: .6; }

/* Attachments */
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 5px 1px 4px;
}

.attach-file {
  position: relative;
  display: flex;
  max-width: 230px;
  min-height: 44px;
  align-items: center;
  gap: 7px;
  padding: 5px 25px 5px 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-2);
}

.attach-file-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.attach-file-icon .icon { width: 15px; height: 15px; }

.attach-file-meta {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.attach-file-name {
  max-width: 155px;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-file-sub {
  color: var(--text-3);
  font-size: 9px;
}
.attach-file-sub.error { color: var(--danger); }

.attach-progress {
  position: absolute;
  right: 7px;
  bottom: 4px;
  left: 7px;
  height: 2px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--border);
}
.attach-progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width .2s;
}

.attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-3);
  opacity: 0;
  transition: opacity .13s, color .13s;
}
.attach-file:hover .attach-remove,
.attach-image:hover .attach-remove { opacity: 1; }
.attach-remove:hover { color: var(--danger); }
.attach-remove .icon { width: 11px; height: 11px; }

.attach-image {
  position: relative;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
}
.attach-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}
img.attach-thumb { cursor: zoom-in; }
.attach-image .attach-remove { top: 2px; right: 2px; width: 17px; height: 17px; }

.user-attachments .attach-file {
  max-width: 250px;
  background: var(--bg);
}
.user-attachments .attach-remove { display: none; }
.user-attachments .attach-image { width: 74px; height: 74px; }

/* ============================================================
   Popover menus
   ============================================================ */

.menu {
  position: fixed;
  z-index: 1500;
  min-width: 272px;
  max-width: calc(100vw - 20px);
  max-height: min(68vh, 560px);
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--elevated);
  box-shadow: var(--shadow-lg);
  animation: menuIn .14s ease;
}

.menu-heading {
  padding: 8px 10px 4px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 9px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.menu-item:hover { background: var(--bg-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.active { background: var(--brand-softer); }

.menu-item-icon {
  display: grid;
  width: 31px;
  height: 31px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-2);
}
.menu-item.active .menu-item-icon { background: var(--brand-soft); color: var(--brand); }
.menu-item.danger .menu-item-icon { background: var(--danger-soft); color: var(--danger); }
.menu-item-icon .icon { width: 16px; height: 16px; }

.menu-item-text {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}
.menu-item-text strong { font-size: 12.5px; font-weight: 600; }
.menu-item-text small { color: var(--text-3); font-size: 10.5px; line-height: 1.35; }

.menu-check { width: 15px; height: 15px; color: var(--brand); }
.menu-sep { height: 1px; margin: 5px 5px; background: var(--border); }
.menu-key {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 9px;
}

.effort-menu .menu-item-icon { font-size: 10px; font-weight: 800; }

@media (max-width: 640px) {
  .menu.sheet {
    position: fixed;
    top: auto !important;
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    min-width: 0;
    max-height: 58vh;
    transform: none;
  }
  .menu.sheet .menu-item { padding: 10px; }
}

/* ============================================================
   Overlays / modals
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 20, 45, .38);
  backdrop-filter: blur(7px);
  animation: fadeIn .18s ease;
}

html[data-theme="dark"] .overlay { background: rgba(0, 0, 0, .58); }

.modal {
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  max-height: min(88dvh, 900px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--elevated);
  box-shadow: var(--shadow-lg);
  animation: modalIn .22s cubic-bezier(.2, .8, .25, 1);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 21px 23px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.modal-head p {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 11px;
}

.modal-close { width: 32px; height: 32px; }
.modal-close .icon { width: 18px; height: 18px; }

.settings-body {
  max-height: calc(88vh - 83px);
  max-height: calc(min(88dvh, 900px) - 83px);
  padding: 4px 23px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-section {
  padding: 19px 0;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: 0; padding-bottom: 8px; }

.settings-section h3 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .02em;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title-row h3 { margin: 0; }
.section-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
}

.setting-label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}
.setting-label strong { font-size: 12.5px; font-weight: 550; }
.setting-label span { color: var(--text-3); font-size: 10.5px; line-height: 1.45; }

.segmented {
  display: inline-flex;
  flex-shrink: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-2);
}
.segmented button {
  min-width: 52px;
  height: 28px;
  padding: 0 9px;
  border-radius: 7px;
  color: var(--text-3);
  font-size: 11px;
  transition: all .14s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--elevated);
  box-shadow: var(--shadow-sm);
  color: var(--brand);
  font-weight: 600;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 7px;
  color: var(--brand-strong);
  font-size: 11px;
}
.text-btn:hover { background: var(--brand-softer); }
.text-btn .icon { width: 13px; height: 13px; }

/* Account */
.account-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.account-item {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-2);
}
.account-item .label {
  color: var(--text-3);
  font-size: 10px;
}
.account-item .value {
  margin-top: 4px;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-item .value.balance { color: var(--brand); font-size: 16px; letter-spacing: -.02em; }
.account-item .value small { color: var(--text-3); font-size: 9.5px; font-weight: 500; }
.account-item.wide { grid-column: span 2; }

.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}
.model-chip {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 9.5px;
}

.skeleton-line {
  height: 58px;
  border-radius: 11px;
  background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

.settings-note {
  margin: 9px 0 0;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.65;
}

/* Mobile access */
.mobile-access {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
}
.url-list {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 5px;
}
.url-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
}
.url-item .label {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 8.5px;
  font-weight: 600;
}
.url-item code {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.url-item .text-btn { padding: 2px 4px; }
.url-item .text-btn .icon { width: 12px; height: 12px; }

.qr-wrap {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
  font-size: 9px;
}
.qr-box {
  width: 108px;
  height: 108px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.qr-box svg { display: block; width: 100% !important; height: 100% !important; }

.install-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.install-row .settings-note { margin: 0; }

.soft-btn {
  display: inline-flex;
  height: 31px;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 11px;
  transition: all .14s;
}
.soft-btn:hover { border-color: var(--brand-border); background: var(--brand-softer); color: var(--brand); }
.soft-btn .icon { width: 14px; height: 14px; }
a.soft-btn { color: var(--text-2); }
a.soft-btn:hover { color: var(--brand); }
.soft-btn.danger { color: var(--danger); }
.soft-btn.danger:hover { border-color: var(--danger-border); background: var(--danger-soft); }
.soft-btn:disabled { opacity: .5; }

.primary-btn {
  display: inline-flex;
  height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 10px;
  background: linear-gradient(145deg, #5d7bff, #3b57e8);
  box-shadow: 0 6px 16px rgba(77, 107, 254, .24);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  transition: transform .13s, box-shadow .13s;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(77, 107, 254, .32); }
.primary-btn:active { transform: scale(.98); }
.primary-btn:disabled { opacity: .6; transform: none; }

/* Data */
.data-actions { display: flex; flex-wrap: wrap; gap: 7px; }

/* About */
.about-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.about-brand .brand-logo.small { width: 38px; height: 38px; border-radius: 11px; }
.about-brand > div { display: flex; flex-direction: column; gap: 2px; }
.about-brand strong { font-size: 12.5px; }
.about-brand span { color: var(--text-3); font-size: 10px; }

.about-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}
.about-list li {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-3);
  font-size: 10.5px;
}
.about-list .icon { width: 13px; height: 13px; color: var(--brand); }

.logout-btn { margin-top: 14px; color: var(--text-3); }
.logout-btn:hover { color: var(--danger); background: var(--danger-soft); }

/* Recharge modal */
.recharge-modal { max-width: 860px; }

.recharge-body {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, .88fr);
  gap: 26px;
  max-height: calc(88vh - 83px);
  max-height: calc(min(88dvh, 900px) - 83px);
  padding: 20px 24px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.recharge-left { min-width: 0; }

.recharge-amount-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.recharge-amount-head small {
  color: var(--text-2);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .08em;
}

.recharge-amount-box {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 10px 14px;
  border: 1.5px solid var(--border-2);
  border-radius: 14px;
  background: var(--bg-2);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.recharge-amount-box:focus-within {
  border-color: var(--brand);
  background: var(--bg);
  box-shadow: 0 0 0 4px var(--brand-glow);
}

.recharge-currency {
  color: var(--text-3);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

#rechargeAmount {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  appearance: textfield;
  -moz-appearance: textfield;
  background: transparent;
  color: var(--text);
  font-size: 40px;
  font-weight: 750;
  letter-spacing: -.035em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
#rechargeAmount::-webkit-outer-spin-button,
#rechargeAmount::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
#rechargeAmount.invalid { color: var(--danger); }

.recharge-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.recharge-presets button {
  min-width: 52px;
  height: 29px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 11px;
  transition: border-color .14s, background .14s, color .14s;
}
.recharge-presets button:hover {
  border-color: var(--brand-border);
  color: var(--brand);
}
.recharge-presets button.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.recharge-summary {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 13px;
  padding: 11px 13px;
  border: 1px solid var(--brand-border);
  border-radius: 10px;
  background: var(--brand-softer);
  color: var(--text-2);
  font-size: 11.5px;
}
.recharge-summary strong {
  color: var(--brand);
  font-size: 19px;
  letter-spacing: -.02em;
}

.recharge-steps {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 15px 0 0;
  padding: 15px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
}
.recharge-steps li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.6;
}
.recharge-steps li > span {
  display: grid;
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  place-items: center;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--text-3);
  font-size: 9px;
  font-weight: 700;
}
.recharge-steps li strong { color: var(--text); }

.recharge-note {
  display: flex;
  gap: 7px;
  margin-top: 14px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 10px;
  line-height: 1.6;
}
.recharge-note .icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--brand);
}

.recharge-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 13px; }

.recharge-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}

.recharge-due {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px;
}
.recharge-due span { color: var(--text-2); font-size: 10.5px; }
.recharge-due strong { color: var(--brand); font-size: 19px; letter-spacing: -.02em; }

.qr-card {
  position: relative;
  display: block;
  width: 100%;
  max-width: 310px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(30, 50, 110, .10);
  cursor: zoom-in;
  transition: transform .15s, box-shadow .15s;
}
.qr-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(30, 50, 110, .16);
}
.qr-card img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
}
.qr-badge {
  position: absolute;
  top: 15px;
  right: 15px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 99px;
  background: var(--wechat);
  color: #053b22;
  font-size: 9px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(7, 193, 96, .25);
}
.qr-badge-check {
  display: grid;
  width: 12px;
  height: 12px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .24);
  font-size: 8px;
  line-height: 1;
}

.recharge-payee { margin: 1px 0 0; color: var(--text-2); font-size: 11px; }
.qr-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.qr-hint {
  margin: 1px 0 0;
  color: var(--text-2);
  font-size: 9.5px;
  line-height: 1.5;
  text-align: center;
}
.qr-hint strong { color: var(--text); }

@media (max-width: 700px) {
  .recharge-modal { max-width: 520px; max-height: 92dvh; }
  .recharge-body {
    grid-template-columns: 1fr;
    gap: 15px;
    max-height: calc(92dvh - 78px);
    padding: 16px 16px 22px;
  }
  .recharge-left { display: contents; }
  .recharge-amount-head { order: 1; margin-bottom: 0; }
  .recharge-amount-box { order: 2; }
  .recharge-presets { order: 3; }
  .recharge-summary { order: 4; margin-top: 0; }
  .recharge-right { order: 5; }
  .recharge-steps { order: 6; margin-top: 2px; }
  .recharge-note { order: 7; margin-top: 0; }
  .recharge-actions { order: 8; margin-top: 0; }
  #rechargeAmount { font-size: 36px; }
  .qr-card { max-width: 280px; }
}

@media (max-width: 420px) {
  #rechargeAmount { font-size: 32px; }
  .recharge-presets button { min-width: 48px; }
}

/* Login */
.login-modal {
  max-width: 380px;
  padding: 30px 28px 25px;
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  overflow: hidden;
  border-radius: 19px;
  box-shadow: 0 14px 36px rgba(55, 82, 220, .28);
}
.login-logo svg { display: block; width: 100%; height: 100%; }
.login-modal h2 { margin: 0 0 7px; font-size: 21px; letter-spacing: -.02em; }
.login-modal > p {
  margin: 0 auto 16px;
  max-width: 300px;
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.65;
}

.login-email-card {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 2px 0 13px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-2);
  text-align: left;
}

.login-email-icon {
  display: grid;
  width: 31px;
  height: 31px;
  flex-shrink: 0;
  place-items: center;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 14px;
  font-weight: 700;
}

.login-email-meta {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}
.login-email-meta small {
  color: var(--text-2);
  font-size: 9px;
}
.login-email-meta strong {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}
.login-email-lock {
  width: 14px !important;
  height: 14px !important;
  flex-shrink: 0;
  color: var(--text-3);
}

.login-main-btn { width: 100%; margin-top: 3px; }

.login-mail-note {
  margin-top: 10px;
  padding: 8px 9px;
  border: 1px solid #f0d18a;
  border-radius: 8px;
  background: #fff8e5;
  color: #7a5200;
  font-size: 9.5px;
  line-height: 1.55;
  text-align: left;
}
html[data-theme="dark"] .login-mail-note {
  border-color: #5c4a22;
  background: #2a2416;
  color: #f3c46b;
}

.login-code-field {
  margin-top: 1px;
}
.login-code-field input {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: .28em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.login-code-field input::placeholder {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}
.login-resend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--text-2);
  font-size: 9.5px;
}
.login-resend-row .text-btn { padding: 3px 5px; font-size: 10px; }
.login-field {
  display: flex;
  height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border-2);
  border-radius: 11px;
  background: var(--bg-2);
  transition: border-color .15s, box-shadow .15s;
}
.login-field:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
  background: var(--bg);
}
.login-field .icon { width: 16px; height: 16px; color: var(--text-3); }
.login-field input {
  width: 100%;
  border: 0;
  background: transparent;
  font-size: 14px;
}
.login-modal .primary-btn { width: 100%; margin-top: 11px; }
.login-error {
  margin-top: 9px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 10.5px;
  text-align: left;
}
.login-foot {
  display: block;
  margin-top: 13px;
  color: var(--text-2);
  font-size: 9px;
}

/* Dialog */
.dialog-modal {
  max-width: 400px;
  padding: 22px 22px 18px;
}
.dialog-modal h2 { margin: 0 0 7px; font-size: 17px; letter-spacing: -.015em; }
.dialog-modal p {
  margin: 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.dialog-input {
  width: 100%;
  height: 38px;
  margin-top: 13px;
  padding: 0 11px;
  border: 1px solid var(--border-2);
  border-radius: 9px;
  background: var(--bg-2);
  font-size: 13px;
}
.dialog-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 18px;
}
.dialog-actions .primary-btn.danger {
  background: linear-gradient(145deg, #f06064, #d93a3f);
  box-shadow: 0 6px 16px rgba(229, 72, 77, .22);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 4vw;
  background: rgba(5, 9, 20, .88);
  backdrop-filter: blur(4px);
  animation: fadeIn .15s ease;
}
.lightbox img {
  max-width: 92vw;
  max-height: 86vh;
  border-radius: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .5);
  object-fit: contain;
}
.lightbox-close {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); color: #fff; }

/* Toast */
.toast-host {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  z-index: 4000;
  display: flex;
  max-width: calc(100vw - 28px);
  flex-direction: column;
  align-items: center;
  gap: 7px;
  pointer-events: none;
  transform: translateX(-50%);
}
.toast {
  display: flex;
  max-width: 100%;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 99px;
  background: rgba(28, 35, 55, .94);
  box-shadow: 0 12px 34px rgba(15, 25, 55, .28);
  color: #fff;
  font-size: 11.5px;
  line-height: 1.4;
  animation: toastIn .22s cubic-bezier(.2, .8, .25, 1);
  pointer-events: auto;
}
.toast .icon { width: 14px; height: 14px; flex-shrink: 0; }
.toast.success { background: rgba(22, 120, 83, .96); }
.toast.error { background: rgba(180, 44, 49, .96); }
.toast.out { animation: toastOut .18s ease forwards; }

/* Scroll bottom */
.scroll-bottom {
  position: absolute;
  right: 50%;
  bottom: 132px;
  z-index: 16;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--elevated);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  transform: translateX(50%);
  animation: fadeIn .15s ease;
}
.scroll-bottom:hover { color: var(--brand); border-color: var(--brand-border); }
.scroll-bottom .icon { width: 16px; height: 16px; }

/* Drop overlay */
.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 2500;
  display: grid;
  place-items: center;
  border: 2px dashed var(--brand);
  border-radius: 22px;
  background: var(--brand-soft);
  background: color-mix(in srgb, var(--brand) 9%, var(--bg));
  backdrop-filter: blur(6px);
  animation: fadeIn .15s ease;
}
.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 30px 38px;
  border: 1px solid var(--brand-border);
  border-radius: 20px;
  background: var(--elevated);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.drop-card .icon { width: 34px; height: 34px; color: var(--brand); }
.drop-card strong { font-size: 15px; }
.drop-card span { color: var(--text-3); font-size: 10.5px; }

/* Offline banner */
.offline-banner {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 3500;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--elevated);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  font-size: 10px;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .45; transform: scale(.82); }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-6px) scale(.97); }
}
@keyframes breathe {
  0%, 100% { transform: scale(.94); opacity: .55; }
  50% { transform: scale(1.05); opacity: .95; }
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1100px) {
  .sidebar { width: 262px; flex-basis: 262px; }
  .sidebar > * { width: 242px; }
  .chat-inner { max-width: 840px; }
}

@media (max-width: 900px) {
  .only-mobile { display: inline-flex !important; }
  .only-desktop { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 286px;
    flex-basis: 286px;
    padding-top: calc(10px + env(safe-area-inset-top));
    box-shadow: 20px 0 60px rgba(20, 35, 80, .16);
    transform: translateX(-104%);
    transition: transform .25s cubic-bezier(.2, .8, .25, 1);
    opacity: 1;
  }
  .sidebar > * { width: 266px; }
  .sidebar.open { transform: translateX(0); }
  .app.sidebar-collapsed .sidebar {
    width: 286px;
    flex-basis: 286px;
    padding: 10px;
    padding-top: calc(10px + env(safe-area-inset-top));
    opacity: 1;
    pointer-events: auto;
    border-right: 1px solid var(--border);
    transform: translateX(-104%);
  }
  .app.sidebar-collapsed .sidebar.open { transform: translateX(0); }
  .sidebar-collapse { display: none; }
  .app.sidebar-collapsed #openSidebar { display: inline-flex !important; }

  .topbar { padding: env(safe-area-inset-top) 12px 0 10px; }
  .topbar-title { max-width: 52vw; font-size: 13.5px; }
  .topbar-mode { display: none; }
  .chat-inner { padding: 18px 20px 24px; }
  .composer-area { padding: 6px 16px calc(11px + env(safe-area-inset-bottom)); }
  .scroll-bottom { bottom: 126px; }
  .settings-body { padding-right: 20px; padding-left: 20px; }
  .modal-head { padding: 18px 20px 13px; }
}

@media (max-width: 640px) {
  .topbar { height: calc(56px + env(safe-area-inset-top)); }
  .login-field input,
  .dialog-input,
  .search-wrap input { font-size: 16px; }
  .topbar-title { max-width: 58vw; }
  .chat-inner { padding: 10px 14px 18px; }
  .msg-list { gap: 25px; }
  .welcome { padding: 2vh 0 5vh; }
  .welcome-logo,
  .welcome-logo .logo { width: 68px; height: 68px; }
  .welcome-logo { margin-bottom: 20px; }
  .welcome-logo::before { inset: -12px; }
  .welcome h1 { margin-bottom: 8px; }
  .welcome > p { font-size: 12.5px; padding: 0 6px; }
  .quick-grid { grid-template-columns: 1fr; gap: 8px; margin: 24px 0 16px; }
  .quick-card { padding: 10px 12px; border-radius: 13px; }
  .quick-icon { width: 34px; height: 34px; border-radius: 10px; }
  .samples { gap: 5px; }
  .sample-chip { padding: 5px 9px; font-size: 10.5px; }
  .samples > span { display: none; }
  .welcome-note { margin-top: 16px; }

  .msg-row.assistant { gap: 9px; }
  .assistant-avatar { width: 28px; height: 28px; border-radius: 9px; }
  .msg-user-wrap { max-width: 88%; }
  .user-bubble { padding: 9px 13px; border-radius: 17px 17px 5px 17px; }

  .msg-actions { opacity: 1; gap: 0; margin-top: 4px; }
  .msg-action { padding: 0 6px; font-size: 10.5px; }
  .msg-meta { width: 100%; padding: 3px 0 0; margin-left: 0; order: 9; }

  .composer-area {
    padding: 4px 8px calc(7px + env(safe-area-inset-bottom));
  }
  .composer {
    padding: 4px 7px 6px 13px;
    border-radius: 21px;
  }
  .prompt-input {
    min-height: 44px;
    max-height: 150px;
    padding-top: 8px;
    font-size: 16px;
  }
  .composer-hint { display: none; }
  .composer-tools { gap: 1px; }
  .tool-pill { height: 29px; padding: 0 6px; font-size: 11px; }
  .tool-pill .icon { width: 14px; height: 14px; }
  .mode-pill { padding: 0 5px; }
  .mode-pill span:not(#modeBtnLabel) { display: none; }
  .effort-pill { padding: 0 3px; font-size: 9.5px; }
  .effort-pill .effort-bars { display: none; }
  .attach-btn { width: 32px; height: 32px; }
  .send-btn { width: 33px; height: 33px; }
  .composer-actions { gap: 2px; }

  .study-panel { padding: 9px 10px 10px; border-radius: 17px; }
  .study-types {
    display: flex;
    gap: 5px;
    padding-bottom: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .study-types::-webkit-scrollbar { display: none; }
  .study-type { min-width: 78px; padding: 7px 8px; }
  .study-options { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .study-options::-webkit-scrollbar { display: none; }
  .settings-body { max-height: calc(92dvh - 76px); }
  .modal { max-height: 92dvh; border-radius: 20px; }
  .overlay { padding: 10px; }
  .modal-head { padding: 17px 17px 12px; }
  .settings-body { padding: 2px 17px 22px; }
  .setting-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .segmented { align-self: flex-start; }
  .account-grid { grid-template-columns: 1fr 1fr; }
  .account-item.wide { grid-column: span 2; }
  .mobile-access { flex-direction: column; }
  .qr-wrap { flex-direction: row; align-self: center; gap: 10px; }
  .qr-box { width: 100px; height: 100px; }
  .login-modal { padding: 26px 20px 22px; }
  .toast-host { top: calc(64px + env(safe-area-inset-top)); }
  .scroll-bottom { bottom: 116px; }
}

@media (max-width: 420px) {
  .quick-grid { grid-template-columns: 1fr; }
  .msg-action span { display: none; }
  .msg-action .icon { width: 15px; height: 15px; }
  .msg-action { padding: 0 7px; }
  .mode-pill #modeBtnLabel { max-width: 58px; overflow: hidden; text-overflow: ellipsis; }
}

@media (hover: none) {
  .conv-more { opacity: 1; }
  .msg-actions { opacity: 1; }
  .attach-remove { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}

@media print {
  body { background: #fff; }
  .sidebar,
  .topbar,
  .composer-area,
  .scroll-bottom,
  .toast-host,
  .overlay,
  .lightbox,
  .msg-actions { display: none !important; }
  .app,
  .main,
  .chat-scroll { display: block; height: auto; overflow: visible; }
  .chat-inner { max-width: 100%; padding: 0; }
}
