:root {
  color-scheme: dark;
  --bg: #10130d;
  --panel: #171b12;
  --panel-2: #20261a;
  --line: #30392a;
  --text: #f7f8f3;
  --muted: #a8b0a0;
  --green: #10f074;
  --green-dark: #0ab957;
  --blue: #2d7dff;
  --danger: #d94444;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #071109;
  cursor: pointer;
  font-weight: 800;
}

button:hover:not(:disabled) {
  background: var(--green-dark);
}

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

button.secondary {
  background: #30372b;
  color: var(--text);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #0f130d;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--green);
}

label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 430px);
}

.auth-brand {
  display: grid;
  place-items: center;
  padding: 48px;
}

.auth-brand img {
  width: min(72vw, 620px);
  height: auto;
  display: block;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  background: rgba(23, 27, 18, 0.96);
  border-left: 1px solid var(--line);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f130d;
}

.tab-button {
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  background: var(--green);
  color: #071109;
}

.auth-form,
.modal-box {
  display: grid;
  gap: 12px;
}

.auth-form h1,
.modal-box h2 {
  margin: 0;
  line-height: 1.1;
}

.two-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-error,
.form-info {
  min-height: 20px;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 750;
}

.form-error {
  color: #ff8c8c;
}

.form-info {
  color: var(--green);
}

.link-button {
  background: transparent;
  color: var(--green);
  border: 1px solid var(--line);
}

.messenger {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  overflow: hidden;
}

.users-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.profile-bar {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.profile-bar img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
}

.profile-bar strong,
.profile-bar span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-bar span,
.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

#logoutButton {
  min-height: 36px;
  padding: 0 10px;
  background: #30372b;
  color: var(--text);
}

.user-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 42px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11160f;
}

.user-row.selected {
  border-color: var(--green);
}

.user-name {
  min-width: 0;
  justify-self: stretch;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-action,
.icon-action {
  width: 42px;
  padding: 0;
  background: var(--panel-2);
  color: var(--green);
  border: 1px solid var(--line);
  font-size: 1rem;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #0f130d;
}

.chat-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 27, 18, 0.92);
}

.chat-header h2 {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
}

.empty-state,
.empty-list {
  color: var(--muted);
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.message {
  width: fit-content;
  max-width: min(78%, 720px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message.mine {
  align-self: flex-end;
  background: #0d2b18;
  border-color: #145f32;
}

.message-meta {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.message-text {
  overflow-wrap: anywhere;
}

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: rgba(23, 27, 18, 0.92);
}

.call-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(560px, calc(100vw - 36px));
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a07;
  box-shadow: var(--shadow);
  z-index: 10;
}

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

#closeCallPanel {
  min-height: 34px;
  padding: 0 10px;
  background: #30372b;
  color: var(--text);
}

.video-grid {
  position: relative;
  min-height: 300px;
  border-radius: 8px;
  overflow: hidden;
  background: #161a12;
}

.video-tile {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 300px;
}

.video-tile.local {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 34%;
  min-height: 0;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.video-tile span {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.58);
  font-size: 0.78rem;
  font-weight: 800;
}

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

.call-controls button.active {
  background: var(--green);
  color: #071109;
}

#callStatus {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.66);
  z-index: 20;
}

.modal-box {
  width: min(100%, 420px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.code-list {
  display: grid;
  gap: 6px;
}

.code-row {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 860px) {
  .auth-screen {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .auth-brand {
    min-height: 28dvh;
    padding: 22px;
  }

  .auth-brand img {
    width: min(82vw, 360px);
  }

  .auth-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    justify-content: flex-start;
    min-height: 72dvh;
    padding: 18px;
  }

  .messenger {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(190px, 36dvh) minmax(0, 1fr);
  }

  .users-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding: 12px;
    gap: 10px;
  }

  .chat-panel {
    min-height: 0;
  }

  .profile-bar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    padding-bottom: 10px;
  }

  .profile-bar img {
    width: 44px;
    height: 44px;
  }

  .user-list {
    gap: 6px;
  }

  .user-row {
    grid-template-columns: minmax(0, 1fr) 38px 38px;
    gap: 6px;
    padding: 6px;
  }

  .mini-action,
  .icon-action {
    width: 38px;
    min-height: 38px;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .messages {
    padding: 14px;
  }

  .message-form {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 560px) {
  button {
    min-height: 44px;
  }

  input {
    min-height: 46px;
  }

  .two-fields,
  .call-controls,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .auth-panel {
    padding: 16px;
  }

  .auth-form {
    gap: 10px;
  }

  .auth-form h1 {
    font-size: 1.5rem;
  }

  .messenger {
    grid-template-rows: minmax(180px, 34dvh) minmax(0, 1fr);
  }

  .users-panel label {
    display: none;
  }

  .profile-bar strong {
    font-size: 0.95rem;
  }

  .profile-bar span {
    font-size: 0.78rem;
  }

  #logoutButton {
    min-height: 34px;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: row;
    padding: 10px 12px;
  }

  .chat-header h2 {
    font-size: 1.08rem;
  }

  .message {
    max-width: 92%;
  }

  .message-form {
    grid-template-columns: minmax(0, 1fr) 82px;
    gap: 8px;
  }

  .call-panel {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    padding: 12px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  .video-grid {
    min-height: 0;
  }

  .video-tile {
    min-height: 0;
    height: 100%;
  }

  .video-tile.local {
    width: 38%;
  }
}

@media (max-width: 390px) {
  .messenger {
    grid-template-rows: minmax(165px, 32dvh) minmax(0, 1fr);
  }

  .users-panel {
    padding: 10px;
  }

  .profile-bar {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .profile-bar img {
    width: 38px;
    height: 38px;
  }

  .user-row {
    grid-template-columns: minmax(0, 1fr) 34px 34px;
  }

  .mini-action,
  .icon-action {
    width: 34px;
    min-height: 34px;
    font-size: 0.9rem;
  }

  .message-form {
    grid-template-columns: 1fr;
  }
}
