:root {
  --app-vh: 1vh;
  --bg-0: #0a1526;
  --bg-1: #0f2139;
  --bg-2: #143050;
  --line: #244464;
  --text: #d6e5ff;
  --text-muted: #9eb7d6;
  --accent: #5db4ff;
  --accent-electric: #2be2ff;
  --warn: #d94848;
  --ok: #5ce0b3;
  --shadow: rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 20%, rgba(32, 74, 118, 0.15), transparent 50%),
    radial-gradient(circle at 80% 10%, rgba(42, 100, 155, 0.1), transparent 45%),
    var(--bg-0);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  min-height: 100%;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.6) 1px, transparent 1.5px);
  background-size: 3px 3px;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  height: calc(var(--app-vh, 1vh) * 100);
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(10, 21, 38, 0.9);
  backdrop-filter: blur(6px);
  z-index: 6;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-wrap {
  position: relative;
}

.brand-link {
  color: var(--text);
  text-decoration: none;
}

.brand-link:hover,
.brand-link:focus-visible {
  color: var(--accent-electric);
}

.brand-hover-card {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(520px, calc(100vw - 32px));
  background: rgba(10, 21, 38, 0.98);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 9;
}

.brand-wrap:hover .brand-hover-card,
.brand-wrap:focus-within .brand-hover-card {
  opacity: 1;
  transform: translateY(0);
}

.brand-hover-title {
  font-weight: 700;
  color: var(--accent-electric);
  margin-bottom: 4px;
}

.brand-hover-body {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.mobile-preview-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--text-muted);
  background: rgba(15, 33, 57, 0.85);
  text-decoration: none;
  font-size: 12px;
  line-height: 1;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.mobile-preview-link:hover,
.mobile-preview-link:focus-visible {
  border-color: var(--accent);
  color: var(--accent-electric);
  background: rgba(20, 48, 80, 0.88);
}

.hidden {
  display: none !important;
}

button,
select,
input,
textarea {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

button {
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

button:hover {
  border-color: var(--accent);
  background: var(--bg-2);
}

button:active { transform: scale(0.99); }

button.primary {
  border-color: var(--accent-electric);
  box-shadow: 0 0 0 1px rgba(43, 226, 255, 0.22) inset;
}

.search-shell {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: min(360px, calc(100vw - max(36px, env(safe-area-inset-left) + env(safe-area-inset-right) + 16px)));
  max-height: 280px;
  overflow: auto;
  background: rgba(10, 21, 38, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
  z-index: 6;
  padding: 6px;
}

.search-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 2px;
  margin-bottom: 6px;
}

.search-item:last-child {
  margin-bottom: 0;
}

.search-item-title {
  font-size: 13px;
  color: var(--text);
}

.search-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.handle-indicator {
  border-radius: 999px;
  border-color: rgba(93, 180, 255, 0.55);
  color: var(--accent-electric);
  background: rgba(13, 36, 58, 0.88);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.device-indicator {
  border-radius: 999px;
  border: 1px solid rgba(93, 180, 255, 0.38);
  background: rgba(13, 36, 58, 0.68);
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 5px 10px;
  white-space: nowrap;
}

.friend-beacon {
  border-radius: 999px;
  border-color: rgba(43, 226, 255, 0.55);
  color: #d6fbff;
  background: radial-gradient(circle at 30% 30%, rgba(214, 251, 255, 0.2), rgba(13, 36, 58, 0.9));
  font-weight: 600;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-beacon:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.friend-beacon.beacon-pulse {
  animation: beaconPulse 880ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes beaconPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(214, 251, 255, 0.72);
    transform: translateY(0);
  }
  35% {
    box-shadow: 0 0 0 8px rgba(214, 251, 255, 0.14);
    transform: translateY(-1px);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(214, 251, 255, 0);
    transform: translateY(0);
  }
}

.mini-avatar {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.mini-avatar.placeholder {
  background: rgba(20, 48, 80, 0.9);
}

.verify-dot {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
  border: 1px solid transparent;
}

.verify-dot.verified {
  color: #0f2a1d;
  background: #5ce0b3;
  border-color: #5ce0b3;
}

.verify-dot.unverified {
  color: #3a0f0f;
  background: #d94848;
  border-color: #d94848;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: var(--accent-electric);
  border-color: rgba(93, 180, 255, 0.55);
  background: radial-gradient(circle at 30% 30%, rgba(43, 226, 255, 0.18), rgba(15, 33, 57, 0.88));
}

.settings-menu {
  position: fixed;
  top: calc(max(6px, env(safe-area-inset-top)) + 54px);
  right: max(10px, env(safe-area-inset-right));
  width: min(520px, calc(100vw - max(20px, env(safe-area-inset-left) + env(safe-area-inset-right) + 20px)));
  max-height: calc(100dvh - max(6px, env(safe-area-inset-top)) - env(safe-area-inset-bottom) - 66px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(10, 21, 38, 0.97);
  border: 1px solid var(--line);
  border-radius: 10px;
  z-index: 120;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
  -webkit-overflow-scrolling: touch;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h3 {
  margin: 0;
}

.settings-close-btn {
  font-size: 22px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-secondary, #aaa);
  cursor: pointer;
}

.settings-tabs {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.settings-tab {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}

.settings-tab.active {
  border-color: var(--accent-electric);
  color: var(--accent-electric);
  background: rgba(19, 52, 82, 0.8);
}

.settings-panels {
  margin-top: 10px;
}

.profile-grid {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.mission-search-row {
  display: flex;
  gap: 8px;
}

.mission-search-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.mission-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-preview {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: rgba(20, 48, 80, 0.9);
}

.profile-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.social-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.social-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(11, 26, 44, 0.72);
}

.social-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.social-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

main {
  display: grid;
  grid-template-columns: 1fr 360px;
  min-height: 0;
  overflow: hidden;
}

#app.planet-mode main {
  grid-template-columns: minmax(320px, 42%) minmax(520px, 58%);
}

#app[data-device="tablet"][data-orientation="portrait"] main {
  grid-template-columns: 1fr;
  grid-template-rows: 48dvh 52dvh;
}

#app[data-device="tablet"][data-orientation="portrait"].planet-mode main {
  grid-template-columns: 1fr;
  grid-template-rows: 34dvh 66dvh;
}

#app[data-device="phone"] main {
  grid-template-columns: 1fr;
  grid-template-rows: 44dvh 56dvh;
}

#app[data-device="phone"].planet-mode main {
  grid-template-columns: 1fr;
  grid-template-rows: 34dvh 66dvh;
}

#space-view {
  position: relative;
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#app[data-device="tablet"] .controls,
#app[data-device="phone"] .controls {
  width: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
}

#app[data-device="tablet"] .controls > :not(#mode-pill):not(#settings-toggle):not(#mobile-return),
#app[data-device="phone"] .controls > :not(#mode-pill):not(#settings-toggle):not(#mobile-return) {
  display: none !important;
}

