/* ============================================================
   Mochat Design System — based on Claude/Anthropic warm-canvas aesthetic
   Cream canvas + Coral CTAs + Dark navy surfaces
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Brand & Accent */
  --color-primary: #cc785c;
  --color-primary-hover: #b86a50;
  --color-primary-active: #a9583e;
  --color-primary-disabled: #e6dfd8;
  --color-accent-teal: #5db8a6;
  --color-accent-amber: #e8a55a;

  /* Surface */
  --color-canvas: #faf9f5;
  --color-surface-soft: #f5f0e8;
  --color-surface-card: #efe9de;
  --color-surface-cream-strong: #e8e0d2;
  --color-surface-dark: #181715;
  --color-surface-dark-elevated: #252320;
  --color-surface-dark-soft: #1f1e1b;

  /* Text */
  --color-ink: #141413;
  --color-body: #3d3d3a;
  --color-body-strong: #252523;
  --color-muted: #6c6a64;
  --color-muted-soft: #8e8b82;
  --color-on-primary: #ffffff;
  --color-on-dark: #faf9f5;
  --color-on-dark-soft: #a09d96;

  /* Hairline & Borders */
  --color-hairline: #e6dfd8;
  --color-hairline-soft: #ebe6df;

  /* Semantic */
  --color-success: #5db872;
  --color-warning: #d4a017;
  --color-error: #c64545;

  /* Typography */
  --font-display: 'Cormorant Garamond', 'Tiempos Headline', Garamond, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-code: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  /* Spacing */
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
  --space-section: 96px;

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 9999px;

  /* Shadow (rare) */
  --shadow-subtle: 0 1px 3px rgba(20,20,19,0.08);
  --shadow-elevated: 0 4px 12px rgba(20,20,19,0.1);
}


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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.55;
  color: var(--color-body);
  background-color: var(--color-canvas);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

main {
  flex: 1;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--color-primary-active);
}

img {
  max-width: 100%;
  display: block;
}


/* --- Typography --- */
/* Design spec: serif display at 400 (Copernicus).
   Cormorant Garamond substitute needs weight 500 to match. */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--color-ink);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

h1 {
  font-size: 2.75rem;   /* ~44px */
  letter-spacing: -0.03em;
  line-height: 1.1;
}

h2 {
  font-size: 2rem;      /* 32px */
  letter-spacing: -0.025em;
}

h3 {
  font-size: 1.5rem;    /* 24px */
}

h4 {
  font-size: 1.125rem;  /* 18px */
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0;
}

p {
  margin-bottom: 1em;
}

p:last-child {
  margin-bottom: 0;
}

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

code {
  font-size: 0.8125rem;
  background: var(--color-surface-soft);
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  color: var(--color-body-strong);
}

small, .text-sm {
  font-size: 0.875rem;
}

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


/* --- Top Navigation --- */
.top-nav {
  border-bottom: 1px solid var(--color-hairline-soft);
  position: sticky;
  top: 0;
  z-index: 100;
  /* Frosted glass: semi-transparent cream + blur */
  background: rgba(250, 249, 245, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  /* 安全区域预留（移动端状态栏） */
  padding-top: env(safe-area-inset-top, 0px);
}

.top-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-brand:hover {
  color: var(--color-ink);
}

.brand-mark {
  color: var(--color-ink);
  flex-shrink: 0;
}

.nav-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  padding: var(--space-xxs) var(--space-xs);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-link:hover {
  color: var(--color-ink);
  background: var(--color-surface-soft);
}

.nav-user {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
}


/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  padding: 10px 20px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn:disabled {
  background: var(--color-primary-disabled);
  color: var(--color-muted);
  cursor: not-allowed;
}

/* Primary — Coral */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-active);
  border-color: var(--color-primary-active);
}

/* Secondary — Cream with hairline */
.btn-secondary {
  background: var(--color-canvas);
  color: var(--color-ink);
  border-color: var(--color-hairline);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-soft);
  border-color: var(--color-hairline);
}

