/* Discord-inspired dark theme for MeshCore archive */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #313338;
  color: #dcddde;
  font-family: "gg sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
}

a { color: #00a8fc; text-decoration: none; }
a:hover { text-decoration: underline; }

body {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}
body.has-results { grid-template-columns: 280px 1fr 360px; }

/* ---------- sidebar ---------- */

#sidebar {
  background: #2b2d31;
  border-right: 1px solid #1e1f22;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.guild {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #1e1f22;
  background: #232428;
}
.guild-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: #5865f2;
  color: #fff;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.guild-name { font-weight: 700; color: #fff; }
.guild-sub  { color: #949ba4; font-size: 12px; }
.guild-repo {
  display: inline-block;
  margin-top: 2px;
  color: #949ba4;
  font-size: 11px;
  text-decoration: none;
}
.guild-repo:hover { color: #dbdee1; text-decoration: underline; }

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid #1e1f22;
}
.sidebar-search input {
  width: 100%;
  background: #1e1f22;
  border: 1px solid #1e1f22;
  border-radius: 6px;
  color: #dcddde;
  padding: 8px 10px;
  font: inherit;
  outline: none;
}
.sidebar-search input:focus { border-color: #404249; }

.thread-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 12px;
}

.forum-group { margin-bottom: 6px; }
.forum-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 4px;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: #949ba4;
  font-weight: 700;
  background: none;
  border: 0;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.forum-header:hover { color: #dbdee1; }
.forum-header:hover .forum-header-count { background: #404249; color: #dbdee1; }
.forum-header-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.forum-header-count {
  color: #80848e;
  font-size: 10px;
  background: #1e1f22;
  border-radius: 10px;
  padding: 1px 6px;
  letter-spacing: 0;
}
.forum-more {
  display: block;
  width: calc(100% - 12px);
  margin: 2px 6px 4px;
  padding: 6px 10px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: #949ba4;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.forum-more:hover { background: #35373c; color: #dbdee1; }
.thread-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin: 1px 6px;
  border-radius: 4px;
  color: #b5bac1;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.3;
}
.thread-link:hover { background: #35373c; color: #dbdee1; text-decoration: none; }
.thread-link.active { background: #404249; color: #fff; }
.thread-link .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.thread-link .count {
  color: #80848e;
  font-size: 11px;
  background: #1e1f22;
  border-radius: 10px;
  padding: 2px 6px;
}

.channel-block { margin: 2px 0; }
.channel-header.thread-link {
  color: #dbdee1;
  font-weight: 600;
}
.channel-header .title { color: inherit; }
.channel-child-count {
  color: #80848e;
  font-size: 11px;
  background: #1e1f22;
  border-radius: 10px;
  padding: 2px 6px;
}
.channel-threads {
  margin: 0 6px 4px 14px;
  padding-left: 8px;
  border-left: 1px solid #2e2f34;
}
.channel-threads .thread-link { margin-left: 0; margin-right: 0; }
.channel-more { margin-left: 0; }

.sidebar-footer {
  padding: 8px 14px;
  font-size: 11px;
  color: #949ba4;
  border-top: 1px solid #1e1f22;
  background: #232428;
}

/* ---------- main ---------- */

#main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #313338;
  border-bottom: 1px solid #1e1f22;
  padding: 12px 20px;
}
.search-wrap { position: relative; }
#search {
  width: 100%;
  background: #1e1f22;
  border: 1px solid #1e1f22;
  border-radius: 8px;
  color: #dcddde;
  padding: 10px 14px;
  font: inherit;
  outline: none;
}
#search:focus { border-color: #5865f2; }
#search.search-loading {
  background-image: linear-gradient(90deg, transparent 0, rgba(88,101,242,0.25) 50%, transparent 100%);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: search-loading-bg 1.2s linear infinite;
}
@keyframes search-loading-bg {
  from { background-position: -40% 0; }
  to   { background-position: 140% 0; }
}
.search-help {
  font-size: 11px;
  color: #80848e;
  padding: 4px 2px 0;
}
.search-help code {
  background: #2b2d31;
  border-radius: 3px;
  padding: 1px 5px;
  color: #dcddde;
  font-size: 11px;
}
.content {
  flex: 1;
  padding: 20px 28px 60px;
  overflow-x: hidden;
}

.welcome h1 { color: #fff; margin-top: 4px; }
.welcome code { background: #2b2d31; padding: 1px 6px; border-radius: 3px; }
#welcome-stats { list-style: none; padding: 0; margin-top: 20px; }
#welcome-stats li {
  padding: 8px 0;
  border-bottom: 1px solid #3a3c42;
  color: #b5bac1;
}

.thread-header {
  margin: 0 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #3a3c42;
}
.thread-header .forum-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #949ba4;
}
.thread-header h1 {
  color: #fff;
  margin: 4px 0 6px;
  font-size: 24px;
}
.thread-header .meta { color: #80848e; font-size: 13px; }

/* ---------- messages ---------- */

.msg-group { margin-bottom: 14px; }
.msg {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 2px 14px;
  padding: 2px 4px;
  border-radius: 4px;
}
.msg:hover { background: #2e3035; }
.msg.highlight {
  position: relative;
  background: rgba(88,101,242,0.22);
  animation: msg-highlight-pulse 1.6s ease-out 2;
}
.msg.highlight::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: #5865f2;
  border-radius: 2px;
}
@keyframes msg-highlight-pulse {
  0%   { background: rgba(88,101,242,0.40); }
  100% { background: rgba(88,101,242,0.22); }
}

.msg .avatar {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 40px; height: 40px;
  border-radius: 50%;
  margin-top: 2px;
  background: #4f545c;
  object-fit: cover;
}

.msg .header {
  grid-column: 2;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.msg .author {
  font-weight: 600;
  color: #fff;
  cursor: pointer;
}
.msg .author:hover { text-decoration: underline; }
.msg .handle { color: #949ba4; font-size: 11px; }
.msg .ts { color: #949ba4; font-size: 12px; }

.msg .body {
  grid-column: 2;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg .body .chatlog__markdown-preserve { white-space: pre-wrap; }

/* Embeds, attachments, reactions — inline styles adapted from DCE output */
.msg .body .chatlog__embed {
  display: flex;
  margin-top: 6px;
  max-width: 520px;
}
.msg .body .chatlog__embed-color-pill {
  flex-shrink: 0;
  width: 4px;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  background-color: #202225;
}
.msg .body .chatlog__embed-content-container {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border: 1px solid rgba(46,48,54,0.6);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  background: rgba(46,48,54,0.3);
}
.msg .body .chatlog__embed-content { display: flex; width: 100%; }
.msg .body .chatlog__embed-text { flex: 1; }
.msg .body .chatlog__embed-title { margin-bottom: 6px; color: #fff; font-weight: 600; font-size: 14px; }
.msg .body .chatlog__embed-description { color: #dcddde; font-size: 13px; }
.msg .body .chatlog__embed-thumbnail {
  max-width: 80px; max-height: 80px; margin-left: 14px; border-radius: 3px;
}
.msg .body .chatlog__embed-images {
  display: grid;
  margin-top: 8px;
  grid-template-columns: repeat(2,1fr);
  gap: 4px;
}
.msg .body .chatlog__embed-image {
  object-fit: cover;
  max-width: 500px;
  max-height: 400px;
  width: 100%;
  border-radius: 3px;
}

.msg .body .chatlog__attachment {
  margin-top: 6px;
  max-width: 520px;
  border-radius: 4px;
  overflow: hidden;
}
.msg .body .chatlog__attachment-media {
  max-width: 100%;
  max-height: 400px;
  border-radius: 4px;
}
.msg .body .chatlog__attachment-generic {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #2b2d31;
  border: 1px solid #1e1f22;
  border-radius: 4px;
}
.msg .body .chatlog__attachment-generic-icon { width: 24px; }
.msg .body .chatlog__attachment-generic-size { color: #949ba4; font-size: 11px; }

.msg .body .chatlog__reactions {
  display: flex;
  flex-wrap: wrap;
  margin-top: 6px;
}
.msg .body .chatlog__reaction {
  display: flex;
  align-items: center;
  margin: 2px 4px 2px 0;
  padding: 3px 6px;
  background: #2b2d31;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
}
.msg .body .chatlog__reaction-count { color: #b9bbbe; margin-left: 5px; font-size: 12px; }
.msg .body .chatlog__emoji { width: 18px; height: 18px; vertical-align: -4px; }
.msg .body .chatlog__markdown-pre {
  background: #2b2d31;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  border-radius: 4px;
}
.msg .body .chatlog__markdown-pre--multiline {
  display: block;
  margin-top: 4px;
  padding: 8px 10px;
  white-space: pre;
  overflow-x: auto;
}
.msg .body .chatlog__markdown-pre--inline {
  display: inline-block;
  padding: 1px 4px;
}
.msg .body .chatlog__markdown-quote {
  border-left: 3px solid #4f545c;
  padding-left: 8px;
  margin: 2px 0;
  color: #b9bbbe;
}
.msg .body .chatlog__markdown-mention {
  background: rgba(88,101,242,0.3);
  color: #dee0fc;
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 500;
}
.msg .body .chatlog__reply {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: #b5b6b8;
  font-size: 13px;
  opacity: 0.85;
}
.msg .body .chatlog__reply-avatar {
  width: 16px; height: 16px; border-radius: 50%;
}
.msg .body .chatlog__reply-author { font-weight: 600; color: #dcddde; }

/* ---------- search results drawer ---------- */

#results-panel:not([hidden]) {
  background: #2b2d31;
  border-left: 1px solid #1e1f22;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  height: 100vh;
}
.results-header {
  padding: 12px 16px;
  border-bottom: 1px solid #1e1f22;
  background: #313338;
}
.results-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.results-title-row h2 {
  margin: 0;
  font-size: 15px;
  color: #fff;
}
.icon-close {
  background: transparent;
  border: 0;
  color: #b5bac1;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
}
.icon-close:hover { background: #404249; color: #fff; }
.results-meta { color: #949ba4; font-size: 12px; margin-top: 6px; }
.results-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}
.results-list .result {
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  margin: 0;
  cursor: pointer;
}
.results-list .result:hover { background: #35373c; }
.results-list .result.active {
  background: #3b3d42;
  border-left-color: #5865f2;
}
.results-list .result .result-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: #949ba4;
  margin-bottom: 3px;
}
.results-list .result .result-thread {
  color: #dbdee1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.results-list .result .result-author { color: #fff; font-weight: 600; font-size: 12px; }
.results-list .result .snippet {
  color: #b5bac1;
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.results-list .result .snippet mark { background: #faa61a; color: #000; border-radius: 2px; padding: 0 2px; }
.results-empty { padding: 18px 16px; color: #949ba4; font-size: 13px; }

/* ---------- misc ---------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2b2d31; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- thread browser modal ---------- */

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  background: #2b2d31;
  border: 1px solid #1e1f22;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #1e1f22;
}
.modal-header h2 {
  margin: 0;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-close {
  background: transparent;
  border: 0;
  color: #b5bac1;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: #fff; }
.modal-search {
  padding: 10px 14px;
  border-bottom: 1px solid #1e1f22;
}
.modal-search input {
  width: 100%;
  background: #1e1f22;
  border: 1px solid #1e1f22;
  border-radius: 6px;
  color: #dcddde;
  padding: 8px 10px;
  font: inherit;
  outline: none;
}
.modal-search input:focus { border-color: #5865f2; }
.modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}
.modal-thread-link { margin: 1px 0; }
.modal-footer {
  padding: 8px 16px;
  border-top: 1px solid #1e1f22;
  font-size: 11px;
  color: #949ba4;
}
body.modal-open { overflow: hidden; }

/* Hidden by default; only used on mobile. */
.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  body.has-results { grid-template-columns: 1fr; grid-template-rows: 1fr 40vh; }

  #sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px; max-width: 85vw;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    will-change: transform;
  }
  body.sidebar-open #sidebar { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #1e1f22;
    color: #dcddde;
    border: 1px solid #1e1f22;
    border-radius: 6px;
    width: 38px; height: 38px;
    margin-right: 8px;
    font-size: 18px;
    cursor: pointer;
  }
  .sidebar-toggle:hover { background: #2b2d31; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }

  #main { height: auto; min-height: 0; }
  #results-panel { height: auto; border-left: 0; border-top: 1px solid #1e1f22; }
}
