:root {
  color-scheme: dark;
  --ink: #eef6f4;
  --muted: #9dafb7;
  --line: #2a3a42;
  --panel: #151f25;
  --soft: #182a29;
  --accent: #1aa384;
  --accent-strong: #138168;
  --danger: #ff7f7f;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0c1216;
  color: var(--ink);
}

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

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111a20;
  color: var(--ink);
  font-size: 16px;
  min-height: 40px;
  padding: 9px 11px;
}

textarea {
  resize: none;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(8, 12, 15, 0.58);
  backdrop-filter: blur(4px);
}

.loader-ring {
  width: 54px;
  height: 54px;
  border: 4px solid rgba(238, 246, 244, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-shell,
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 15%, rgba(26, 163, 132, 0.2), transparent 32%),
    radial-gradient(circle at 82% 22%, rgba(82, 114, 255, 0.12), transparent 26%),
    #0c1216;
}

.auth-card,
.install-panel {
  width: min(460px, 100%);
  background: rgba(21, 31, 37, 0.94);
  border: 1px solid rgba(116, 143, 153, 0.28);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #172026;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

.auth-card h1 {
  margin: 0 0 18px;
  font-size: 2rem;
}

.auth-card p,
.install-panel p {
  color: var(--muted);
}

.auth-form,
.modal-form,
.stack-form {
  display: grid;
  gap: 14px;
}

.chat-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 310px 1fr;
}

.mobile-nav {
  display: none;
}

.sidebar {
  min-height: 100vh;
  border-right: 1px solid #26343b;
  background:
    linear-gradient(180deg, rgba(17, 120, 100, 0.18), transparent 36%),
    #11191e;
  color: #edf5f3;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

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

.profile-chip {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.profile-chip img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #117864;
}

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

.profile-chip small {
  color: #9fb2ba;
  font-size: 0.8rem;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.eyebrow {
  display: block;
  color: #9fb2ba;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.icon-text,
.admin-link,
.ghost-button {
  background: #223039;
  color: #edf5f3;
}

.icon-text:hover,
.admin-link:hover {
  background: #2d424c;
}

.primary-action {
  width: 100%;
}

.join-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.sidebar input {
  background: #18242a;
  border-color: #33454e;
  color: #edf5f3;
}

.sidebar input::placeholder {
  color: #8297a1;
}

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

.room-item {
  display: grid;
  gap: 3px;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  color: #edf5f3;
  border: 1px solid #2d3d45;
  padding: 12px;
  min-height: 64px;
}

.room-item:hover,
.room-item.active {
  background: rgba(17, 120, 100, 0.2);
  border-color: #117864;
}

.room-item span {
  color: #9fb2ba;
  font-size: 0.82rem;
  text-transform: capitalize;
}

.chat-main {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: #0c1216;
}

.room-header {
  min-height: 76px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.room-header h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.room-header p {
  margin: 0;
  color: var(--muted);
}

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

.key-panel {
  margin: 18px 22px 0;
  padding: 18px;
  border: 1px solid #2b514b;
  background: var(--soft);
  border-radius: 8px;
}

.key-panel form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(680px, 86%);
  align-self: flex-start;
}

.message.own {
  align-self: flex-end;
}

.message-meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0 0 5px 3px;
}

.message-body {
  background: #151f25;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.message.own .message-body {
  background: #15362f;
  border-color: #1f6d5c;
}

.seen-state {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
}

.decrypt-error {
  color: var(--danger);
}

.chat-image {
  display: block;
  width: min(420px, 100%);
  max-height: 360px;
  object-fit: contain;
  border-radius: 7px;
  margin-bottom: 8px;
}

.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
}

.attachment-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid #28443f;
  border-radius: 8px;
  background: #10231f;
}

.attachment-preview img {
  width: 54px;
  height: 54px;
  border-radius: 7px;
  object-fit: cover;
}

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

.attachment-preview span {
  color: var(--muted);
  font-size: 0.82rem;
}

.attachment-preview button {
  background: #253742;
}

.file-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #223039;
  color: var(--ink);
  cursor: pointer;
}

.file-button input {
  display: none;
}

.profile-modal {
  width: min(620px, calc(100vw - 24px));
}

.profile-editor {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 18px;
  align-items: start;
}

.avatar-preview {
  width: 150px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #11191e;
  overflow: hidden;
  border: 1px solid var(--line);
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.password-modal {
  width: min(460px, calc(100vw - 24px));
}

.password-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.password-box strong {
  color: var(--ink);
}

dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: min(92dvh, 760px);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(12, 20, 24, 0.45);
}

.modal-form {
  padding: 22px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 4px 0 0;
  padding: 0;
}

menu button:first-child {
  background: #223039;
  color: var(--ink);
}

.check-row {
  display: flex;
  align-items: center;
}

.check-row input {
  width: auto;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 150px auto;
  gap: 8px;
  margin-top: 14px;
}

.list-row,
.admin-user {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:has(button) {
  grid-template-columns: 1fr auto auto;
}

.list-row button {
  background: #442125;
  color: #ffdede;
}

.list-row button:hover {
  background: #5a2a30;
}

.list-row strong {
  text-transform: capitalize;
}

#adminDialog {
  width: min(1120px, calc(100vw - 24px));
  background: #10181d;
  overflow: hidden;
}

