/* ============================================================
   SONORA Icon Rail Communities Dock, Mobile Hide,
   Listen Sync Popover & Shared Tracks
   ============================================================ */

/* JOINED COMMUNITIES ICON RAIL INSIDE FAR-LEFT ICON RAIL */
.sidebar-comms-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 2px 0 8px;
}

.sb-comm-item {
    position: relative;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    background: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
}

.sb-comm-item::before {
    content: '';
    position: absolute;
    left: -13px;
    top: 50%;
    width: 4px;
    height: 0;
    border-radius: 0 4px 4px 0;
    background: var(--md-primary);
    transform: translateY(-50%);
    transition: height 0.18s var(--ease-emphasized);
}

.sb-comm-item:hover::before {
    height: 20px;
}

.sb-comm-item.active::before {
    height: 32px;
}

.sb-comm-emblem {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-radius 0.18s var(--ease-emphasized), border-color 0.16s, transform 0.16s;
}

.sb-comm-item:hover .sb-comm-emblem {
    border-radius: 13px;
    transform: translateY(-1px);
}

.sb-comm-item.active .sb-comm-emblem {
    border-radius: 13px;
    border-color: var(--md-primary);
}

.sb-comm-emblem img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.sb-comm-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    border: 1px dashed var(--md-outline);
    background: var(--md-surface-container);
    color: var(--md-on-surface-variant);
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-radius 0.18s var(--ease-emphasized), background-color 0.16s, color 0.16s, border-color 0.16s;
}

.sb-comm-action-btn:hover {
    border-radius: 13px;
    border-style: solid;
    border-color: var(--md-primary);
    background: var(--md-primary-container);
    color: var(--md-primary);
}

@media (max-width: 860px) {
    .sidebar-comms-rail {
        display: none;
    }
}

/* LISTEN-SYNC FOOTER BUTTON & POPOVER MENU */
.ls-btn-label {
    max-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    font-weight: 600;
}

.ls-count-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--md-primary);
    color: var(--md-on-primary);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 700;
    display: inline-grid;
    place-items: center;
}

.listen-sync-popover {
    position: fixed;
    bottom: 84px;
    z-index: 680;
    width: min(310px, calc(100vw - 24px));
    background: var(--md-surface-container-high);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-lg);
    box-shadow: var(--md-shadow-3);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: toast-in 0.16s var(--ease-emphasized);
}

.ls-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--md-outline-variant);
    font-size: 14px;
}

.ls-pop-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ls-pop-title {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--md-on-surface-variant);
}

.ls-pop-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 210px;
    overflow-y: auto;
}

.ls-pop-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline-variant);
    cursor: pointer;
    transition: border-color 0.14s, background-color 0.14s;
}

.ls-pop-row:hover {
    border-color: var(--md-primary);
    background: var(--md-surface-container-highest);
}

.ls-pop-meta {
    min-width: 0;
    flex: 1;
}

.ls-pop-meta strong,
.ls-pop-meta span {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ls-pop-meta strong { font-size: 13px; }
.ls-pop-meta span { font-size: 11px; color: var(--md-on-surface-variant); }

.ls-pop-empty {
    font-size: 12px;
    color: var(--md-on-surface-variant);
    padding: 8px 4px;
    line-height: 1.45;
}

/* SHARED TRACK CARD WITH SHARER PROFILE FOOTER */
.shared-track-wrap {
    margin-top: 6px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--md-outline-variant);
    overflow: hidden;
    cursor: pointer;
    max-width: 390px;
    transition: border-color 0.15s, background-color 0.15s;
}

.dm-msg-row.me .shared-track-wrap {
    background: rgba(10, 12, 18, 0.28);
    border-color: rgba(255, 255, 255, 0.24);
}

.shared-track-wrap:hover {
    border-color: var(--md-primary);
}

.shared-track-main {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
}

.shared-track-main img {
    width: 60px;
    height: 38px;
    border-radius: 7px;
    object-fit: cover;
    flex-shrink: 0;
}

.shared-track-copy {
    min-width: 0;
    flex: 1;
}

.shared-track-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shared-track-sub {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    opacity: 0.82;
    margin-top: 2px;
}

.shared-track-sub.is-live {
    color: var(--md-online);
    font-weight: 600;
    opacity: 1;
}

.shared-track-ico {
    font-size: 22px;
    color: var(--md-primary);
    flex-shrink: 0;
}

.dm-msg-row.me .shared-track-ico {
    color: #fff;
}

.shared-track-sharer {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.18);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11.5px;
}

.shared-track-sharer:hover {
    background: rgba(255, 255, 255, 0.06);
}

