/**
 * Community — frame styles (2026-08-11; self-sufficient rewrite 2026-08-12, #652).
 * Loaded by shell-community.php BEFORE community.css (the interior).
 *
 * SELF-SUFFICIENT since the public-first move: admin.css is no longer loaded —
 * this file owns the whole shell structure (cm-shell / cm-sidebar / cm-main /
 * cm-topbar / cm-overlay, the mobile slide pattern) plus the design tokens.
 * Discord's shape, OUR ramp (palette history in git).
 *
 * Two body modes (shell sets body.cm-mode-*):
 *   cm-mode-app — the full-height chat frame; BODY never scrolls.
 *   cm-mode-doc — normal scrolling document (ticker permalink pages).
 */

:root {
    --cm-bg-chat:     #1c2332;
    --cm-bg-panel:    #181e2c;
    --cm-bg-deep:     #141a2a;
    --cm-bg-hover:    #202838;
    --cm-bg-active:   #272f3f;
    --cm-bg-input:    #222a3c;
    --cm-text:        #e2e8f0;
    --cm-text-strong: #f8fafc;
    --cm-text-muted:  #94a3b8;
    --cm-line:        #171c2a;
    --cm-accent:      #059669;   /* Delvantic emerald */
    --cm-accent-soft: #34d399;
    --cm-gold:        #e0a526;   /* the Gem gold — reserved for special moments */
}

/* Ground + modes. overflow lock is APP-MODE ONLY (2026-08-12) — doc pages
   (ticker permalinks) scroll like normal documents. */
body.cm-layout { background: var(--cm-bg-deep); color: var(--cm-text); }
body.cm-mode-app { overflow: hidden; height: 100%; }
html:has(body.cm-mode-app) { height: 100%; }

/* ── Shell structure (replaces admin.css's admin-wrapper/sidebar/main) ────── */
.cm-shell { display: flex; min-height: 100vh; }
body.cm-mode-app .cm-shell { height: 100vh; min-height: 100vh; }
/* Mobile URL-bar fix (2026-08-12): 100vh overshoots the VISIBLE viewport on
   iOS/Android (the collapsing browser chrome), hiding the composer behind the
   toolbar. dvh tracks the real visible height; vh above stays as the fallback. */
@supports (height: 100dvh) {
    body.cm-mode-app .cm-shell { height: 100dvh; min-height: 100dvh; }
    body.cm-mode-app .cm-main  { height: 100dvh; }
}

.cm-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
    display: flex; flex-direction: column;
    background: var(--cm-bg-panel);
    border-right: 1px solid var(--cm-line);
    z-index: 1040;
}
.cm-main { flex: 1; display: flex; flex-direction: column; margin-left: 260px; min-width: 0; }
body.cm-mode-app .cm-main { height: 100vh; }

.cm-content {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
    padding: 0; margin: 0;               /* kills main.css's public-page margins */
    background: var(--cm-bg-chat);
}
body.cm-mode-app .cm-content { overflow: hidden; }
body.cm-mode-doc .cm-content { overflow: visible; }

/* ── Sidebar interior ─────────────────────────────────────────────────────── */
/* Head + topbar share one height so their bottom borders run as one seam —
   change BOTH together (78px, roomier since 2026-08-12; was 71). */
.cm-sidebar-head { height: 78px; padding: 0 20px; display: flex; align-items: center; gap: 13px;
    border-bottom: 1px solid var(--cm-line); flex-shrink: 0; }
.cm-sidebar-head canvas { width: 42px; height: 42px; flex-shrink: 0; }
.cm-sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.cm-sidebar-brand { font-size: 17.5px; font-weight: 800; letter-spacing: -.01em; line-height: 1.1;
    color: var(--cm-text-strong); text-decoration: none; }
.cm-sidebar-brand:hover { color: var(--cm-accent-soft); }
.cm-sidebar-sub { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .11em; color: var(--cm-text-muted); }

