.page {
  max-width: 1100px;
  margin: 24px auto;
  font-family: Segoe UI, sans-serif;
  color: #ddd;
  padding: 0 10px;
}

body {
  background: #111;
  margin: 0;
  color: #e4e8ef;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

.card {
  background: #161616;
  border: 1px solid #343434;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.row-create .field {
  flex: 1;
  min-width: 300px;
}
.row-create button {
  width: 180px;
  height: 38px;
  align-self: flex-end;
}

.links-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}
.links-table th,
.links-table td {
  border: 1px solid #2f2f2f;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}
.link-token {
  cursor: pointer;
  user-select: all;
}
.link-token:hover {
  color: #9ad0ff;
}

.muted {
  color: #9aa0aa;
}

input,
textarea,
button {
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 8px;
  background: #1c1c1c;
  color: #eee;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 10px;
}
button {
  cursor: pointer;
}
.field label {
  display: block;
  margin-bottom: 6px;
  color: #c9ced7;
}

.presence-box {
  display: grid;
  gap: 8px;
  margin: 8px 0 10px;
}

.presence-item {
  border: 1px solid #2a3442;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

.presence-on {
  color: #86f5a6;
  background: rgba(36, 102, 56, 0.3);
  border-color: #2f7a45;
}

.presence-off {
  color: #ff9ca0;
  background: rgba(126, 41, 41, 0.28);
  border-color: #7f3d43;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0f131a;
  border: 1px solid #2a3442;
  border-radius: 8px;
  padding: 10px;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 34px);
  min-height: 560px;
  background: #121317;
  border: 1px solid #2a2f3a;
  border-radius: 12px;
  overflow: hidden;
}

.chat-top {
  padding: 12px 14px 8px;
  border-bottom: 1px solid #262c36;
}
.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.top-row .muted {
  margin: 0;
  flex: 1;
}

.chat-title {
  margin: 0;
  font-size: 20px;
  margin-bottom: 8px;
}

.presence-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #262c36;
  align-items: center;
}

.presence-pill {
  flex: 1;
  text-align: center;
  border-radius: 999px;
  border: 1px solid #2a3442;
  padding: 7px 10px;
  font-size: 13px;
}

.call-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
}

.call-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  font-size: 14px;
  background: #1a212c;
  border-color: #2f3f56;
}

.call-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: #d8e6fa;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #13161d 0%, #0f1218 100%);
}

.msg {
  max-width: 78%;
  border-radius: 14px;
  padding: 8px 10px;
  line-height: 1.3;
  word-break: break-word;
}

.msg-me {
  align-self: flex-end;
  background: #1a4f8a;
  border: 1px solid #2a67a8;
}

.msg-peer {
  align-self: flex-start;
  background: #1e252f;
  border: 1px solid #2e3948;
}

.msg-system {
  align-self: center;
  max-width: 92%;
  color: #9aa7bb;
  font-size: 12px;
  padding: 4px 8px;
}

.join-error {
  min-height: 18px;
  color: #ff9ca0;
  padding: 4px 12px 0;
  font-size: 13px;
}

.danger-btn {
  width: auto;
  min-width: 92px;
  margin: 0;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid #8e3942;
  background: #4a1e24;
  color: #ffd8dd;
}

.expired-state {
  margin: 12px;
  padding: 12px;
  border: 1px solid #5d3b42;
  border-radius: 10px;
  background: #23171a;
  color: #f1d9de;
}
.expired-state h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.expired-state p {
  margin: 0;
  color: #e8cbd1;
  line-height: 1.35;
}

.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid #262c36;
  background: #141922;
}

.composer-input {
  flex: 1;
  margin: 0;
}

.composer-textarea {
  min-height: 38px;
  max-height: 130px;
  resize: none;
  overflow-y: auto;
  line-height: 1.3;
  padding-top: 8px;
  padding-bottom: 8px;
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 10px;
  padding: 0;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.send-btn {
  background: #215e9f;
  border-color: #2f74c0;
  color: #eaf3ff;
}

.danger-btn-lite {
  background: #4a1e24;
  border-color: #8e3942;
  color: #ffe5e8;
}

.incoming-call-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.incoming-call-card {
  width: min(320px, calc(100vw - 30px));
  border: 1px solid #4a6a9a;
  border-radius: 12px;
  background: #1a2434;
  padding: 14px;
  color: #f0f4fc;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  font-family: inherit;
}

.incoming-call-card h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 600;
  color: #f5f8ff;
  font-family: inherit;
}

.incoming-call-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.incoming-call-actions .icon-btn {
  width: 48px;
  min-width: 48px;
  height: 48px;
  font-size: 20px;
  border-width: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.call-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: min(420px, calc(100vw - 24px));
  border: 1px solid #4a6a9a;
  border-radius: 12px;
  background: #1a2434;
  z-index: 15;
  overflow: hidden;
  color: #f0f4fc;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.call-video-wrap.call-video-wrap--hidden-audio {
  position: absolute;
  width: 2px;
  height: 2px;
  opacity: 0;
  overflow: hidden;
  left: 0;
  bottom: 0;
  pointer-events: none;
  border: 0;
  clip-path: inset(50%);
}

.call-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #2d3f5c;
  background: #152030;
}

.call-panel-head strong {
  color: #f5f8ff;
  font-weight: 600;
}

.call-panel-head .icon-btn {
  border-width: 2px;
}

.call-video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #05070b;
}

.call-video-wrap #remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.call-video-wrap #localVideo {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 30%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1px solid #445a78;
  object-fit: cover;
  background: #0d1118;
}

.call-audio-waves {
  padding: 10px 12px 12px;
  background: #121a28;
  border-top: 1px solid #2d3f5c;
}

.call-wave-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.call-wave-row:last-child {
  margin-bottom: 0;
}

.call-audio-label {
  flex: 0 0 88px;
  font-size: 12px;
  color: #b8c8e8;
  font-weight: 500;
}

.call-wave-row canvas {
  flex: 1;
  height: 44px;
  width: 100%;
  max-width: 100%;
  border-radius: 8px;
  background: #0a0e14;
  border: 1px solid #2a3d58;
}

@media (max-width: 768px) {
  .page {
    margin: 0;
    max-width: none;
    padding: 0;
  }
  #manageCard {
    margin: 10px;
  }
  .chat-shell {
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .chat-title {
    font-size: 18px;
  }
  .presence-row {
    gap: 6px;
    padding: 8px;
    flex-wrap: wrap;
  }
  .presence-pill {
    font-size: 12px;
    padding: 6px 8px;
  }
  .msg {
    max-width: 88%;
  }
  .call-actions {
    margin-left: 0;
  }
  .call-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    border-radius: 10px 10px 0 0;
    border-left: 0;
    border-right: 0;
  }
}

body.join-mode {
  overflow: hidden;
}

body.join-mode .page {
  margin: 0;
  max-width: none;
  padding: 0;
  height: calc(var(--app-vh, 1vh) * 100);
}

body.join-mode .chat-shell {
  height: calc(var(--app-vh, 1vh) * 100);
  min-height: calc(var(--app-vh, 1vh) * 100);
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  margin: 0;
}

@supports (height: 100dvh) {
  body.join-mode .page {
    height: 100dvh;
  }
  body.join-mode .chat-shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

body.join-mode .composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* Ссылка с токеном: конструктор ссылок не показываем (в т.ч. до загрузки app.js). */
html.web-join-link #webIntro,
html.web-join-link #manageCard {
  display: none !important;
}

html.web-join-link #joinCard.chat-shell {
  display: flex !important;
  flex-direction: column;
}
