/* =====================================================================
   Discord-style layout. Loaded last.
   Desktop/tablet (>760px): a 72px server rail on the left, the channel
   list beside it with the user panel at its foot, then the chat and the
   member list. Built with CSS grid over the existing markup: .deck and
   .shell use display:contents so their children become grid cells.
   Phones: the drawer shows the server rail as a column next to the
   channel list.
   Colours only change for the default dark theme so user themes keep working.
   ===================================================================== */

:root:not([data-theme]), :root[data-theme="dark"] {
  --bg: #1e1f22;      /* server rail, inputs */
  --bg-1: #313338;    /* chat */
  --bg-2: #2b2d31;    /* channel list, member list */
  --bg-3: #383a40;    /* composer, raised controls */
  --bg-4: #404249;
  --bg-hover: #35373c; --bg-active: #404249;
  --line: #3f4147; --text: #f2f3f5; --text-2: #b5bac1; --muted: #949ba4;
  --panel-foot: #232428; /* user panel */
}
:root { --sq: 50%; --rail-w: 72px; --side-w: 240px; --hdr-h: 48px; }

/* avatars are circles */
.av, .av .av-img, .member .av, .msg .m-av { border-radius: 50%; }

@media (min-width: 761px) {
  .app {
    display: grid; height: 100vh; height: 100dvh; padding: 0;
    grid-template-columns: var(--rail-w) var(--side-w) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }
  body.has-pcbar .app { height: calc(100dvh - var(--pcbar-h, 0px)); }
  :root:not(.fx-on) .app { background: var(--bg); }
  .deck, .shell { display: contents; }

  /* ----- server rail ----- */
  .deck > .menu-btn, .deck-brand { display: none !important; }
  .deck-servers {
    grid-column: 1; grid-row: 1 / -1; display: flex; flex-direction: column; align-items: center;
    gap: 8px; padding: 12px 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
    -webkit-mask-image: none; mask-image: none; background: var(--bg); min-height: 0;
  }
  .deck-servers::-webkit-scrollbar { display: none; }
  .deck-servers > * { flex: none; }
  .dtile { position: relative; width: var(--rail-w); display: flex; justify-content: center; }
  .dtile-btn {
    width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--bg-2); color: var(--text);
    font-size: 15px; font-weight: 600; transition: border-radius .15s ease, background .15s, color .15s; box-shadow: none !important;
  }
  .dtile-btn:hover, .dtile.active .dtile-btn { border-radius: 16px; background: var(--gold); color: #1b1600; transform: none; }
  .dtile-btn.has-img:hover, .dtile.active .dtile-btn.has-img { background: var(--bg-2); }
  /* home button carries the logo */
  .dtile.home .dtile-btn { background: var(--bg-2) url(/brand/vexel-mark.svg) center / 28px no-repeat; color: transparent; }
  .dtile.home .dtile-btn svg { display: none; }
  .dtile.home .dtile-btn:hover, .dtile.home.active .dtile-btn { background-color: #3a3523; }
  .dtile.action .dtile-btn { background: var(--bg-2); border: 0; color: var(--green); }
  .dtile.action .dtile-btn:hover, .dtile.action.active .dtile-btn { background: var(--green); color: #fff; }
  /* the white pill on the left edge */
  .dtile::after, .dtile.active::after, .dtile.unread:not(.active)::after {
    content: ''; display: block; position: absolute; left: 0; top: 50%; bottom: auto; transform: translateY(-50%) scale(0);
    width: 4px; height: 8px; border-radius: 0 4px 4px 0; background: var(--text); transition: transform .15s, height .15s;
  }
  .dtile.unread:not(.active)::after { transform: translateY(-50%) scale(1); height: 8px; }
  .dtile:hover::after { transform: translateY(-50%) scale(1); height: 20px; }
  .dtile.active::after { transform: translateY(-50%) scale(1); height: 40px; }
  /* the ping count sits on the icon's bottom-right corner, drawn over it */
  .dtile .badge { top: auto; bottom: -4px; right: calc(50% - 30px); border: 3px solid var(--bg); }
  .dtile .rail-voice { right: 8px; bottom: -3px; }
  .dtile-sep { width: 32px; height: 2px; margin: 0 auto; background: var(--line); border-radius: 1px; }
  .dtile.muted .dtile-btn { opacity: .45; }

  /* ----- channel list column ----- */
  .nav { grid-column: 2; grid-row: 1 / 3; width: auto; min-height: 0; display: flex; }
  .sidebar { border: 0; border-radius: 0; background: var(--bg-2); width: 100%; }
  .drawer-servers { display: none !important; }
  /* "Find or start a conversation" sits on top of the home list only */
  .deck-search {
    grid-column: 2; grid-row: 1; z-index: 2; align-self: start; margin: 10px 10px 0; width: auto; height: 28px;
    border-radius: 4px; background: var(--bg); border: 0; color: var(--muted); font-size: 13px; padding: 0 8px;
  }
  .deck-search kbd { display: none; }
  .deck-search span { display: inline !important; }
  .app:has(.sidebar .server-card) .deck-search { display: none; }
  .app:not(:has(.sidebar .server-card)) .side-inner { padding-top: 48px; }
  .app:not(:has(.sidebar .server-card)) .deck-search { box-shadow: 0 1px 0 rgba(0,0,0,.2); }
  .panel-head { height: var(--hdr-h); border-bottom: 1px solid rgba(0, 0, 0, .25); }

  /* server header: plain name + chevron, like a menu button */
  .sidebar .server-card { border: 0; border-radius: 0; background: transparent; box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
  .sidebar .server-card:not(.has-banner) .sc-row { min-height: var(--hdr-h); padding: 0 12px 0 16px; }
  .sidebar .server-card:not(.has-banner) .sc-icon { display: none; }
  .sidebar .server-card .sc-text .name { font-size: 15px; font-weight: 600; }
  .sidebar .server-card .sc-text small { display: none; }
  .sidebar .server-card:hover { background: var(--bg-hover); }

  .cat { padding: 16px 8px 4px 8px; font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
  .cat:hover { color: var(--text-2); }
  .chan { min-height: 32px; margin: 1px 8px; padding: 0 8px; border-radius: 4px; color: var(--muted); font-size: 15px; font-weight: 500; }
  .chan > svg:first-child { color: var(--muted); }
  .chan:hover { background: var(--bg-hover); color: var(--text-2); }
  .chan.active { background: var(--bg-active); color: var(--text); }
  .chan.active > svg:first-child { color: var(--text-2); }
  .chan.unread { color: var(--text); font-weight: 600; }
  .dm-item { margin: 1px 8px; border-radius: 4px; }
  .dm-item .dname { color: var(--muted); font-size: 15px; font-weight: 500; }
  .dm-item:hover .dname, .dm-item.active .dname { color: var(--text); }
  .dm-item.active { background: var(--bg-active); }
  .hub-tile { border-radius: 4px; color: var(--muted); font-size: 15px; font-weight: 500; }
  .hub-tile:hover { color: var(--text-2); background: var(--bg-hover); }
  .hub-tile.active { color: var(--text); background: var(--bg-active); }
  .community-navigation { padding: 8px 8px 0; }
  .community-navigation button { border-radius: 4px; color: var(--muted); }
  .community-navigation button.on { color: var(--text); background: var(--bg-active); }

  /* ----- voice + user panel at the foot of the channel list ----- */
  #voicepanel { grid-column: 2; grid-row: 3; background: var(--panel-foot, var(--bg-2)); border-bottom: 1px solid var(--line); }
  #voicepanel:empty { display: none; }
  #voicepanel .live-pill { height: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px; border: 0; border-radius: 0; background: transparent; animation: none; }
  #voicepanel .lp-where { flex: 1 1 100%; height: auto; padding: 2px 4px; flex-direction: row; color: var(--green); font-size: 14px; }
  #voicepanel .lp-name { display: inline !important; max-width: 150px; color: var(--green); }
  #voicepanel .lp-count { display: inline-flex !important; }
  #voicepanel .lp-count { margin-left: auto; color: var(--muted); }
  #voicepanel .lp-btn { flex: 1; height: 32px; border-radius: 4px; background: var(--bg-2); color: var(--text-2); }
  #voicepanel .lp-btn:hover { background: var(--bg-hover); color: var(--text); }
  #voicepanel .lp-btn.leave { flex: 0 0 40px; background: transparent; color: var(--red); }
  #voicepanel .lp-btn.leave:hover { background: rgba(242, 63, 67, .15); }
  #userpanel { grid-column: 2; grid-row: 4; background: var(--panel-foot, var(--bg-2)); padding: 0 8px; height: 52px; display: flex; align-items: center; }
  .me-cluster { display: flex; width: 100%; align-items: center; gap: 0; }
  .me-chip { order: -1; flex: 1; min-width: 0; margin: 0 4px 0 -2px; padding: 4px; gap: 8px; border: 0; border-radius: 4px; background: transparent; max-width: none; }
  .me-chip:hover { background: var(--bg-hover); }
  .me-chip .who { display: block !important; }
  .me-chip .who b { font-size: 14px; font-weight: 600; }
  .me-chip .who span { font-size: 12px; color: var(--muted); }
  .me-chip .av { width: 32px; height: 32px; }
  .me-chip .av .dot { border-color: var(--panel-foot, var(--bg-2)); }
  .me-cluster .icon-btn { width: 32px; height: 32px; min-width: 32px; border-radius: 4px; color: var(--text-2); }
  .me-cluster .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
  .me-cluster .icon-btn svg { width: 20px; height: 20px; }

  /* ----- chat column ----- */
  .main { grid-column: 3; grid-row: 1 / -1; min-width: 0; min-height: 0; border: 0; border-radius: 0; background: var(--bg-1); }
  .topbar { height: var(--hdr-h); min-height: var(--hdr-h); padding: 0 8px 0 16px; border-bottom: 0; box-shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 1.5px 0 rgba(6, 6, 7, .05), 0 2px 0 rgba(4, 4, 5, .05); position: relative; z-index: 2; background: var(--bg-1); }
  .topbar .t-name { font-size: 16px; font-weight: 600; }
  .topbar .t-name > svg { color: var(--muted); width: 22px; height: 22px; }
  .topbar .t-topic { border-left: 1px solid var(--line); color: var(--muted); font-size: 14px; }
  .t-actions .icon-btn { color: var(--text-2); border-radius: 4px; }
  .t-actions .icon-btn:hover { color: var(--text); background: transparent; }
  .t-actions .icon-btn.active { color: var(--text); background: transparent; }
  .topbar .search input { height: 24px; border-radius: 4px; border: 0; background: var(--bg); font-size: 13px; width: 144px; transition: width .15s; }
  .topbar .search input:focus { width: 240px; box-shadow: none; }

  .msg { margin: 0; border-radius: 0; padding-left: 72px; padding-right: 48px; }
  .msg .m-av { left: 16px; width: 40px; height: 40px; }
  .msg:hover { background: rgba(2, 2, 2, .06); }
  .msg.head { margin-top: 17px; }
  .m-meta .m-author { font-size: 16px; font-weight: 500; }
  .m-meta .m-time { font-size: 12px; color: var(--muted); }
  .m-content { font-size: 16px; line-height: 1.375; }
  :root:not([data-theme]) .m-content, :root[data-theme="dark"] .m-content { color: #dbdee1; }
  .m-tools { top: -16px; right: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); background: var(--bg-1); box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
  .day-sep { margin: 24px 16px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
  .chan-intro { padding: 16px 16px 0; }
  .ci-card { padding: 0 0 8px; }
  .ci-card .ci-icon { width: 68px; height: 68px; border-radius: 50%; background: var(--bg-4); color: var(--text); }
  .ci-card h2 { font-size: 32px; font-weight: 700; }

  .composer { padding: 0 16px 24px; }
  .compose-box { border: 0; border-radius: 8px; background: var(--bg-3); padding: 0 8px 0 4px; min-height: 44px; align-items: center; }
  .compose-box:focus-within { border: 0; box-shadow: none; }
  .compose-box textarea { font-size: 16px; padding: 11px 6px; }
  .compose-box .icon-btn { color: var(--text-2); border-radius: 4px; }
  .compose-box .icon-btn:hover { background: transparent; color: var(--text); }
  .compose-box .send-btn { background: transparent; color: var(--text-2); padding: 0 6px; min-height: 32px; box-shadow: none; }
  .compose-box .send-btn span { display: none; }
  .compose-box .send-btn:hover { color: var(--gold); background: transparent; }
  .typing { padding-left: 16px; }

  .members { width: 240px; padding: 0 8px 20px; background: var(--bg-2); border-left: 0; }
  .members h4, .members .mgroup-title, .members .cat { padding: 24px 8px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
  .member { border-radius: 4px; padding: 1px 8px; min-height: 42px; }
  .member:hover { background: var(--bg-hover); }
  .member .av { width: 32px; height: 32px; }
  .member .mn b { font-weight: 500; font-size: 15px; }
  .member.offline { opacity: .4; }

  /* ----- controls in Discord proportions ----- */
  .btn { border-radius: 3px; font-weight: 500; }
  .input, .select, .textarea { border-radius: 3px; background: var(--bg); border-color: transparent; }
  .input:focus, .select:focus, .textarea:focus { border-color: transparent; box-shadow: 0 0 0 2px var(--gold); }
  .modal, .modal.wide { border-radius: 8px; border: 0; box-shadow: 0 8px 16px rgba(0,0,0,.24); }
  .modal:not(.wide) .modal-foot { background: var(--bg-2); border-top: 0; }
  .modal-back { background: rgba(0, 0, 0, .7); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .menu, .popover > .menu { border-radius: 4px; background: #111214; border: 0; padding: 6px 8px; }
  .menu button { border-radius: 2px; font-size: 14px; font-weight: 500; }
  .menu button:hover { background: var(--gold); color: #1b1600; }
  .menu button.danger:hover { background: var(--red); color: #fff; }
  .settings-nav { background: var(--bg-2); }
  .settings-nav button { border-radius: 4px; color: var(--text-2); }
  .settings-nav button.active { background: var(--bg-active); color: var(--text); }
  .modal.wide.settings-modal .settings-main { background: var(--bg-1); }

  ::-webkit-scrollbar { width: 16px; }
  ::-webkit-scrollbar-thumb { background: #1a1b1e; border: 4px solid transparent; background-clip: padding-box; border-radius: 8px; }
  * { scrollbar-color: #1a1b1e transparent; }
}

/* Tablets: no room for a fixed member list; it slides over like on phones */
@media (min-width: 761px) and (max-width: 900px) {
  :root { --side-w: 220px; }
  .members { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; }
}

/* =====================================================================
   Phones: the drawer shows the server rail beside the channel list
   ===================================================================== */
@media (max-width: 760px) {
  .sidebar { display: flex; flex-direction: row; width: min(352px, calc(100vw - 40px)); border-radius: 0 12px 12px 0; overflow: hidden; background: var(--bg-2); }
  .drawer-servers {
    flex-direction: column; flex: 0 0 72px; align-items: center; gap: 8px; overflow-y: auto; overflow-x: hidden;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 0 12px; border-bottom: 0; background: var(--bg);
  }
  .drawer-servers .dtile { position: relative; width: 72px; display: flex; justify-content: center; }
  .drawer-servers .dtile-btn { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--bg-2); box-shadow: none !important; }
  .drawer-servers .dtile.active .dtile-btn { border-radius: 16px; background: var(--gold); color: #1b1600; }
  .drawer-servers .dtile.active .dtile-btn.has-img { background: var(--bg-2); }
  .drawer-servers .dtile.home .dtile-btn { background: var(--bg-2) url(/brand/vexel-mark.svg) center / 26px no-repeat; color: transparent; }
  .drawer-servers .dtile.home .dtile-btn svg { display: none; }
  .drawer-servers .dtile.action .dtile-btn { color: var(--green); }
  .drawer-servers .dtile::after { display: block; content: ''; position: absolute; left: 0; top: 50%; bottom: auto; transform: translateY(-50%); width: 4px; height: 0; border-radius: 0 4px 4px 0; background: var(--text); }
  .drawer-servers .dtile.active::after { height: 40px; }
  .drawer-servers .dtile.unread:not(.active)::after { height: 8px; width: 4px; }
  .drawer-servers .dtile .badge { top: auto; bottom: -4px; right: calc(50% - 30px); }
  .drawer-servers .dtile-sep { width: 32px; height: 2px; margin: 0 auto; background: var(--line); }
  .side-inner { flex: 1; min-width: 0; padding-top: env(safe-area-inset-top, 0px); }
  .sidebar .server-card { box-shadow: 0 1px 0 rgba(0, 0, 0, .25); border: 0; }
  .sidebar .server-card:not(.has-banner) .sc-icon { display: none; }
  .cat { text-transform: uppercase; font-size: 12px; letter-spacing: .02em; }
  .chan, .dm-item { border-radius: 4px; }
  .msg .m-av { border-radius: 50%; }
}

/* Ping count on server and DM icons, the way Discord draws it: a small red pill with a bold white number,
   cut out of the rail by a ring in the rail's colour, sitting on the icon's bottom-right corner.
   Written with enough specificity to win over the older rail styles in pulsed.css and workspace.css. */
.app .dtile .badge, .deck-servers .dtile .badge, .drawer-servers .dtile .badge {
  position: absolute; left: auto; top: auto; right: calc(50% - 28px); bottom: -4px; z-index: 3; pointer-events: none;
  min-width: 10px; height: 16px; padding: 0 3px; box-sizing: content-box; /* one digit: a 16px circle */
  border: 4px solid var(--bg); border-radius: 12px; background: #f23f43; color: #fff;
  font: 700 11px/16px var(--font); letter-spacing: 0; text-align: center; font-variant-numeric: tabular-nums;
}
.drawer-servers .dtile .badge { border-color: var(--bg); }
