/* ═══════════════════════════════════════════════════════════════════
   股智 (StockWisdom) — Design System
   "The Analyst's Desk" — cool slate, precision typography,
   Chinese market semantics. Mobile-first.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ───────────────────────────────────────────────── */
:root {
  /* Palette — cool slate, not warm cream */
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-hover: #f7f8fa;
  --bg-input: #f0f1f4;
  --border: #dde1e7;
  --border-light: #e8ebf0;

  /* Text */
  --text: #1a1d23;
  --text-muted: #5f6b7a;
  --text-dim: #8b94a3;

  /* Semantic — Chinese market conventions: red=up, green=down */
  --accent: #d92d3b;      /* 中国红 — only for market-up, send, active */
  --accent-hover: #b8222f;
  --accent-subtle: rgba(217, 45, 59, 0.07);
  --success: #0c9e6a;     /* Jade green — market-down, success */
  --success-subtle: rgba(12, 158, 106, 0.07);
  --highlight: #d4890a;   /* Amber — stock codes, data spark */
  --highlight-subtle: rgba(212, 137, 10, 0.08);
  --danger: #d92d3b;
  --danger-subtle: rgba(217, 45, 59, 0.07);

  /* Shape */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.10);

  /* Typography */
  --font: "PingFang SC", "Microsoft YaHei", -apple-system,
    BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", "Consolas",
    Menlo, monospace;

  /* Spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Sidebar width */
  --sidebar-width: 272px;
}

/* ── Reset & Base ────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
}

/* ── Icons ──────────────────────────────────────────────────────── */
.ti {
  font-size: 1.1em;
  vertical-align: -0.125em;
  display: inline-block;
  line-height: 1;
}

/* ── Spinner animation ──────────────────────────────────────────── */
.ti-spin {
  animation: ti-spin 1s linear infinite;
}
@keyframes ti-spin {
  to { transform: rotate(360deg); }
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}
.btn:active {
  transform: scale(0.985);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-full {
  width: 100%;
}

.btn-danger {
  background: transparent;
  border-color: rgba(217, 45, 59, 0.25);
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-subtle);
  border-color: var(--danger);
}

/* ── Auth Pages ──────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-md);
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.auth-title .ti {
  color: var(--accent);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 15px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.auth-form input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.auth-error {
  padding: 10px 14px;
  background: var(--danger-subtle);
  border: 1px solid rgba(217, 45, 59, 0.2);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13px;
}

.auth-switch {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* ── Auth Redirect (unauthenticated landing) ─────────────────────── */
.auth-redirect {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  background: var(--bg);
  padding: var(--space-md);
}
.auth-redirect h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.auth-redirect h1 .ti {
  color: var(--accent);
}
.auth-redirect p {
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── App Shell ───────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.logo .ti {
  color: var(--accent);
  font-size: 1.2em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  font-size: 13px;
  color: var(--text-muted);
  padding: 3px 10px;
  background: var(--bg);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.token-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  background: var(--highlight-subtle);
  border: 1px solid rgba(212, 137, 10, 0.18);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--highlight);
  white-space: nowrap;
}

.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar toggle checkbox (hidden, pure-CSS mobile sidebar driver) */
.sidebar-toggle-check {
  display: none;
}

/* ── Mobile hamburger ────────────────────────────────────────────── */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
  margin-right: 4px;
  border-radius: var(--radius-sm);
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.menu-toggle:hover {
  background: var(--surface-hover);
}

/* Sidebar overlay background (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 199;
}

/* ── Chat Layout ─────────────────────────────────────────────────── */
.chat-container {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 200;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .btn {
  width: 100%;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

/* Sidebar footer — legal links, hidden on desktop, visible on mobile */
.sidebar-footer {
  display: none;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  flex-shrink: 0;
}
.sidebar-footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}
.sidebar-footer a:hover {
  color: var(--accent);
}
.sidebar-footer-divider {
  color: var(--border);
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
  margin-bottom: 2px;
  -webkit-tap-highlight-color: transparent;
}
.session-item:hover {
  background: var(--surface-hover);
}
.session-item.active {
  background: var(--accent-subtle);
  color: var(--text);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding-left: 9px;
}

.session-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.session-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 8px;
  flex-shrink: 0;
}

.session-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
  font-size: 14px;
  line-height: 1;
}
.session-item:hover .session-delete {
  opacity: 1;
}
.session-delete:hover {
  color: var(--danger);
}

/* ── Chat Area ───────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.chat-toolbar .btn {
  width: auto;
}

/* ── Mobile "+" FAB menu (≤768px only) ──────────────────────────────
   Replaces toolbar strategy/redeem buttons on mobile.
   Red circle button → dropdown with two items.
   Hidden on desktop; CSS @media shows it.
   ═══════════════════════════════════════════════════════════════════ */
.mobile-plus-menu {
  display: none;                          /* hidden on desktop */
}

.mobile-plus-btn {
  display: none;                          /* hidden on desktop */
}

.mobile-plus-dropdown {
  display: none;                          /* hidden on desktop */
}

/* ── Messages ────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 24px;
  position: relative;
  /* Block layout — avoids Chrome flex+overflow scrollHeight bug.
     overflow-anchor:none prevents browser scroll anchoring from
     freezing scrollHeight when content grows below the viewport. */
}

.message {
  display: flex;
  gap: 12px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto 20px auto;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--bg-input);
  color: var(--text-muted);
}
.message.user .message-avatar {
  background: var(--accent);
  color: #fff;
}

.message-content {
  padding: 12px 16px;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  line-height: 1.7;
  overflow-wrap: break-word;
  min-width: 0;
}
.message.user .message-content {
  background: var(--accent);
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  color: #fff;
}

