:root {
    /* Core Colors - Modern gray palette */
    --bg-sidebar: #18181b;
    --bg-main: #1f1f23;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(255, 255, 255, 0.1);

    /* Accent Colors - Gray tones */
    --accent-primary: #a1a1aa;
    --accent-secondary: #71717a;
    --accent-gradient: linear-gradient(135deg, #3f3f46 0%, #27272a 100%);

    /* Text Colors */
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-channel-hash: #a1a1aa;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-separator: rgba(255, 255, 255, 0.1);

    /* Avatars */
    --avatar-size: 40px;
    --avatar-radius: 10px;

    /* Spacing */
    --gutter-width: 52px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.46668;
}

/* Layout Skeleton */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    user-select: none;
}

.sidebar-header {
    height: 49px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 700;
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-sidebar);
}

.sidebar-header h2 {
    font-size: 16px;
    margin: 0;
    font-weight: 700;
}

#channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

/* Scrollbar for sidebar */
#channel-list::-webkit-scrollbar {
    width: 6px;
    background: transparent;
}

#channel-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Channel Items */
.channel-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    margin: 2px 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    height: 32px;
    border-left: 3px solid transparent;
}

.channel-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.channel-item.active {
    background-color: var(--bg-active);
    color: #fff;
    border-left-color: #fff;
}

.channel-hash {
    color: var(--text-channel-hash);
    margin-right: 8px;
    font-size: 16px;
    font-weight: 500;
    opacity: 0.7;
}

.channel-item.active .channel-hash {
    color: #fff;
    opacity: 1;
}

.channel-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-main);
    min-width: 0;
    /* Text truncation fix */
}

#messages-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Channel Top Bar */
.channel-top-bar {
    height: 49px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.channel-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.channel-title {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 17px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.channel-title-hash {
    color: var(--text-secondary);
    font-weight: 500;
}

.channel-desc {
    font-size: 12px;
    color: var(--text-muted);
}


/* Messages List */
.messages-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 0 20px 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.messages-scroll::-webkit-scrollbar {
    width: 8px;
    background: transparent;
}

.messages-scroll::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 4px;
}

/* Individual Message Group */
.message-group {
    display: flex;
    padding: 8px 20px;
    line-height: 1.46668;
    position: relative;
}

.message-group:hover {
    background-color: var(--bg-hover);
}

.message-gutter {
    width: 40px;
    margin-right: 12px;
    flex-shrink: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--avatar-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 16px;
    text-transform: uppercase;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    /* Default gradient - will be overridden by JS for unique colors */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Unique avatar colors based on data-node-id attribute */
.user-avatar[data-node-id] {
    background: var(--avatar-gradient, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
}

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

.message-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 4px;
    gap: 12px;
}

.sender-info {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    min-width: 0;
}

.sender-info:hover .sender-name {
    text-decoration: underline;
}

.sender-primary-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.sender-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.3;
}

.sender-id {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.3;
}

.sender-secondary {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.3;
}

.timestamp {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 2px;
}

.message-body {
    color: var(--text-primary);
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    padding: 2px 0;
}

/* Multi-line message styling */
.message-body:has(br),
.message-group:has(.message-body:not(:empty)) .message-body {
    padding: 4px 0;
}

.message-metadata {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Date Separators */
.date-separator {
    display: flex;
    align-items: center;
    padding: 16px 20px 8px;
    position: relative;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-separator);
}

.date-separator-text {
    padding: 4px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-main);
    border: 1px solid var(--border-separator);
    border-radius: 20px;
    white-space: nowrap;
}

/* Sticky Date Separator */
.sticky-date-separator {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    background: transparent;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    margin-top: -40px;
}

.sticky-date-separator.visible {
    opacity: 1;
    transform: translateY(0);
}

.sticky-date-separator.fading {
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.sticky-date-separator .date-separator-text {
    box-shadow: var(--shadow-md);
    background: var(--bg-main);
}

/* Empty State */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 16px;
}

.loading {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
}

/* Reactions */
.reactions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.reaction-pill {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.1s;
    user-select: none;
}

.reaction-pill:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.reaction-emoji {
    line-height: 1;
}

