:root {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  color: #202124;
  background: #fff;
  --blue: #0b57d0;
  --line: #e4e9f0;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
}

.login {
  height: 100dvh;
  background: #f3f6fb;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  overflow: auto;
}

.login-panel {
  width: min(100%, 1080px);
  min-height: 420px;
  background: #fff;
  border-radius: 28px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 430px);
  gap: 72px;
  align-items: start;
  padding: 56px;
}

.brand-logo {
  width: 56px;
  height: auto;
  display: block;
  margin: 0 0 36px;
}

.login h1 {
  font-size: 42px;
  line-height: 1.08;
  font-weight: 400;
  margin: 0 0 24px;
  color: #202124;
  letter-spacing: 0;
}

.login p {
  font-size: 20px;
  line-height: 1.35;
  color: #030303;
  margin: 0;
}

.login-fields {
  padding-top: 98px;
  display: grid;
  gap: 14px;
}

.login label {
  display: block;
  margin: 0;
}

.login label span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.login input {
  outline: none;
}

.login input {
  width: 100%;
  height: 56px;
  border: 1px solid #747775;
  border-radius: 4px;
  padding: 0 16px;
  color: #202124;
  background: #fff;
  font-size: 17px;
}

.login input::placeholder {
  color: #3c4043;
  opacity: 1;
}

.login input:focus {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.login-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 28px;
}

.login button,
#composer button {
  border: 0;
  background: var(--blue);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.login button {
  min-width: 88px;
  height: 48px;
  border-radius: 24px;
  padding: 0 24px;
  font-size: 16px;
}

.login output {
  display: block;
  color: #b3261e;
  font-size: 14px;
  line-height: 1.4;
  min-width: 0;
}

main {
  height: 100dvh;
  display: grid;
  grid-template-columns: 330px 1fr;
  background: #fff;
  overflow: hidden;
  min-height: 0;
}

aside {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

aside header {
  min-height: 70px;
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

aside header > div {
  min-width: 0;
}

.conversation > header {
  height: 70px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.conversation > header > div {
  min-width: 0;
}

header small {
  display: block;
  color: #7b8798;
  margin-top: 2px;
}

.ghost {
  background: none;
  border: 0;
  color: #667285;
  cursor: pointer;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px #0b57d019;
}

.login button:hover,
#composer button:hover {
  background: #084dbb;
}

.ghost:hover {
  color: #334155;
}

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--line);
}

.notification-toggle {
  position: relative;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #667285;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.notification-toggle:hover,
.notification-toggle.enabled {
  background: #f1f5ff;
  color: #0b57d0;
}

.notification-toggle:disabled {
  cursor: wait;
  opacity: .65;
}

.notification-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notification-state {
  display: none;
  position: absolute;
  right: 8px;
  top: 8px;
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: transparent;
}

.notification-toggle.enabled .notification-state {
  display: block;
  background: #0b57d0;
}

.account-menu {
  position: relative;
}

.account-menu-toggle {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #202124;
  cursor: pointer;
  padding: 8px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.account-menu-toggle:hover,
.account-menu-toggle[aria-expanded="true"] {
  background: #f1f5ff;
}

.account-avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: #dbe6ff;
  color: #2759c4;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

.account-menu-toggle b,
.account-menu-toggle small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu-toggle small {
  color: #738093;
  font-size: 12px;
  margin-top: 2px;
}

.account-menu-toggle i {
  color: #667285;
  font-style: normal;
  font-weight: 800;
}

.account-menu-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px #2235551f;
  display: grid;
  gap: 2px;
  z-index: 20;
}

.account-menu-panel .ghost {
  width: 100%;
  min-height: 38px;
  border-radius: 6px;
  padding: 0 10px;
  color: #3d4857;
  text-align: left;
  font-weight: 700;
}

.account-menu-panel .ghost:hover {
  background: #f1f5ff;
  color: #202124;
}

.mobile-menu {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #667285;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
}

.mobile-menu:hover {
  background: #f1f5ff;
  color: #334155;
}

nav {
  min-height: 0;
  overflow-y: auto;
}

.chat {
  display: grid;
  grid-template-columns: 43px 1fr auto;
  gap: 11px;
  padding: 13px 15px;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.chat.group-parent {
  cursor: default;
  padding-bottom: 8px;
}

.chat.group-parent:hover {
  background: transparent;
  border-left-color: transparent;
}

.chat.topic-chat {
  grid-template-columns: 32px 1fr auto;
  padding: 9px 15px 9px 32px;
}

.chat:hover,
.chat.active {
  background: #f1f5ff;
  border-left-color: var(--blue);
}

.avatar {
  width: 43px;
  height: 43px;
  border-radius: 13px;
  background: #dbe6ff;
  color: #2759c4;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.topic-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #eef4e8;
  color: #497038;
}

.chat b,
.chat span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat span {
  font-size: 13px;
  color: #738093;
  display: block;
  margin-top: 4px;
}

.badge {
  background: var(--blue);
  color: white;
  border-radius: 99px;
  padding: 2px 7px;
  font-size: 11px;
  height: max-content;
}

.conversation {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: #f8fafc;
}

.conversation h2 {
  font-size: 17px;
  margin: 0;
}

.message-search {
  min-width: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, auto) minmax(130px, auto) auto auto auto;
  gap: 10px;
  align-items: end;
}

.message-search label {
  display: grid;
  gap: 4px;
  color: #667285;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.message-search input {
  width: 100%;
  height: 38px;
  border: 1px solid #cfd7e3;
  border-radius: 7px;
  color: #202124;
  background: #fff;
  padding: 0 11px;
  outline: none;
}

.message-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px #0b57d019;
}

