/* Frozen in Time — Discord-flavoured viewer styles. */

:root {
  --bg-rail: #1e1f22;
  --bg-channels: #2b2d31;
  --bg-messages: #313338;
  --bg-members: #2b2d31;
  --bg-input: #1e1f22;
  --bg-hover: #35373c;
  --bg-active: #404249;

  --text: #f2f3f5;
  --text-muted: #b5bac1;
  --text-faint: #80848e;
  --text-link: #00a8fc;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #f23f42;

  --border: #1f2023;

  --rail-w: 72px;
  --channels-w: 240px;
  --members-w: 240px;
  --header-h: 48px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg-messages);
  color: var(--text);
  font-family: "gg sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}
body {
  display: grid;
  grid-template-columns: var(--rail-w) var(--channels-w) 1fr var(--members-w);
  grid-template-rows: 100vh;
  overflow: hidden;
}

/* -------- server rail -------- */
.rail {
  background: var(--bg-rail);
  padding: 12px 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.rail::-webkit-scrollbar { display: none; }

.server-icon {
  width: 48px; height: 48px;
  border: 0; padding: 0;
  background: var(--bg-channels);
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-radius 150ms, background 150ms;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 18px;
}
.server-icon:hover, .server-icon.active {
  border-radius: 16px;
  background: var(--accent);
}
.server-icon.add {
  color: #23a559;
  font-size: 24px;
  line-height: 1;
}
.server-icon.add:hover {
  background: #23a559;
  color: #fff;
}
.server-icon img {
  width: 100%; height: 100%; object-fit: cover;
}

/* -------- channels column -------- */
.channels {
  background: var(--bg-channels);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.server-header {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  display: flex; align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#channelListBody {
  flex: 1; overflow-y: auto;
  padding: 8px 8px 32px 8px;
}

.category {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  padding: 16px 8px 4px 8px;
  letter-spacing: 0.4px;
}

.channel-row {
  display: flex; align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  margin: 1px 0;
}
.channel-row:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.channel-row.active {
  background: var(--bg-active);
  color: var(--text);
}
.channel-row.thread {
  margin-left: 18px;
  font-size: 14px;
}
.channel-icon {
  flex: 0 0 18px;
  text-align: center;
  color: var(--text-faint);
  font-weight: bold;
}
.channel-name {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.channel-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-rail);
  padding: 1px 6px;
  border-radius: 8px;
}

/* -------- messages -------- */
.messages {
  display: flex;
  flex-direction: column;
  background: var(--bg-messages);
  overflow: hidden;
}
.channel-header {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  z-index: 1;
}
.message-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: auto;
  padding-bottom: 24px;
  /* Anchor scroll to bottom on incoming layout shifts within this scroller. */
  overflow-anchor: none;
}
.load-more {
  text-align: center;
  padding: 12px;
}
.load-more button {
  background: var(--bg-active);
  color: var(--text);
  border: 0;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.load-more button:hover { background: var(--accent); }

.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 48px 16px;
}
.empty.welcome { text-align: left; padding: 64px 32px; max-width: 720px; margin: 0 auto; }
.empty.welcome h2 { color: var(--text); margin: 0 0 12px 0; font-size: 28px; }
.empty.welcome code { background: var(--bg-input); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* forum thread list (post browser) */
.forum-threads {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  padding: 24px;
}
.forum-thread-row {
  background: var(--bg-channels);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  padding: 14px 16px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 80ms;
}
.forum-thread-row:hover { background: var(--bg-active); }
.forum-thread-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.forum-thread-meta {
  font-size: 12px;
  color: var(--text-faint);
}

/* messages */
.msg {
  display: grid;
  grid-template-columns: 56px 1fr;
  padding: 4px 16px 4px 0;
  margin-top: 18px;
  position: relative;
}
.msg.grouped { margin-top: 0; padding-top: 1px; padding-bottom: 1px; }
.msg:hover { background: rgba(0,0,0,0.07); }

.msg-avatar {
  display: flex; justify-content: center; padding-top: 2px;
}
.msg-avatar img {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-rail);
}
.avatar-fallback {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-rail);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  color: var(--text);
}
.avatar-fallback.small {
  width: 32px; height: 32px;
  font-size: 13px;
}
.msg-time-margin {
  font-size: 11px;
  color: var(--text-faint);
  display: block;
  margin-top: 4px;
  text-align: right;
  padding-right: 8px;
  width: 100%;
  opacity: 0;
  transition: opacity 80ms;
}
.msg.grouped:hover .msg-time-margin { opacity: 1; }