.reaction-count {
    margin-left: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Right Sidebar */
.right-sidebar {
    width: 0;
    overflow: hidden;
    background-color: var(--bg-main);
    /* Slack uses same as main usually, or slightly different */
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: width 0.15s ease-out;
    flex-shrink: 0;
}

body.sidebar-open .right-sidebar {
    width: 350px;
}

.node-info-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.node-details-header {
    border-bottom: 1px solid var(--border-subtle);
}

.node-details-title-container {
    height: 49px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.node-details-title {
    font-weight: 700;
    font-size: 16px;
    flex: 1;
}

.close-button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.close-button:hover {
    color: var(--text-primary);
}

.node-details-hero {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.node-avatar-large {
    width: 200px;
    height: 200px;
    background-color: var(--avatar-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    font-weight: 700;
    color: white;
    margin-bottom: 16px;
    text-transform: uppercase;
}

.node-name-large {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.node-status-badge {
    font-size: 13px;
    color: var(--text-secondary);
}

.node-details-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 15px;
    color: var(--text-primary);
}

.empty-sidebar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

.sender-name {
    cursor: pointer;
}

.sender-name:hover {
    text-decoration: underline;
}

.node-map {
    width: 100%;
    height: 250px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    position: relative;
}

/* Mobile Back Button */
.back-button {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    margin-right: 12px;
    padding: 4px;
    line-height: 1;
}

.back-button:hover {
    color: var(--text-primary);
}

/* ==================== */
/* MOBILE RESPONSIVE    */
/* ==================== */

@media (max-width: 768px) {

    /* Show back buttons on mobile */
    .back-button {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Base mobile layout - all panels position absolute for fullscreen behavior */
    .app-container {
        position: relative;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        border-right: none;
    }

    .main-content {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.25s ease-out;
    }

    .right-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 30;
        border-left: none;
        transform: translateX(100%);
        transition: transform 0.25s ease-out;
    }

    /* State: Messages panel is open */
    body.mobile-messages-open .main-content {
        transform: translateX(0);
    }

    /* State: Node details panel is open */
    body.mobile-node-open .right-sidebar {
        transform: translateX(0);
        width: 100%;
    }

    /* Override desktop sidebar-open behavior on mobile */
    body.sidebar-open .right-sidebar {
        width: 100%;
    }

    /* Channel top bar adjustments for mobile */
    .channel-top-bar {
        padding: 0 12px;
        justify-content: flex-start;
    }

    /* Node details title container adjustments */
    .node-details-title-container {
        padding: 0 12px;
    }

    /* Message padding adjustments for mobile */
    .message-group {
        padding: 8px 12px;
    }

    /* Smaller node avatar on mobile */
    .node-avatar-large {
        width: 120px;
        height: 120px;
        font-size: 48px;
    }

    /* Sidebar header adjustments */
    .sidebar-header {
        padding: 0 12px;
    }

    /* Channel item margins for mobile */
    .channel-item {
        margin: 0 4px;
    }
}

/* Reply Styles */
.reply-bar {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-muted);
    position: relative;
}

.reply-spine {
    width: 34px;
    height: 14px;
    border-left: 2px solid var(--border-separator);
    border-top: 2px solid var(--border-separator);
    border-top-left-radius: 6px;
    margin-right: 8px;
    margin-bottom: -6px;
    flex-shrink: 0;
    margin-left: -22px;
    margin-top: 2px;
}

.reply-content {
    display: flex;
    align-items: baseline;
    gap: 6px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 2px 6px;
    border-radius: 4px;
    max-width: 100%;
    transition: all 0.1s;
    opacity: 0.8;
}

.message-group:has(.reply-bar) .user-avatar {
    margin-top: 26px;
}

.reply-content:hover {
    background: var(--bg-hover);
    opacity: 1;
}

.sender-name-small {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
}

.reply-text-preview {
    color: var(--text-muted);
    overflow: hidden;
    font-size: 12px;
}

@keyframes highlight-pulse {
    0% {
        background-color: rgba(255, 255, 255, 0.0);
    }

    10% {
        background-color: rgba(255, 255, 255, 0.1);
    }

    100% {
        background-color: rgba(255, 255, 255, 0.0);
    }
}

.highlight-message {
    animation: highlight-pulse 2s ease-out;
}