:root {
  color-scheme: dark;
  --bg: #0b141a;
  --panel: #111b21;
  --panel-soft: #17252d;
  --line: #233138;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --bubble: #202c33;
  --bubble-mine: #005c4b;
  --danger: #ff7b7b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(
    circle at top left,
    #18333a 0,
    #0b141a 38%,
    #060a0d 100%
  );
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

select {
  font: inherit;
}

button {
  appearance: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  height: 100vh;
  max-width: 1500px;
  margin: 0 auto;
  border-inline: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--bg);
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 96%, black);
}

.brand,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 27, 33, 0.94);
  backdrop-filter: blur(14px);
}

.chat-header {
  align-items: flex-start;
  flex-wrap: wrap;
}

.chat-title-block {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(260px, 100%);
}

.chat-title-text {
  margin-right: 4px;
}

.chat-title-edit {
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-header:hover .chat-title-edit {
  opacity: 1;
}

.chat-title-edit:hover {
  background: var(--panel-soft);
}

.chat-title-input {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: 10px;
  outline: 0;
  padding: 8px 10px;
  color: var(--text);
  background: var(--panel-soft);
  font-size: 18px;
  font-weight: 700;
}

.brand h1,
.chat-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.1;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.current-user {
  max-width: 110px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-link {
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--text);
  background: #202c33;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.danger-link {
  color: #ffd1d1;
  background: rgba(122, 28, 28, 0.72);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.icon-button,
.button {
  border: 0;
  border-radius: 999px;
  color: #06120f;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.icon-button {
  width: 40px;
  height: 40px;
  color: var(--text);
  background: var(--panel-soft);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
}

.button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.button:disabled,
.disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.secondary {
  color: var(--text);
  background: #24343d;
}

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

.upload-card {
  margin: 16px;
  padding: 16px;
  border: 1px dashed #31515b;
  border-radius: 20px;
  background: linear-gradient(
    145deg,
    rgba(0, 168, 132, 0.12),
    rgba(32, 44, 51, 0.74)
  );
}

.upload-card.dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.18);
}

.upload-copy {
  display: grid;
  gap: 4px;
}

.upload-copy span,
.progress-wrap span,
.conversation-item small,
.message-count {
  color: var(--muted);
  font-size: 13px;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.progress-wrap {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #223039;
}

progress::-webkit-progress-bar {
  background: #223039;
}

progress::-webkit-progress-value,
progress::-moz-progress-bar {
  background: var(--accent);
}

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

.search-box {
  display: grid;
  gap: 7px;
  padding: 0 16px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box input,
.date-filter input,
.chat-search input,
.chat-date-filter input,
.auth-form input,
.admin-form input,
.admin-form select,
.user-row input,
.user-row select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  outline: 0;
  padding: 12px 14px;
  color: var(--text);
  background: #202c33;
}

.search-box input:focus,
.date-filter input:focus,
.chat-search input:focus,
.chat-date-filter input:focus,
.auth-form input:focus,
.admin-form input:focus,
.admin-form select:focus,
.user-row input:focus,
.user-row select:focus {
  border-color: var(--accent);
}

.search-box input:disabled,
.date-filter input:disabled,
.chat-search input:disabled,
.chat-date-filter input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.date-filter {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 0 16px 14px;
}

.date-filter label,
.chat-search,
.chat-date-filter label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chat-tools {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
  min-width: min(520px, 100%);
}

.chat-search {
  min-width: min(250px, 100%);
}

.chat-date-filter {
  display: grid;
  grid-template-columns: repeat(2, minmax(116px, 1fr));
  gap: 8px;
}

.conversation-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: stretch;
  border-bottom: 1px solid rgba(134, 150, 160, 0.14);
}

.conversation-row:hover,
.conversation-row.active {
  background: #202c33;
}

.conversation-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  border: 0;
  padding: 13px 16px;
  color: inherit;
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.conversation-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 0;
}

.delete-conversation {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 123, 123, 0.38);
  border-radius: 999px;
  color: #ffd1d1;
  background: rgba(122, 28, 28, 0.72);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.delete-conversation:hover {
  color: white;
  background: #d83b3b;
}

.rename-conversation {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(0, 168, 132, 0.38);
  border-radius: 999px;
  color: #a0e8d6;
  background: rgba(0, 168, 132, 0.15);
  cursor: pointer;
  font-size: 13px;
}

.rename-conversation:hover {
  background: rgba(0, 168, 132, 0.3);
}

