/* =======================================================
   Discord-y Log Viewer — Cleaned CSS
   ======================================================= */

/* ---------- Theme Vars ---------- */
:root {
  --bg:       #2b2d31;
  --bg-2:     #313338;
  --bg-3:     #1e1f22;
  --text:     #dbdee1;
  --muted:    #a3a6aa;
  --accent:   #5865f2;
  --danger:   #da373c;

  /* dynamic space for bottom nav; set by JS if needed */
  --bottom-nav-h: 0px;
}

/* ---------- Base ---------- */
html, body {
  height: 100%;
  overflow: hidden;            /* Prevent page scroll */
  background: var(--bg);
  color: var(--text);
}

/* ---------- App Layout ---------- */
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar content";
}

/* ---------- Sidebar (with sticky header) ---------- */
.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-3);
  border-right: 1px solid #202225;
}

.sticky-header {
  background: var(--bg-3);
  position: sticky;
  top: 0;
  z-index: 2;
}

.channel-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;               /* allows proper flex scrolling */
}

/* ---------- Top Header ---------- */
.header {
  grid-area: header;
  background: var(--bg-2);
  border-bottom: 1px solid #202225;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .75rem;
  gap: .75rem;
}

/* truncate long channel names nicely */
.header .d-flex { min-width: 0; }
#headerChannelName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60vw;
}

/* ---------- Main Content ---------- */
.content {
  grid-area: content;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;               /* important for inner scroll */
}

/* Messages container is the only thing that scrolls */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
  padding-bottom: calc(var(--bottom-nav-h) + 12px);
  scroll-padding-bottom: calc(var(--bottom-nav-h) + 12px);
}

#loadingOlder {
  margin-bottom: calc(var(--bottom-nav-h) + 8px);
}

/* ---------- Channel List Items ---------- */
.channel-item {
  padding: .5rem .75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
}
.channel-item:hover,
.channel-item.active { background: #3a3c41; }
.channel-item:active { filter: brightness(1.08); }

.channel-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Topic Bar ---------- */
.topic-bar {
  font-size: .9rem;
  color: var(--muted);
  padding-left: .25rem;
}

/* ---------- Message Rows ---------- */
.message-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: .75rem;
  padding: .25rem .75rem;
}

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #444;
  object-fit: cover;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: .5rem;
}

.display-name { font-weight: 600; }
.username     { color: var(--muted); font-size: .85rem; }
.timestamp    { color: var(--muted); font-size: .8rem; }

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Deleted / edited badges */
.deleted .msg-text { opacity: .55; text-decoration: line-through; }
.badge-deleted     { background: var(--danger); margin-left: .5rem; }
.edited            { color: var(--muted); font-size: .8rem; margin-left: .5rem; }

