:root {
  color-scheme: light;
  --bg: #edf1f5;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #6d7884;
  --line: #d9e0e7;
  --accent: #0e8f78;
  --accent-2: #2556d9;
  --danger: #c83a3a;
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 460px) minmax(320px, 420px);
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 32px;
}

.auth-brand span {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13px;
}

.auth-brand h1 {
  margin: 10px 0;
  font-size: 56px;
  line-height: 1;
}

.auth-brand p {
  color: var(--muted);
  font-size: 19px;
  line-height: 1.5;
}

.auth-panel,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(24, 38, 52, 0.12);
}

.auth-panel {
  padding: 24px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: #eef3f7;
  border-radius: 8px;
  margin-bottom: 18px;
}

.tab {
  border-radius: 6px;
  padding: 10px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(20, 30, 40, 0.1);
}

label {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 143, 120, 0.12);
}

.primary,
.send {
  width: 100%;
  border-radius: 8px;
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.status,
.upload-status {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.chat-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
  background: #f9fbfc;
  border-right: 1px solid var(--line);
}

.side-head,
.chat-head {
  min-height: 76px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.side-head strong {
  display: block;
  font-size: 20px;
}

.side-head span,
.chat-head span {
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #eef3f7;
  color: var(--ink);
}

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

.side-actions button {
  min-height: 40px;
  border-radius: 8px;
  background: #e7edf3;
  color: var(--ink);
  font-weight: 700;
}

.side-scroll {
  overflow: auto;
}

.side-section {
  padding: 8px;
}

.side-label {
  padding: 8px 4px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.group-list,
.user-nav {
  display: grid;
  gap: 2px;
}

.group-list {
  padding: 0;
}

.empty-mini {
  padding: 10px 4px 12px;
  color: var(--muted);
  font-size: 13px;
}

.group-item,
.user-item {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  background: transparent;
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
}

.group-item {
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
}

.user-item {
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
}

.chat-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #dcebe8;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 12px;
}

.image-avatar img,
.chat-head-avatar-inner img,
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-summary {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.group-item:hover,
.group-item.active,
.user-item:hover {
  background: #e8f3f1;
}

.group-item strong,
.user-item strong {
  font-size: 15px;
}

.group-item span,
.user-item span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: #f4f7fa;
}

.drop-overlay {
  position: absolute;
  inset: 90px 20px 84px;
  z-index: 12;
  display: none;
  place-items: center;
  gap: 8px;
  align-content: center;
  color: var(--accent);
  text-align: center;
  background: rgba(232, 243, 241, 0.92);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  pointer-events: none;
}

.conversation.drop-active .drop-overlay {
  display: grid;
}

.drop-overlay strong {
  font-size: 24px;
}

.drop-overlay span {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.chat-head {
  background: rgba(255, 255, 255, 0.78);
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-head-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

.chat-head-avatar-inner {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
  background: #dcebe8;
  color: var(--accent);
  font-weight: 900;
}

.chat-head h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.small-tool {
  min-height: 30px;
  border-radius: 8px;
  padding: 6px 10px;
  background: #eef3f7;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.chat-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #e8eef4;
  border-radius: 8px;
}

.view-tab {
  min-width: 72px;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.view-tab.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(20, 30, 40, 0.1);
}

.notify-setting {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
}

.notify-setting input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.notify-setting span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.messages {
  overflow: auto;
  padding: 20px;
}

.empty-state {
  margin: 40px auto;
  max-width: 420px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.files-panel,
.media-panel {
  overflow: auto;
  padding: 20px;
}

.files-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.files-head strong {
  font-size: 18px;
}

.files-head span {
  color: var(--muted);
  font-size: 13px;
}

.files-list {
  display: grid;
  gap: 10px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.media-card {
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(18, 33, 48, 0.05);
}

.media-preview {
  height: 150px;
  display: grid;
  place-items: center;
  background: #e7edf3;
}

.media-preview img,
.media-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-preview span {
  color: var(--muted);
  font-weight: 700;
}

.media-body {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.media-body strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.media-body span {
  color: var(--muted);
  font-size: 12px;
}

.file-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(18, 33, 48, 0.05);
}

.file-kind {
  width: 52px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e7edf3;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.file-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row span {
  color: var(--muted);
  font-size: 13px;
}

.file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-actions a,
.file-actions button {
  min-height: 34px;
  border-radius: 8px;
  padding: 8px 10px;
  background: #e7edf3;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.file-actions .danger {
  background: #ffe9e9;
  color: var(--danger);
}

.message {
  max-width: 760px;
  margin: 0 0 12px;
  display: grid;
  gap: 6px;
}

.message.own {
  margin-left: auto;
}

.message {
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
}

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

.bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 2px 8px rgba(18, 33, 48, 0.05);
}

.message.own .bubble {
  background: #daf3ee;
  border-color: #b7ded6;
}

.message.critical .bubble {
  border-color: #f0a43a;
  background: #fff8e8;
}

.message.own.critical .bubble {
  background: #ffe7dd;
  border-color: #f1a589;
}

.message-avatar,
.user-avatar {
  display: grid;
  place-items: center;
  background: #dcebe8;
  color: var(--accent);
  font-weight: 900;
  overflow: hidden;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 12px;
}

.message.own .message-avatar {
  grid-column: 2;
  grid-row: 1;
}

.message-body {
  display: grid;
  gap: 6px;
}

.message.own .message-body {
  grid-column: 1;
  grid-row: 1;
}

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.critical-badge {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff1d6;
  color: #9c4e00;
  font-size: 11px;
  font-weight: 900;
}

.text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.attachments {
  display: grid;
  gap: 8px;
}

.attachment-card {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  max-width: 560px;
  padding: 8px;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.attachment-preview {
  min-height: 74px;
  border-radius: 8px;
  overflow: hidden;
  background: #e7edf3;
  text-decoration: none;
}

.attachment-preview.image {
  display: block;
}

.attachment-preview img,
.attachment-preview video {
  width: 100%;
  height: 100%;
  min-height: 74px;
  max-height: 150px;
  object-fit: cover;
  display: block;
}

.attachment-preview.icon {
  display: grid;
  place-items: center;
  gap: 4px;
  align-content: center;
  color: var(--accent);
  font-size: 20px;
  font-weight: 900;
}

.attachment-preview.icon span {
  color: var(--muted);
  font-size: 11px;
}

.attachment-info {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-content: center;
}

.attachment-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-info span {
  color: var(--muted);
  font-size: 12px;
}

.message-delete {
  margin-left: auto;
  border-radius: 999px;
  padding: 3px 8px;
  background: #ffe9e9;
  color: var(--danger);
  font-size: 11px;
  font-weight: 800;
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  color: var(--accent-2);
  text-decoration: none;
  background: #eef3ff;
  border-radius: 8px;
  padding: 8px 10px;
}

.composer {
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr) 120px;
  gap: 10px;
  padding: 14px;
  background: #ffffff;
  border-top: 1px solid var(--line);
}

#file-input {
  display: none;
}

.attach {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e7edf3;
  font-size: 24px;
}

.critical-toggle {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #fff1d6;
  color: #a85b00;
  font-size: 22px;
  font-weight: 900;
}

.critical-toggle.active {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(224, 50, 50, 0.18);
}

.composer textarea {
  min-height: 42px;
  max-height: 150px;
  resize: none;
}

.send {
  width: auto;
}

.upload-status {
  padding: 0 16px 10px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 26, 38, 0.42);
}

.modal-panel {
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: auto;
  padding: 18px;
}

.modal-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.modal-panel h2 {
  margin: 0;
}

.modal-panel header button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #eef3f7;
}

.settings-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.setting-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 190px;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.setting-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.setting-row span {
  color: var(--ink);
  font-weight: 700;
}

.settings-hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.avatar-preview {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin: 8px 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #eef3f7;
}

.profile-preview-fallback {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  background: #dcebe8;
  color: var(--accent);
  font-size: 24px;
  font-weight: 900;
}

.user-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.member-picker {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.member-picker strong {
  font-size: 14px;
}

.member-picker span {
  color: var(--muted);
  font-size: 13px;
}

.member-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.member-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
}

.member-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-row strong {
  display: block;
}

.user-row span {
  color: var(--muted);
  font-size: 13px;
}

.user-row button {
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent-2);
  color: white;
  font-weight: 700;
}

.admin-actions {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto auto;
  gap: 8px;
  align-items: center;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  z-index: 20;
  pointer-events: none;
}

.toast {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(24, 38, 52, 0.16);
}

.toast strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.toast span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .auth-screen {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 20px;
  }

  .auth-brand h1 {
    font-size: 42px;
  }

  .chat-screen {
    grid-template-columns: 1fr;
    grid-template-rows: 38vh 62vh;
  }

  .sidebar,
  .conversation {
    min-height: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .composer {
    grid-template-columns: 42px 42px minmax(0, 1fr);
  }

  .send {
    grid-column: 1 / -1;
  }

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

  .setting-row select {
    grid-column: 1 / -1;
  }

  .user-row {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    grid-template-columns: 1fr;
  }

  .chat-head {
    align-items: flex-start;
    gap: 10px;
  }

  .chat-tools {
    align-items: flex-end;
    flex-direction: column;
    gap: 8px;
  }

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

  .file-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .notify-setting span {
    font-size: 13px;
  }
}