/* Text link button */
.btn-text {
  background: transparent;
  color: var(--color-muted);
  padding: var(--space-xxs) var(--space-xs);
  height: auto;
  border: none;
}

.btn-text:hover {
  color: var(--color-ink);
}

/* Danger */
.btn-danger {
  background: transparent;
  color: var(--color-error);
  border-color: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(198, 69, 69, 0.08);
}

/* Dark surface button */
.btn-dark {
  background: var(--color-surface-dark-elevated);
  color: var(--color-on-dark);
  border-color: var(--color-surface-dark-elevated);
}

.btn-dark:hover:not(:disabled) {
  background: var(--color-surface-dark-soft);
}

/* Small */
.btn-sm {
  font-size: 0.8125rem;
  padding: 6px 14px;
  height: 32px;
}

/* Extra small */
.btn-xs {
  font-size: 0.75rem;
  padding: 2px 8px;
  height: 24px;
  border-radius: var(--radius-sm);
}


/* --- Cards --- */
.card {
  background: var(--color-surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: box-shadow 0.2s ease;
}

.card-flat {
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
}

.card-dark {
  background: var(--color-surface-dark);
  color: var(--color-on-dark);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
}

.card-interactive:hover {
  box-shadow: var(--shadow-elevated);
}


/* --- Flash Messages --- */
.flash-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
}

.flash {
  background: var(--color-surface-soft);
  border: 1px solid var(--color-hairline);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  color: var(--color-body-strong);
  margin-bottom: var(--space-xs);
}


/* --- Forms & Inputs --- */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-body-strong);
  margin-bottom: var(--space-xxs);
}

/* Scope selects: standalone form selects get full width, inline ones don't */
select {
  width: 100%;
}

.admin-table .actions select,
.inline-form select,
.inline-select {
  width: auto;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--color-ink);
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(204, 120, 92, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-muted-soft);
}

textarea {
  resize: vertical;
  line-height: 1.55;
}


/* ================================================================
   Page: Auth (Login & Register)
   ================================================================ */
.auth-page {
  min-height: calc(100vh - 64px - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-section) var(--space-lg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-xl);
  padding: var(--space-xxl);
  box-shadow: var(--shadow-subtle);
}

.auth-card h1 {
  font-size: 2rem;
  margin-bottom: var(--space-xs);
  text-align: center;
}

.auth-card .auth-subtitle {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.9375rem;
  margin-bottom: var(--space-xl);
}

.auth-card .btn[type="submit"] {
  width: 100%;
  margin-top: var(--space-sm);
}

.auth-footer {
  text-align: center;
  margin-top: var(--space-lg);
  font-size: 0.875rem;
  color: var(--color-muted);
}

.auth-footer a {
  font-weight: 500;
}


/* ================================================================
   Page: Chat List
   ================================================================ */
.chat-list-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-section);
}

.chat-list-page h1 {
  margin-bottom: var(--space-xs);
}

.chat-list-page .page-subtitle {
  color: var(--color-muted);
  margin-bottom: var(--space-xl);
}

/* Conversation cards */
.conv-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-xxl);
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.conv-item:hover {
  border-color: var(--color-hairline);
  box-shadow: var(--shadow-subtle);
}

.conv-item.active {
  border-left: 3px solid var(--color-primary);
  background: var(--color-surface-soft);
}

.conv-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
  color: var(--color-ink);
  min-width: 0;
}

.conv-link:hover {
  color: var(--color-ink);
}

.conv-title {
  font-weight: 500;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  font-size: 0.8125rem;
  color: var(--color-muted-soft);
  flex-shrink: 0;
  margin-left: var(--space-md);
}

.conv-delete {
  margin-left: var(--space-sm);
  flex-shrink: 0;
}

/* Character grid */
.section-label {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--color-ink);
  margin-bottom: var(--space-md);
  letter-spacing: -0.02em;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-md);
}