/* User message markdown overrides */
.message.user .message-content strong { color: #fff; }
.message.user .message-content a { color: #fff; text-decoration: underline; }
.message.user .message-content code {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.message.user .message-content pre {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}
.message.user .message-content blockquote {
  background: rgba(0, 0, 0, 0.15);
  border-left-color: rgba(255, 255, 255, 0.4);
  color: rgba(255, 255, 255, 0.85);
}
.message.user .message-content h1,
.message.user .message-content h2,
.message.user .message-content h3,
.message.user .message-content h4 { color: #fff; }
.message.user .message-content th {
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
}
.message.user .message-content td {
  border-color: rgba(255, 255, 255, 0.15);
}
.message.user .message-content hr {
  border-color: rgba(255, 255, 255, 0.2);
}

.message-content p {
  margin-bottom: 8px;
}
.message-content p:last-child {
  margin-bottom: 0;
}

.message-content pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  margin: 10px 0;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}
.message-content pre code {
  background: none;
  padding: 0;
}

/* ── Markdown Body — "Analyst's Report" typography ───────────────── */
.message-content .markdown-body {
  line-height: 1.72;
  font-size: 14.5px;
  color: var(--text);
}

.message-content .markdown-body > *:first-child {
  margin-top: 0;
}

/* ── Paragraphs ───────────────────────────────────── */
.message-content .markdown-body p {
  margin: 10px 0;
}

/* ── Headings — structured hierarchy with restrained character ── */
.message-content .markdown-body h1,
.message-content .markdown-body h2,
.message-content .markdown-body h3,
.message-content .markdown-body h4,
.message-content .markdown-body h5,
.message-content .markdown-body h6 {
  margin: 22px 0 10px;
  font-weight: 650;
  line-height: 1.35;
  color: var(--text);
  letter-spacing: 0.01em;
}
.message-content .markdown-body h1 {
  font-size: 1.45em;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.message-content .markdown-body h2 {
  font-size: 1.25em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}
.message-content .markdown-body h3 {
  font-size: 1.1em;
  padding-left: 10px;
  border-left: 3px solid var(--highlight);
}
.message-content .markdown-body h4 {
  font-size: 1.02em;
  color: var(--text-muted);
}
.message-content .markdown-body h5,
.message-content .markdown-body h6 {
  font-size: 0.94em;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Inline emphasis ───────────────────────────────── */
.message-content .markdown-body strong {
  font-weight: 650;
  color: var(--text);
}
.message-content .markdown-body em {
  font-style: italic;
  color: var(--text-muted);
}
.message-content .markdown-body del {
  color: var(--text-dim);
  text-decoration: line-through;
}

/* ── Links ─────────────────────────────────────────── */
.message-content .markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-subtle);
  transition: border-color 0.15s;
}
.message-content .markdown-body a:hover {
  border-bottom-color: var(--accent);
}

/* ── Lists — clean spacing, intentional markers ───── */
.message-content .markdown-body ul,
.message-content .markdown-body ol {
  margin: 10px 0;
  padding-left: 22px;
}
.message-content .markdown-body li {
  margin-bottom: 5px;
}
.message-content .markdown-body li::marker {
  color: var(--text-dim);
}
.message-content .markdown-body ul > li::marker {
  color: var(--highlight);
}
.message-content .markdown-body li > ul,
.message-content .markdown-body li > ol {
  margin: 4px 0;
}

/* ── Blockquote — emphasis with restraint ──────────── */
.message-content .markdown-body blockquote {
  margin: 12px 0;
  padding: 10px 16px;
  border-left: 3px solid var(--highlight);
  background: var(--highlight-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-size: 0.96em;
}
.message-content .markdown-body blockquote p {
  margin-bottom: 4px;
}
.message-content .markdown-body blockquote strong {
  color: var(--highlight);
}

/* ── Code — inline and block ───────────────────────── */
.message-content .markdown-body code {
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--text-muted);
}
.message-content .markdown-body pre {
  margin: 12px 0;
  padding: 14px 16px;
  background: #1a1d23;
  border: 1px solid #2a2d33;
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.55;
}
.message-content .markdown-body pre code {
  padding: 0;
  background: transparent;
  border: none;
  font-size: 0.85em;
  color: #c8ccd4;
}

/* ── Horizontal rule ───────────────────────────────── */
.message-content .markdown-body hr {
  margin: 20px 0;
  border: none;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    var(--border) 20%,
    var(--border) 80%,
    transparent
  );
}

/* ── Images ────────────────────────────────────────── */
.message-content .markdown-body img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}

/* ── Thinking Block (multi-agent pipeline progress) ── */
.message-content .markdown-body details.thinking-block {
  max-height: 280px;
  overflow-y: auto;
  margin: 8px 0;
  padding: 10px 14px;
  background: #f0f1f4;
  border: 1px solid #dde1e7;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #8b94a3;
  opacity: 0.72;
}
.message-content .markdown-body details.thinking-block[open] {
  opacity: 0.78;
}
.message-content .markdown-body details.thinking-block summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #5f6b7a;
  padding: 2px 0 6px;
  user-select: none;
}
.message-content .markdown-body details.thinking-block summary:hover {
  color: #3a404a;
}
.message-content .markdown-body details.thinking-block pre,
.message-content .markdown-body details.thinking-block code {
  background: transparent;
  font-size: 11px;
  color: inherit;
}

/* ── Agent Blocks (multi-agent pipeline — per-agent collapsible sections) ── */
.message-content .agent-blocks {
  margin-bottom: 12px;
}

.message-content .agent-blocks details.agent-block {
  margin: 6px 0;
  padding: 10px 14px;
  border: 1px solid #dde1e7;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}
.message-content .agent-blocks details.agent-block[open] {
  background: #f8f9fb;
}
.message-content .agent-blocks details.agent-block summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #3a404a;
  padding: 2px 0 6px;
  user-select: none;
}
.message-content .agent-blocks details.agent-block summary:hover {
  color: #1a1f26;
}
.message-content .agent-blocks .agent-block-content {
  max-height: 320px;
  overflow-y: auto;
  margin: 6px 0 2px;
  padding: 8px 10px;
  background: #f0f1f4;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.55;
  color: #5f6b7a;
  white-space: pre-wrap;
  word-break: break-word;
}
.message-content .agent-blocks .agent-block-content code {
  background: transparent;
  font-size: inherit;
  color: inherit;
  padding: 0;
}

