:root {
  --bg: #0b0f14;
  --bg-2: #111823;
  --panel: #131b26;
  --line: #1e2836;
  --text: #e9eef6;
  --muted: #8695a8;
  --mint: #5eead4;
  --mint-dim: #16323a;
  --mine: #14313a;
  --mine-line: #23515c;
  --danger: #ff8a80;
  --r: 18px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background:
    radial-gradient(900px 520px at 12% -12%, #16232e 0%, transparent 60%),
    radial-gradient(700px 500px at 100% 100%, #10202a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; border: none; background: none; }

.app { height: 100dvh; }
.screen { height: 100%; }

/* ---------- вход ---------- */
.login { display: grid; place-items: center; padding: 22px; }

.login-card {
  width: min(400px, 100%);
  text-align: center;
  padding: 34px 26px 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 40px 80px -50px #000;
  backdrop-filter: blur(6px);
}

.mark { color: var(--mint); display: grid; place-items: center; margin-bottom: 8px; }

h1 { margin: 0 0 8px; font-size: 27px; letter-spacing: 0.6px; font-weight: 650; }

.sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.5; }

#login-form { display: grid; gap: 10px; }

input[type="text"], #login-name, #input, #add-code-input, #rename-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus { border-color: var(--mint); }

#login-btn, .wide-btn {
  padding: 13px 18px;
  border-radius: 13px;
  background: var(--mint);
  color: #04211d;
  font-weight: 650;
  transition: filter 0.15s, transform 0.08s;
}

#login-btn:hover, .wide-btn:hover { filter: brightness(1.06); }
#login-btn:active, .wide-btn:active { transform: scale(0.985); }
#login-btn:disabled { opacity: 0.6; cursor: default; }

.wide-btn { display: block; width: 100%; margin-top: 10px; }

.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.error {
  color: var(--danger); font-size: 13px; margin: 12px 0 0;
  white-space: pre-line; line-height: 1.45; text-align: left;
}

.fineprint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 16px 0 0; white-space: pre-line; }

.btn {
  display: inline-block; padding: 13px 18px; border-radius: 13px;
  background: var(--mint); color: #04211d; font-weight: 650; text-decoration: none;
}

/* ---------- каркас ---------- */
.main { display: grid; grid-template-columns: 1fr; min-height: 0; }

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(17, 24, 35, 0.75);
  border-right: 1px solid var(--line);
}

.me-bar {
  display: flex; align-items: center; gap: 11px;
  padding: 15px 14px 13px;
}

.me-text { min-width: 0; flex: 1; }
.me-name { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 14px;
  background: linear-gradient(150deg, #1d4a52, #123039);
  color: var(--mint);
  font-weight: 700; text-transform: uppercase;
  border: 1px solid var(--mine-line);
}

.status { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.status.online { color: var(--mint); }
.status.offline { color: #e0a54a; }

.icon-btn {
  color: var(--muted); font-size: 17px; padding: 7px 9px;
  border-radius: 11px; line-height: 1;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 8px;
  font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--muted);
}

.mini-btn {
  width: 26px; height: 26px; border-radius: 9px;
  background: var(--mint-dim); color: var(--mint);
  font-size: 17px; line-height: 1; display: grid; place-items: center;
}
.mini-btn:hover { filter: brightness(1.15); }

.contacts { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }

.contact {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 15px; cursor: pointer;
  transition: background 0.12s;
}
.contact:hover { background: rgba(255, 255, 255, 0.045); }
.contact.active { background: rgba(94, 234, 212, 0.1); }

.contact-body { min-width: 0; flex: 1; }
.contact-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4a5e; }
.dot.online { background: var(--mint); box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.14); }

.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--mint); color: #04211d; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

.empty { color: var(--muted); font-size: 13px; line-height: 1.55; padding: 10px 18px; margin: 0; }

