:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: rgba(16, 19, 24, 0.78);
  --surface-solid: #111419;
  --surface-hover: rgba(255, 255, 255, 0.045);
  --text: #f2f3f5;
  --muted: #8f98a5;
  --muted-strong: #bac0c8;
  --line: rgba(255, 255, 255, 0.085);
  --line-strong: rgba(255, 255, 255, 0.15);
  --accent: #8ca0ff;
  --accent-soft: rgba(140, 160, 255, 0.13);
  --danger: #ff8495;
  --canvas-alpha: .44;
  --shadow: 0 24px 80px rgba(0, 0, 0, .28);
  --radius: 20px;
  --content: 760px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-hover: rgba(20, 28, 38, 0.04);
  --text: #17191d;
  --muted: #717986;
  --muted-strong: #4e5661;
  --line: rgba(20, 28, 38, 0.085);
  --line-strong: rgba(20, 28, 38, 0.14);
  --accent: #596dd8;
  --accent-soft: rgba(89, 109, 216, 0.10);
  --danger: #c74c60;
  --canvas-alpha: .23;
  --shadow: 0 24px 70px rgba(53, 61, 74, .10);
}

* { box-sizing: border-box; }
html { min-width: 300px; min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.ambient-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: var(--canvas-alpha);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 1120px);
  min-height: 100svh;
  margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.site-header {
  min-height: 76px;
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 720;
  letter-spacing: -.02em;
}

.brand-mark {
  position: relative;
  width: 24px;
  height: 16px;
  display: inline-block;
}
.brand-mark::before,
.brand-mark::after,
.brand-mark span::before,
.brand-mark span::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: currentColor;
}
.brand-mark::before { width: 5px; height: 5px; left: 1px; top: 6px; }
.brand-mark::after { width: 5px; height: 5px; right: 1px; top: 6px; }
.brand-mark span:first-child::before { width: 11px; height: 1px; left: 6px; top: 8px; border-radius: 0; opacity: .8; }
.brand-mark span:first-child::after { width: 3px; height: 3px; left: 11px; top: 7px; background: var(--accent); }

.theme-toggle {
  min-height: 40px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  color: var(--muted-strong);
}
.theme-toggle:hover { background: var(--surface-hover); }
.theme-icon {
  position: relative;
  width: 15px;
  height: 15px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
}
.theme-icon::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  right: -4px;
  top: -3px;
  border-radius: 50%;
  background: var(--surface-solid);
  transition: transform .2s ease, opacity .2s ease;
}
html[data-theme="light"] .theme-icon::after { opacity: 0; transform: scale(.5); }
.theme-text { font-size: 12px; font-weight: 650; }

.workspace {
  display: grid;
  place-items: center;
  padding: clamp(32px, 7vh, 84px) 0;
}

.setup-panel {
  width: min(100%, var(--content));
  padding: clamp(20px, 3vw, 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-solid) 75%, transparent);
}
.mode-tab {
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 680;
  white-space: nowrap;
}
.mode-tab:hover { color: var(--text); background: var(--surface-hover); }
.mode-tab.is-active {
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: 0 1px 0 var(--line-strong), 0 8px 24px rgba(0,0,0,.08);
}

.setup-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-top: clamp(30px, 5vw, 44px);
}
.mode-caption {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.setup-heading h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
  letter-spacing: -.045em;
  font-weight: 720;
}
.memory-state {
  flex: 0 0 auto;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
}
.memory-state i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.mode-description {
  max-width: 610px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}


.runtime-warning {
  margin: 18px 0 0;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 36%, var(--line));
  border-radius: 11px;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--muted-strong);
  font-size: 12px;
  line-height: 1.65;
}

.session-form { margin-top: clamp(30px, 5vw, 42px); }
.field {
  display: grid;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 670;
}
.field + .field { margin-top: 18px; }
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-solid) 72%, transparent);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
  resize: vertical;
}
.field input { min-height: 48px; }
.field textarea { min-height: 88px; }
.field input::placeholder,
.field textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.field input:focus,
.field textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 66%, var(--line));
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.intent-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 18px 0 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-solid) 64%, transparent);
}
.intent-switch label { position: relative; cursor: pointer; }
.intent-switch input { position: absolute; opacity: 0; pointer-events: none; }
.intent-switch span {
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 690;
}
.intent-switch input:checked + span {
  background: var(--surface-solid);
  color: var(--text);
}

.join-field { margin-top: 18px; }
.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.form-footer p {
  max-width: 430px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}
.primary-button,
.danger-ghost {
  min-height: 44px;
  border-radius: 11px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 720;
}
.primary-button {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: var(--text);
  color: var(--bg);
}
.primary-button:hover { opacity: .9; }

.security-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 10px;
}
.security-line i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .55;
}

.site-footer {
  min-height: 58px;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .02em;
}

