:root, [data-theme="light"] {
  color-scheme: light;
  --app-bg: #f2f2f7;
  --sidebar: #3f0e40;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.16);
  --chat-bg: #f2f2f7;
  --panel: #ffffff;
  --line: rgba(60, 60, 67, 0.08);
  --line-strong: rgba(60, 60, 67, 0.16);
  --text: #000000;
  --muted: #8e8e93;
  --soft: #c7c7cc;
  --green: #34c759;
  --green-dark: #248a3d;
  --blue: #007aff;
  --yellow: #ff9f0a;
  --red: #ff3b30;
  --purple: #af52de;
  --bubble: #ffffff;
  --bubble-me: #dcf8c6;
  --bubble-me-text: inherit;
  --danger: #ff3b30;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --app-bg: #000000;
  --sidebar: #000000;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(255, 255, 255, 0.12);
  --chat-bg: #000000;
  --panel: #1c1c1e;
  --line: rgba(84, 84, 88, 0.35);
  --line-strong: rgba(84, 84, 88, 0.55);
  --text: #ffffff;
  --muted: #8e8e93;
  --soft: #48484a;
  --green: #30d158;
  --green-dark: #30d158;
  --blue: #0a84ff;
  --yellow: #ffd60a;
  --red: #ff453a;
  --purple: #bf5af2;
  --bubble: #2c2c2e;
  --bubble-me: #1a3a2a;
  --bubble-me-text: inherit;
  --danger: #ff453a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  -ms-touch-action: pan-x pan-y;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  background: var(--app-bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* ─── Auth Shell ────────────────────────────────────────────────────────────── */

.auth-shell {
  height: 100dvh;
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--chat-bg);
}