.admin-modal {
  width: 100%;
  padding: 0;
  background:
    linear-gradient(135deg, rgba(26, 163, 132, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(82, 114, 255, 0.1), transparent 30%),
    #10181d;
}

.admin-hero {
  min-height: 112px;
  padding: 24px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(145, 167, 176, 0.22);
  background: rgba(17, 25, 30, 0.72);
  backdrop-filter: blur(10px);
}

.admin-hero h3 {
  margin: 3px 0 0;
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 0.95;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
  gap: 18px;
  padding: 18px;
}

.admin-panel {
  min-width: 0;
  border: 1px solid rgba(145, 167, 176, 0.22);
  border-radius: 8px;
  background: rgba(21, 31, 37, 0.9);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.22);
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h4 {
  margin: 0;
  font-size: 1.15rem;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.form-grid {
  display: grid;
  gap: 10px;
}

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

.form-grid.three-col {
  grid-template-columns: 1.1fr 1fr 170px;
}

.admin-user {
  grid-template-columns: minmax(170px, 1fr) 156px auto auto;
  gap: 10px;
  border: 1px solid rgba(145, 167, 176, 0.22);
  border-radius: 8px;
  background: #111a20;
  padding: 12px;
  margin-bottom: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.admin-create-user {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.admin-user-list {
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}

.admin-user-main {
  min-width: 0;
}

.admin-user span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-style: normal;
  font-weight: 900;
  text-transform: uppercase;
}

.status-pill.active {
  background: #15362f;
  color: #72e4c6;
}

.status-pill.disabled {
  background: #442125;
  color: var(--danger);
}

.admin-user button,
.admin-user select {
  min-height: 36px;
}

.admin-user button[data-toggle] {
  background: #253742;
}

.admin-user button[data-toggle]:hover {
  background: #2c3a42;
}

.permission-grid {
  display: grid;
  gap: 9px;
}

.permission-grid label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid rgba(145, 167, 176, 0.24);
  border-radius: 8px;
  background: #111a20;
  color: var(--ink);
}

.permission-grid input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.form-note {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
}

.error-text,
.notice.error {
  color: var(--danger);
}

.success-text {
  color: #72e4c6;
}

.notice {
  padding: 12px;
  border-radius: 7px;
  margin: 16px 0;
}

.notice.success {
  color: #72e4c6;
  background: #15362f;
}

@media (max-width: 820px) {
  body {
    overflow-x: hidden;
  }

  button {
    min-height: 44px;
  }

  .auth-shell,
  .auth-page {
    padding: 14px;
    align-items: start;
    padding-top: 8dvh;
  }

  .auth-card,
  .install-panel {
    padding: 22px;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
    padding-bottom: 72px;
  }

  .sidebar {
    min-height: calc(100dvh - 72px);
    border-right: 0;
    border-bottom: 0;
    padding: 12px;
    gap: 10px;
  }

  #app.mobile-chat-active .sidebar {
    display: none;
  }

  #app:not(.mobile-chat-active) .chat-main {
    display: none;
  }

  .sidebar-top {
    align-items: flex-start;
  }

  .profile-chip {
    grid-template-columns: 42px 1fr;
  }

  .profile-chip img {
    width: 42px;
    height: 42px;
  }

  .join-box {
    grid-template-columns: 1fr;
  }

  .room-list {
    grid-auto-flow: row;
    grid-auto-columns: unset;
    overflow: visible;
    padding-bottom: 2px;
  }

  .room-item {
    min-height: 58px;
  }

  .chat-main {
    height: calc(100dvh - 72px);
    min-height: 0;
  }

  .room-header {
    min-height: auto;
    padding: 14px;
    flex-direction: column;
    gap: 10px;
  }

  .room-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .key-panel {
    margin: 12px;
    padding: 14px;
  }

  .messages {
    padding: 12px;
  }

  .composer {
    padding: 10px;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }

  .composer textarea {
    min-height: 44px;
    max-height: 120px;
  }

  .file-button {
    min-height: 44px;
    padding: 0 10px;
  }

  dialog {
    width: calc(100vw - 16px);
    max-height: 90dvh;
  }

  .modal-form {
    padding: 16px;
  }

  menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .composer,
  .key-panel form,
  .inline-form,
  .profile-editor,
  .admin-grid,
  .form-grid.two-col,
  .form-grid.three-col,
  .admin-user {
    grid-template-columns: 1fr;
  }

  .admin-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .message {
    max-width: 100%;
  }

  .mobile-nav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 900;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    border: 1px solid rgba(145, 167, 176, 0.24);
    border-radius: 8px;
    background: rgba(17, 25, 30, 0.94);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(12px);
  }

  .mobile-nav.hidden {
    display: none;
  }

  .mobile-nav button {
    min-height: 44px;
    padding: 0 8px;
    background: #223039;
    color: #d6e5e1;
    font-size: 0.86rem;
  }

  .mobile-nav button.active {
    background: var(--accent);
    color: #fff;
  }

  .mobile-nav button:disabled {
    opacity: 0.45;
  }
}

@media (max-width: 480px) {
  .auth-card h1 {
    font-size: 1.6rem;
  }

  .sidebar-actions,
  .room-actions,
  menu {
    grid-template-columns: 1fr;
  }

  .chat-main {
    height: calc(100dvh - 72px);
    min-height: 0;
  }

  .room-list {
    grid-auto-columns: unset;
  }

  .room-header h2 {
    font-size: 1.1rem;
  }

  .composer {
    grid-template-columns: 1fr auto;
  }

  .file-button {
    grid-column: 1 / -1;
  }

  .attachment-preview {
    grid-template-columns: 46px 1fr;
  }

  .attachment-preview button {
    grid-column: 1 / -1;
  }

  .attachment-preview img {
    width: 46px;
    height: 46px;
  }

  .admin-hero {
    padding: 18px;
  }

  .admin-hero h3 {
    font-size: 2rem;
  }

  .mobile-nav {
    grid-template-columns: repeat(2, 1fr);
  }
}