.session-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.session-panel {
  width: min(100%, 1040px);
  height: min(100%, 760px);
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.session-topbar {
  min-height: 76px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.session-topbar .mode-caption { margin-bottom: 4px; }
.session-topbar h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.danger-ghost {
  border: 1px solid color-mix(in srgb, var(--danger) 32%, var(--line));
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  color: var(--danger);
}
.session-placeholder {
  height: calc(100% - 76px);
  padding: 28px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}
.session-placeholder h3 { margin: 18px 0 8px; font-size: 20px; }
.session-placeholder p { max-width: 520px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.connection-glyph {
  position: relative;
  width: 88px;
  height: 28px;
}
.connection-glyph span {
  position: absolute;
  top: 7px;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-solid);
}
.connection-glyph span:first-child { left: 3px; }
.connection-glyph span:nth-child(2) { right: 3px; }
.connection-glyph i {
  position: absolute;
  left: 17px;
  right: 17px;
  top: 13px;
  height: 1px;
  background: linear-gradient(90deg, var(--line), var(--accent), var(--line));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
[hidden] { display: none !important; }

@media (max-width: 640px) {
  .app-shell {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .site-header { min-height: 64px; }
  .theme-toggle { width: 40px; padding: 0; justify-content: center; }
  .theme-text { display: none; }
  .workspace { align-items: start; padding: 22px 0 34px; }
  .setup-panel { border-radius: 16px; padding: 18px; }
  .mode-switch { grid-template-columns: 1fr; gap: 2px; }
  .mode-tab { min-height: 38px; }
  .setup-heading { margin-top: 28px; }
  .memory-state { display: none; }
  .setup-heading h1 { font-size: 30px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; min-height: 48px; }
  .security-line { gap: 8px; }
  .site-footer { min-height: 54px; }
  .site-footer span:last-child { display: none; }
  .session-topbar { align-items: flex-start; }
  .danger-ghost { min-height: 40px; padding: 0 12px; font-size: 12px; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .workspace { padding: 48px 0; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .site-header { min-height: 56px; }
  .workspace { padding: 18px 0; place-items: start center; }
  .setup-heading { margin-top: 24px; }
  .session-form { margin-top: 24px; }
  .site-footer { min-height: 48px; }
}

@media (hover: none) and (pointer: coarse) {
  .mode-tab,
  .theme-toggle,
  .primary-button,
  .danger-ghost { min-height: 44px; }
  .field input { min-height: 48px; }
}

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

.session-meta,
.invite-output {
  width: min(100%, 620px);
  margin-top: 22px;
  text-align: left;
}
.session-meta {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-solid) 58%, transparent);
}
.meta-row {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--muted);
  font-size: 11px;
}
.meta-row code {
  overflow: hidden;
  color: var(--muted-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.invite-output > label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 700;
}
.invite-copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}
.invite-copy-row textarea {
  width: 100%;
  min-height: 84px;
  padding: 11px 12px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface-solid) 72%, transparent);
  color: var(--text);
  font: 10px/1.55 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.secondary-button {
  min-width: 68px;
  min-height: 44px;
  padding: 0 13px;
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-solid);
  color: var(--muted-strong);
  cursor: pointer;
  font-weight: 700;
}
.secondary-button:hover { background: var(--surface-hover); color: var(--text); }
.invite-output > p {
  margin-top: 8px;
  font-size: 10px;
  line-height: 1.55;
}
.primary-button:disabled {
  cursor: wait;
  opacity: .55;
}

@media (max-width: 640px) {
  .invite-copy-row { grid-template-columns: 1fr; }
  .secondary-button { width: 100%; min-height: 44px; }
  .meta-row { align-items: flex-start; flex-direction: column; gap: 4px; }
  .meta-row code { width: 100%; }
}

#safetyCode {
  color: var(--text);
  letter-spacing: .08em;
  font-weight: 760;
}
#networkState[data-state="ready"] { color: var(--accent); }
#networkState[data-state="error"] { color: var(--danger); }

/* Stage 4/5 chat surfaces */
.direct-chat,
.group-chat {
  height: calc(100% - 76px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
}

.chat-statusbar,
.group-statusbar {
  min-height: 58px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 55%, transparent);
}

.peer-summary {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.peer-summary > div { min-width: 0; display: grid; gap: 2px; }
.peer-summary strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.peer-summary span:not(.presence-dot) {
  color: var(--muted);
  font-size: 10px;
}
.presence-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 10%, transparent);
}
.presence-dot[data-state="ready"] {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.presence-dot[data-state="error"] {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 10%, transparent);
}

.chat-status-actions,
.group-status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.latency-text {
  color: var(--muted);
  font: 10px/1.3 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.text-button {
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.text-button:hover { background: var(--surface-hover); color: var(--text); }

.security-drawer {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent-soft) 46%, transparent);
}
.security-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
}
.security-grid > div { min-width: 0; display: grid; gap: 3px; }
.security-grid span { color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.security-grid code,
.security-grid strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted-strong);
  font-size: 11px;
}
.security-drawer .compact-button { margin-top: 12px; }