.shared-track-sharer-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shared-track-sharer-tag {
    opacity: 0.72;
    font-size: 11px;
}

.shared-track-sync-pill {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    background: rgba(124, 155, 255, 0.18);
    color: inherit;
    flex-shrink: 0;
}

.shared-track-sync-pill .ms-icon { font-size: 13px; }

/* FLAT GROUPED ROOM CHAT */
.room-chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 6px 0 10px;
}

.room-chat-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 2px 8px;
    position: relative;
    border-radius: var(--radius-xs);
    transition: background-color 0.1s;
}

.room-chat-row:hover {
    background: color-mix(in srgb, var(--md-surface-container) 62%, transparent);
}

.room-chat-row.is-group-start {
    margin-top: 9px;
    padding-top: 3px;
}

.room-chat-row.is-group-start:first-child {
    margin-top: 2px;
}

.room-chat-av-slot {
    width: 30px;
    flex-shrink: 0;
    padding-top: 2px;
    cursor: pointer;
}

.room-chat-gutter {
    width: 30px;
    flex-shrink: 0;
    text-align: right;
    padding-top: 2px;
    user-select: none;
}

.room-chat-gutter-time {
    font-family: var(--font-mono);
    font-size: 9.5px;
    color: var(--md-on-surface-variant);
    opacity: 0;
}

.room-chat-row.is-continuation:hover .room-chat-gutter-time {
    opacity: 0.78;
}

.room-chat-content {
    flex: 1;
    min-width: 0;
}

.room-chat-head {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 1px;
    font-size: 13px;
}

.room-chat-head strong { font-size: 13px; font-weight: 600; cursor: pointer; }
.room-chat-head span { font-family: var(--font-mono); font-size: 10.5px; color: var(--md-on-surface-variant); }
.room-chat-text { font-size: 13.5px; line-height: 1.4; word-break: break-word; }

.room-chat-actions {
    position: absolute;
    top: 2px;
    right: 6px;
    opacity: 0;
    transition: opacity 0.12s;
}

.room-chat-row:hover .room-chat-actions { opacity: 1; }

/* DANGER SETTINGS CARD & VOICE USER CURSOR */
.danger-settings-card {
    border-color: color-mix(in srgb, var(--md-dnd) 38%, var(--md-outline-variant));
    margin-top: 16px;
}

.comm-voice-user { cursor: pointer; }
.comm-voice-user:hover { background: var(--md-surface-container); color: var(--md-on-surface); }
.voice-peer-pill { cursor: pointer; }
.voice-peer-pill:hover { border-color: var(--md-primary); }

/* AVATAR DECORATION OVERFLOW FIXES IN CHAT / DM / ROOMS */
.comm-msg-av-slot,
.room-chat-av-slot,
.dm-msg-av-slot {
    overflow: visible !important;
}

.dm-msg-av-slot {
    width: 30px;
    flex-shrink: 0;
    cursor: pointer;
    align-self: flex-end;
    margin-bottom: 2px;
}

.dm-msg-av-spacer {
    width: 30px;
    flex-shrink: 0;
}

/* LEFT-TABBED COMMUNITY SETTINGS MODAL & ROLES EDITOR */
.m3-modal-dialog.comm-settings-dialog {
    width: min(880px, 95vw) !important;
    max-width: min(880px, 95vw) !important;
    padding: 0 !important;
    overflow: hidden;
}

.cs-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: 540px;
    max-height: 86vh;
}

.cs-right-pane {
    min-width: 0;
    overflow-y: auto;
}

.cs-roles-split {
    min-width: 0;
}

.cs-left-nav {
    background: var(--md-surface-container-lowest);
    border-right: 1px solid var(--md-outline-variant);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cs-left-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--md-on-surface-variant);
    padding: 4px 10px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-nav-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    border: 0;
    background: transparent;
    color: var(--md-on-surface-variant);
    font-family: var(--font-body);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.cs-nav-btn:hover { background: var(--md-surface-container); color: var(--md-on-surface); }
.cs-nav-btn.active { background: var(--md-primary-container); color: var(--md-on-primary-container); font-weight: 600; }
.cs-nav-btn.danger { color: var(--md-dnd); margin-top: auto; }
.cs-nav-btn.danger:hover { background: color-mix(in srgb, var(--md-dnd) 14%, transparent); }

.cs-right-pane {
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cs-roles-split {
    display: grid;
    grid-template-columns: 195px 1fr;
    gap: 14px;
    min-height: 390px;
}

.cs-roles-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-right: 1px solid var(--md-outline-variant);
    padding-right: 12px;
}