#app[data-device="tablet"] .topbar,
#app[data-device="phone"] .topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

#app[data-device="tablet"] .mode-pill,
#app[data-device="phone"] .mode-pill {
  font-size: 10px;
  padding: 4px 8px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

#app[data-device="phone"] .topbar {
  min-height: 48px;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  gap: 8px;
  z-index: 70;
}

#app[data-device="phone"] .brand {
  font-size: 12px;
  letter-spacing: 0.06em;
}

#app[data-device="phone"] .controls {
  gap: 6px;
  position: relative;
  z-index: 80;
}

#app[data-device="tablet"] .mobile-return,
#app[data-device="phone"] .mobile-return {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 10px;
  font-size: 11px;
}

#app[data-device="phone"] #settings-toggle {
  position: relative;
  z-index: 90;
  pointer-events: auto;
}

#app[data-device="tablet"] .settings-menu,
#app[data-device="phone"] .settings-menu {
  top: max(6px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  width: auto;
  max-height: calc(var(--visible-vh, 100vh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px);
}

#cy {
  width: 100%;
  height: 100%;
}

#planet-view {
  background: linear-gradient(180deg, rgba(15, 33, 57, 0.95), rgba(10, 21, 38, 0.95));
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.planet-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.08fr) minmax(320px, 0.92fr);
  gap: 10px;
  min-height: 0;
  height: 100%;
}

.planet-column {
  min-height: 0;
  overflow: auto;
  border-left: 1px solid rgba(36, 68, 100, 0.35);
}

.planet-column:first-child {
  border-left: none;
}

.section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.kv,
.trajectory,
.chat-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: rgba(11, 26, 44, 0.75);
}

.kv-key { color: var(--text-muted); font-size: 12px; }
.kv-value { margin-top: 4px; font-size: 13px; word-break: break-word; }

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.mode-pill {
  border-radius: 999px;
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid var(--line);
}

.mode-pill.offline { color: var(--ok); }
.mode-pill.backend { color: var(--accent-electric); }

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

.breadcrumb {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  background: rgba(10, 21, 38, 0.8);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: default;
  user-select: none;
}

.breadcrumb.is-actionable {
  cursor: pointer;
  border-color: color-mix(in srgb, var(--accent-electric) 55%, var(--line));
  color: color-mix(in srgb, var(--accent-electric) 82%, var(--text));
}

