:root {
  --chat-bg: #eef3f7;
  --chat-ink: #111827;
  --chat-muted: #64748b;
  --chat-panel: #ffffff;
  --chat-soft: #f7fafc;
  --chat-line: #d7e0ea;
  --chat-teal: #0f766e;
  --chat-teal-strong: #115e59;
  --chat-blue: #2563eb;
  --chat-amber: #b45309;
  --chat-danger: #b42318;
  --chat-shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
  --chat-composer-space: 94px;
}

body.chatBody {
  background: var(--chat-bg);
  color: var(--chat-ink);
}

.chatShell {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 12px 12px calc(var(--chat-composer-space) + env(safe-area-inset-bottom) + 12px);
}

.chatTopbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 0 -12px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid rgba(215, 224, 234, 0.78);
  background: rgba(238, 243, 247, 0.94);
  backdrop-filter: blur(16px);
}

.chatTitle,
.chatTopbarActions {
  min-width: 0;
}

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

.iconButton {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 0.78rem;
}

.iconButton[data-active="true"] {
  border-color: rgba(15, 118, 110, 0.38);
  background: rgba(15, 118, 110, 0.1);
  color: var(--chat-teal-strong);
}

.chatLogin {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
  padding: 14px;
}

.chatLogin .field {
  margin-bottom: 0;
}

.chatApp {
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.chatStatusGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.chatStatusGrid > div {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: var(--chat-panel);
  padding: 10px;
}

.chatStatusGrid span {
  color: var(--chat-muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.chatStatusGrid strong {
  min-width: 0;
  overflow: hidden;
  color: var(--chat-ink);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversationPanel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
  padding: 10px;
}

.conversationPanelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversationPanelHeader > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.conversationPanelHeader strong {
  min-width: 0;
  overflow: hidden;
  font-size: 0.96rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversationPanelHeader button {
  width: auto;
  min-width: 72px;
  padding: 0 12px;
}

.conversationList {
  display: grid;
  gap: 6px;
  max-height: min(42dvh, 360px);
  overflow: auto;
  padding-right: 2px;
  overscroll-behavior: contain;
}

.conversationItem {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: var(--chat-soft);
  color: var(--chat-ink);
  padding: 9px 10px;
  text-align: left;
}

.conversationItem[data-active="true"] {
  border-color: rgba(15, 118, 110, 0.48);
  background: rgba(15, 118, 110, 0.1);
}

.conversationTitle {
  min-width: 0;
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversationMeta {
  border: 1px solid rgba(100, 116, 139, 0.28);
  border-radius: 999px;
  color: var(--chat-muted);
  padding: 3px 7px;
  font-size: 0.72rem;
  font-weight: 900;
}

.conversationItem[data-active="true"] .conversationMeta {
  border-color: rgba(15, 118, 110, 0.28);
  color: var(--chat-teal-strong);
}

.conversationEmpty {
  margin: 0;
  border: 1px dashed var(--chat-line);
  border-radius: 8px;
  color: var(--chat-muted);
  padding: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.browserPanel {
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
  padding: 10px;
}

.browserBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.browserBar > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.browserBar strong {
  min-width: 0;
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screenFrame {
  position: relative;
  width: 100%;
  min-height: 360px;
  max-height: calc(100dvh - var(--chat-composer-space) - 210px);
  overflow: hidden;
  border: 1px solid #162033;
  border-radius: 8px;
  aspect-ratio: 430 / 920;
  background: #0b1220;
  touch-action: none;
  user-select: none;
  overscroll-behavior: contain;
}

.screenImage {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b1220;
  object-fit: contain;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.screenEmpty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  color: #dbeafe;
  text-align: center;
}

.screenEmpty strong {
  font-size: 1.06rem;
}

.screenEmpty p {
  max-width: 270px;
  color: #9fb0c7;
  font-size: 0.88rem;
  line-height: 1.45;
}

.screenBusy {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #ffffff;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.remoteControls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.remoteControls button {
  min-width: 0;
  padding: 0 8px;
}

.chatComposer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
  width: min(560px, 100%);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(215, 224, 234, 0.88);
  background: rgba(238, 243, 247, 0.94);
  box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.09);
  transform: translateX(-50%);
  backdrop-filter: blur(16px);
}

.chatComposer textarea {
  min-height: 52px;
  max-height: 150px;
  resize: none;
}

.chatComposer button {
  align-self: end;
  height: 52px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--chat-composer-space) + env(safe-area-inset-bottom) + 8px);
  z-index: 6;
  width: min(520px, calc(100% - 24px));
  margin: 0;
  border: 1px solid rgba(37, 99, 235, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--chat-blue);
  padding: 10px 12px;
  box-shadow: var(--chat-shadow);
  font-size: 0.88rem;
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
}

.toast[data-tone="bad"] {
  border-color: rgba(180, 35, 24, 0.28);
  color: var(--chat-danger);
}

.toast[data-tone="warn"] {
  border-color: rgba(180, 83, 9, 0.3);
  color: var(--chat-amber);
}

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

  .chatStatusGrid > div:last-child {
    grid-column: 1 / -1;
  }

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

  .chatComposer {
    grid-template-columns: minmax(0, 1fr) 78px;
  }
}

@media (min-width: 760px) {
  .chatShell {
    padding-top: 16px;
  }

  .screenFrame {
    max-height: 720px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --chat-bg: #0c1118;
    --chat-ink: #e8eef8;
    --chat-muted: #9aa7bb;
    --chat-panel: #121a25;
    --chat-soft: #172033;
    --chat-line: #2b3648;
    --chat-shadow: none;
  }

  .chatTopbar,
  .chatComposer {
    background: rgba(12, 17, 24, 0.92);
  }

  .toast {
    background: rgba(18, 26, 37, 0.97);
  }
}