/* ---------- Tools Row ---------- */
.tools {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sticky-bottom-shadow {
  box-shadow: inset 0 -12px 12px -12px rgba(0,0,0,.5);
}

/* ---------- Embeds ---------- */
.embed-card {
  border-left: 4px solid var(--accent);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 6px;
  max-width: 640px;
  position: relative;
}

.embed-inner { display: flex; flex-direction: column; gap: 6px; }

.embed-author {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 0.95rem;
}
.embed-author-icon { width: 20px; height: 20px; border-radius: 50%; }

.embed-title { font-weight: 700; font-size: 1rem; }
.embed-title a { text-decoration: none; }

.embed-description { white-space: normal; }

.embed-fields { display: grid; gap: 8px; }
.embed-field { background: rgba(255,255,255,0.03); border-radius: 6px; padding: 6px; }
.embed-field-inline { display: inline-block; min-width: 180px; vertical-align: top; margin-right: 8px; }
.embed-field-name  { font-weight: 700; font-size: 0.85rem; margin-bottom: 4px; }
.embed-field-value { font-size: 0.9rem; }

.embed-thumb-wrap { position: absolute; top: 10px; right: 10px; }
.embed-thumb {
  width: 80px; height: 80px;
  object-fit: cover; border-radius: 6px;
}

.embed-image-wrap { margin-top: 6px; }
.embed-image {
  max-width: 360px; width: 100%; height: auto; border-radius: 6px;
}

.embed-footer {
  display: flex; align-items: center; gap: 8px;
  opacity: 0.7; font-size: 0.85rem;
}
.embed-footer-icon { width: 16px; height: 16px; border-radius: 50%; }

.embed-pre  { background: #1e1f22; padding: 8px; border-radius: 6px; overflow:auto; }
.embed-code { background: #1e1f22; padding: 2px 4px; border-radius: 4px; }

/* ---------- Discord Custom Emoji ---------- */
.emoji {
  height: 22px; width: 22px;
  vertical-align: text-bottom;
  border-radius: 4px;
  image-rendering: auto;
}

/* ---------- Mobile Bottom Nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: 56px;
  background: var(--bg-2);
  border-top: 1px solid #202225;
  z-index: 1001;
  display: none;                        /* shown on mobile via media query */
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom); /* iOS notch */
}

.bn-btn {
  background: none; border: 0; color: var(--text);
  height: 100%; width: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; font-size: .75rem; opacity: .9;
}
.bn-btn:active { opacity: 1; }
.bn-btn i { font-size: 1.1rem; }

/* bottom-nav select styled like a button */
.bn-select {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; position: relative;
}
.bn-select i { font-size: 1.1rem; }

.bn-select select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background: transparent; border: 0; color: var(--text);
  font-size: .75rem; text-align: center; padding-right: 16px;
  max-width: 22vw;
}
@media (min-width: 901px) { .bn-select select { max-width: 160px; } }

.bn-select::after {
  content: "▾";
  position: absolute; bottom: 8px; right: 10px;
  font-size: .75rem; opacity: .7; pointer-events: none;
}

/* ---------- Overlay (for off-canvas) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  z-index: 1000;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "content";
  }

  /* off-canvas sidebar */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(82vw, 320px);
    max-width: 90vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 1002;
  }
  .sidebar.open { transform: translateX(0); }

  /* make header stick on mobile too */
  .header { position: sticky; top: 0; z-index: 5; }

  /* show bottom nav and pad messages so it doesn't cover them */
  .bottom-nav { display: grid; }
  .messages-wrap { padding-bottom: calc(56px + 12px); }
}
/* prettier bottom-nav select */
.bn-select.nice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* visually pretty part */
.bn-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  font-size: .78rem;
  line-height: 1;
  color: var(--text);
  pointer-events: none;        /* clicks go to the native select */
}

.bn-select-btn i { font-size: 1rem; opacity: .9; }

/* caret */
.bn-caret {
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(255,255,255,0.7);
  margin-left: 2px;
}

/* keep your native select for accessibility, but make it invisible and on top */
.bn-select.nice select {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* focus ring when keyboarding */
.bn-select.nice select:focus-visible + ._focus-ring,
.bn-select.nice select:focus-visible ~ .bn-select-btn,
.bn-select.nice select:focus-visible ~ * {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* compact for bottom nav */
.bottom-nav .bn-select.nice .bn-select-btn {
  padding: 6px 8px;
  border-radius: 12px;
}
/* Server sheet */
.server-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-2);
  border-top: 1px solid #202225;
  transform: translateY(110%);
  transition: transform .2s ease;
  z-index: 1003;
  max-height: 70vh;
  display: flex; flex-direction: column;
}
.server-sheet.open { transform: translateY(0); }

.server-sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid #202225;
}
.ss-close { background: none; border: 0; color: var(--text); font-size: 1.25rem; }

.server-list {
  overflow-y: auto; padding: 8px 8px 10px;
  display: grid; gap: 6px;
}
.server-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: var(--bg-3); border: 1px solid #202225;
  border-radius: 10px; padding: 10px;
  color: var(--text); cursor: pointer;
}
.server-item:active { filter: brightness(1.05); }
.server-icon { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.server-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