.breadcrumb.is-actionable:hover {
  background: color-mix(in srgb, rgba(10, 21, 38, 0.8) 70%, var(--accent-electric) 30%);
}

.breadcrumb.is-actionable:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent-electric) 65%, #ffffff 35%);
  outline-offset: 2px;
}

.life-legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  display: grid;
  gap: 4px;
  background: rgba(10, 21, 38, 0.84);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.life-legend strong {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

.life-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.edge-hover-card {
  position: absolute;
  z-index: 6;
  width: min(360px, calc(100% - 24px));
  max-height: min(260px, calc(100% - 24px));
  overflow: auto;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(10, 21, 38, 0.96);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.34);
  pointer-events: none;
}

.edge-hover-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.edge-hover-title span {
  color: var(--accent-electric);
}

.edge-hover-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.edge-hover-section {
  border-top: 1px solid rgba(36, 68, 100, 0.55);
  padding-top: 7px;
  margin-top: 7px;
}

.edge-hover-label {
  color: var(--accent-electric);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.life-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
}

.life-dot.active {
  background: #2be2ff;
  box-shadow: 0 0 10px rgba(43, 226, 255, 0.75);
}

.life-dot.friend {
  background: #d6fbff;
  box-shadow: 0 0 12px rgba(214, 251, 255, 0.9);
}

.panel-scroll {
  overflow: auto;
  min-height: 0;
}

.planet-actions {
  display: grid;
  gap: 8px;
}

.planet-actions-inline {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.node-url-input {
  width: 100%;
  font-size: 12px;
}

.planet-identity {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--planet-border, var(--line));
  background: linear-gradient(180deg, color-mix(in srgb, var(--planet-fill, var(--bg-1)) 55%, transparent), transparent);
  border-left: 3px solid var(--planet-accent, var(--accent));
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: center;
}

.planet-identity::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.22;
  pointer-events: none;
  background-image: var(--planet-texture-image);
  background-size: 96px 96px;
  background-repeat: repeat;
  mix-blend-mode: screen;
}

.planet-identity::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 8px;
  border: calc(1px + var(--planet-ring, 1) * 0.4px) solid color-mix(in srgb, var(--planet-accent, var(--accent)) calc(22% + var(--planet-accent-strength, 0.4) * 50%), transparent);
  opacity: calc(0.22 + var(--planet-brightness, 0.2));
  pointer-events: none;
}

.planet-glyph {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--planet-border, var(--line));
  display: grid;
  place-items: center;
  color: var(--planet-accent, var(--accent));
  font-weight: 700;
  background: rgba(10, 21, 38, 0.6);
}

.planet-title {
  font-size: 16px;
  font-weight: 600;
  margin: 2px 0 4px;
}

.neighbor-card {
  background: rgba(12, 30, 50, 0.78);
}

.trajectory.low-certainty {
  opacity: 0.6;
  border-style: dashed;
}

.comms-open {
  border-left: 2px solid color-mix(in srgb, var(--accent-electric) 66%, transparent);
}

.active-channel-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  background: var(--accent-electric);
  box-shadow: 0 0 10px rgba(43, 226, 255, 0.75);
}

#chat-section {
  min-height: 300px;
}

.identity-hint {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.identity-hint button {
  padding: 3px 8px;
  font-size: 12px;
}

.chat-log {
  max-height: 280px;
  overflow: auto;
  padding-right: 4px;
}

.chat-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.chat-avatar {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.chat-avatar.placeholder {
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(20, 48, 80, 0.9);
}

textarea { width: 100%; min-height: 64px; resize: vertical; }

@media (max-width: 1320px) {
  .controls {
    gap: 8px;
  }

  .search-shell input {
    width: min(36vw, 280px);
  }
}

@media (max-width: 1000px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 52dvh 48dvh;
  }

  #app.planet-mode main {
    grid-template-columns: 1fr;
    grid-template-rows: 36dvh 64dvh;
  }

  .planet-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  #space-view { border-right: none; border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar {
    align-items: center;
    padding-bottom: 10px;
  }

  .brand-wrap {
    width: auto;
    min-width: 0;
  }

  .controls {
    width: auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
  }

  .controls > * {
    min-width: 0;
  }

  #settings-toggle {
    justify-self: end;
  }

  .settings-menu {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .profile-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

#comms-dock-root {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  pointer-events: none;
  touch-action: manipulation;
}

#comms-dock-root.touch-dock {
  pointer-events: auto;
}

#app.settings-open #comms-dock-root {
  display: none;
}

.comms-shell {
  position: relative;
  pointer-events: auto;
}