.avatar {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  color: #dff7f1;
  background: linear-gradient(135deg, #00a884, #245c70);
  font-weight: 900;
}

.conversation-text {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.conversation-text strong,
.conversation-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.conversation-meta b {
  min-width: 22px;
  border-radius: 999px;
  padding: 3px 6px;
  color: #06251f;
  text-align: center;
  background: var(--accent);
}

.muted-card,
.empty-results,
.loading {
  margin: 16px;
  padding: 18px;
  border-radius: 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.chat-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.messages {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(14px, 3vw, 46px);
  background:
    linear-gradient(rgba(11, 20, 26, 0.92), rgba(11, 20, 26, 0.92)),
    radial-gradient(
      circle at 20% 20%,
      rgba(0, 168, 132, 0.16),
      transparent 28%
    ),
    radial-gradient(
      circle at 80% 10%,
      rgba(52, 107, 122, 0.22),
      transparent 30%
    );
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  margin-bottom: 6px;
  color: var(--text);
}

.message {
  width: fit-content;
  max-width: min(680px, 78%);
  margin: 0 0 10px;
  padding: 9px 11px 7px;
  border-radius: 12px 12px 12px 2px;
  background: var(--bubble);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.message.mine {
  margin-left: auto;
  border-radius: 12px 12px 2px 12px;
  background: var(--bubble-mine);
}

.message strong {
  display: block;
  margin-bottom: 4px;
  color: #6ad7c1;
  font-size: 13px;
}

.message-body {
  color: #f0f4f5;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
}

.message time {
  display: block;
  margin-top: 6px;
  color: rgba(233, 237, 239, 0.58);
  font-size: 11px;
  text-align: right;
}

.jump-conversation {
  display: inline-flex;
  margin-bottom: 7px;
  border: 0;
  border-radius: 999px;
  padding: 4px 9px;
  color: #06120f;
  background: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.load-more-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 14px;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
}

.load-more-btn:hover {
  background: rgba(0, 168, 132, 0.08);
  border-color: var(--accent);
}

.load-more-btn:disabled {
  cursor: wait;
  opacity: 0.6;
}

mark {
  border-radius: 4px;
  padding: 0 2px;
  color: #07110f;
  background: #96f7d2;
}

.media-preview,
.attachment {
  display: block;
  margin-top: 8px;
}

.media-preview img,
.media-video {
  display: block;
  max-width: min(420px, 100%);
  max-height: 360px;
  border-radius: 10px;
}

.media-audio {
  width: min(360px, 100%);
  margin-top: 8px;
}

.attachment {
  color: #9ee8da;
  font-weight: 800;
}

.auth-page,
.admin-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card,
.admin-shell {
  width: min(100%, 440px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 26px;
  padding: 28px;
  background: rgba(17, 27, 33, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.auth-card h1,
.admin-header h1,
.admin-card h2 {
  margin: 6px 0 0;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.5;
}

.auth-form,
.admin-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.auth-form label,
.admin-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.auth-error,
.auth-success {
  margin: 14px 0;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
}

.auth-error {
  color: #ffd1d1;
  background: rgba(122, 28, 28, 0.72);
}

.auth-success {
  color: #c8fff1;
  background: rgba(0, 168, 132, 0.18);
}

.admin-page {
  place-items: start center;
}

.admin-shell {
  width: min(100%, 1120px);
}

.admin-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.035);
}

.admin-card + .admin-card {
  margin-top: 18px;
}

.admin-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1.2fr) minmax(
      140px,
      0.7fr
    ) auto auto;
  align-items: end;
}

.check-label {
  display: inline-flex !important;
  grid-auto-flow: column;
  gap: 8px !important;
  align-items: center;
  min-height: 44px;
}

.check-label input {
  width: auto;
}

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

.user-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.4fr) minmax(120px, 0.7fr) auto minmax(
      180px,
      1fr
    ) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(134, 150, 160, 0.15);
  border-radius: 16px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.14);
}

.user-info {
  display: grid;
  gap: 4px;
}

.user-info small {
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

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

  .conversation-list {
    max-height: 42vh;
  }

  .chat-panel {
    min-height: 52vh;
  }

  .messages {
    min-height: 52vh;
  }

  .message {
    max-width: 92%;
  }

  .date-filter,
  .chat-date-filter {
    grid-template-columns: 1fr;
  }

  .chat-tools {
    justify-content: stretch;
  }

  .chat-search {
    width: 100%;
  }

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