.character-card {
  background: var(--color-surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  transition: box-shadow 0.2s ease;
}

.character-card:hover {
  box-shadow: var(--shadow-elevated);
}

.character-card h3 {
  font-size: 1.125rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0;
}

.character-card p {
  font-size: 0.875rem;
  color: var(--color-muted);
  flex: 1;
}

.empty-hint {
  color: var(--color-muted-soft);
  font-size: 0.9375rem;
  padding: var(--space-lg) 0;
}


/* ================================================================
   Sidebar + Chat Layout
   ================================================================ */
body.chat-layout {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  overflow: hidden;
  background: var(--color-surface-dark);
}

.chat-layout .sidebar {
  width: 16rem;
  flex-shrink: 0;
  background: var(--color-canvas);
  border-right: 1px solid var(--color-hairline-soft);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-layout .chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--color-surface-dark);
}

/* Sidebar header */
.sidebar-header {
  padding: var(--space-md) var(--space-md) var(--space-sm);
  border-bottom: 1px solid var(--color-hairline-soft);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-username {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--color-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-greeting {
  font-size: 0.75rem;
  color: var(--color-muted-soft);
}

/* Sidebar actions */
.sidebar-actions {
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.sidebar-btn-new {
  width: 100%;
  font-size: 0.8125rem;
  height: 36px;
}

.sidebar-search {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.8125rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-hairline);
  background: var(--color-canvas);
  color: var(--color-ink);
  outline: none;
  transition: border-color 0.15s ease;
}

.sidebar-search:focus {
  border-color: var(--color-primary);
}

.sidebar-search::placeholder {
  color: var(--color-muted-soft);
}

/* Conversation list */
.sidebar-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xs) 0;
}

.sidebar-conv-list::-webkit-scrollbar {
  width: 4px;
}

.sidebar-conv-list::-webkit-scrollbar-thumb {
  background: var(--color-hairline);
  border-radius: 2px;
}

.sidebar-date-group {
  margin-bottom: var(--space-xxs);
}

.sidebar-date-label {
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted-soft);
  padding: var(--space-xs) var(--space-md) var(--space-xxs);
}

.sidebar-conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  margin: 1px var(--space-xs);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-body);
  transition: background 0.12s ease;
  cursor: pointer;
}

.sidebar-conv-item:hover {
  background: var(--color-surface-card);
  color: var(--color-body);
}

.sidebar-conv-item.active {
  background: var(--color-surface-card);
  border-left: 3px solid var(--color-primary);
  margin-left: 0;
  padding-left: calc(var(--space-md) - 3px);
}

.sidebar-conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-conv-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-conv-char {
  font-size: 0.6875rem;
  color: var(--color-muted-soft);
}

.sidebar-conv-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar-conv-action {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--color-muted-soft);
  cursor: pointer;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.12s ease, background 0.12s ease;
}

.sidebar-conv-action svg {
  display: block;
}

.sidebar-conv-action:hover {
  color: var(--color-primary);
  background: rgba(204, 120, 92, 0.08);
}

.sidebar-conv-delete {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--color-muted-soft);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.sidebar-conv-delete:hover {
  color: var(--color-error);
  background: rgba(198, 69, 69, 0.08);
}

/* Rename input (inline) */
.sidebar-rename-input {
  width: 100%;
  padding: 2px 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-xs);
  background: var(--color-canvas);
  color: var(--color-ink);
  outline: none;
}

.sidebar-empty {
  font-size: 0.8125rem;
  color: var(--color-muted-soft);
  text-align: center;
  padding: var(--space-xl) var(--space-md);
}

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-hairline-soft);
  flex-shrink: 0;
}

.sidebar-admin-link {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-muted);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-admin-link:hover {
  color: var(--color-ink);
  background: var(--color-surface-card);
}

.sidebar-logout-link {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-muted);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-logout-link:hover {
  color: var(--color-ink);
  background: var(--color-surface-card);
}

/* Sidebar toggle (inside chat-header, mobile only) */
.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--color-body);
  flex-shrink: 0;
  padding: 0;
}

