:root {
  --bg: #07130d;
  --bg-2: #0b1d14;
  --panel: #0e2418;
  --panel-2: #123020;
  --line: #1d4530;
  --text: #e6f7ec;
  --muted: #8fb7a1;
  --accent: #5be08a;
  --accent-2: #2fbf6a;
  --danger: #ff7a7a;
  --bubble-in: #163a26;
  --bubble-out: #1f7a46;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

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

body {
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(91, 224, 138, .16), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(47, 191, 106, .12), transparent 55%),
    linear-gradient(160deg, #06110b 0%, #081a11 45%, #050d08 100%);
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

a { color: var(--accent); }

[hidden] { display: none !important; }

#app {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px;
  gap: 14px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, rgba(18, 48, 32, .92), rgba(10, 26, 18, .92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 12px;
  object-fit: cover;
  background: #0a1a10;
  border: 1px solid var(--line);
}

.avatar.sm { width: 38px; height: 38px; flex-basis: 38px; border-radius: 10px; }

.me-name { font-weight: 650; letter-spacing: .2px; }
.me-state { font-size: 12.5px; color: var(--muted); }
.me > div { min-width: 0; flex: 1; }
.me-name, .me-state { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover { border-color: var(--accent-2); }

.menu {
  position: absolute;
  top: 58px;
  right: 12px;
  z-index: 30;
  min-width: 190px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0d2116;
  box-shadow: var(--shadow);
}

.menu a, .menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  font-size: 14px;
}

.menu a:hover, .menu button:hover { background: rgba(91, 224, 138, .12); }

.search { padding: 12px 14px 0; }

.search input, .field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .25);
  outline: none;
}

.search input:focus, .field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(91, 224, 138, .12);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 14px 8px;
}

.tabs button {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  font-size: 13.5px;
}

.tabs button.on {
  color: #06210f;
  background: var(--accent);
  font-weight: 650;
}

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 10px; }
.list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: rgba(91, 224, 138, .2);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.group-title {
  padding: 10px 10px 4px;
  font-size: 11.5px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 11px;
  cursor: pointer;
  border: 1px solid transparent;
}

.row:hover { background: rgba(91, 224, 138, .07); }
.row.on { background: rgba(91, 224, 138, .13); border-color: rgba(91, 224, 138, .3); }

.row-main { min-width: 0; flex: 1; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-time { margin-left: auto; font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.row-preview {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #06210f;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 9px;
  background: #4b5f53;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .25);
}

.dot.online { background: var(--accent); }
.dot.away, .dot.idle { background: #f5c451; }
.dot.dnd, .dot.occupied { background: #ff7a7a; }
.dot.invisible { background: #7d8f84; }

.side-foot {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}

.btn {
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
}

.btn:hover { border-color: var(--accent-2); }

.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #05230f;
  font-weight: 650;
}

.btn.primary:hover { filter: brightness(1.05); }

.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255, 122, 122, .35); }

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, rgba(18, 48, 32, .88), rgba(8, 22, 15, .92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.empty {
  margin: auto;
  max-width: 420px;
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 8px; }

#chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, .12);
}

.chat-head .name { font-weight: 650; }
.chat-head .sub { font-size: 12.5px; color: var(--muted); }
.chat-head .icon-btn { margin-left: auto; font-size: 15px; width: auto; padding: 0 12px; }
.chat-head .back { margin-left: 0; padding: 0; width: 36px; font-size: 18px; }

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

.day {
  align-self: center;
  margin: 10px 0 4px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .25);
  color: var(--muted);
  font-size: 11.5px;
}

.msg {
  max-width: min(620px, 78%);
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--bubble-in);
  border: 1px solid rgba(255, 255, 255, .04);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  align-self: flex-start;
  position: relative;
}

.msg.out {
  align-self: flex-end;
  background: linear-gradient(180deg, #238a50, #1b6f40);
  border-color: rgba(91, 224, 138, .25);
}

.msg .meta {
  display: block;
  margin-top: 4px;
  font-size: 10.5px;
  color: rgba(230, 247, 236, .62);
  text-align: right;
  user-select: none;
}

.msg.pending { opacity: .7; }
.msg.failed { outline: 1px solid rgba(255, 122, 122, .6); }
.msg.failed .meta { color: #ffc3c3; }

.typing {
  padding: 2px 20px 0;
  height: 20px;
  font-size: 12px;
  color: var(--muted);
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, .12);
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .28);
  outline: none;
}

.composer textarea:focus { border-color: var(--accent-2); }

.composer .btn { height: 44px; padding: 0 18px; }

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login form {
  width: min(400px, 100%);
  padding: 30px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 48, 32, .94), rgba(8, 22, 15, .96));
  box-shadow: var(--shadow);
}

.login h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 2px;
  color: var(--accent);
}

.login p { color: var(--muted); margin: 6px 0 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field textarea { min-height: 90px; resize: vertical; }

.error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  background: rgba(255, 122, 122, .12);
  border: 1px solid rgba(255, 122, 122, .35);
  color: #ffc3c3;
  font-size: 13px;
}

.hint { margin: 16px 0 0; font-size: 13px; }

.login .btn { width: 100%; height: 44px; }

.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 8, 5, .72);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(520px, 100%);
  max-height: min(82vh, 760px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0f281a, #0a1d12);
  box-shadow: var(--shadow);
}

.modal h3 { margin: 0 0 4px; font-size: 19px; }
.modal .muted { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}

.profile-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.profile-head .avatar { width: 72px; height: 72px; flex-basis: 72px; border-radius: 16px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.statuses { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.statuses button {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  text-align: left;
}

.statuses button.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91, 224, 138, .16); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(520px, 90vw);
  padding: 11px 16px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #0f2a1a;
  box-shadow: var(--shadow);
  font-size: 13.5px;
}

.toast.err { border-color: rgba(255, 122, 122, .45); color: #ffc3c3; }

.result {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid rgba(29, 69, 48, .6);
}

.result:last-child { border-bottom: 0; }
.result .grow { flex: 1; min-width: 0; }
.result .name { font-weight: 600; }
.result .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 780px) {
  #app {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }
  .sidebar { border-radius: 0; border: 0; }
  .main {
    position: fixed;
    inset: 0;
    z-index: 20;
    border-radius: 0;
    border: 0;
    transform: translateX(100%);
    transition: transform .22s ease;
  }
  body.chat-open .main { transform: translateX(0); }
  .sidebar { height: 100vh; height: 100dvh; }
  .chat-head .back { display: inline-flex; }
}

.chat-head .back { display: none; }