.cs-role-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--md-on-surface);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.cs-role-pill:hover { background: var(--md-surface-container); }
.cs-role-pill.active { background: var(--md-primary-container); border-color: var(--md-primary); }

.cs-role-editor {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.cs-perm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline-variant);
    cursor: pointer;
}

.cs-perm-row strong { display: block; font-size: 12.5px; }
.cs-perm-row span { display: block; font-size: 11px; color: var(--md-on-surface-variant); }

/* CATEGORIES, DND MARKERS, BOT BADGE & INLINE ROLE MENU */
.comm-cat-group { margin-bottom: 10px; border-radius: var(--radius-sm); }
.comm-cat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 5px 6px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    user-select: none;
}
.comm-cat-head:hover { color: var(--md-on-surface); }
.comm-cat-group.is-collapsed .comm-cat-items { display: none; }
.is-dragging { opacity: 0.42; }
.dnd-over-top { box-shadow: inset 0 2px 0 var(--md-primary); }
.dnd-over-bottom { box-shadow: inset 0 -2px 0 var(--md-primary); }
.dnd-over-cat { background: color-mix(in srgb, var(--md-primary) 12%, transparent); }

.bot-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 5px;
    border-radius: 4px;
    background: #5865F2;
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.comm-readonly-bar {
    padding: 12px 16px;
    text-align: center;
    font-size: 12.5px;
    color: var(--md-on-surface-variant);
    border-top: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-low);
}

.ctx-roles-box { display: flex; flex-direction: column; gap: 3px; padding: 4px 6px; max-height: 150px; overflow-y: auto; }
.ctx-role-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: var(--md-on-surface);
    font-size: 12.5px;
    cursor: pointer;
    text-align: left;
}
.ctx-role-toggle:hover { background: var(--md-surface-container); }

@media (max-width: 720px) {
    .cs-layout,
    .cs-roles-split {
        grid-template-columns: 1fr;
    }
    .cs-left-nav {
        flex-direction: row;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--md-outline-variant);
    }
    .cs-nav-btn.danger { margin-top: 0; }
    .cs-roles-list { border-right: 0; border-bottom: 1px solid var(--md-outline-variant); padding-right: 0; padding-bottom: 10px; }
}

/* BOT DISCOVER & INSTALL MODAL */
.bots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(305px, 1fr));
    gap: 16px;
}

.bot-discover-card {
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline-variant);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.bot-discover-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--md-primary) 55%, transparent);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}

.bot-card-banner {
    height: 74px;
    position: relative;
    padding: 10px 12px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
}

.bot-live-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    backdrop-filter: blur(8px);
    background: rgba(11, 14, 23, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
}

.bot-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #64748B;
}

.bot-live-pill.is-online .bot-live-dot {
    background: var(--md-online);
    box-shadow: 0 0 8px var(--md-online);
}

.bot-card-body {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 10px;
}

.bot-card-top {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 0;
}

.bot-card-avatar {
    width: 58px;
    height: 58px;
    margin-top: -29px;
    position: relative;
    z-index: 3;
    border-radius: 16px;
    border: 4px solid var(--md-surface-container);
    background: var(--md-surface-container);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    color: #fff;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.bot-card-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.bot-card-idmeta { min-width: 0; flex: 1; padding-top: 8px; position: relative; z-index: 2; }
.bot-card-name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bot-card-name-row strong {
    font-size: 15.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bot-card-handle {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11.5px;
    color: var(--md-on-surface-variant);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bot-card-desc {
    margin: 0;
    font-size: 13px;
    line-height: 1.48;
    color: var(--md-on-surface-variant);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 38px;
}

.bot-card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.bot-tag-chip {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(124, 155, 255, 0.12);
    color: var(--md-primary);
    border: 1px solid rgba(124, 155, 255, 0.24);
}
.bot-tag-chip.is-muted {
    background: var(--md-surface-container-low);
    color: var(--md-on-surface-variant);
    border-color: var(--md-outline-variant);
}

.bot-card-foot {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--md-outline-variant);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
.bot-card-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
}
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bot-card-stats .ms-icon { font-size: 15px; }
.bot-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.bot-install-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
    background: var(--md-surface-container-low);
    border: 1px solid var(--md-outline-variant);
}

.bot-comm-pick-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 150px;
    overflow-y: auto;
}

.bot-comm-pick-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-low);
    color: var(--md-on-surface);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}

.bot-comm-pick-item.is-selected {
    border-color: var(--md-primary);
    background: rgba(124, 155, 255, 0.12);
}

.bot-comm-pick-dot {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    flex-shrink: 0;
}

.pm-bot-meta-box {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--md-surface-container-low);
    border: 1px solid var(--md-outline-variant);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12.5px;
}