.message-search button {
  height: 38px;
  border: 0;
  border-radius: 19px;
  padding: 0 15px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.message-search .ghost {
  background: transparent;
  color: #667285;
}

.message-search output {
  min-width: 62px;
  color: #738093;
  font-size: 13px;
  line-height: 38px;
}

#history {
  padding: 24px clamp(16px, 4vw, 60px);
  min-height: 0;
  overflow: visible;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty {
  margin: auto;
  text-align: center;
  color: #8390a0;
  display: grid;
  gap: 7px;
}

.empty b {
  color: #3d4857;
}

.message {
  max-width: min(680px, 82%);
  padding: 10px 13px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px 15px 15px 15px;
  box-shadow: 0 2px 6px #1f355308;
}

.message.outgoing {
  align-self: flex-end;
  background: #e6efff;
  border-radius: 15px 6px 15px 15px;
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: #7a8798;
  margin-bottom: 5px;
}

.meta b {
  color: #3b67bb;
}

.message p {
  white-space: pre-wrap;
  margin: 0;
  line-height: 1.45;
}

.attachment-card {
  display: block;
  color: #2459be;
  text-decoration: none;
}

.attachment-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.attachment-unavailable {
  color: #7a8798;
}

.inline-delete {
  border: 0;
  background: transparent;
  color: #b3261e;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  padding: 0;
}

.inline-delete:hover {
  color: #7f1d1d;
  text-decoration: underline;
}

.status {
  font-size: 10px;
  color: #8a6670;
}

#composer {
  margin: 0 clamp(14px, 3vw, 45px) 20px;
  background: white;
  border: 1px solid #dce2eb;
  border-radius: 14px;
  padding: 9px;
  display: flex;
  align-items: end;
  gap: 8px;
  box-shadow: 0 8px 30px #22355510;
}

#composer textarea {
  resize: none;
  flex: 1;
  border: 0;
  outline: 0;
  padding: 9px;
  max-height: 140px;
}

.attach {
  font-size: 25px;
  color: #68758a;
  cursor: pointer;
  padding: 3px;
}

.attach input {
  display: none;
}

.signature {
  font-size: 12px;
  color: #6f7b8d;
  align-self: center;
}

.admin-panel {
  display: grid;
  grid-template-rows: 70px 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #f8fafc;
}

.admin-panel > header {
  height: 70px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
}

#new-user {
  margin-left: auto;
}

.admin-panel h2 {
  font-size: 17px;
  margin: 0;
}

.admin-content {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(420px, 760px);
  gap: 24px;
  padding: 24px clamp(18px, 3vw, 42px);
  overflow-y: auto;
  align-content: start;
}