.cm-sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 10px; }
.cm-sidebar-group + .cm-sidebar-group { margin-top: 16px; }
.cm-sidebar-cat { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
    color: var(--cm-text-muted); padding: 0 10px 6px; }
.cm-channel-link {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 600; color: var(--cm-text-muted); text-decoration: none;
    padding: 6px 10px; border-radius: 7px; margin-bottom: 1px;
}
.cm-channel-link:hover { background: var(--cm-bg-hover); color: var(--cm-text); }
.cm-channel-link.cm-active { background: var(--cm-bg-active); color: var(--cm-text-strong); }
.cm-channel-link .bi-hash { font-size: 14px; opacity: .7; }
.cm-channel-kind { margin-left: auto; font-size: 11px; opacity: .55; }

/* Individual Stock Rooms (2026-08-13) — ticker permalink pages listed like rooms. */
.cm-ticker-dollar { font-size: 14px; opacity: .7; width: 14px; text-align: center; }
.cm-ticker-count { margin-left: auto; font-size: 10.5px; font-weight: 700; opacity: .55;
    background: var(--cm-bg-hover); border-radius: 999px; padding: 1px 7px; }

.cm-sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--cm-line); flex-shrink: 0;
    display: flex; flex-direction: column; gap: 8px; }
.cm-foot-cta { display: block; text-align: center; background: var(--cm-accent); color: #fff;
    font-size: 13.5px; font-weight: 700; text-decoration: none; border-radius: 8px; padding: 9px 12px; }