/* ---------- чат ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; position: relative; }

.chat-empty {
  margin: auto; padding: 24px; max-width: 330px; text-align: center; color: var(--muted);
  font-size: 14px;
}
.halo {
  width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 34px;
  background: radial-gradient(circle at 35% 30%, rgba(94, 234, 212, 0.22), transparent 70%);
  border: 1px solid rgba(94, 234, 212, 0.18);
}

.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.78); backdrop-filter: blur(10px);
}
.chat-title { min-width: 0; flex: 1; }
.chat-name { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 11.5px; color: var(--muted); }

.back { display: none; color: var(--text); font-size: 26px; line-height: 1; padding: 0 6px; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 10px;
  display: flex; flex-direction: column; gap: 7px;
}

.bubble {
  max-width: min(76%, 520px);
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--bg-2);
  border: 1px solid var(--line);
  line-height: 1.45;
  overflow-wrap: anywhere;
  animation: rise 0.16s ease-out;
}

@keyframes rise { from { opacity: 0; transform: translateY(5px); } }

.bubble.mine {
  align-self: flex-end;
  background: linear-gradient(160deg, #16333c, var(--mine));
  border-color: var(--mine-line);
  border-bottom-right-radius: 7px;
}

.bubble.theirs { align-self: flex-start; border-bottom-left-radius: 7px; }

.bubble .time {
  display: block; font-size: 10px; color: rgba(233, 238, 246, 0.45);
  margin-top: 5px; text-align: right;
}

.bubble.failed { border-color: var(--danger); }

.bubble img.photo {
  display: block; max-width: 100%; border-radius: 12px; margin-bottom: 4px;
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(19, 27, 38, 0.9);
}

.attach {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--muted);
  display: grid; place-items: center; font-size: 20px; cursor: pointer;
}
.attach:hover { color: var(--mint); border-color: var(--mine-line); }

#input { resize: none; max-height: 140px; line-height: 1.4; padding: 11px 15px; border-radius: 15px; }

#send {
  width: 44px; height: 44px; flex: 0 0 44px; padding: 0; border-radius: 50%;
  background: var(--mint); color: #04211d; font-size: 18px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------- диалоги ---------- */
.dialog {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #16202c, #121a24);
  color: var(--text);
  border-radius: 22px;
  padding: 20px;
  width: min(400px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 40px 80px -40px #000;
}

.dialog::backdrop { background: rgba(4, 8, 12, 0.7); backdrop-filter: blur(3px); }

.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dialog h2 { margin: 0; font-size: 18px; font-weight: 620; }
.dialog-text { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 4px 0 12px; }

.qr-wrap { display: grid; place-items: center; padding: 10px 0 6px; }
.qr { background: #fff; padding: 12px; border-radius: 16px; line-height: 0; }
.qr svg { width: 190px; height: 190px; display: block; }

.qr-caption { text-align: center; color: var(--muted); font-size: 12.5px; margin: 8px 0 4px; }
.my-code { text-align: center; margin: 6px 0 4px; font-size: 14px; }
.my-code b { letter-spacing: 2.5px; color: var(--mint); font-size: 16px; }

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 2px; border-top: 1px solid var(--line); margin-top: 8px;
  font-size: 14px;
}
.settings-value { color: var(--muted); font-size: 12.5px; max-width: 55%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.switch {
  padding: 7px 14px; border-radius: 11px; font-size: 13px;
  background: var(--mint-dim); color: var(--mint); border: 1px solid var(--mine-line);
}
.switch.off { background: transparent; color: var(--muted); border-color: var(--line); }

.row-buttons { display: flex; gap: 8px; }
.row-buttons .wide-btn { margin-top: 10px; }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 12px 16px; border-radius: 13px;
  background: #18232f; border: 1px solid var(--line);
  box-shadow: 0 20px 40px -20px #000;
  font-size: 13px; line-height: 1.5; z-index: 30;
  white-space: pre-wrap; text-align: center;
}

/* ---------- адаптив ---------- */
@media (max-width: 759px) {
  .main .chat { display: none; }
  .main.chat-open .sidebar { display: none; }
  .main.chat-open .chat { display: flex; }
  .back { display: block; }
}

@media (min-width: 760px) {
  .main { grid-template-columns: minmax(270px, 330px) 1fr; }
}
