/* ---- Theme tokens -------------------------------------------------------- */
:root {
  /* Dark (default). JS sets data-theme explicitly, so this is the fallback. */
  --bg: #15181d;
  --panel: #1e232b;
  --panel-2: #222831;
  --hover: #2a313c;
  --border: #2f3742;
  --text: #e7ebf0;
  --muted: #98a2b1;
  --accent: #4f9dff;
  --accent-weak: rgba(79, 157, 255, 0.14);
  --on-accent: #fff;
  --green: #43c463;
  --red: #e8604f;
  --amber: #e0a23b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 8px 22px rgba(0, 0, 0, 0.22);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --hover: #eef2f7;
  --border: #e1e6ec;
  --text: #1b2430;
  --muted: #647082;
  --accent: #2f7ce0;
  --accent-weak: rgba(47, 124, 224, 0.12);
  --on-accent: #fff;
  --green: #2e9e4f;
  --red: #d6452f;
  --amber: #b97d12;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 26px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

/* ---- Base ---------------------------------------------------------------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.muted { color: var(--muted); }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

/* ---- Header (banner) ----------------------------------------------------- */
#topbar {
  position: relative;
  line-height: 0; /* remove inline-image gap */
}
.banner {
  display: block;
  width: 100%;
  height: auto;
}
/* Swap the banner with the theme (theme is set pre-paint, so no flash). */
.banner-light { display: none; }
:root[data-theme="light"] .banner-dark { display: none; }
:root[data-theme="light"] .banner-light { display: block; }

/* Server info + controls overlaid across the bottom of the banner. A gradient
   scrim keeps them readable; the inner .wrap aligns them with the content
   column below (name with the tree/stats, controls with the right edge). */
.banner-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 46px 0 16px;
  color: #fff;
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  line-height: 1.35;
}
.title { display: flex; align-items: center; gap: 10px; }
.info-text { display: flex; flex-direction: column; }
.info-text .server-name { font-size: 16px; font-weight: 650; }
#server-sub { font-size: 12.5px; }
.banner-bar .muted { color: rgba(255, 255, 255, 0.8); }
.banner-bar .icon-btn { color: #fff; border-color: rgba(255, 255, 255, 0.35); }
.banner-bar .icon-btn:hover { background: rgba(255, 255, 255, 0.16); }
.banner-bar .auto { color: rgba(255, 255, 255, 0.9); }
.banner-bar .copy-btn { color: rgba(255, 255, 255, 0.85); }
.banner-bar .copy-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.16); }

/* Light mode: the light banner is bright, so drop the dark scrim and use normal
   dark text/control colors so the server info + controls stay readable. */
:root[data-theme="light"] .banner-bar { background: none; color: var(--text); }
:root[data-theme="light"] .banner-bar .muted,
:root[data-theme="light"] .banner-bar .auto,
:root[data-theme="light"] .banner-bar .copy-btn { color: var(--muted); }
:root[data-theme="light"] .banner-bar .copy-btn:hover { color: var(--text); background: var(--hover); }
:root[data-theme="light"] .banner-bar .icon-btn { color: var(--muted); border-color: var(--border); }
:root[data-theme="light"] .banner-bar .icon-btn:hover { color: var(--text); background: var(--hover); }

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  margin-left: 6px;
  border-radius: 5px;
  vertical-align: -3px;
}
.copy-btn:hover { color: var(--text); background: var(--hover); }
.copy-btn.copied { color: var(--green); }
.copy-btn .ic { width: 14px; height: 14px; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 9px;
}
.dot.online { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.dot.offline { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent); }

.controls { display: flex; align-items: center; gap: 12px; }
.controls .auto {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.controls .auto input { accent-color: var(--accent); width: 15px; height: 15px; }

/* Buttons */
#refresh {
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 5px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: filter 0.15s ease, opacity 0.15s ease;
}
#refresh:hover { filter: brightness(1.07); }
#refresh:disabled { opacity: 0.55; cursor: default; }

.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { color: var(--text); background: var(--hover); }
.icon-btn .ic { width: 18px; height: 18px; }

/* ---- Stats strip --------------------------------------------------------- */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.stat {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 15px;
  min-width: 96px;
  box-shadow: var(--shadow);
}
.stat .k { position: relative; display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 2px; }
.stat .v { position: relative; font-size: 16px; font-weight: 650; }

/* Large, faintly tinted watermark icon sitting behind each stat card's text. */
.stat .bg-ic {
  position: absolute;
  right: -8px;
  bottom: -10px;
  width: 58px;
  height: 58px;
  color: var(--accent);
  opacity: 0.1;
  pointer-events: none;
}

/* ---- Layout -------------------------------------------------------------- */
/* Left column holds the stat strip + channel tree, sized to their content. The
   user-info card fills the empty area to their right (top-aligned) when a user
   is clicked, and the recently-seen row spans the full width underneath. */
#layout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  padding-top: 18px;
  padding-bottom: 8px;
}