.sidebar-toggle:hover {
  background: var(--color-surface-soft);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.4);
  z-index: 190;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.modal-card {
  background: var(--color-canvas);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-elevated);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-lg) var(--space-md);
}

.modal-header h3 {
  font-size: 1.25rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--color-muted);
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--color-ink);
  background: var(--color-surface-soft);
}

.modal-body {
  padding: 0 var(--space-lg) var(--space-lg);
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--space-sm);
}

.modal-char-card {
  background: var(--color-surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  cursor: pointer;
  transition: box-shadow 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.modal-char-card:hover {
  box-shadow: var(--shadow-elevated);
  background: var(--color-surface-cream-strong);
}

.modal-char-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-char-avatar-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.modal-char-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-ink);
}

.modal-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-muted-soft);
  padding: var(--space-xl) 0;
}

/* Chat welcome (no conversation selected) */
.chat-welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-welcome-inner {
  text-align: center;
  color: var(--color-muted);
}

.chat-welcome-inner .brand-mark {
  color: var(--color-hairline);
  margin: 0 auto var(--space-lg);
}

.chat-welcome-inner h2 {
  font-size: 1.5rem;
  color: var(--color-muted);
  margin-bottom: var(--space-xs);
}

.chat-welcome-inner p {
  font-size: 0.9375rem;
  color: var(--color-muted-soft);
}

/* ================================================================
   Page: Chat (Conversation)
   ================================================================ */

.chat-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  background: var(--color-canvas);
}

/* Header bar */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-hairline-soft);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
  flex: 1;
}

.chat-header-left .nav-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-header-left .nav-brand .brand-mark {
  color: var(--color-primary);
}

.conv-title-inline {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-muted-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.conv-title-inline:hover {
  color: var(--color-text);
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 1.125rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header h2:hover {
  color: var(--color-primary);
}

.chat-header input[type="text"] {
  flex: 1;
  max-width: 400px;
  font-size: 1rem;
  padding: 4px 10px;
  height: 34px;
}

.chat-header .model-select {
  font-size: 0.8125rem;
  color: var(--color-muted-soft);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
}

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg) 0;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.messages-area::-webkit-scrollbar {
  width: 6px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: var(--color-hairline);
  border-radius: 3px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 88%;
}

.message-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-user .message-content {
  background: #d4e0ed;
  border-radius: 16px;
  border-top-right-radius: 4px;
  padding: 11px 15px;
  box-shadow: 0 1px 4px rgba(20,20,19,0.08);
  align-self: flex-end;
}

.message-assistant .message-content {
  background: #fff;
  border: 1px solid var(--color-hairline-soft);
  border-radius: 16px;
  border-top-left-radius: 4px;
  padding: 11px 15px;
  box-shadow: 0 1px 4px rgba(20,20,19,0.08);
  color: #1a2030;
  align-self: flex-start;
}

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

.message-user .message-avatar-wrap {
  /* show small avatar like reference page */
}

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

.message-user .message-header-info {
  align-items: flex-end;
}

.message-user .message-content {
  background: #d4e0ed;
  border-radius: 16px;
  border-top-right-radius: 4px;
  padding: 11px 15px;
  box-shadow: 0 1px 4px rgba(20,20,19,0.08);
}

.message-user .message-actions {
  justify-content: flex-end;
}

.message-user .message-edit-actions {
  justify-content: flex-end;
}

.message-assistant {
  align-self: flex-start;
}

.message-assistant .message-content {
  background: #fff;
  border: 1px solid var(--color-hairline-soft);
  border-radius: 16px;
  border-top-left-radius: 4px;
  padding: 11px 15px;
  box-shadow: 0 1px 4px rgba(20,20,19,0.08);
  color: #1a2030;
}

.message-system {
  margin: 0 auto;
  text-align: center;
  display: block;
  max-width: 100%;
}

.message-system .message-content {
  background: var(--color-surface-soft);
  border-radius: var(--radius-pill);
  padding: var(--space-xxs) var(--space-md);
  font-size: 0.8125rem;
  color: var(--color-muted);
  display: inline-block;
}

.message-content {
  font-size: 14px;
  line-height: 1.75;
  color: var(--color-body-strong);
  /* 不要在外壳用 pre-wrap：SSR 缩进空白会变成可见文本导致排版乱 */
  word-break: break-word;
}

/* 正文才保留换行（用户/助手统一走 .message-reply，避免外壳 pre-wrap 吃 SSR 空白） */
.message-reply {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xxs);
}