/* ── Reasoning Block (native model chain-of-thought) ── */
.message-content .markdown-body details.reasoning-block {
  max-height: 240px;
  overflow-y: auto;
  margin: 8px 0;
  padding: 10px 14px;
  background: #f4f0fa;
  border: 1px solid #dcd1f0;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #8b7da8;
  opacity: 0.72;
}
.message-content .markdown-body details.reasoning-block[open] {
  opacity: 0.78;
}
.message-content .markdown-body details.reasoning-block summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #6b5e8a;
  padding: 2px 0 6px;
  user-select: none;
}
.message-content .markdown-body details.reasoning-block summary:hover {
  color: #4a3e60;
}
.message-content .markdown-body details.reasoning-block pre,
.message-content .markdown-body details.reasoning-block code {
  background: transparent;
  font-size: 11px;
  color: inherit;
}

/* ── Encrypted Strategy — frosted glass blur ────────── */
.tool-calls-block.encrypted-strategy,
.message-content .agent-blocks.encrypted-strategy {
  position: relative;
  overflow: hidden;
}
.tool-calls-block.encrypted-strategy::after,
.message-content .agent-blocks.encrypted-strategy::after {
  content: "🔒 加密策略 — 计算步骤已隐藏";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(242, 244, 247, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  z-index: 10;
  pointer-events: none;
  letter-spacing: 0.03em;
}

/* ── Tables — financial data precision ─────────────── */
.message-content .markdown-body table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.message-content .markdown-body thead {
  border-bottom: 2px solid var(--border);
}
.message-content .markdown-body th,
.message-content .markdown-body td {
  padding: 7px 12px;
  text-align: left;
  vertical-align: top;
}
.message-content .markdown-body th {
  background: var(--surface-hover);
  font-weight: 650;
  font-size: 0.92em;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.message-content .markdown-body td {
  border-top: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums;
}
.message-content .markdown-body tbody tr:hover td {
  background: var(--highlight-subtle);
}

/* ── Input Area ──────────────────────────────────────────────────── */
.chat-input-area {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 800px;
  margin: 0 auto;
}

.chat-input-row textarea {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  resize: none;
  outline: none;
  min-height: 46px;
  max-height: 200px;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.chat-input-row .btn {
  height: 46px;
  padding: 0 20px;
}

/* ── Empty State ─────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-xl);
}

/* Inside scrollable messages container — absolute centering */
.messages > .empty-state {
  position: absolute;
  inset: 0;
}

/* Direct child of chat-area (no active session) — fill flex space */
.chat-area > .empty-state {
  flex: 1;
}
.empty-state .ti {
  font-size: 48px;
  margin-bottom: 4px;
  color: var(--text-dim);
}
.empty-state h2 {
  font-size: 20px;
  color: var(--text);
  font-weight: 600;
}
.empty-state p {
  max-width: 400px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Typing Indicator ────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Tool Call Cards ─────────────────────────────────────────────── */
.tool-calls-block {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-call-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}
.tool-call-card:hover {
  border-color: var(--text-dim);
  background: var(--surface-hover);
}
.tool-call-card.running {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.tool-call-card.error {
  border-color: var(--danger);
  background: var(--danger-subtle);
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  user-select: none;
}

.tool-call-icon {
  flex-shrink: 0;
  font-size: 14px;
}

.tool-call-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.tool-call-args {
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.tool-call-chevron {
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 12px;
  transition: transform 0.15s;
}

.tool-call-body {
  padding: 0 12px 10px;
  border-top: 1px solid var(--border-light);
  margin: 0 12px;
  overflow-x: auto;
}

.tool-call-body pre {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 8px 0 0;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-call-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: none;
  padding: 0;
}

.tool-call-body .typing-indicator {
  padding: 8px 0 4px;
}

.tool-call-empty {
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.modal-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* ── Confirm Dialog ─────────────────────────────────────────────── */
.confirm-dialog {
  max-width: 420px;
  text-align: center;
}

.confirm-dialog-body {
  padding: 32px 24px 20px;
}

.confirm-dialog-body h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--text);
}

.confirm-dialog-body p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

.confirm-dialog-body .ti {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 8px;
}

.confirm-dialog-body input[type="text"] {
  width: 100%;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-mono);
  text-align: center;
  letter-spacing: 2px;
  outline: none;
  transition: border-color 0.15s;
}
.confirm-dialog-body input[type="text"]:focus {
  border-color: var(--accent);
}

.confirm-dialog-actions {
  display: flex;
  gap: 10px;
  padding: 0 24px 24px;
  justify-content: center;
}

.confirm-dialog-actions .btn {
  min-width: 120px;
}

/* ── Redeem input + message ─────────────────────────────────────── */
.redeem-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font-mono);
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  margin-top: 12px;
}
.redeem-input:focus {
  border-color: var(--accent);
}
.redeem-input::placeholder {
  color: var(--text-dim);
  letter-spacing: 1px;
}

.redeem-msg {
  margin-top: 12px;
  font-size: 14px;
  font-weight: 500;
}
.msg-success {
  color: var(--success);
}
.msg-error {
  color: var(--danger);
}

/* ── Strategy List ──────────────────────────────────────────────── */
.strategy-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 0;
  font-size: 14px;
}

.strategy-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.strategy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 12px;
  transition: border-color 0.15s;
}

.strategy-item.encrypted {
  border-color: rgba(212, 137, 10, 0.2);
  background: var(--highlight-subtle);
}