.msg-body {
  min-width: 0;
}
.msg-header {
  display: flex; align-items: baseline;
  gap: 8px;
  margin: 0 0 2px 0;
}
.msg-author {
  font-weight: 600;
  color: var(--text);
}
.msg-time {
  color: var(--text-faint);
  font-size: 12px;
}
.msg-content {
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg-content code {
  background: var(--bg-input);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px;
}
.msg-content pre.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 4px 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px;
}
.msg-content pre.code-block code {
  background: transparent;
  padding: 0;
}
.msg-content a { color: var(--text-link); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.mention {
  background: rgba(88, 101, 242, 0.18);
  color: #c9cdfb;
  padding: 0 2px;
  border-radius: 3px;
}

.msg-sticker {
  margin-top: 4px;
  font-style: italic;
  color: var(--text-faint);
}

/* attachments */
.attachment { margin-top: 6px; max-width: 520px; }
.attachment-image {
  display: block;
  max-width: 100%;
  max-height: 360px;
  /* Let aspect-ratio drive the inline reserved size. height:auto stops the
     fixed pixel height (from the width/height attributes) from forcing a
     non-aspect-ratio render before the blob is ready. */
  width: auto;
  height: auto;
  border-radius: 4px;
  background: var(--bg-rail);
}
.attachment-video, .attachment-audio {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 360px;
  border-radius: 4px;
}
.attachment-file {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-channels);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.attachment-file:hover { background: var(--bg-active); }
.attachment-size { color: var(--text-faint); font-size: 12px; }
.attachment-error {
  background: rgba(242, 63, 66, 0.1);
  color: var(--danger);
  padding: 8px;
  border-radius: 4px;
  font-size: 13px;
}

/* embeds */
.embed {
  --embed-color: #4f545c;
  margin-top: 6px;
  max-width: 520px;
  background: var(--bg-channels);
  border-left: 4px solid var(--embed-color);
  border-radius: 4px;
  padding: 10px 14px;
}
.embed-author { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.embed-title {
  display: block;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 4px;
}
a.embed-title { color: var(--text-link); }
a.embed-title:hover { text-decoration: underline; }
.embed-description {
  color: var(--text-muted);
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.embed-field { margin-top: 8px; }
.embed-field-name { font-weight: 600; font-size: 13px; }
.embed-field-value { color: var(--text-muted); font-size: 13px; white-space: pre-wrap; }
.embed-image, .embed-thumb {
  margin-top: 8px;
  max-width: 100%;
  border-radius: 4px;
}
.embed-thumb { max-width: 80px; float: right; margin: 0 0 8px 8px; }
.embed-footer { color: var(--text-faint); font-size: 12px; margin-top: 8px; }

/* -------- members -------- */
.members {
  background: var(--bg-members);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.members-header {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  display: flex; align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-faint);
  letter-spacing: 0.4px;
}
#memberListBody {
  flex: 1; overflow-y: auto;
  padding: 8px;
}
.member-row {
  display: flex; align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: default;
  color: var(--text-muted);
}
.member-row:hover { background: var(--bg-hover); color: var(--text); }
.member-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-rail);
  overflow: hidden;
  flex: 0 0 32px;
  display: flex; align-items: center; justify-content: center;
}
.member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.member-name {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}

/* -------- dialog -------- */
.dialog {
  border: 0;
  background: var(--bg-channels);
  color: var(--text);
  border-radius: 8px;
  padding: 0;
  max-width: 520px;
  width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
.dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog form {
  display: flex; flex-direction: column;
  padding: 24px;
  gap: 16px;
}
.dialog h2 { margin: 0; font-size: 20px; }
.dialog label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.dialog input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  text-transform: none;
  font-weight: normal;
  letter-spacing: 0;
}
.dialog input:focus {
  outline: none;
  border-color: var(--accent);
}
.dialog-actions {
  display: flex; justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.dialog-actions button {
  background: var(--bg-active);
  color: var(--text);
  border: 0;
  padding: 10px 18px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.dialog-actions button.primary {
  background: var(--accent);
}
.dialog-actions button.primary:hover { background: var(--accent-hover); }

/* -------- toast -------- */
.toast {
  position: fixed;
  right: 16px; bottom: 16px;
  background: var(--bg-channels);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 480px;
  z-index: 50;
}
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--accent); }

/* -------- scrollbars -------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-rail);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #111214; }

/* -------- responsive -------- */
@media (max-width: 1100px) {
  body { grid-template-columns: var(--rail-w) var(--channels-w) 1fr; }
  .members { display: none; }
}
@media (max-width: 720px) {
  body { grid-template-columns: var(--rail-w) 1fr; }
  .channels { display: none; }
}