.message-avatar-wrap {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  margin-top: 2px;
}

.message-avatar,
.message-avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
}

.message-avatar {
  object-fit: cover;
}

.message-avatar-fallback {
  background: var(--color-surface-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-muted);
}

.message-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.message-role {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-ink);
}

.message-time {
  font-size: 0.75rem;
  color: var(--color-muted-soft);
  margin-top: 2px;
}

/* Message actions */
.message-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.message-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--color-muted-soft);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.message-action-btn:hover {
  background: var(--color-surface-soft);
  color: var(--color-body);
}

.message-action-btn svg {
  display: block;
}

/* Message edit form */
.message-edit-form {
  margin-top: var(--space-xs);
}

.message-edit-textarea {
  width: 100%;
  min-height: 60px;
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--color-ink);
  background: var(--color-canvas);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  outline: none;
  resize: vertical;
}

.message-edit-actions {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.message-edit-save {
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 4px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-on-primary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.message-edit-save:hover {
  background: var(--color-primary-hover);
}

.message-edit-cancel {
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 4px 14px;
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-sm);
  background: var(--color-canvas);
  color: var(--color-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.message-edit-cancel:hover {
  background: var(--color-surface-soft);
  color: var(--color-body);
}

/* Thinking dots animation */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-muted);
  animation: thinking-bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Typing cursor */
.typing-cursor {
  animation: cursor-blink 0.8s step-end infinite;
  color: var(--color-muted);
  font-size: 0.875em;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Message input */
.message-input-area {
  padding: var(--space-md) 0 var(--space-lg);
  border-top: 1px solid var(--color-hairline-soft);
  flex-shrink: 0;
}

.message-input-container {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xs);
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline);
  border-radius: 22px;
  padding: var(--space-xs) var(--space-sm);
  transition: border-color 0.15s ease;
}

.message-input-container:focus-within {
  border-color: var(--color-primary);
}

.message-input-container textarea {
  flex: 1;
  min-height: 32px;
  max-height: 200px;
  padding: 6px 4px;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--color-ink);
  resize: none;
}

.message-input-container textarea::placeholder {
  color: var(--color-muted-soft);
}

.send-button {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.send-button:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.send-button:active:not(:disabled) {
  transform: scale(0.95);
}

.send-button:disabled {
  background: var(--color-primary-disabled);
  color: var(--color-muted);
  cursor: not-allowed;
}

.stop-button {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--color-body-strong);
  color: var(--color-on-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.stop-button:hover {
  background: var(--color-ink);
}

.stop-button.hidden,
.send-button.hidden {
  display: none;
}

/* 内心戏 — 位于对话框(.message-content)内部顶部 */
.message-monologue {
  margin: 0 0 10px;
  padding: 0;
  border: 1px solid rgba(20, 20, 19, 0.06);
  border-radius: 10px;
  background: rgba(245, 240, 232, 0.85);
  overflow: hidden;
}

.message-monologue-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-muted);
  text-align: left;
}

.message-monologue-toggle:hover {
  color: var(--color-body-strong);
  background: rgba(20, 20, 19, 0.04);
}

.message-monologue-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.message-monologue.is-collapsed .message-monologue-chevron {
  transform: rotate(-90deg);
}

.message-monologue-title {
  letter-spacing: 0.02em;
  color: var(--color-body);
}

.message-monologue-status {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-primary);
}

.message-monologue.is-streaming .message-monologue-status::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  vertical-align: middle;
  animation: monologue-pulse 1s ease-in-out infinite;
}