#comms-dock-root .comms-shell-collapsed {
  pointer-events: auto;
}

.comms-console {
  width: min(520px, 52vw);
  min-width: 360px;
  max-height: calc(calc(var(--app-vh, 1vh) * 100) - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(7, 24, 44, 0.94), rgba(3, 14, 26, 0.98));
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}

.comms-console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
}

.comms-console-title {
  flex: 1 1 auto;
  min-width: 0;
  cursor: grab;
  user-select: none;
}

.comms-console-title .small {
  overflow-wrap: anywhere;
  word-break: break-word;
}

#comms-dock-root.touch-dock .comms-console-title,
#comms-dock-root.touch-dock .comms-collapsed-handle {
  cursor: default;
}

.comms-head-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  margin-left: auto;
  gap: 6px;
}

#comms-dock-root.dragging .comms-console-title,
#comms-dock-root.dragging .comms-collapsed-handle {
  cursor: grabbing;
}

.comms-console-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px 6px;
}

.comms-console-controls .small {
  flex: 1 1 100%;
}

.comms-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 1px solid rgba(101, 176, 255, 0.25);
  border-radius: 999px;
  background: rgba(9, 30, 52, 0.75);
}

.comms-mode-toggle button {
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.2;
  padding: 5px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
}

.comms-mode-toggle button.active {
  border-color: rgba(43, 226, 255, 0.55);
  color: #d9f7ff;
  background: rgba(43, 226, 255, 0.18);
}

.comms-console-log {
  min-height: 120px;
  max-height: 220px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 6px 12px;
  border-top: 1px solid rgba(101, 176, 255, 0.15);
  border-bottom: 1px solid rgba(101, 176, 255, 0.15);
}

.comms-msg {
  display: grid;
  gap: 2px;
  margin-bottom: 6px;
}

.comms-msg strong {
  font-size: 11px;
  color: #9ec6ff;
}

.comms-msg span {
  font-size: 12px;
}

.comms-console-compose {
  padding: 8px 12px 10px;
}

.comms-console-compose textarea {
  min-height: 60px;
}

.comms-config {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: calc(var(--app-vh, 1vh) * 100);
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(6, 22, 40, 0.98), rgba(3, 14, 26, 0.99));
  box-shadow: -12px 0 30px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  transition: transform 180ms ease;
  will-change: transform;
  z-index: 100;
  pointer-events: auto;
}

.comms-config.open {
  transform: translateX(0);
}

.comms-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.comms-config-body {
  max-height: calc(calc(var(--app-vh, 1vh) * 100) - 56px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 10px;
}

.comms-block {
  padding: 8px;
  border: 1px solid rgba(101, 176, 255, 0.2);
  border-radius: 10px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 0;
}

.comms-block input,
.comms-block select,
.comms-block textarea,
.comms-block button {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.craft-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nearby-craft-row {
  border: 1px solid rgba(101, 176, 255, 0.2);
  border-radius: 10px;
  padding: 6px;
  display: grid;
  gap: 6px;
  background: rgba(7, 24, 44, 0.7);
}

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

.nearby-craft-row button.selected {
  border-color: rgba(92, 224, 179, 0.75);
  background: rgba(92, 224, 179, 0.16);
  color: #dfffee;
}

.spacecraft-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.craft-overlay-shell {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.craft-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(8, 24, 46, 0.92);
  color: #d8efff;
  border-radius: 999px;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  font-size: 11px;
  box-shadow: 0 0 0 1px rgba(126, 224, 255, 0.15), 0 8px 18px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.craft-marker.self {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 10px 26px rgba(0, 0, 0, 0.4);
  cursor: default;
}

.craft-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--craft-accent, #7ee0ff);
  display: inline-block;
}

.craft-tether {
  color: #9ec6ff;
  font-size: 10px;
}

.comms-inline-action {
  padding: 6px 12px;
  border-top: 1px solid rgba(101, 176, 255, 0.15);
  border-bottom: 1px solid rgba(101, 176, 255, 0.15);
  display: grid;
  gap: 6px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  max-height: min(42dvh, 360px);
}

.comms-inline-action .chips,
.comms-config-body .chips {
  min-width: 0;
}

.comms-inline-action .chips button {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.comms-chat-focus {
  padding: 8px 12px;
  border-top: 1px solid rgba(101, 176, 255, 0.15);
  border-bottom: 1px solid rgba(101, 176, 255, 0.15);
  display: grid;
  gap: 8px;
  background: rgba(6, 22, 40, 0.6);
}

.comms-console--chat .comms-console-log {
  min-height: 220px;
  max-height: min(56dvh, 520px);
}

.comms-console--chat .comms-console-compose textarea {
  min-height: 84px;
}

.comms-console--browse .comms-console-log {
  max-height: 180px;
}

.inline-requests {
  align-items: center;
}

.comms-shell-collapsed {
  width: max-content;
}

.comms-collapsed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(7, 24, 44, 0.94), rgba(3, 14, 26, 0.98));
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.comms-collapsed-handle {
  cursor: grab;
  padding: 4px 8px;
  font-size: 11px;
}

#comms-dock-root.touch-dock .comms-shell-collapsed {
  width: max-content;
  margin-left: auto;
}

#comms-dock-root.touch-dock .comms-collapsed {
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.comms-fab {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  color: #d9f7ff;
  border: 1px solid rgba(43, 226, 255, 0.55);
  background: radial-gradient(circle at 30% 30%, rgba(43, 226, 255, 0.28), rgba(9, 30, 52, 0.95));
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(43, 226, 255, 0.18) inset;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.comms-fab svg {
  display: block;
}

.comms-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  color: #0f2a1d;
  background: #5ce0b3;
  border: 1px solid rgba(9, 30, 52, 0.75);
}

#app[data-device="tablet"] #comms-dock-root {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
}