.strategy-item.expired {
  opacity: 0.55;
  border-color: rgba(217, 45, 59, 0.15);
}

.strategy-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.strategy-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.strategy-lock {
  font-size: 12px;
  color: var(--highlight);
}

.strategy-expired-badge {
  display: inline-block;
  font-size: 11px;
  background: var(--danger-subtle);
  color: var(--danger);
  padding: 1px 8px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 500;
}

.strategy-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Strategy Form ──────────────────────────────────────────────── */
.strategy-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.strategy-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.strategy-name-input,
.strategy-content-input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.strategy-name-input:focus,
.strategy-content-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.strategy-content-input {
  resize: vertical;
  min-height: 140px;
  line-height: 1.6;
}

.strategy-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.strategy-form-right {
  display: flex;
  gap: 8px;
}

.polish-error {
  padding: 8px 12px;
  background: var(--danger-subtle);
  border: 1px solid rgba(217, 45, 59, 0.2);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13px;
}

/* ── Share / Import Dialog ──────────────────────────────────────── */
.share-dialog {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.share-dialog h3 {
  font-size: 16px;
  font-weight: 600;
}

.share-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  user-select: none;
}

.share-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.share-dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.share-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
}

.share-code-display {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--highlight);
  background: var(--highlight-subtle);
  border: 1px solid rgba(212, 137, 10, 0.2);
  border-radius: var(--radius);
  padding: 12px 24px;
  user-select: all;
}

.share-hint {
  font-size: 13px;
  color: var(--text-dim);
}

/* ── Mention Dropdown ───────────────────────────────────────────── */
.mention-dropdown {
  max-width: 800px;
  margin: 0 auto 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.mention-item:hover,
.mention-item.active {
  background: var(--surface-hover);
}
.mention-item.active {
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}

.mention-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.mention-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Admin Layout (sidebar + content) ───────────────────────────── */
.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────── */
.admin-sidebar {
  width: 220px;
  min-width: 220px;
  background: #1a1d23;
  color: #a0a7b4;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.admin-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #e0e4ea;
  letter-spacing: 0.02em;
}

.admin-sidebar-brand .ti {
  font-size: 20px;
  color: var(--accent);
}

/* Mobile top bar — hidden on desktop */
.admin-mobile-bar {
  display: none;
}

.admin-sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.admin-nav {
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: #8b94a3;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

.admin-nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #c8ced6;
}

.admin-nav-item.active {
  background: rgba(255,255,255,0.10);
  color: #e8ecf1;
  font-weight: 600;
}

.admin-nav-item .ti {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.admin-nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 12px;
}

.admin-sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-sidebar-user {
  font-size: 13px;
  color: #e0e4ea;
  font-weight: 500;
}

.admin-sidebar-back {
  font-size: 12px;
  color: #6b7385;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.admin-sidebar-back:hover {
  color: #a0a7b4;
}

/* ── Main Content ───────────────────────────── */
.admin-main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 20px 24px;
}

/* Stats bar */
.admin-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.admin-stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.admin-stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* Cards */
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.admin-card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.admin-card .admin-table {
  margin-bottom: 0;
}

.admin-card .admin-form {
  padding: 20px;
}

.admin-card .admin-pager {
  padding: 0 20px 16px;
}

.admin-card .admin-toolbar {
  margin-bottom: 0;
}

.admin-card .admin-hint {
  padding: 12px 20px 4px;
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.admin-tab-content {
  /* container only, no extra styling */
}

/* ── Admin Rebate Modal ─────────────────────── */
.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90vw;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-rebate .modal-header h3,
.modal-rebate .modal-header h2 {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-rebate .modal-header {
  padding: 16px 20px;
}

.modal-rebate .modal-body {
  padding: 20px;
}

/* Modal: user info + rate form */
.rebate-modal-user {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.rebate-modal-user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rebate-modal-username {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.rebate-modal-email {
  font-size: 13px;
  color: var(--text-muted);
}

.rebate-modal-rate {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.rebate-modal-rate strong {
  color: var(--accent);
}

.rebate-modal-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
}

.rebate-modal-form label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.rebate-modal-form-row {
  display: flex;
  gap: 8px;
}

.rebate-modal-form-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text);
  min-width: 0;
}

.rebate-modal-form-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.rebate-modal-msg {
  font-size: 12px;
  min-height: 18px;
}

.rebate-modal-records h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 8px;
}

@media (max-width: 640px) {
  .modal-panel {
    width: 95vw;
    max-height: 90vh;
    border-radius: var(--radius);
  }
  .rebate-modal-user {
    flex-direction: column;
  }
  .rebate-modal-form {
    width: 100%;
  }
}

/* Table — keep existing */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table th,
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
}

.admin-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-hover);
}

.admin-table td {
  color: var(--text);
}

.admin-table code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 4px;
}

.admin-table tr.code-expired td {
  opacity: 0.4;
  text-decoration: line-through;
}

.admin-table tr.code-used-up td {
  opacity: 0.6;
}

/* ── Admin table scroll wrapper (mobile horizontal scroll) ── */
.admin-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Sticky first column on mobile — keeps row identity visible while scrolling */
@media (max-width: 640px) {
  .admin-table-scroll .admin-table {
    min-width: 640px;
    font-size: 13px;
  }
  .admin-table-scroll .admin-table th:first-child,
  .admin-table-scroll .admin-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: 2px 0 6px -2px rgba(0,0,0,0.08);
    font-weight: 500;
  }
  .admin-table-scroll .admin-table th:first-child {
    background: var(--surface-hover);
    z-index: 2;
  }
}

/* ── Admin search & pager ─────────────────── */

.admin-toolbar {
  display: flex;
  gap: 8px;
}

.admin-search {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  width: 240px;
}

.admin-search:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.pager-info {
  font-size: 13px;
  color: var(--text-muted);
}