@keyframes monologue-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.message-monologue-body {
  padding: 0 10px 9px;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--color-muted);
  white-space: pre-wrap;
  word-break: break-word;
  /* 展开时全量显示，不截断、不内部滚动 */
  max-height: none;
  overflow: visible;
  font-style: italic;
}

/* 默认折叠：只保留标题栏 */
.message-monologue.is-collapsed .message-monologue-body {
  display: none;
}

/* AI 回复正文（对话框内、内心戏下方） */
.message-reply {
  min-width: 0;
}

/* Soft compression banner */
.compression-banner.soft {
  background: #fbf4e8;
  border-color: #e8d4a8;
}

.compression-banner-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  flex-wrap: wrap;
}

.load-older-indicator {
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-muted-soft);
  padding: var(--space-sm) 0;
  user-select: none;
}

/* Action text inside messages */
.action-text {
  color: var(--color-muted-soft);
  font-style: italic;
  font-size: 0.92em;
}

/* Typing dots inside message bubble */
.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-muted);
  animation: typing-bounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Typing indicator (avatar + bubble with dots) */
.typing-indicator {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  align-self: flex-start;
  max-width: 88%;
}

.typing-indicator .message-avatar-wrap {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  margin-top: 2px;
}

.typing-bubble {
  background: #fff;
  border: 1px solid var(--color-hairline-soft);
  border-radius: 16px;
  border-top-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: 0 1px 4px rgba(20,20,19,0.08);
}

.typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-muted);
  animation: typing-bounce 1.2s infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Admin chat view fallback */
.admin-chat-view .message {
  display: block;
  max-width: 100%;
}

/* Compression banner */
.compression-banner {
  background: var(--color-surface-soft);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  flex-shrink: 0;
  margin: var(--space-md) 0;
}

.compression-banner p {
  color: var(--color-body-strong);
  margin-bottom: var(--space-sm);
}


/* ================================================================
   Page: Compress
   ================================================================ */
.compress-page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-section);
}

.compress-page h2 {
  margin-bottom: var(--space-lg);
}

.compress-info {
  background: var(--color-surface-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.compress-info p {
  font-size: 0.9375rem;
  color: var(--color-body-strong);
  margin-bottom: var(--space-xs);
}

.compress-info p:last-child {
  margin-bottom: 0;
  color: var(--color-muted);
  font-size: 0.875rem;
}

.compress-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

#summarySection h3 {
  font-size: 1.125rem;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0;
  margin-bottom: var(--space-sm);
}

#summarySection textarea {
  font-family: var(--font-code);
  font-size: 0.875rem;
  line-height: 1.6;
  min-height: 300px;
}

#resultSection {
  background: var(--color-surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
}

#resultSection p {
  font-size: 1rem;
  color: var(--color-body-strong);
  margin-bottom: var(--space-md);
}


/* ================================================================
   Admin
   ================================================================ */
.admin-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-section);
  display: flex;
  gap: var(--space-xl);
}

.admin-nav {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}

.admin-nav a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.admin-nav a:hover {
  color: var(--color-ink);
  background: var(--color-surface-soft);
}

.admin-nav a.active {
  color: var(--color-ink);
  background: var(--color-surface-card);
  font-weight: 500;
}

.admin-content {
  flex: 1;
  min-width: 0;
}

.admin-content h1 {
  font-size: 2rem;
  margin-bottom: var(--space-lg);
}

/* Stats grid (dashboard) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
}

.stat-card {
  background: var(--color-surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
}

.stat-card h3 {
  font-size: 0.875rem;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-xs);
}

.stat-number {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 500;
  color: var(--color-ink);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Admin table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th {
  text-align: left;
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--color-hairline);
  white-space: nowrap;
}

.admin-table td {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--color-hairline-soft);
  color: var(--color-body-strong);
  vertical-align: middle;
  white-space: nowrap;
}

.admin-table tr:hover td {
  background: var(--color-surface-soft);
}

.admin-table .actions {
  display: flex;
  gap: var(--space-xs);
}

/* Admin form card */
.admin-form-card {
  background: var(--color-canvas);
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 640px;
}