#app[data-device="phone"] #comms-dock-root {
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + var(--keyboard-inset, 0px));
  transition: bottom 0.12s ease-out;
}

/* When config panel is open on phone: expand dock root to full viewport and hide
   the console. Config panel renders as a normal flow element (position:static)
   inside the expanded dock root — same pattern as messaging. */
#app[data-device="phone"] #comms-dock-root.config-open {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  transition: none;
}
#app[data-device="phone"] #comms-dock-root.config-open .comms-console,
#app[data-device="phone"] #comms-dock-root.config-open .comms-shell-collapsed {
  display: none;
}

/* Tablet: expand dock root for config overlay (tablets don't have the iOS touch bug) */
#app[data-device="tablet"] #comms-dock-root.config-open {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  transition: none;
}
#app[data-device="tablet"] #comms-dock-root.config-open .comms-console {
  pointer-events: none;
  opacity: 0;
}

#app[data-device="tablet"] .comms-console {
  width: min(680px, calc(100vw - 22px));
  min-width: 0;
}

#app[data-device="phone"] .comms-console {
  width: 100%;
  min-width: 0;
  max-width: none;
  max-height: calc(var(--visible-vh, calc(var(--app-vh, 1vh) * 100)) - 66px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  border-radius: 12px;
}

#app[data-device="phone"] .comms-shell {
  width: 100%;
}

#app[data-device="phone"] .comms-head-actions {
  gap: 4px;
  justify-self: end;
  align-self: start;
}

#app[data-device="phone"] .comms-head-actions button {
  min-height: 44px;
  padding: 6px 10px;
  font-size: 13px;
}

#app[data-device="phone"] .comms-console-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 8px 10px 7px;
}

#app[data-device="phone"] .comms-console-title strong {
  font-size: 15px;
}

/* #comms-config-open on phone is now inside .comms-controls-row */

#app[data-device="phone"] #comms-collapse {
  font-weight: 700;
  padding: 8px 10px;
  border-color: rgba(43, 226, 255, 0.65);
}

#app[data-device="phone"] .comms-console-controls {
  display: grid;
  grid-template-columns: 1fr;
  align-items: flex-start;
  gap: 7px;
  padding: 7px 10px 6px;
}

#app[data-device="phone"] .comms-controls-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

#app[data-device="phone"] .comms-controls-row .comms-mode-toggle {
  flex: 1 1 auto;
}

#app[data-device="phone"] .comms-controls-row #comms-config-open {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#app[data-device="phone"] .comms-mode-toggle {
  justify-self: start;
}

#app[data-device="phone"] .comms-mode-toggle button {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 13px;
}

#app[data-device="phone"] .comms-inline-action {
  max-height: min(30dvh, 280px);
  padding: 6px 10px;
  gap: 5px;
}

#app[data-device="phone"] .comms-collapsed {
  justify-content: space-between;
}

#app[data-device="phone"] .comms-fab {
  width: 58px;
  height: 58px;
}

/* On phone: config panel is a normal flow element (like .comms-console).
   Hidden by default, shown when .open. No position/transform — iOS Safari
   breaks touch events on positioned elements inside position:fixed parents. */
#app[data-device="phone"] .comms-config {
  position: static;
  width: 100%;
  height: auto;
  max-height: calc(var(--visible-vh, calc(var(--app-vh, 1vh) * 100)) - 28px);
  transform: none;
  border-left: none;
  box-shadow: none;
  display: none;
}
#app[data-device="phone"] .comms-config.open {
  display: block;
  transform: none;
}