.pager-btns {
  display: flex;
  gap: 4px;
  align-items: center;
}

.pager-btns .btn-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pager-ellipsis {
  padding: 0 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.admin-form input {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.admin-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.admin-form button[type="submit"] {
  align-self: flex-start;
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ── Focus visible ───────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE — ≤ 768px
   "Trading Floor Terminal" — tight, precise, palm-sized.
   Intentional spacing rhythm, proportional type scale.
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── App Shell ────────────────────────────────────── */
  .app-header {
    padding: 0 16px;
    height: 48px;
  }

  .logo {
    font-size: 16px;
    gap: 5px;
  }
  .logo .ti {
    font-size: 1.15em;
  }
  .logo-subtitle {
    display: none;
  }

  .header-right {
    gap: 6px;
  }
  .header-right .token-badge,
  .header-right .user-badge {
    font-size: 11px;
    padding: 2px 8px;
  }
  /* Icon-only for admin/settings button, compact for logout */
  .header-right .btn-sm:has(.ti) {
    font-size: 0;
    padding: 6px 9px;
  }
  .header-right .btn-sm:has(.ti) .ti {
    font-size: 18px;
  }
  .header-right button.btn-sm {
    font-size: 12px;
    padding: 5px 9px;
  }

  .menu-toggle {
    display: block;
    font-size: 20px;
    padding: 6px;
    margin-right: 2px;
  }

  /* ── Sidebar — slide-in overlay ───────────────────── */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), 85vw);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }
  #sidebar-toggle:checked ~ .app-main .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  #sidebar-toggle:checked ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-header {
    padding: 12px 14px;
  }

  .session-item {
    padding: 11px 12px;
  }
  .session-item.active {
    border-left-width: 2px;
    padding-left: 10px;
  }
  .session-title {
    font-size: 13px;
  }

  /* Show legal links inside sidebar */
  .sidebar-footer {
    display: flex;
  }

  /* ── Chat Area ────────────────────────────────────── */
  .chat-toolbar {
    display: none;     /* hidden on mobile — "+" menu replaces it */
  }

  /* ── Mobile "+" FAB ──────────────────────────────── */
  .mobile-plus-menu {
    display: inline-flex;
    position: relative;
  }

  .mobile-plus-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(217, 45, 59, 0.30);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }
  .mobile-plus-btn:active {
    transform: scale(0.92);
  }

  .mobile-plus-menu.open .mobile-plus-btn {
    background: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }

  /* ── Dropdown ────────────────────────────────────── */
  .mobile-plus-dropdown {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 120px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 1;
    animation: plus-dropdown-in 0.18s ease both;
    transform-origin: top right;
  }

  @keyframes plus-dropdown-in {
    from {
      opacity: 0;
      transform: translateY(-6px) scale(0.94);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  .mobile-plus-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    cursor: pointer;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border-light);
  }
  .mobile-plus-item:last-child {
    border-bottom: none;
  }
  .mobile-plus-item:hover {
    background: var(--surface-hover);
  }
  .mobile-plus-item:active {
    background: var(--accent-subtle);
  }
  .mobile-plus-item .ti {
    font-size: 18px;
    color: var(--text-muted);
    width: 20px;
    text-align: center;
  }

  .messages {
    padding: 14px 16px;
  }

  .message {
    max-width: 100%;
    gap: 10px;
    margin: 0 auto 18px auto;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .message-content {
    font-size: 14px;
    padding: 10px 14px;
    border-left-width: 2px;
    line-height: 1.6;
    border-radius: 3px var(--radius) var(--radius) 3px;
  }
  .message.user .message-content {
    border-left-width: 2px;
    border-radius: var(--radius) 3px var(--radius) var(--radius);
  }

  /* ── Analyst-report typography — scaled for mobile ─ */
  .message-content .markdown-body {
    font-size: 14px;
    line-height: 1.65;
  }
  .message-content .markdown-body h1,
  .message-content .markdown-body h2,
  .message-content .markdown-body h3,
  .message-content .markdown-body h4,
  .message-content .markdown-body h5,
  .message-content .markdown-body h6 {
    margin: 18px 0 8px;
    line-height: 1.3;
  }
  .message-content .markdown-body h1 {
    font-size: 1.3em;
    padding-bottom: 6px;
  }
  .message-content .markdown-body h2 {
    font-size: 1.15em;
    padding-bottom: 4px;
  }
  .message-content .markdown-body h3 {
    font-size: 1.05em;
    padding-left: 8px;
    border-left-width: 2px;
  }
  .message-content .markdown-body h4 {
    font-size: 0.98em;
  }
  .message-content .markdown-body h5,
  .message-content .markdown-body h6 {
    font-size: 0.9em;
  }

  .message-content .markdown-body p {
    margin: 8px 0;
  }
  .message-content .markdown-body ul,
  .message-content .markdown-body ol {
    margin: 8px 0;
    padding-left: 20px;
  }
  .message-content .markdown-body li {
    margin-bottom: 4px;
  }
  .message-content .markdown-body blockquote {
    margin: 10px 0;
    padding: 8px 14px;
    font-size: 0.94em;
  }
  .message-content .markdown-body pre {
    margin: 10px 0;
    padding: 12px 14px;
    font-size: 12px;
  }
  .message-content .markdown-body table {
    font-size: 12px;
  }
  .message-content .markdown-body th,
  .message-content .markdown-body td {
    padding: 6px 8px;
  }

  /* ── Collapsible blocks — tighter on mobile ─────── */
  .message-content .agent-blocks details.agent-block {
    padding: 8px 12px;
  }
  .message-content .agent-blocks details.agent-block summary {
    font-size: 12px;
  }
  .message-content .agent-blocks .agent-block-content {
    max-height: 240px;
    font-size: 11px;
    padding: 6px 8px;
  }

  .message-content .markdown-body details.thinking-block,
  .message-content .markdown-body details.reasoning-block {
    max-height: 200px;
    padding: 8px 12px;
  }

  /* ── Tool call cards ──────────────────────────────── */
  .tool-call-header {
    padding: 7px 10px;
    font-size: 12px;
  }
  .tool-call-body {
    padding: 0 10px 8px;
    margin: 0 10px;
  }
  .tool-call-body pre {
    font-size: 11px;
    padding: 8px 10px;
  }

  /* ── Input Area ───────────────────────────────────── */
  .chat-input-area {
    padding: 12px 14px;
    /* Safe area for notched phones */
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }

  .chat-input-row {
    max-width: 100%;
    gap: 10px;
  }

  .chat-input-row textarea {
    font-size: 16px; /* Prevent iOS zoom on focus */
    min-height: 44px;
    padding: 10px 14px;
    border-radius: var(--radius);
  }

  .chat-input-row .btn {
    height: 44px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 600;
  }

  /* ── Empty State ──────────────────────────────────── */
  .empty-state {
    padding: 32px 20px;
  }
  .empty-state .ti {
    font-size: 40px;
    margin-bottom: 2px;
  }
  .empty-state h2 {
    font-size: 19px;
  }
  .empty-state p {
    font-size: 14px;
    max-width: 300px;
  }

  /* ── Modals — full screen on mobile ───────────────── */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    max-width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
  }

  .confirm-dialog {
    max-width: 100%;
  }

  .confirm-dialog-body {
    padding: 28px 24px 16px;
  }

  .confirm-dialog-actions {
    padding: 0 24px 24px;
  }

  .modal-header {
    padding: 18px 20px 14px;
  }
  .modal-header h2 {
    font-size: 17px;
  }
  .modal-body {
    padding: 16px 20px;
  }

  /* ── Auth Pages ───────────────────────────────────── */
  .auth-card {
    max-width: 100%;
    padding: 36px 28px;
    border-radius: var(--radius-lg);
  }

  .auth-title {
    font-size: 26px;
  }

  .auth-redirect h1 {
    font-size: 28px;
  }
  .auth-redirect p {
    font-size: 15px;
  }
  .auth-redirect .btn {
    min-width: 140px;
  }

  /* ── Strategy Modal ───────────────────────────────── */
  .strategy-item {
    flex-wrap: wrap;
    gap: 8px;
  }
  .strategy-item-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .strategy-form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .strategy-form-right {
    justify-content: flex-end;
  }

  /* ── Share Dialog ─────────────────────────────────── */
  .share-code-display {
    font-size: 22px;
    padding: 10px 18px;
    letter-spacing: 1px;
  }

  /* ── Admin ────────────────────────────────────────── */
  .admin-sidebar {
    width: 180px;
    min-width: 180px;
  }
  .admin-main {
    padding: 12px 14px;
  }
  .admin-stats {
    flex-direction: column;
    gap: 8px;
  }
  .admin-stat {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
  }
  .admin-stat-value {
    font-size: 20px;
  }
  .admin-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-form {
    max-width: 100%;
  }
  .admin-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .admin-search {
    width: 100%;
  }

  /* ── Mention Dropdown ──────────────────────────────── */
  .mention-dropdown {
    max-width: 100%;
    margin-bottom: 4px;
  }
  .mention-item {
    padding: 10px 12px;
    gap: 10px;
  }
  .mention-item.active {
    border-left-width: 2px;
    padding-left: 10px;
  }
  .mention-name {
    font-size: 13px;
  }
  .mention-preview {
    font-size: 11px;
  }

  /* ── Redeem dialog ─────────────────────────────────── */
  .redeem-input {
    font-size: 15px;
    padding: 10px 12px;
  }

  /* ── Token badge on mobile header ─────────────────── */
  .token-badge {
    padding: 2px 8px;
    font-size: 11px;
  }
  .token-badge .ti {
    font-size: 1em;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   SMALL MOBILE — ≤ 374px
   Extra-tight for narrow screens (iPhone SE, etc.)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .header-right .user-badge {
    display: none;
  }
  .header-right .token-badge {
    font-size: 11px;
    padding: 2px 6px;
    gap: 2px;
  }
  .header-right button.btn-sm {
    font-size: 11px;
    padding: 4px 7px;
  }
}