.chat-messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(14px, 2.4vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.chat-empty {
  margin: auto;
  display: grid;
  place-items: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}
.chat-empty span {
  width: 30px;
  height: 20px;
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}
.chat-empty span::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 1px;
  left: 10px;
  top: 9px;
  background: var(--accent);
}
.chat-empty p { margin: 0; font-size: 11px; line-height: 1.6; }
.message-row {
  width: min(78%, 640px);
  display: grid;
  gap: 4px;
  align-self: flex-start;
}
.message-row.is-own { align-self: flex-end; }
.message-meta {
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 9px;
}
.message-row.is-own .message-meta { flex-direction: row-reverse; }
.message-bubble {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 13px 13px 13px 5px;
  background: var(--surface-solid);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.55;
}
.message-row.is-own .message-bubble {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 13px 13px 5px 13px;
  background: color-mix(in srgb, var(--accent-soft) 62%, var(--surface-solid));
}

.chat-composer {
  position: relative;
  padding: 12px 14px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 67%, transparent);
}
.chat-composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 150px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface-solid) 86%, transparent);
  color: var(--text);
  outline: 0;
  line-height: 1.45;
}
.chat-composer textarea:focus { border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); }
.send-button {
  min-width: 72px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  font-weight: 720;
}
.send-button:disabled { cursor: not-allowed; opacity: .45; }
.composer-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 9px;
}
.reconnect-bar {
  min-height: 44px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid color-mix(in srgb, var(--danger) 25%, var(--line));
  background: color-mix(in srgb, var(--danger) 6%, transparent);
  color: var(--muted-strong);
  font-size: 11px;
}
.compact-button { min-height: 34px; padding: 0 10px; align-self: auto; font-size: 10px; }

/* Host-group */
.group-chat { grid-template-rows: auto minmax(0, 1fr); }
.group-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}
.group-sidebar {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 48%, transparent);
}
.group-side-section { padding: 14px; border-bottom: 1px solid var(--line); }
.group-side-section:last-child { border-bottom: 0; }
.side-heading {
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.side-heading strong { font-size: 11px; }
.side-heading span { color: var(--muted); font-size: 9px; }
.group-side-section textarea {
  width: 100%;
  min-height: 70px;
  padding: 9px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-solid);
  color: var(--muted-strong);
  font: 9px/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.group-side-section .secondary-button { width: 100%; margin-top: 7px; }
.member-list { display: grid; gap: 6px; }
.member-item {
  min-width: 0;
  padding: 8px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
}
.member-item:hover { border-color: var(--line); background: var(--surface-hover); }
.member-monogram {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-solid);
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 760;
}
.member-info { min-width: 0; display: grid; gap: 2px; }
.member-info strong,
.member-info code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-info strong { font-size: 10px; }
.member-info code { color: var(--muted); font-size: 8px; }
.member-role { color: var(--muted); font-size: 8px; }
.member-actions { display: flex; gap: 4px; }
.member-action {
  min-height: 28px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
}
.member-action:hover { background: var(--surface-hover); color: var(--text); }
.member-action.is-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }

.group-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  position: relative;
}
.group-waiting {
  position: absolute;
  inset: 0 0 69px;
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 24px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  text-align: center;
}
.group-waiting strong { font-size: 14px; }
.group-waiting p { max-width: 390px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.waiting-mark {
  width: 34px;
  height: 34px;
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}
.waiting-mark::before,
.waiting-mark::after {
  content: "";
  position: absolute;
  top: 16px;
  width: 7px;
  height: 1px;
  background: var(--accent);
}
.waiting-mark::before { left: 7px; }
.waiting-mark::after { right: 7px; }

@media (max-width: 820px) {
  .session-view { padding: 0; }
  .session-panel { width: 100%; height: 100%; border: 0; border-radius: 0; }
  .session-topbar { min-height: 66px; padding-top: max(12px, env(safe-area-inset-top)); }
  .direct-chat,
  .group-chat { height: calc(100% - 66px); }
  .group-layout { grid-template-columns: 1fr; position: relative; }
  .group-sidebar {
    position: absolute;
    z-index: 8;
    inset: 0 0 0 auto;
    width: min(88vw, 320px);
    border-right: 0;
    border-left: 1px solid var(--line);
    box-shadow: -20px 0 60px rgba(0,0,0,.22);
    background: var(--surface-solid);
    transform: translateX(0);
  }
  .group-sidebar.is-collapsed { transform: translateX(102%); }
  .group-main { grid-column: 1; }
}

@media (max-width: 640px) {
  .chat-statusbar,
  .group-statusbar { min-height: 54px; padding: 8px 10px; }
  .chat-status-actions,
  .group-status-actions { gap: 6px; }
  .message-row { width: min(88%, 620px); }
  .chat-messages { padding: 12px 10px; gap: 10px; }
  .chat-composer { padding: 9px 10px max(9px, env(safe-area-inset-bottom)); }
  .send-button { min-width: 64px; }
  .desktop-send-hint { display: none; }
  .security-grid { grid-template-columns: 1fr; }
  .group-waiting { inset-bottom: 66px; }
}

@media (hover: none) and (pointer: coarse) {
  .text-button,
  .send-button,
  .secondary-button,
  .member-action { min-height: 44px; }
  .chat-composer textarea { min-height: 48px; }
}