#app[data-device="phone"] .comms-config-body {
  max-height: calc(var(--visible-vh, calc(var(--app-vh, 1vh) * 100)) - 56px - env(safe-area-inset-bottom));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#app[data-device="phone"] .comms-config-body input,
#app[data-device="phone"] .comms-config-body select,
#app[data-device="phone"] .comms-config-body textarea {
  min-height: 44px;
  font-size: 16px;
  padding: 8px 12px;
}

#app[data-device="phone"] .comms-config-body button {
  min-height: 44px;
  font-size: 15px;
}

#app[data-device="phone"] .comms-config-body label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

/* Mobile config overlay — lives on document.body, completely outside the dock root.
   Bypasses all dock stacking/pointer-events/re-render issues on iOS Safari. */
#mobile-config-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(180deg, rgba(6, 22, 40, 0.98), rgba(3, 14, 26, 0.99));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 8px) max(env(safe-area-inset-bottom), 8px) max(env(safe-area-inset-left), 8px);
}
#mobile-config-overlay .comms-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
#mobile-config-overlay .comms-config-head strong {
  font-size: 16px;
}
#mobile-config-overlay .comms-config-head button {
  min-height: 44px;
  min-width: 64px;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  color: inherit;
  cursor: pointer;
}
#mobile-config-overlay .comms-block {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(101, 176, 255, 0.2);
  border-radius: 10px;
  margin-bottom: 8px;
}
#mobile-config-overlay input,
#mobile-config-overlay select,
#mobile-config-overlay textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  min-height: 44px;
  font-size: 16px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: inherit;
}
#mobile-config-overlay button#mc-save {
  min-height: 44px;
  width: 100%;
  font-size: 15px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(101, 176, 255, 0.15);
  color: inherit;
  cursor: pointer;
}
#mobile-config-overlay .craft-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
#mobile-config-overlay label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 14px;
}
#mobile-config-overlay .small {
  font-size: 12px;
  opacity: 0.7;
}

#app[data-device="phone"] .comms-console-log {
  min-height: 96px;
  max-height: min(calc(var(--visible-vh, 100vh) * 0.24), 200px);
  padding: 6px 10px;
}

#app[data-device="phone"] .comms-console--chat .comms-console-log {
  max-height: min(calc(var(--visible-vh, 100vh) * 0.45), 360px);
}

#app[data-device="phone"] .comms-chat-focus--compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 10px;
}

#app[data-device="phone"] .comms-chat-focus--compact .chips {
  flex: 0 0 auto;
  display: flex;
  gap: 5px;
}

#app[data-device="phone"] .comms-chat-focus--compact .chips button {
  min-height: 44px;
  padding: 8px 12px;
}

#app[data-device="phone"] .chat-scope-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

#app[data-device="phone"] .comms-chat-focus,
#app[data-device="phone"] .comms-console-compose {
  padding-left: 10px;
  padding-right: 10px;
}

#app[data-device="phone"] .comms-console-compose {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#app[data-device="phone"] .comms-console-compose textarea {
  min-height: 54px;
  resize: none;
  width: 100%;
}

#app[data-device="phone"] #scope-send {
  width: 100%;
  min-height: 48px;
}

#app[data-device="phone"] .comms-console button,
#app[data-device="phone"] .comms-console select,
#app[data-device="phone"] .comms-console input,
#app[data-device="phone"] .comms-console textarea {
  min-height: 44px;
  font-size: 16px;
}

#app[data-device="phone"] .comms-console .small {
  font-size: 11px;
}

#app[data-device="phone"] .settings-menu input,
#app[data-device="phone"] .settings-menu select,
#app[data-device="phone"] .settings-menu textarea,
#app[data-device="phone"] .settings-menu button {
  font-size: 16px;
  touch-action: manipulation;
}

#app[data-device="phone"] .settings-menu input,
#app[data-device="phone"] .settings-menu select,
#app[data-device="phone"] .settings-menu textarea {
  -webkit-user-select: text;
  user-select: text;
  pointer-events: auto;
}

#app[data-device="phone"] .nearby-craft-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

#app[data-device="phone"] .nearby-craft-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#app[data-device="phone"] .nearby-craft-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#app[data-device="phone"] .nearby-craft-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 5px;
  align-items: center;
}

#app[data-device="phone"] .nearby-craft-actions button {
  width: auto;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 12px;
}

#app.comms-touch-open[data-device="phone"] #space-view {
  touch-action: none;
}

#app.comms-touch-open[data-device="tablet"] #space-view {
  touch-action: none;
}