@media (max-width: 374px) {
  .app-header {
    padding: 0 10px;
  }
  .logo {
    font-size: 0;
    gap: 2px;
  }
  .logo .ti {
    font-size: 20px;
  }

  .header-right {
    gap: 4px;
  }
  .header-right a.btn-sm {
    display: none;
  }
  .header-right button.btn-sm {
    font-size: 11px;
    padding: 4px 6px;
  }
  .header-right .token-badge {
    font-size: 10px;
    padding: 2px 5px;
  }

  .messages {
    padding: 10px 12px;
  }

  .message {
    gap: 8px;
    margin: 0 auto 14px auto;
  }

  .message-avatar {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  .message-content {
    padding: 8px 12px;
    font-size: 13px;
  }
  .message-content .markdown-body {
    font-size: 13px;
    line-height: 1.6;
  }
  .message-content .markdown-body h1 {
    font-size: 1.2em;
  }
  .message-content .markdown-body h2 {
    font-size: 1.08em;
  }

  .chat-input-area {
    padding: 10px 10px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }

  .chat-input-row {
    gap: 8px;
  }

  .chat-input-row .btn {
    padding: 0 14px;
    font-size: 13px;
  }

  .empty-state {
    padding: 24px 16px;
  }
  .empty-state .ti {
    font-size: 32px;
  }
  .empty-state h2 {
    font-size: 17px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   TABLET — 769–1024px
   ═══════════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }
  .messages {
    padding: 22px;
  }
  .message {
    max-width: 640px;
    margin: 0 auto 22px auto;
  }
  .message-avatar {
    width: 32px;
    height: 32px;
  }
  .message-content {
    padding: 11px 15px;
  }
  .chat-input-area {
    padding: 14px 18px 16px;
  }
  .chat-input-row {
    max-width: 640px;
  }
}

/* ── Registration Agreement Checkbox ─────────────────────────────── */
.agree-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.agree-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.agree-label a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.agree-label a:hover {
  text-decoration: underline;
}

/* ── App Footer ──────────────────────────────────────────────────── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.app-footer a:hover {
  color: var(--accent);
}
.footer-divider {
  color: var(--border);
}

/* ── Bottom Navigation (mobile only, ≤768px) ────────────────────────
   "The Analyst's Desk" — three stations at thumb level.
   Hidden on desktop; the header links serve there.
   Visible on mobile as primary navigation.
   ═══════════════════════════════════════════════════════════════════ */
.bottom-nav {
  display: none;                          /* hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
  z-index: 200;
  /* flex row of equal-width tabs */
  display: none;
  align-items: stretch;
  justify-content: space-around;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 0;
  color: var(--text-dim);
  text-decoration: none;
  position: relative;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  outline-offset: -2px;
}

/* Active indicator — 3px pill above the icon, like a trading-desk light */
.bottom-nav-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 20px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  transition: transform 0.2s ease;
}

