*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", Tahoma, Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: #222;
  background: #0c0c0e;
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

.snow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.snow span {
  position: absolute;
  top: -4vh;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.35;
  animation: snow-fall linear infinite;
  will-change: transform;
}

@keyframes snow-fall {
  0% {
    transform: translate3d(0, 0, 0);
    opacity: 0;
  }
  8% {
    opacity: var(--flake-o, 0.35);
  }
  92% {
    opacity: var(--flake-o, 0.35);
  }
  100% {
    transform: translate3d(var(--flake-drift, 12px), 105vh, 0);
    opacity: 0;
  }
}

.page {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 14px 24px;
}

.auth-gate {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 14px;
  max-width: 820px;
  margin: 0 auto;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fafafa;
  border: 1px solid #c5c5c5;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  padding: 16px 18px 18px;
}

.auth-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: #2b579a;
}

.auth-blurb {
  margin: 0 0 14px;
  font-size: 12px;
  color: #666;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-label {
  font-size: 12px;
  color: #555;
  margin-top: 4px;
}

.auth-form input {
  padding: 6px 8px;
  border: 1px solid #ababab;
  border-radius: 2px;
  font: inherit;
  background: #fff;
}

.auth-form input:focus {
  outline: none;
  border-color: #7aa2d8;
  box-shadow: 0 0 0 2px rgba(122, 162, 216, 0.35);
}

.auth-submit {
  margin-top: 10px;
  align-self: flex-start;
}

.auth-switch {
  margin: 12px 0 0;
  font-size: 12px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: #2b579a;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:hover {
  color: #1a3d73;
}

.auth-error {
  margin: 12px 0 0;
  font-size: 12px;
  color: #b00020;
}

.user-slot {
  font-size: 12px;
  color: #444;
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.user-name {
  font-weight: 600;
  color: #2b579a;
}

.header-avatar-wrap {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #b0b0b0;
  background: #e8e8e8;
}

.header-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.header-avatar--placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #444;
  background: linear-gradient(180deg, #f5f5f5, #dcdcdc);
}

.avatar-tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #ccc;
  font-size: 11px;
  color: #555;
}

.avatar-tool-label {
  font-weight: 600;
  color: #444;
}

.avatar-tool-hint {
  color: #888;
  font-style: italic;
}

.topbar {
  background: #f7f7f7;
  border: 1px solid #c5c5c5;
  border-radius: 4px 4px 0 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.85) inset, 0 1px 3px rgba(0, 0, 0, 0.06);
}

.topbar-inner {
  padding: 10px 14px;
  border-bottom: 1px solid #d0d0d0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 16px;
}

.title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #2b579a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.tagline {
  font-size: 12px;
  color: #666;
}

.presence {
  font-size: 12px;
  color: #5a7a35;
}

.presence::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #6aad3c;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  vertical-align: 0.1em;
}

.presence.is-offline {
  color: #a04444;
}

.presence.is-offline::before {
  background: #c75c5c;
}

/* Must not use flex:1 without a defined height on .page — it collapses main to 0. */
.main {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fafafa;
  border: 1px solid #c5c5c5;
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.chat-panel {
  flex: none;
  height: 360px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.empty-hint {
  flex-shrink: 0;
  margin: 0;
  padding: 20px 14px;
  text-align: center;
  font-size: 13px;
  color: #888;
  border-bottom: 1px dashed #d0d0d0;
  background: #f6f6f6;
}

.empty-hint[hidden] {
  display: none;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px 10px;
  background: linear-gradient(180deg, #f3f3f3 0%, #fafafa 22px);
}

.msg {
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #d8d8d8;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  animation: msg-in 0.35s ease-out;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.msg-avatar-wrap {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin-top: 1px;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #c8c8c8;
  background: #ececec;
}

.msg-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.msg-avatar--placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  color: #4a4a4a;
  background: linear-gradient(180deg, #f2f2f2, #dadada);
  user-select: none;
}

.msg-body-col {
  flex: 1;
  min-width: 0;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 12px;
  color: #707070;
  margin-bottom: 4px;
  line-height: 1.25;
}

.msg-meta .msg-author {
  color: #2b579a;
  font-weight: 600;
}

.msg-meta time {
  color: #999;
  font-size: 11px;
  font-weight: 400;
}

.msg-delete {
  margin-left: auto;
  padding: 0 2px;
  border: none;
  background: none;
  font: inherit;
  font-size: 11px;
  color: #888;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.1em;
}

.msg-delete:hover {
  color: #b00020;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-body a {
  color: #1a5fb4;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.msg-body a:hover {
  color: #063d82;
}

.msg-body a:visited {
  color: #5c3d9a;
}

.msg-img {
  margin-top: 6px;
  display: block;
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 2px;
  border: 1px solid #ddd;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.msg-img:hover {
  box-shadow: 0 2px 8px rgba(43, 87, 154, 0.2);
  transform: scale(1.01);
}

.composer-wrap {
  border-top: 1px solid #d0d0d0;
  padding: 6px 10px 6px;
  background: #f0f0f0;
  border-radius: 0 0 3px 3px;
}

.nick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.nick-row label {
  font-size: 12px;
  color: #555;
  width: 42px;
}

.nick-row input {
  flex: 1;
  max-width: 240px;
  padding: 3px 7px;
  border: 1px solid #ababab;
  border-radius: 2px;
  font: inherit;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nick-row input:focus {
  outline: none;
  border-color: #7aa2d8;
  box-shadow: 0 0 0 2px rgba(122, 162, 216, 0.35);
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 48px;
  max-height: 140px;
  padding: 6px 8px;
  border: 1px solid #ababab;
  border-radius: 2px;
  font: inherit;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset;
  margin-bottom: 5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer textarea:focus {
  outline: none;
  border-color: #7aa2d8;
  box-shadow: 0 0 0 2px rgba(122, 162, 216, 0.35);
}

.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}

.emoji-picker-wrap {
  position: relative;
}

.emoji-panel {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 5px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 6px;
  max-width: 236px;
  background: #fff;
  border: 1px solid #ababab;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  z-index: 20;
}

.emoji-panel[hidden] {
  display: none !important;
}

.emoji-choice {
  font-family: "Segoe UI Emoji", "Segoe UI Symbol", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 17px;
  line-height: 1.2;
  padding: 3px 2px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: #fafafa;
  cursor: pointer;
}

.emoji-choice:hover {
  background: #e8f0ff;
  border-color: #a8c4e8;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.btn.primary {
  background: linear-gradient(180deg, #5a8fd4 0%, #3d73c9 100%);
  border-color: #2e5a9e;
  color: #fff;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}

.btn.primary:hover {
  background: linear-gradient(180deg, #6a9bdc 0%, #457dce 100%);
}

.btn.primary:active {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) inset;
}

.btn.secondary {
  background: linear-gradient(180deg, #fafafa 0%, #e8e8e8 100%);
  border-color: #adadad;
  color: #333;
}

.btn.secondary:hover {
  background: linear-gradient(180deg, #fff 0%, #f0f0f0 100%);
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.status {
  margin: 8px 0 0;
  min-height: 1.2em;
  font-size: 12px;
  color: #666;
}

.status.error {
  color: #b00020;
}

.foot-link {
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.3;
}

.foot-link a {
  color: #2b579a;
  text-decoration: none;
}

.foot-link a:hover {
  text-decoration: underline;
}