@media (max-width: 360px) {
  #app[data-device="phone"] .settings-tab {
    font-size: 11px;
    padding: 6px 8px;
  }

  #app[data-device="phone"] .comms-console-head {
    padding: 7px 8px 6px;
  }

  #app[data-device="phone"] .comms-console-controls,
  #app[data-device="phone"] .comms-inline-action,
  #app[data-device="phone"] .comms-console-log,
  #app[data-device="phone"] .comms-chat-focus,
  #app[data-device="phone"] .comms-console-compose {
    padding-left: 8px;
    padding-right: 8px;
  }
}

@media (max-width: 1000px) {
  #comms-dock-root {
    left: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .comms-console {
    width: auto;
    min-width: 0;
    max-height: calc(var(--visible-vh, 100vh) - 20px);
  }

  .comms-inline-action {
    max-height: min(calc(var(--visible-vh, 100vh) * 0.45), 320px);
  }
}

/* Chat v2 */
#comms-dock-root {
  pointer-events: none;
}

#comms-dock-root .chat-v2-shell {
  pointer-events: auto;
}

.chat-v2-shell {
  width: min(980px, calc(100vw - 28px));
}

.chat-v2-shell.is-collapsed {
  width: auto;
}

.chat-v2-fab {
  border: 1px solid rgba(111, 211, 170, 0.55);
  border-radius: 999px;
  min-height: 48px;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(11, 30, 47, 0.96), rgba(8, 20, 33, 0.98));
  color: #e6f4ff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.42);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.chat-v2-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(7, 19, 31, 0.97), rgba(5, 14, 24, 0.98));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.44);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(360px, 64vh);
}

.chat-v2-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(119, 166, 206, 0.2);
}

.chat-v2-head strong {
  font-size: 14px;
}

.chat-v2-head .small {
  margin-top: 2px;
}

.chat-v2-head button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.chat-v2-recent-rail {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(119, 166, 206, 0.14);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.chat-v2-recent-item {
  display: grid;
  align-content: center;
  gap: 2px;
  min-width: 176px;
  max-width: 208px;
  text-align: left;
  border-radius: 10px;
  border: 1px solid rgba(119, 166, 206, 0.24);
  padding: 7px 9px;
  background: rgba(10, 27, 42, 0.75);
  color: #dbeeff;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-v2-recent-item.is-active,
.chat-v2-recent-item.is-cursor {
  border-color: rgba(111, 211, 170, 0.65);
  background: rgba(17, 45, 57, 0.86);
}

.chat-v2-recent-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-v2-recent-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-v2-main {
  display: grid;
  grid-template-columns: minmax(220px, 25%) minmax(0, 75%);
  min-height: 0;
}

.chat-v2-roster {
  border-right: 1px solid rgba(119, 166, 206, 0.16);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  background: rgba(8, 22, 35, 0.9);
}

.chat-v2-search-wrap {
  padding: 10px;
}

.chat-v2-search-wrap input {
  width: 100%;
  min-height: 38px;
}

.chat-v2-filters {
  display: flex;
  gap: 5px;
  padding: 0 10px 8px;
  flex-wrap: wrap;
}

.chat-v2-filters button {
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 11px;
  border: 1px solid rgba(119, 166, 206, 0.24);
  color: var(--text-muted);
  background: rgba(7, 20, 31, 0.8);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-v2-filters button.active {
  border-color: rgba(111, 211, 170, 0.7);
  color: #e8fff4;
  background: rgba(25, 63, 56, 0.82);
}

.chat-v2-member-list {
  overflow: auto;
  padding: 0 10px 10px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.chat-v2-group {
  margin-bottom: 12px;
}

.chat-v2-group h4 {
  margin: 0 0 5px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.chat-v2-group-list {
  display: grid;
  gap: 5px;
}

.chat-v2-member {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  border: 1px solid rgba(119, 166, 206, 0.2);
  border-radius: 9px;
  background: rgba(8, 24, 37, 0.86);
  color: #e3f2ff;
  text-align: left;
  padding: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-v2-member.is-active,
.chat-v2-member.is-cursor {
  border-color: rgba(111, 211, 170, 0.7);
  background: rgba(15, 43, 52, 0.92);
}

.chat-v2-member-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.chat-v2-member-main strong {
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-v2-member-sub,
.chat-v2-member-note {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-v2-member-note {
  color: #9eb8cf;
}

.chat-v2-presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-top: 4px;
  display: inline-block;
  background: #88939f;
}

.chat-v2-presence-dot.is-online {
  background: #3bc47a;
}

.chat-v2-presence-dot.is-away {
  background: #f0b24f;
}

.chat-v2-presence-dot.is-busy {
  background: #d75151;
}

.chat-v2-presence-dot.is-offline {
  background: #76808b;
}

.chat-v2-conversation {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(6, 18, 28, 0.9);
}

.chat-v2-conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(119, 166, 206, 0.16);
}

.chat-v2-conversation-title {
  display: grid;
  min-width: 0;
  gap: 2px;
}

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

.chat-v2-conversation-title .small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chat-v2-conversation-actions {
  display: inline-flex;
  gap: 6px;
}

.chat-v2-back {
  min-height: 36px;
  padding: 6px 12px;
}

.chat-v2-messages {
  overflow: auto;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.chat-v2-msg {
  max-width: min(80ch, 84%);
  display: grid;
  gap: 3px;
}

.chat-v2-msg.mine {
  justify-self: end;
  text-align: right;
}

.chat-v2-msg.theirs {
  justify-self: start;
  text-align: left;
}

.chat-v2-msg-body {
  font-size: 14px;
  line-height: 1.45;
  background: rgba(19, 43, 61, 0.68);
  border: 1px solid rgba(119, 166, 206, 0.2);
  border-radius: 9px;
  padding: 8px 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-v2-msg.mine .chat-v2-msg-body {
  background: rgba(31, 71, 66, 0.78);
  border-color: rgba(111, 211, 170, 0.35);
}

.chat-v2-msg-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-v2-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(119, 166, 206, 0.16);
}

.chat-v2-compose textarea {
  width: 100%;
  min-height: 60px;
  max-height: 180px;
  resize: vertical;
}

.chat-v2-compose button {
  min-width: 88px;
  min-height: 42px;
}

.chat-v2-unread {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  color: #061a11;
  background: #7ee3ae;
  border: 1px solid rgba(12, 40, 26, 0.45);
}

.chat-v2-empty {
  color: var(--text-muted);
  font-size: 12px;
}

.chat-v2-empty--center {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
}

#comms-dock-root .chat-v2-shell.is-touch {
  width: min(1000px, calc(100vw - 20px));
}

#app[data-device="tablet"] #comms-dock-root .chat-v2-shell {
  width: min(1000px, calc(100vw - 20px));
}

#app[data-device="phone"] #comms-dock-root {
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + var(--keyboard-inset, 0px));
}

#app[data-device="phone"] #comms-dock-root .chat-v2-shell {
  width: 100%;
}

#app[data-device="phone"] #comms-dock-root .chat-v2-panel {
  border-radius: 12px;
  grid-template-rows: auto auto minmax(0, calc(var(--visible-vh, 100vh) - 180px));
  max-height: calc(var(--visible-vh, 100vh) - 24px);
}

#app[data-device="phone"] .chat-v2-head {
  padding: 8px 10px;
}