.bottom-nav-item.active::before {
  transform: translateX(-50%) scaleX(1);
}

.bottom-nav-item.active {
  color: var(--accent);
}

.bottom-nav-item .ti {
  font-size: 22px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.bottom-nav-item:active .ti {
  transform: scale(0.9);
}

.bottom-nav-label {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
}

.bottom-nav-item.active .bottom-nav-label {
  font-weight: 500;
}

/* ── Admin privilege dot — amber spark, matches --highlight ──────── */
.bottom-nav-privilege-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 24px);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--highlight);
  opacity: 0.85;
}

/* Admin tab enters with a fade */
.bottom-nav--admin .bottom-nav-item[data-tab="admin"] {
  animation: bottom-nav-admin-enter 0.35s ease both;
}

@keyframes bottom-nav-admin-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Legal Pages (Terms & Privacy) ──────────────────────────────── */
.legal-page {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  padding: 32px var(--space-md) 60px;
  background: var(--bg);
  overflow-y: auto;
}

.legal-card {
  width: 100%;
  max-width: 760px;
  padding: 40px 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 20px;
  transition: color 0.15s;
}
.legal-back:hover {
  color: var(--accent);
}

.legal-card > h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.legal-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.legal-body {
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text);
}

.legal-body h2 {
  font-size: 18px;
  font-weight: 650;
  margin: 28px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.legal-body h3 {
  font-size: 15px;
  font-weight: 650;
  margin: 20px 0 8px;
  color: var(--text);
}

.legal-body p {
  margin: 10px 0;
}

.legal-body ol,
.legal-body ul {
  margin: 10px 0;
  padding-left: 22px;
}

.legal-body li {
  margin-bottom: 6px;
}
.legal-body li::marker {
  color: var(--text-dim);
}

.legal-body strong {
  font-weight: 650;
}

.legal-body a {
  color: var(--accent);
  text-decoration: none;
}
.legal-body a:hover {
  text-decoration: underline;
}

.legal-notice {
  padding: 12px 16px;
  background: var(--highlight-subtle);
  border: 1px solid rgba(212, 137, 10, 0.18);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--highlight);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.legal-notice .ti {
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Responsive: Legal Pages ────────────────────────────────────── */
@media (max-width: 640px) {
  .legal-card {
    padding: 24px 20px;
  }
  .legal-card > h1 {
    font-size: 22px;
  }
  .legal-body {
    font-size: 14px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .sidebar {
    transition: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   PROFILE PAGE
   Single-column personal dashboard
   ═══════════════════════════════════════════════════════════════════ */

.profile-layout {
  min-height: 100vh;
  background: var(--bg);
}

/* ── Header ────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 20px;
}

.profile-back {
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}

.profile-back:hover {
  color: var(--text);
}

.profile-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.profile-header-spacer {
  width: 60px; /* balance the back link */
}

/* ── Body ──────────────────────────────────── */
.profile-body {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Card ──────────────────────────────────── */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.profile-card-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Identity card ─────────────────────────── */
.profile-identity {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
}

.profile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-identity-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-name {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.profile-email {
  font-size: 13px;
  color: var(--text-muted);
}

.profile-since {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Balance card (signature) ──────────────── */
.profile-balance {
  text-align: center;
  padding: 32px 24px;
  border-left: 3px solid var(--accent);
}

.profile-balance-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.profile-balance-value {
  display: block;
  font-size: 40px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-bottom: 12px;
}

.profile-balance-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.profile-balance-meta strong {
  color: var(--text);
}

.profile-balance-divider {
  color: var(--text-dim);
}

/* ── Invite card ───────────────────────────── */
.profile-invite-code-row,
.profile-invite-link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.profile-invite-label {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 56px;
  flex-shrink: 0;
}

.profile-invite-code {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--accent);
  flex-shrink: 0;
}

.profile-invite-link-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg-input);
}

.profile-invite-link-input:focus {
  outline: none;
  border-color: var(--accent);
}

.profile-invite-hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.profile-invite-hint strong {
  color: var(--accent);
}

.profile-invite-generate {
  text-align: center;
  padding: 12px 0 4px;
}

.profile-invite-generate p {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Copy button ───────────────────────────── */
.profile-copy-btn {
  flex-shrink: 0;
}

.profile-copy-btn.copied {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* ── Empty state ───────────────────────────── */
.profile-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-dim);
  font-size: 14px;
}

.profile-empty .ti {
  font-size: 32px;
}

/* ── Table ─────────────────────────────────── */
.profile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.profile-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.profile-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

.profile-table tr:last-child td {
  border-bottom: none;
}

.profile-table .rebate-amount {
  color: var(--success);
  font-weight: 600;
}

/* ── Danger zone ───────────────────────────── */
.profile-danger {
  border-color: var(--danger);
}

.profile-danger .profile-card-title {
  color: var(--danger);
}

.profile-danger-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 14px;
}

/* ── Delete confirm dialog ─────────────────── */
.delete-confirm-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 8px;
}

.delete-confirm-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  text-align: center;
  background: var(--bg-input);
  color: var(--text);
  letter-spacing: 0.05em;
}

.delete-confirm-input:focus {
  outline: none;
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-subtle);
}