.server-info {
  grid-column: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.server-info > * { width: 100%; }
.detail { grid-column: 2; align-self: start; }
#recent { grid-column: 1 / -1; }

.tree {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 9px;
  border-radius: 5px;
  white-space: nowrap;
}
.channel { font-weight: 600; }
.channel:hover, .client:hover { background: var(--hover); }
.channel .count { color: var(--muted); font-weight: 400; font-size: 12px; }
.icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 16px; color: var(--muted); }

/* Colored circular user avatars. The filled circle + white glyph reads on both
   light and dark themes; a faint inset ring keeps the edge crisp on any color. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}
.avatar .ic { width: 56%; height: 56%; }
.av-recent { width: 40px; height: 40px; }
.channel .icon { color: var(--accent); }
.ic { width: 16px; height: 16px; display: block; }
.chan-icon { width: 16px; height: 16px; object-fit: contain; display: block; border-radius: 3px; }

.client { cursor: pointer; }
.client .name { overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }

/* Role (server-group) icons and myTeamSpeak badges shown after the nickname. */
.adorn { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
.client .adorn { margin-left: 8px; }
.role-icon, .badge { object-fit: contain; display: block; }
.role-icon { border-radius: 3px; }
.adorn .sm { width: 16px; height: 16px; }
.detail .adorn { margin: 0 0 12px; gap: 7px; flex-wrap: wrap; }
.detail h2 .adorn { margin: 0 0 0 8px; }
.detail h2 .badge { width: 18px; height: 18px; }
.adorn .lg { width: 22px; height: 22px; }

.flag {
  width: 16px;
  height: 12px;
  margin-right: 7px;
  vertical-align: -1px;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border);
}
.detail h2 .flag { width: 20px; height: 15px; margin-right: 9px; vertical-align: -2px; }
.flags { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding-left: 12px; color: var(--muted); }
.flags span { display: inline-flex; }
.flags .ic { width: 15px; height: 15px; }
.flag-muted { color: var(--red); }
.flag-away { color: var(--amber); }

.spacer {
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
}
.spacer.empty { border-top: 1px solid var(--border); margin: 7px 4px; padding: 0; height: 0; }

.children { margin-left: 19px; border-left: 1px solid var(--border); padding-left: 9px; }

/* ---- Detail panel -------------------------------------------------------- */
/* Rendered inline inside the server-info column, below the channel tree. */
.detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.detail h2 { display: flex; align-items: center; margin: 0 0 12px; font-size: 16px; }
.detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-word; }
.detail .close { float: right; background: none; border: 0; color: var(--muted); padding: 0; font-size: 20px; line-height: 1; cursor: pointer; }
.detail .close:hover { color: var(--text); }

/* Sections + chips inside the detail card */
.detail-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.section-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 9px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.detail h2 + .chips { margin-bottom: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12.5px;
  line-height: 1.2;
  color: var(--text);
}
.chip .ic { width: 14px; height: 14px; color: var(--muted); }
.chip-on { background: color-mix(in srgb, var(--green) 16%, transparent); border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.chip-on .ic { color: var(--green); }
.chip-off { background: color-mix(in srgb, var(--red) 14%, transparent); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.chip-off .ic { color: var(--red); }
.chip-warn { background: color-mix(in srgb, var(--amber) 16%, transparent); border-color: color-mix(in srgb, var(--amber) 42%, transparent); }
.chip-warn .ic { color: var(--amber); }
.role-chip .role-icon.sm { width: 14px; height: 14px; }

/* ---- Recently seen ------------------------------------------------------- */
.recent { padding-top: 6px; padding-bottom: 4px; }
.recent-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
/* Five stretched cards per row (10 total → 2 rows). */
.recent-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.recent-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.recent-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.recent-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 1px; }
.recent-ago { font-size: 12.5px; color: var(--muted); }
.recent-stats { font-size: 11px; opacity: 0.8; }

/* ---- Misc ---------------------------------------------------------------- */
.error {
  margin-top: 16px;
  padding: 13px 16px;
  background: color-mix(in srgb, var(--red) 12%, transparent);
  border: 1px solid var(--red);
  border-radius: 5px;
  color: var(--text);
}

footer { padding-top: 14px; padding-bottom: 28px; font-size: 12px; }

@media (max-width: 640px) {
  .wrap { padding-left: 16px; padding-right: 16px; }
  #layout { grid-template-columns: 1fr; }
  .server-info, .detail, #recent { grid-column: 1; }
  .recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* The short banner can't hold the overlay on phones — drop it below the
     image in normal theme colors. */
  .banner-bar {
    position: static;
    background: none;
    color: var(--text);
    padding: 12px 0 0;
  }
  .banner-bar .muted, .banner-bar .auto { color: var(--muted); }
  .banner-bar .icon-btn { color: var(--muted); border-color: var(--border); }
  .banner-bar .copy-btn { color: var(--muted); }
  .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .controls { justify-content: space-between; }
}