#app[data-device="phone"] .chat-v2-head button,
#app[data-device="phone"] .chat-v2-back,
#app[data-device="phone"] .chat-v2-compose button,
#app[data-device="phone"] .chat-v2-filters button,
#app[data-device="phone"] .chat-v2-member,
#app[data-device="phone"] .chat-v2-recent-item {
  min-height: 44px;
}

#app[data-device="phone"] .chat-v2-recent-item {
  min-width: 150px;
}

#app[data-device="phone"] .chat-v2-main {
  grid-template-columns: 1fr;
}

#app[data-device="phone"] .chat-v2-shell.mobile-members .chat-v2-conversation {
  display: none;
}

#app[data-device="phone"] .chat-v2-shell.mobile-conversation .chat-v2-roster,
#app[data-device="phone"] .chat-v2-shell.mobile-conversation .chat-v2-recent-rail {
  display: none;
}

#app[data-device="phone"] .chat-v2-shell.mobile-conversation .chat-v2-conversation {
  display: grid;
  min-height: calc(var(--visible-vh, 100vh) - 140px);
}

#app[data-device="phone"] .chat-v2-roster {
  border-right: none;
}

#app[data-device="phone"] .chat-v2-search-wrap {
  padding: 8px;
}

#app[data-device="phone"] .chat-v2-filters {
  padding: 0 8px 6px;
}

#app[data-device="phone"] .chat-v2-member-list {
  padding: 0 8px 8px;
}

#app[data-device="phone"] .chat-v2-conversation-head {
  padding: 8px 10px;
}

#app[data-device="phone"] .chat-v2-messages {
  padding: 10px;
}

#app[data-device="phone"] .chat-v2-msg {
  max-width: 90%;
}

#app[data-device="phone"] .chat-v2-compose {
  grid-template-columns: 1fr;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}

#app[data-device="phone"] .chat-v2-compose textarea {
  min-height: 66px;
  font-size: 16px;
}