.auth-panel {
  width: min(420px, 100%);
  padding: 32px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-avatar {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #007aff, #5856d6);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
}

h3 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

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

input,
textarea,
select {
  width: 100%;
  border: 0.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-size: 16px;
}

input {
  height: 44px;
  padding: 0 14px;
}

textarea {
  padding: 10px 14px;
  resize: none;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.auth-actions {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */

.button,
.send-button,
.icon-button {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.1s, background 0.2s, opacity 0.2s;
}

.button:active,
.send-button:active {
  transform: scale(0.97);
}

.button,
.send-button {
  min-height: 44px;
  padding: 0 18px;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  border-radius: 10px;
}

.button.ghost {
  background: rgba(120, 120, 128, 0.08);
  color: var(--blue);
}

.button:hover,
.send-button:hover {
  opacity: 0.85;
}

.button.ghost:hover {
  background: rgba(120, 120, 128, 0.12);
}

button:disabled,
.disabled button,
.disabled textarea {
  cursor: not-allowed;
  opacity: 0.4;
}

/* ─── Badge & Notice ────────────────────────────────────────────────────────── */

.badge,
.notice {
  border-radius: 20px;
  border: none;
}

.badge {
  min-height: 24px;
  padding: 3px 10px;
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.soft {
  background: rgba(0, 122, 255, 0.1);
  color: var(--blue);
}

.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.notice.warning {
  background: rgba(255, 159, 10, 0.1);
  color: #8a650f;
}

/* ─── Chat Shell (main layout) ──────────────────────────────────────────────── */

.chat-shell {
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  background: var(--panel);
  overflow: hidden;
  position: relative;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--sidebar);
  color: #fff;
}

.sidebar-header {
  min-height: 68px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.self-profile,
.conversation {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.self-profile {
  min-width: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  cursor: pointer;
}

.self-meta {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.self-meta strong,
.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.self-meta small,
.conversation-preview,
.conversation-side,
.chat-title p,
.profile-bio,
.profile-meta {
  color: var(--muted);
}

.sidebar .self-meta small,
.sidebar .conversation-preview,
.sidebar .conversation-side {
  color: rgba(255, 255, 255, 0.6);
}

.sidebar .icon-button {
  color: rgba(255, 255, 255, 0.6);
}

.sidebar .icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.chat-actions,
.composer-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
}

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

.icon-button:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}

.icon-button.subtle {
  width: 26px;
  height: 26px;
}

.search-box {
  margin: 0 12px 10px;
  height: 36px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
}

.search-box svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 1.8;
}

.search-box input {
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 14px;
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

/* ─── Conversation List ─────────────────────────────────────────────────────── */

.conversation-list {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.conversation {
  width: 100%;
  min-height: 64px;
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
  position: relative;
  border-bottom: 0.5px solid var(--line);
}

.conversation:last-child {
  border-bottom: none;
}

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

.conversation:active {
  background: var(--sidebar-active);
}

.conversation.active {
  background: var(--sidebar-active);
}

.conversation-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.conversation-title {
  font-weight: 600;
  font-size: 14px;
}

.conversation-preview {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-side {
  align-self: start;
  padding-top: 2px;
  font-size: 11px;
}

.unread-badge {
  position: absolute;
  bottom: 10px;
  right: 14px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.empty-list,
.empty-chat {
  color: var(--muted);
  text-align: center;
}

.empty-list {
  padding: 32px 16px;
  font-size: 14px;
}

/* ─── Chat Panel ────────────────────────────────────────────────────────────── */

.chat-panel {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--chat-bg);
}

.mobile-back-btn {
  display: none;
}

.chat-header {
  min-height: 64px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
  z-index: 20;
}

[data-theme="dark"] .chat-header {
  background: rgba(28, 28, 30, 0.92);
}

.chat-title {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.chat-title h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.chat-header-bio {
  margin-left: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

.chat-title p {
  margin-top: 2px;
  font-size: 12px;
}

.empty-chat {
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 24px;
}

.empty-chat strong {
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
}

/* ─── Messages ──────────────────────────────────────────────────────────────── */

.messages-list {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px 24px;
}

.date-divider,
.system-message {
  width: fit-content;
  max-width: 80%;
  margin: 16px auto;
  padding: 4px 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.system-message {
  background: rgba(0, 0, 0, 0.04);
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 6px 0;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-avatar {
  flex: 0 0 auto;
}

.message-bubble {
  max-width: min(70%, 600px);
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--bubble);
  animation: bubble-in 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.no-animate .message-bubble {
  animation: none;
}

@keyframes bubble-in {
  from { opacity: 0; transform: scale(0.96) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.message-bubble.sent-animate {
  animation: bubble-sent 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bubble-sent {
  0% { opacity: 0; transform: scale(0.6) translateY(20px); }
  50% { opacity: 1; transform: scale(1.03) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}


.message-row.mine .message-bubble {
  background: var(--bubble-me);
  border-radius: 18px 18px 4px 18px;
}

.message-row:not(.mine) .message-bubble {
  border-radius: 18px 18px 18px 4px;
}

.message-sender,
.message-meta {
  font-size: 11px;
  color: var(--muted);
}

.message-sender {
  margin-bottom: 3px;
  font-weight: 500;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
  font-size: 15px;
}

.message-text a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-quote {
  margin-bottom: 6px;
  padding: 6px 10px;
  border-left: 3px solid rgba(0, 0, 0, 0.12);
  border-radius: 0 6px 6px 0;
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.message-files {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.file-attachment {
  display: grid;
  gap: 6px;
}

.file-attachment img,
.file-attachment video,
.file-attachment iframe {
  max-width: min(280px, 100%);
  border-radius: var(--radius);
}

.file-attachment .img-placeholder {
  width: 200px;
  height: 150px;
  border-radius: var(--radius);
  background: var(--chat-bg);
  display: block;
  overflow: hidden;
}

.file-attachment .img-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.file-attachment .img-placeholder img.loaded {
  opacity: 1;
}

.file-attachment video {
  max-height: 280px;
  background: #000;
}

.file-attachment audio {
  width: min(320px, 100%);
}

.file-attachment iframe {
  width: min(380px, 100%);
  height: 240px;
  border: 1px solid var(--line);
}

.file-attachment.unavailable {
  opacity: 0.5;
}

.transcribe-btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 14px;
  cursor: pointer;
  margin-top: 4px;
}

.transcribe-btn:hover {
  background: rgba(10, 132, 255, 0.08);
}

.transcribe-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.transcribe-result {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-sm);
}

[data-theme="dark"] .transcribe-result {
  background: rgba(255, 255, 255, 0.05);
}

.attachment-image-link {
  display: block;
  width: fit-content;
  max-width: 100%;
}

.file-bubble {
  min-width: min(240px, 100%);
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.04);
}

.file-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(52, 199, 89, 0.12);
  color: var(--green-dark);
  font-size: 9px;
  font-weight: 800;
}

.file-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.file-text strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
}

.file-text small {
  color: var(--muted);
  font-size: 12px;
}

.message-meta {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.delivery-status {
  color: var(--green-dark);
}

.edited-label {
  font-style: italic;
  color: var(--soft);
}

.message-meta button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  font-size: 11px;
}

.message-meta button:hover {
  color: var(--blue);
}

/* ─── Manage Menu (dropdown) ─────────────────────────────────────────────────── */

.chat-header {
  position: relative;
}

.manage-menu {
  position: absolute;
  top: 58px;
  right: 16px;
  z-index: 10;
  min-width: 180px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.manage-menu-item {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.manage-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.manage-menu-item.danger {
  color: var(--danger);
}

.manage-menu-item.danger:hover {
  background: rgba(255, 59, 48, 0.08);
}

/* ─── Chat Search Bar ───────────────────────────────────────────────────────── */

.chat-search-bar {
  padding: 8px 12px;
  background: var(--chat-bg);
  position: relative;
  z-index: 5;
}

.chat-search-field {
  display: flex;
  align-items: center;
  height: 36px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 0 4px 0 14px;
  gap: 2px;
}

.chat-search-field:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.12);
}

.chat-search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 14px;
  outline: none;
}

.chat-search-field input:focus {
  box-shadow: none;
}

.chat-search-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 4px;
}

.chat-search-field .icon-button.subtle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-search-field .icon-button.subtle:hover {
  background: rgba(0, 0, 0, 0.06);
}

.chat-search-field .icon-button.subtle svg {
  width: 14px;
  height: 14px;
}

.search-highlight {
  background: rgba(255, 204, 0, 0.4);
  border-radius: 2px;
  padding: 1px 0;
}

.search-highlight.active {
  background: rgba(255, 149, 0, 0.55);
}

/* ─── Composer ──────────────────────────────────────────────────────────────── */

.composer {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}

[data-theme="dark"] .composer {
  background: rgba(28, 28, 30, 0.92);
}

.composer.dragover {
  box-shadow: inset 0 0 0 2px var(--blue);
}

.quote-bar,
.attachment-preview {
  margin: 10px 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.upload-progress {
  margin: 10px 14px 0;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: rgba(52, 199, 89, 0.06);
  border: 1px solid rgba(52, 199, 89, 0.2);
  position: relative;
  overflow: hidden;
}

.upload-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: rgba(52, 199, 89, 0.12);
  transition: width 0.2s ease;
}

.upload-progress-text {
  position: relative;
  z-index: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--green-dark);
  white-space: nowrap;
}

.quote-bar {
  min-height: 40px;
  padding: 8px 10px 8px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.quote-bar div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.quote-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview {
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.attachment-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.05);
  font-size: 13px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.composer-row {
  min-height: 56px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 68px;
  align-items: end;
  gap: 8px;
}

.composer-tools {
  padding-bottom: 4px;
}

.composer textarea {
  min-height: 36px;
  max-height: 140px;
  line-height: 1.45;
  background: var(--chat-bg);
  border: 0.5px solid var(--line-strong);
  border-radius: 18px;
  padding: 8px 14px;
  overflow-y: auto;
  scrollbar-width: none;
}

.composer textarea::-webkit-scrollbar {
  display: none;
}

.send-button {
  height: 34px;
  border-radius: 17px;
  font-size: 14px;
  min-height: 34px;
  padding: 0 14px;
}

/* ─── Voice Recorder ───────────────────────────────────────────────────────── */

.voice-recorder {
  min-height: 56px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 68px;
  align-items: center;
  gap: 8px;
}

.voice-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
}

.voice-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: voice-pulse 1s ease-in-out infinite;
}

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

.voice-timer {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ─── Profile Panel ─────────────────────────────────────────────────────────── */

.profile-panel {
  display: none;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  width: 100%;
  padding: 40px 48px;
  background: var(--chat-bg);
  overflow: auto;
  overscroll-behavior: contain;
  position: relative;
}

.profile-panel.open {
  display: block;
}

.profile-close-btn {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 40px;
  height: 40px;
}

.profile-close-btn svg {
  width: 24px;
  height: 24px;
}

.profile-view {
  display: grid;
  gap: 16px;
  justify-items: stretch;
  padding-top: 32px;
  max-width: 600px;
  margin: 0 auto;
}

.profile-form {
  display: block;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  justify-self: center;
  font-size: 30px;
  border-radius: 50%;
}

.profile-view h3,
.profile-bio {
  text-align: center;
}

.profile-bio {
  min-height: 22px;
  line-height: 1.5;
  font-size: 14px;
}

.profile-meta {
  display: grid;
  gap: 0;
  margin: 10px 0 0;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}

.profile-meta div {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--line);
}

.profile-meta div:last-child {
  border-bottom: none;
}

.profile-meta dt,
.profile-meta dd {
  margin: 0;
  font-size: 14px;
}

.profile-meta dt {
  color: var(--muted);
}

.profile-editor-head {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-top: 24px;
  margin-bottom: 8px;
}

.settings-display-name {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  margin: 0;
}

.settings-display-bio {
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

/* ─── Settings pages / navigation ──────────────────────────────────────────── */

.settings-page {
  display: grid;
  gap: 16px;
  max-width: 600px;
  margin: 0 auto;
  animation: settings-slide-in 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.settings-page.slide-back {
  animation: settings-slide-back 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes settings-slide-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes settings-slide-back {
  from { opacity: 0; transform: translateX(-40px); }
  to { opacity: 1; transform: translateX(0); }
}

.settings-back {
  display: flex;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--blue);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  margin: 0;
}

.settings-back svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
}

.settings-page-title {
  font-size: 34px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.4px;
}

.settings-group {
  background: var(--panel);
  border-radius: var(--radius);
}

.settings-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: none;
  border-bottom: 0.5px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 17px;
  text-align: left;
  cursor: pointer;
  gap: 12px;
}

.settings-cell > span:first-child {
  flex-shrink: 0;
}

.settings-cell:last-child {
  border-bottom: none;
}

.settings-cell:not(.static):active {
  background: rgba(0, 0, 0, 0.04);
  transition: background 0s;
}

.settings-cell svg {
  width: 18px;
  height: 18px;
  stroke: var(--muted);
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.settings-cell.static {
  cursor: default;
}

.settings-cell.danger span {
  color: var(--danger);
}

.settings-cell-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.settings-cell-right svg {
  width: 16px;
  height: 16px;
  stroke: var(--soft);
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.settings-value {
  color: var(--muted);
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.settings-color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.settings-cell.avatar-row {
  height: 58px;
}

.settings-avatar-sm {
  width: 40px;
  height: 40px;
  font-size: 15px;
  border-radius: 50%;
}

/* ─── Edit Modal (Level 3) ─────────────────────────────────────────────────── */

.edit-modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: var(--chat-bg);
  display: grid;
  grid-template-rows: auto 1fr;
  animation: edit-slide-up 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes edit-slide-up {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.edit-modal-bar {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  height: 44px;
  padding: 0 16px;
  border-bottom: 0.5px solid var(--line);
  background: var(--panel);
}

.edit-modal-cancel {
  border: none;
  background: transparent;
  color: var(--blue);
  font-size: 17px;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.edit-modal-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.edit-modal-done {
  border: none;
  background: transparent;
  color: var(--blue);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-align: right;
}

.edit-modal-body {
  padding: 20px 16px;
}

.edit-modal-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 0.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  outline: none;
}

.edit-modal-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.edit-modal-color {
  width: 100%;
  height: 60px;
  border: none;
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
}

.button.small {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

.toggle-btn {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  border: none;
  background: var(--soft);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-btn::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.toggle-btn.active {
  background: var(--green);
}

.toggle-btn.active::after {
  transform: translateX(18px);
}

/* ─── Avatar ────────────────────────────────────────────────────────────────── */

.avatar {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Status Dot ────────────────────────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.25);
}

.status-dot.offline {
  background: var(--soft);
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */

.toast-rack {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(60px + env(safe-area-inset-top, 0));
  z-index: 100;
  display: grid;
  gap: 8px;
  justify-items: center;
}

.toast {
  max-width: 300px;
  padding: 12px 20px;
  border-radius: 20px;
  background: rgba(45, 45, 45, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.error {
  background: rgba(255, 59, 48, 0.9);
}

/* ─── Crop Modal ────────────────────────────────────────────────────────────── */

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.crop-dialog {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.crop-dialog h3 {
  text-align: center;
}

.crop-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #000;
  cursor: grab;
  touch-action: none;
}

.crop-container:active {
  cursor: grabbing;
}

.crop-container canvas {
  position: absolute;
  top: 0;
  left: 0;
}

.crop-circle {
  position: absolute;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

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

/* ─── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
  .chat-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .chat-shell {
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  /* ─── Mobile: sidebar as full-screen conversation list ──────────────────── */

  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 30;
    background: var(--panel);
    color: var(--text);
    grid-template-rows: auto auto minmax(0, 1fr);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .chat-shell.mobile-chat-open .sidebar {
    transform: translateX(-30%);
    pointer-events: none;
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
  }

  .sidebar-header {
    min-height: 56px;
    padding: 12px 16px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }

  .self-profile {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 12px;
  }

  .self-meta {
    display: grid;
  }

  .self-meta strong {
    color: var(--text);
    font-size: 17px;
    font-weight: 600;
  }

  .self-meta small {
    color: var(--muted);
    font-size: 12px;
  }

  .sidebar .self-meta small {
    color: var(--muted);
  }

  .search-box {
    margin: 0;
    padding: 8px 16px;
    height: 52px;
    background: var(--panel);
    border-radius: 0;
    border: none;
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
  }

  .search-box::before {
    content: '';
    position: absolute;
    inset: 8px 16px;
    background: rgba(120, 120, 128, 0.08);
    border-radius: 10px;
    pointer-events: none;
  }

  .search-box svg {
    position: relative;
    stroke: var(--muted);
    margin-left: 10px;
  }

  .search-box input {
    position: relative;
    color: var(--text);
    font-size: 16px;
    background: transparent;
  }

  .search-box input::placeholder {
    color: var(--muted);
  }

  .sidebar .icon-button {
    color: var(--muted);
  }

  .sidebar .icon-button:hover {
    background: transparent;
    color: var(--muted);
  }

  .sidebar .icon-button:active {
    color: var(--text);
  }

  .conversation-list {
    background: var(--panel);
  }

  .conversation {
    min-height: 68px;
    padding: 12px 16px;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 12px;
  }

  .conversation:hover {
    background: transparent;
  }

  .conversation:active {
    background: rgba(0, 0, 0, 0.05);
    transition: background 0s;
  }

  .conversation.active {
    background: transparent;
  }

  .conversation .avatar {
    width: 48px;
    height: 48px;
    font-size: 17px;
  }

  .conversation-main {
    display: grid;
    gap: 4px;
  }

  .conversation-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
  }

  .conversation-preview {
    font-size: 14px;
    color: var(--muted);
  }

  .conversation-side {
    align-self: start;
    padding-top: 4px;
    font-size: 12px;
    color: var(--muted);
  }

  .sidebar .conversation-preview,
  .sidebar .conversation-side {
    color: var(--muted);
  }

  .conversation .unread-badge {
    position: absolute;
    bottom: 14px;
    right: 16px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
    border-radius: 9px;
  }

  /* ─── Mobile: chat panel full-screen ────────────────────────────────────── */

  .chat-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .chat-header {
    padding: 10px 12px;
    min-height: 52px;
    gap: 8px;
  }

  .mobile-back-btn {
    display: inline-grid;
  }

  .chat-title {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
  }

  .chat-title .avatar {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .chat-title h2 {
    font-size: 16px;
  }

  .chat-title p {
    font-size: 11px;
  }

  .messages-list {
    padding: 10px 12px 18px;
  }

  .message-row {
    gap: 8px;
  }

  .message-bubble {
    max-width: 80%;
    padding: 10px 12px;
    font-size: 15px;
  }

  .message-avatar {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .composer-row {
    grid-template-columns: auto minmax(0, 1fr) 52px;
    padding: 8px 10px;
    gap: 6px;
    min-height: 50px;
  }

  .composer-tools {
    gap: 2px;
  }

  .composer-tools .icon-button {
    width: 32px;
    height: 32px;
  }

  .send-button {
    height: 34px;
    font-size: 14px;
    padding: 0 10px;
  }

  .composer textarea {
    min-height: 34px;
    font-size: 15px;
    padding: 7px 14px;
    border-radius: 18px;
  }

  /* ─── Mobile: profile panel ─────────────────────────────────────────────── */

  .profile-panel {
    position: fixed;
    inset: 0;
    z-index: 40;
    max-width: none;
    padding: 0;
    padding-top: env(safe-area-inset-top, 0);
    display: block !important;
    overflow-y: auto;
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.15s ease;
  }

  .profile-panel.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .profile-panel > .profile-view,
  .profile-panel > .profile-form {
    padding: 48px 20px 24px;
  }

  .profile-close-btn {
    top: calc(12px + env(safe-area-inset-top, 0));
    right: 12px;
    z-index: 2;
  }

  .profile-avatar {
    width: 72px;
    height: 72px;
    font-size: 26px;
  }
}

/* ─── Safe Area (iOS PWA) ───────────────────────────────────────────────────── */

@supports (padding-top: env(safe-area-inset-top)) {
  .chat-shell {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar {
    padding-top: env(safe-area-inset-top);
  }

  .composer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