.user-list,
.user-form {
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-list {
  overflow: hidden;
}

.user-list-head {
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-list-head span {
  color: #738093;
  font-size: 13px;
}

#users-list {
  max-height: calc(100vh - 172px);
  overflow: auto;
}

.user-row {
  width: 100%;
  min-height: 70px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
  align-items: center;
  cursor: pointer;
}

.user-row:hover,
.user-row.selected {
  background: #f1f5ff;
}

.user-row b,
.user-row small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row small {
  margin-top: 4px;
  color: #738093;
  font-size: 12px;
}

.role,
.inactive {
  justify-self: end;
  border-radius: 999px;
  padding: 3px 8px;
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.role-user {
  color: #385075;
  background: #edf2f8;
}

.role-admin {
  color: #8a3b12;
  background: #fff0d9;
}

.inactive {
  grid-column: 2;
  color: #7a3540;
  background: #fde7eb;
}

.user-form {
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.user-form label {
  display: grid;
  gap: 7px;
  color: #4b5565;
  font-size: 13px;
  font-weight: 700;
}

.user-form .wide {
  grid-column: 1 / -1;
}

.user-form input,
.user-form select {
  width: 100%;
  height: 44px;
  border: 1px solid #cfd7e3;
  border-radius: 7px;
  color: #202124;
  background: #fff;
  padding: 0 12px;
  outline: none;
}

.user-form input:focus,
.user-form select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px #0b57d019;
}

.check-row {
  display: flex !important;
  grid-template-columns: none;
  flex-direction: row;
  align-items: center;
  gap: 9px !important;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.user-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
}

.user-form button {
  border: 0;
  background: var(--blue);
  color: #fff;
  height: 42px;
  border-radius: 21px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

.user-form button:hover {
  background: #084dbb;
}

.user-form output {
  color: #b3261e;
  font-size: 13px;
  line-height: 1.4;
}

.groups-content {
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(18px, 3vw, 42px);
}

.groups-notice {
  max-width: 760px;
  color: #667285;
  line-height: 1.5;
  margin-bottom: 18px;
}

.groups-list {
  max-width: 760px;
  display: grid;
  gap: 10px;
}

.group-row {
  min-width: 0;
  min-height: 70px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 43px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-row b,
.group-row small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-row small {
  margin-top: 4px;
  color: #738093;
  font-size: 12px;
}

.group-row button,
#refresh-groups {
  border: 0;
  background: var(--blue);
  color: #fff;
  height: 38px;
  border-radius: 19px;
  padding: 0 15px;
  font-weight: 800;
  cursor: pointer;
}

.group-row button:hover,
#refresh-groups:hover {
  background: #084dbb;
}

.group-row button.danger {
  color: #b3261e;
  background: #fdecef;
}

.group-row button.danger:hover {
  color: #7f1d1d;
  background: #fbd5dc;
}

.group-row button:disabled {
  cursor: wait;
  opacity: .65;
}

.help-content {
  max-width: 900px;
  padding: 28px clamp(18px, 4vw, 56px);
  min-height: 0;
  overflow-y: auto;
}

.help-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.help-section:last-child {
  border-bottom: 0;
}

.help-section h3 {
  margin: 0 0 12px;
  font-size: 16px;
  color: #202124;
}

.help-section ol,
.help-section ul {
  margin: 0;
  padding-left: 22px;
  color: #3d4857;
  line-height: 1.6;
}

.help-section li + li {
  margin-top: 6px;
}

.help-section code {
  color: #0b57d0;
  background: #edf4ff;
  border-radius: 4px;
  padding: 2px 5px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #202a38;
  color: white;
  padding: 12px 16px;
  border-radius: 9px;
  pointer-events: none;
}

@media (max-width: 820px) {
  .login {
    align-items: flex-start;
    padding: 24px;
  }

  .login-panel {
    grid-template-columns: 1fr;
    gap: 32px;
    min-height: auto;
    padding: 36px 28px;
    border-radius: 24px;
  }

  .brand-logo {
    width: 52px;
    margin-bottom: 30px;
  }

  .login h1 {
    font-size: 40px;
    margin-bottom: 18px;
  }

  .login p {
    font-size: 19px;
  }

  .login-fields {
    padding-top: 0;
    gap: 14px;
  }

  .login input {
    height: 56px;
    font-size: 16px;
  }

  .login-actions {
    margin-top: 24px;
  }

  .login button {
    height: 46px;
    min-width: 86px;
    font-size: 16px;
  }

  main {
    grid-template-columns: 1fr;
  }

  .message-search {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .message-search input,
  .message-search button {
    height: 42px;
  }

  .message-search > input,
  .message-search output {
    grid-column: 1 / -1;
  }

  .message-search output {
    line-height: 1.4;
  }

  .conversation {
    display: none;
  }

  .mobile-menu {
    display: grid;
    place-items: center;
  }

  main.chat-open aside {
    display: none;
  }

  main.chat-open .conversation {
    display: flex;
  }

  main.admin-open aside {
    display: none;
  }

  main.admin-open .admin-panel:not([hidden]) {
    display: grid;
  }

  .admin-content {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .groups-content {
    padding: 16px;
  }

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

  .group-actions {
    grid-column: 2;
    flex-wrap: wrap;
  }

  #users-list {
    max-height: none;
  }

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

  .signature {
    display: none;
  }
}