.cm-foot-cta:hover { background: #047857; color: #fff; }
.cm-foot-link { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600;
    color: var(--cm-text-muted); text-decoration: none; }
.cm-foot-link:hover { color: var(--cm-text); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.cm-topbar {
    height: 78px; flex-shrink: 0;   /* keep equal to .cm-sidebar-head — the seam */
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px;
    background: var(--cm-bg-panel); border-bottom: 1px solid var(--cm-line);
}
.cm-topbar-toggle { background: none; border: 0; color: var(--cm-text); font-size: 22px; padding: 4px 8px; cursor: pointer; }
.cm-topbar-title { font-size: 16px; font-weight: 700; color: var(--cm-text-strong);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cm-topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.cm-topbar-link { font-size: 13.5px; font-weight: 600; color: var(--cm-text-muted); text-decoration: none; }
.cm-topbar-link:hover { color: var(--cm-text); }
.cm-topbar-cta { font-size: 13.5px; font-weight: 700; color: #fff; background: var(--cm-accent);
    text-decoration: none; border-radius: 8px; padding: 7px 14px; white-space: nowrap; }
.cm-topbar-cta:hover { background: #047857; color: #fff; }

.cm-user-btn { display: inline-flex; align-items: center; gap: 9px; color: var(--cm-text); text-decoration: none; }
.cm-user-btn:hover, .cm-user-btn:focus { color: var(--cm-text-strong); }
.cm-user-avatar { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #10b981, var(--cm-accent)); }
.cm-topbar .dropdown-menu { background: var(--cm-bg-panel); border: 1px solid var(--cm-line);
    box-shadow: 0 10px 28px rgba(0,0,0,.45); }
.cm-topbar .dropdown-header { color: var(--cm-text); }
.cm-topbar .dropdown-header .text-muted { color: var(--cm-text-muted) !important; }
.cm-topbar .dropdown-divider { border-color: var(--cm-line); }
.cm-topbar .dropdown-item { color: var(--cm-text); }
.cm-topbar .dropdown-item:hover, .cm-topbar .dropdown-item:focus { background: var(--cm-bg-hover); color: var(--cm-text-strong); }
.cm-topbar .dropdown-item.text-danger { color: #f87171 !important; }
.cm-topbar .dropdown-item.text-danger:hover { background: rgba(248,113,113,.12); }

/* ── Guest bar (where the composer sits for logged-out viewers) ───────────── */
.cm-guestbar { flex-shrink: 0; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 14px 20px; background: var(--cm-bg-panel); border-top: 1px solid var(--cm-line); }
.cm-guestbar-text { font-size: 14px; font-weight: 600; color: var(--cm-text); }
.cm-guestbar-cta { font-size: 13.5px; font-weight: 700; color: #fff; background: var(--cm-accent);
    text-decoration: none; border-radius: 8px; padding: 8px 16px; }
.cm-guestbar-cta:hover { background: #047857; color: #fff; }
.cm-guestbar-link { font-size: 13.5px; font-weight: 600; color: var(--cm-text-muted); text-decoration: none; }
.cm-guestbar-link:hover { color: var(--cm-text); }

/* ── Doc mode (ticker permalink pages) ────────────────────────────────────── */
/* ── Doc mode: the Reddit posture (2026-08-13, William) ─────────────────────
   Content floats as a CARD on a deeper canvas — a constrained ~740px reading
   column centered in the main area, with the canvas showing as "dead space"
   either side. The card is the elevated surface; the canvas is the room. */
body.cm-mode-doc .cm-content { background: var(--cm-bg-deep); }
/* Wider + hugging the left (2026-08-13, William) — the column sits tight
   against the sidebar with a slim gutter; all dead space pools right.
   Width includes a ~3-level nesting RESERVE: messages cap at 950px (rule in
   the doc-feed section) while the container runs 1120, so replies keep the
   SAME width as their root for the first ~3 depths — they translate right
   into the reserve instead of narrowing (William 2026-08-13). */
.cm-doc { max-width: 1120px; width: 100%; margin: 18px 0 60px 12px; padding: 0 16px 0 0; }
.cm-doc-head {
    background: var(--cm-bg-panel); border: 1px solid var(--cm-line);
    border-radius: 12px; padding: 20px 22px; margin-bottom: 14px;
}
.cm-doc-feed, .cm-doc-pager {
    background: var(--cm-bg-panel); border: 1px solid var(--cm-line);
    border-radius: 12px; padding: 8px 22px;
}
.cm-doc-pager { margin-top: 14px; padding: 14px 22px; }
/* Separators mark CONVERSATIONS: only a new root strand draws the line —
   plus the rail-less left edge below, that's Reddit's "new thread" signal. */
.cm-doc-feed > .cm-strand + .cm-strand {
    border-top: 1px solid var(--cm-line); margin-top: 12px; padding-top: 16px;
}
.cm-doc-title { font-size: 26px; font-weight: 800; color: var(--cm-text-strong); margin: 0 0 8px; }
.cm-doc-title-sub { font-size: 15px; font-weight: 600; color: var(--cm-text-muted); }
.cm-doc-links { display: flex; gap: 18px; flex-wrap: wrap; }
.cm-doc-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600;
    color: var(--cm-accent-soft); text-decoration: none; }
.cm-doc-link:hover { color: var(--cm-text-strong); }
/* Horizontal padding so the hover box never hugs the content (2026-08-13,
   William via fingerprint 00d5f00b — roots had 0 while children had 13px).
   margin-left drops 15→2 to compensate, so the TEXT stays at the tuned x
   while the box gains its breathing room. Nested msgs pin their own margin
   below (same-specificity rule, later in file). */
.cm-doc-feed .cm-msg { padding: 14px 13px; margin-left: 2px; max-width: 950px; }

/* ── Per-post tweaks in the ticker room. The two-row anatomy itself now
   lives in the DOM (messages.php/.cm-msg-meta — 2026-08-13 rework); only
   room-specific presentation remains here. Parent-quote lines are NOISE once
   the cascade shows the relationship (Reddit draws none). */
.cm-doc-feed .cm-msg-replyctx { display: none; }
.cm-doc-feed .cm-msg-channel { white-space: nowrap; }

/* ── The Twitter flip (2026-08-13) ──────────────────────────────────────────
   Aggregate room: tagged messages are click-through cards to their ticker
   room. Ticker room: composer at top, strand replies indented, arrived-at
   message glows via :target. */
.cm-msg-stretch { position: absolute; inset: 0; z-index: 0; }
.cm-msg-linked { cursor: pointer; }
.cm-msg-linked:hover { background: var(--cm-bg-hover); border-radius: 8px; }
/* Lift inner links above the SSR stretch overlay. .cm-msg-actions must NOT
   be here (2026-08-13 bug): position:relative overrode the live toolbar's
   absolute positioning, dropping it into the flow — the toolbar only exists
   in the live app, where there is no stretch overlay to lift above. */
.cm-msg-linked .cm-msg-body a,
.cm-msg-linked .cm-msg-channel, .cm-msg-linked .cm-msg-replylink { position: relative; z-index: 1; }

/* ── Nested strands + continuous rails (2026-08-13, Reddit's boundary
   anatomy). Each subtree renders inside .cm-msg-kids; its rail — a real,
   CLICKABLE element — runs the subtree's full height, so "where the rail
   ends, the thread ends" holds by construction. Clicking the rail collapses
   the subtree to the stub; elbows (└) attach each child to its rail. */
.cm-strand { position: relative; }
/* Every .cm-msg keeps the global 15px left margin (William) — the kids
   gutter is sized so rail + margin still lands a ~30px step per level. */
.cm-msg-kids { position: relative; margin-left: 24px; padding-left: 6px; }
.cm-msg-kids .cm-msg { padding-top: 8px; padding-bottom: 8px; margin-top: 4px; padding-left: 13px; margin-left: 15px; }

.cm-rail {
    position: absolute; left: 0; top: 4px; bottom: 4px; width: 16px;
    background: none; border: 0; padding: 0; cursor: pointer;
}
.cm-rail::before {
    content: ''; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px;
    background: #2a3450; border-radius: 2px;
}
.cm-rail:hover::before { background: var(--cm-accent-soft); }

/* Elbow: └ from the rail to each direct child's avatar row. */
.cm-msg-kids > .cm-strand > .cm-msg::before {
    content: ''; position: absolute; left: -14px; top: 4px; width: 12px; height: 14px;
    border-left: 2px solid #2a3450; border-bottom: 2px solid #2a3450;
    border-bottom-left-radius: 10px; pointer-events: none;
}

/* Collapsed: subtree hidden, stub shows the boundary explicitly. */
.cm-strand-stub {
    display: none; align-items: center; gap: 6px; margin: 2px 0 8px 15px;
    background: none; border: 0; padding: 2px 6px; cursor: pointer;
    font-size: 12px; font-weight: 700; color: var(--cm-text-muted); border-radius: 6px;
}
.cm-strand-stub:hover { color: var(--cm-accent-soft); background: var(--cm-bg-hover); }
.cm-strand.cm-collapsed > .cm-msg-kids { display: none; }
.cm-strand.cm-collapsed > .cm-strand-stub { display: inline-flex; }
.cm-msg-kids .cm-strand-stub { margin-left: 0; }

/* Channel badge on the ROOT only (Reddit shows the subreddit on the post,
   not every comment) — replies inherit the conversation's home. */
.cm-msg-kids .cm-msg-channel { display: none; }
@media (max-width: 991.98px) {
    .cm-msg-kids { margin-left: 8px; padding-left: 2px; }
    .cm-msg-kids > .cm-strand > .cm-msg::before { left: -10px; width: 8px; }
}
/* Action row under the content (Reddit's spot): quiet until hovered. */
.cm-msg-actionsrow { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.cm-msg-replylink { font-size: 12px; font-weight: 700; color: var(--cm-text-muted); text-decoration: none;
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 6px; margin-left: -6px; }
.cm-msg-replylink:hover { color: var(--cm-accent-soft); background: var(--cm-bg-hover); }

.cm-msg:target { background: rgba(5, 150, 105, .12); border-radius: 8px; animation: cmArrive 2.4s ease-out; }
@keyframes cmArrive { 0%, 55% { background: rgba(5, 150, 105, .28); } 100% { background: rgba(5, 150, 105, .12); } }

.cm-doc-flash { background: rgba(220, 38, 38, .12); border: 1px solid rgba(220, 38, 38, .4);
    color: #fca5a5; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }

.cm-doc-composer {
    background: var(--cm-bg-panel); border: 1px solid var(--cm-line);
    border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
}
.cm-doc-composer-guest { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    font-size: 13.5px; color: var(--cm-text-muted); }
.cm-doc-input {
    width: 100%; background: var(--cm-bg-input); color: var(--cm-text);
    border: 1px solid var(--cm-line); border-radius: 9px; padding: 10px 12px;
    font-size: 14px; resize: vertical;
}
.cm-doc-input:focus { outline: none; border-color: var(--cm-accent); }
.cm-doc-composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.cm-doc-composer-hint { font-size: 11.5px; color: var(--cm-text-muted); }
.cm-doc-send { background: var(--cm-accent); color: #fff; border: 0; border-radius: 8px;
    font-size: 13.5px; font-weight: 700; padding: 7px 18px; cursor: pointer; }
.cm-doc-send:hover { background: #047857; }
.cm-doc-replybar { display: flex; align-items: center; gap: 7px; font-size: 12.5px;
    color: var(--cm-text-muted); margin-bottom: 8px; flex-wrap: wrap; }
.cm-doc-replysnip { opacity: .8; font-style: italic; }
.cm-doc-replycancel { color: var(--cm-text-muted); text-decoration: none; font-weight: 700; margin-left: auto; }
.cm-doc-replycancel:hover { color: var(--cm-text-strong); }
.cm-msg-channel { font-size: 11px; font-weight: 700; color: var(--cm-text-muted); text-decoration: none;
    background: var(--cm-bg-panel); border: 1px solid var(--cm-line); border-radius: 999px; padding: 1px 9px; margin-left: 8px; }
.cm-msg-channel:hover { color: var(--cm-text); border-color: var(--cm-bg-active); }
.cm-doc-pager { margin-top: 20px; }
.cm-doc-pager a { font-size: 14px; font-weight: 700; color: var(--cm-accent-soft); text-decoration: none; }
.cm-doc-pager a:hover { color: var(--cm-text-strong); }
.cm-doc-empty, .cm-feed-empty { color: var(--cm-text-muted); font-size: 14px; padding: 18px 0; }

/* ── Mobile: sidebar slides (same pattern admin.css used, cm- names) ──────── */
.cm-overlay { display: none; }
@media (max-width: 991.98px) {
    .cm-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .cm-main { margin-left: 0; }
    body.cm-sidebar-open .cm-sidebar { transform: translateX(0); }
    body.cm-sidebar-open .cm-overlay { display: block; position: fixed; inset: 0;
        background: rgba(0,0,0,.5); z-index: 1035; }
    /* Compact chrome — the 78px bars are desktop luxury; on a phone they eat
       ~20% of a landscape viewport. Both together (the seam rule). */
    .cm-sidebar-head, .cm-topbar { height: 60px; }
    .cm-topbar { padding: 0 12px; gap: 10px; }
    .cm-sidebar-head { padding: 0 14px; gap: 10px; }
    .cm-sidebar-head canvas { width: 34px; height: 34px; }
    .cm-doc { margin: 12px 0 40px; padding: 0 10px; }
    .cm-doc-head, .cm-doc-feed { padding: 14px 16px; border-radius: 10px; }
    .cm-doc-title { font-size: 21px; }
}
@media (min-width: 992px) {
    .cm-topbar-toggle { display: none; }
}