.admin-form-card input[type="text"],
.admin-form-card input[type="email"],
.admin-form-card input[type="password"],
.admin-form-card input[type="number"],
.admin-form-card input[type="url"],
.admin-form-card textarea {
  width: 100%;
}

/* Admin chat view (read-only conversation viewer) */
.admin-chat-view {
  max-width: 800px;
  border: 1px solid var(--color-hairline-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  background: var(--color-canvas);
}

.admin-chat-view .message {
  max-width: 100%;
}

.admin-form-card h2 {
  font-size: 1.5rem;
  margin-bottom: var(--space-lg);
}

.admin-form-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-hairline-soft);
}


/* --- Footer --- */
.site-footer {
  background: var(--color-surface-dark);
  color: var(--color-on-dark-soft);
  margin-top: auto;
  /* 安全区域预留（移动端导航栏） */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-on-dark);
}

.footer-brand .brand-mark {
  color: var(--color-on-dark);
}

.footer-copy {
  font-size: 0.8125rem;
  color: var(--color-on-dark-soft);
}


/* ================================================================
   Utility
   ================================================================ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }


/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 768px) {
  .top-nav-inner {
    padding: 0 var(--space-md);
  }

  .nav-left {
    gap: var(--space-sm);
  }

  .chat-list-page,
  .compress-page {
    padding: var(--space-lg) var(--space-md) var(--space-section);
  }

  h1 {
    font-size: 2rem;
  }

  .character-grid {
    grid-template-columns: 1fr;
  }

  .admin-layout {
    flex-direction: column;
    padding: var(--space-lg) var(--space-md) var(--space-section);
  }

  .admin-nav {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .admin-content {
    overflow-x: auto;
  }

  .admin-table {
    min-width: 600px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .auth-card {
    padding: var(--space-xl);
  }

  .message {
    max-width: 95%;
  }

  .chat-header .model-select {
    display: none;
  }

  .chat-header h2 {
    font-size: 1rem;
  }

  .footer-inner {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }

  /* Sidebar: mobile — slide-out overlay */
  .chat-layout .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .chat-layout .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar-overlay {
    display: block;
  }

  .chat-page {
    padding: 0 var(--space-md);
  }

  .chat-welcome {
    padding-top: 0;
  }

  /* 移动端安全区域预留（为系统状态栏和导航栏留空间） */
  .chat-header {
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
  }

  .chat-input-area {
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  }

  .chat-layout .sidebar {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .conv-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }

  .conv-link {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xxs);
  }

  .conv-time {
    margin-left: 0;
  }

  .modal-body {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

/* ── Alert / Confirm Modal (glassmorphism) ── */
.modal-alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 19, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-alert-overlay.active {
  opacity: 1;
}

.modal-alert-card {
  background: rgba(250, 249, 245, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(20, 20, 19, 0.12);
  max-width: 380px;
  width: 90%;
  padding: 32px 28px 24px;
  text-align: center;
  transform: scale(0.92);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.modal-alert-overlay.active .modal-alert-card {
  transform: scale(1);
  opacity: 1;
}

.modal-alert-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
}

.modal-alert-icon-info {
  background: var(--color-primary);
}

.modal-alert-icon-confirm {
  background: var(--color-primary);
}

.modal-alert-msg {
  font-size: 0.9375rem;
  color: var(--color-body-strong);
  line-height: 1.6;
  margin-bottom: 24px;
  word-break: break-word;
}

.modal-alert-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-alert-btn {
  min-width: 96px;
  padding: 10px 24px;
  border: none;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.modal-alert-btn:active {
  transform: scale(0.97);
}

.modal-alert-cancel {
  background: var(--color-surface-soft);
  color: var(--color-body);
  border: 1px solid var(--color-hairline);
}

.modal-alert-cancel:hover {
  background: var(--color-surface-card);
}

.modal-alert-confirm {
  background: var(--color-primary);
  color: #fff;
}

.modal-alert-confirm:hover {
  background: var(--color-primary-hover);
}