/* ── User badge link ───────────────────────── */
.user-badge-link {
  text-decoration: none;
}

.user-badge-link:hover .user-badge {
  text-decoration: underline;
}

/* Admin rebate extras */
.admin-table .rebate-amount {
  color: var(--success);
  font-weight: 600;
}

/* ── Responsive ────────────────────────────── */
@media (max-width: 640px) {
  .profile-body {
    padding: 0 12px 32px;
    gap: 12px;
  }
  .profile-card {
    padding: 18px 16px;
  }
  .profile-balance {
    padding: 24px 16px;
  }
  .profile-balance-value {
    font-size: 32px;
  }
  .profile-identity {
    padding: 16px;
  }
  .profile-invite-code-row,
  .profile-invite-link-row {
    flex-wrap: wrap;
  }
  .profile-invite-label {
    min-width: auto;
    width: 100%;
    margin-bottom: 2px;
  }
  .profile-header {
    padding: 12px 14px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE-XS — ≤ 640px
   Admin sidebar → top bar + hamburger dropdown menu
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .admin-layout {
    flex-direction: column;
  }

  /* ── Toggle checkbox (hidden) ── */
  .admin-menu-toggle-check {
    display: none;
  }

  /* ── Top bar ── */
  .admin-sidebar {
    width: 100%;
    min-width: 0;
    height: 52px;
    padding: 0;
    overflow: visible;
    z-index: 100;
    position: relative;
    flex-shrink: 0;
  }

  .admin-mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    height: 100%;
  }

  .admin-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: #a0a7b4;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }
  .admin-menu-btn:hover {
    background: rgba(255,255,255,0.08);
  }
  .admin-menu-btn .ti {
    font-size: 22px;
  }

  .admin-mobile-brand {
    font-size: 15px;
    font-weight: 600;
    color: #e0e4ea;
  }

  .admin-sidebar-brand {
    display: none;
  }

  /* ── Dropdown panel (nav + footer) ── */
  .admin-sidebar-body {
    display: none;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    background: #1a1d23;
    box-shadow: var(--shadow-lg);
    z-index: 101;
    max-height: calc(100vh - 52px);
    overflow-y: auto;
  }

  #admin-menu-toggle:checked ~ .admin-sidebar .admin-sidebar-body {
    display: flex;
  }

  .admin-nav {
    flex-direction: column;
    padding: 8px 0;
    gap: 0;
  }

  .admin-nav-item {
    padding: 13px 20px;
    font-size: 15px;
    border-radius: 0;
    border-left: 3px solid transparent;
    white-space: nowrap;
  }
  .admin-nav-item.active {
    border-left-color: var(--accent);
    background: rgba(255,255,255,0.06);
  }
  .admin-nav-item .ti {
    font-size: 18px;
    width: 24px;
  }

  .admin-nav-divider {
    margin: 4px 12px;
  }

  .admin-sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 14px 20px;
    margin-top: auto;
    flex-shrink: 0;
  }

  /* ── Backdrop overlay ── */
  .admin-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 99;
  }
  #admin-menu-toggle:checked ~ .admin-menu-overlay {
    display: block;
  }

  .admin-main {
    padding: 12px;
  }
  .admin-stats {
    flex-direction: row;
    gap: 8px;
    margin-bottom: 12px;
  }
  .admin-stat {
    padding: 10px 12px;
    flex: 1;
    min-width: 0;
  }
  .admin-stat-value {
    font-size: 18px;
  }
  .admin-stat-label {
    font-size: 11px;
  }

  /* Forms — full width on mobile */
  .admin-form {
    max-width: 100%;
    gap: 10px;
  }
  .admin-form input {
    padding: 10px 12px;
    font-size: 16px; /* prevent iOS zoom on focus */
  }
  .admin-form label span {
    font-size: 12px;
  }

  /* Search — full width */
  .admin-search {
    width: 100%;
    font-size: 16px; /* prevent iOS zoom */
    padding: 8px 12px;
  }

  /* Card header — stack on mobile */
  .admin-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  /* Pager — compact */
  .admin-pager {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-top: 10px;
  }
  .pager-info {
    font-size: 12px;
  }
  .pager-btns {
    gap: 3px;
  }
  .pager-btns .btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    min-width: 32px;
  }
  .pager-ellipsis {
    padding: 0 2px;
    font-size: 12px;
  }

  /* Card padding tighten */
  .admin-card .admin-form {
    padding: 14px;
  }
  .admin-card .admin-pager {
    padding: 0 14px 12px;
  }
  .admin-hint {
    padding: 8px 14px 2px;
    font-size: 12px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Mobile footer — placed AFTER base .app-footer to win cascade
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .app-footer {
    display: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Mobile bottom navigation — primary nav at thumb level
   Wins cascade over base .bottom-nav { display: none }
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
  }

  /* Hide header profile + admin links — bottom nav takes over */
  .header-right .user-badge-link,
  .header-right a.btn-sm[href="/admin"] {
    display: none;
  }

  /* Push main content up so nothing hides behind the bottom nav */
  .app-main {
    padding-bottom: 56px;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* Profile page body also needs bottom clearance */
  .profile-body {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
  }

  /* Admin main content bottom clearance */
  .admin-main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
  }
}
