:root {
    --sidebar-width: 250px;
    --header-height: 60px;
    --composer-height: 60px;
    
    /* Code for NL official color scheme */
    --codefor-orange: #ff6600;
    --codefor-orange-dark: #e55a00;
    --codefor-orange-light: #ff8533;
    
    /* Sidebar/menu colors - donkergrijs zoals relays sectie */
    --sidebar-bg: #2c3e50;
    --sidebar-bg-light: #34495e;
    --sidebar-bg-dark: #1a252f;
    --sidebar-text: #ecf0f1;
    --sidebar-text-muted: #bdc3c7;
    --sidebar-border: #34495e;
    --sidebar-hover: #3c5064;
    --sidebar-active: #4a6078;
    
    /* Main content colors - wit/licht zoals codefor.nl */
    --content-bg: #ffffff;
    --content-bg-alt: #f8f9fa;
    --content-text: #2c3e50;
    --content-text-muted: #7f8c8d;
    --content-border: #ecf0f1;
    
    /* Interactive elements */
    --hover-bg: #f1f2f6;
    --active-bg: #dfe4ea;
    --focus-color: var(--codefor-orange);
    
    /* Cards and surfaces */
    --card-bg: #ffffff;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Dark mode colors */
@media (prefers-color-scheme: dark) {
    :root {
        /* Sidebar wordt nog donkerder in dark mode */
        --sidebar-bg: #1a252f;
        --sidebar-bg-light: #2c3e50;
        --sidebar-bg-dark: #0f1419;
        --sidebar-text: #f8f9fa;
        --sidebar-text-muted: #95a5a6;
        --sidebar-border: #2c3e50;
        --sidebar-hover: #34495e;
        --sidebar-active: #3c5064;
        
        /* Content wordt donker */
        --content-bg: #1e1e1e;
        --content-bg-alt: #2a2a2a;
        --content-text: #e8eaed;
        --content-text-muted: #bdc1c6;
        --content-border: #3c4043;
        
        --hover-bg: #3a3a3a;
        --active-bg: #4a4a4a;
        --card-bg: #2d2d2d;
        --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
}

:root {
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-size-base: 16px;
    --font-size-sm: 14px;
    --font-size-lg: 18px;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 700;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh; /* Use dynamic viewport height for mobile */
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--content-text);
    background-color: var(--content-bg);
}

.chat {
    display: flex;
    flex-direction: row;
    height: 100%;
    position: relative;
}

.channels-menu {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile */
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-right: 1px solid var(--sidebar-border);
    z-index: 1000;
    border-right: 1px solid var(--border-light);
    box-shadow: var(--shadow);
}

.channels-menu.open {
    transform: translateX(0);
}

.channels-menu .user-status {
    padding: 20px;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg-light);
    color: var(--sidebar-text);
}

.channels-menu .user-status h3 {
    margin: 0 0 10px 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.channels-menu .user-status .current-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    color: white;
    margin-bottom: 12px;
}

.channels-menu .user-status .user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.channels-menu .user-status .username {
    flex: 1;
    min-width: 0;
    word-wrap: break-word;
}

.channels-menu .user-status .user-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.channels-menu .user-status .download-key-btn,
.channels-menu .user-status .logout-btn,
.channels-menu .user-status .import-key-btn,
.channels-menu .user-status .new-account-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    width: 100%;
}

.channels-menu .user-status .download-key-btn:hover,
.channels-menu .user-status .logout-btn:hover,
.channels-menu .user-status .import-key-btn:hover,
.channels-menu .user-status .new-account-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.channels-menu .user-status .download-key-btn:active,
.channels-menu .user-status .logout-btn:active,
.channels-menu .user-status .import-key-btn:active,
.channels-menu .user-status .new-account-btn:active {
    transform: translateY(0);
}

.channels-menu .user-status .download-key-btn {
    background: rgba(255, 255, 255, 0.15);
}

.channels-menu .user-status .import-key-btn {
    background: rgba(255, 255, 255, 0.25);
    font-weight: var(--font-weight-bold);
}

.channels-menu .user-status .new-account-btn {
    background: rgba(255, 255, 255, 0.1);
    border-style: dashed;
}

.channels-menu .relay-status {
    padding: 0;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
}

.channels-menu .relay-status .relay-header {
    padding: 20px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.channels-menu .relay-status .relay-header:hover {
    background: var(--sidebar-hover);
}

.channels-menu .relay-status .relay-header:focus {
    outline: 2px solid var(--codefor-orange);
    outline-offset: -2px;
}

.channels-menu .relay-status h3 {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex: 1;
}

.channels-menu .relay-status .relay-indicators-compact {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.channels-menu .relay-status .relay-indicators-compact .relay-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.channels-menu .relay-status .relay-expand-icon {
    font-size: 12px;
    color: var(--sidebar-text-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    user-select: none;
}

.channels-menu .relay-status .relay-header[aria-expanded="true"] .relay-expand-icon {
    transform: rotate(180deg);
}

.channels-menu .relay-status .relay-list {
    padding: 0 20px 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.channels-menu .relay-status .relay-list[aria-hidden="false"] {
    max-height: 200px;
    padding: 20px 20px 15px;
}

.channels-menu .relay-status .relay-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    transition-delay: 0.1s;
}

.channels-menu .relay-status .relay-list[aria-hidden="false"] .relay-item {
    opacity: 1;
    transform: translateY(0);
}

.channels-menu .relay-status .relay-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 12px;
}

.channels-menu .relay-status .relay-indicator.connected {
    background: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
}

.channels-menu .relay-status .relay-indicator.disconnected {
    background: #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
}

.channels-menu .relay-status .relay-url {
    font-size: var(--font-size-sm);
    color: #ecf0f1;
    font-weight: var(--font-weight-medium);
}

.channels-menu .channel-menu {
    padding: 15px 20px;
    cursor: pointer;
    font-weight: var(--font-weight-medium);
    color: var(--sidebar-text);
    border-bottom: 1px solid var(--sidebar-border);
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.channels-menu .channel-menu:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.channels-menu .channel-menu.active {
    background: var(--codefor-orange);
    color: white;
    font-weight: var(--font-weight-bold);
    border-left: 4px solid var(--codefor-orange-light);
}

.channels-menu .channel-menu.has-unread {
    font-weight: var(--font-weight-bold);
}

.channels-menu .channel-menu .channel-name {
    flex: 1;
}

.channels-menu .channel-menu .unread-counter {
    background: var(--codefor-orange);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    min-width: 20px;
    text-align: center;
    margin-left: 8px;
}

.channels-menu .channel-menu.active .unread-counter {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.channels-container {
    flex: 1;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile */
    position: relative;
}

.channel {
    height: 100%;
    position: relative;
}

.channel .channel-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: var(--content-bg);
    color: var(--content-text);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--content-border);
    box-shadow: var(--shadow);
    z-index: 10;
}

.channel .channel-header .header-logo {
    display: flex;
    align-items: center;
}

.channel .channel-header .logo {
    height: 32px;
    width: auto;
}

.channel .channel-header h1 {
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--codefor-orange);
}

.channel .channel-header .menu-toggle {
    background: none;
    border: none;
    color: var(--content-text);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.channel .channel-header .menu-toggle:hover {
    background: var(--hover-bg);
}

.channel .channel-messages {
    position: absolute;
    top: var(--header-height);
    bottom: var(--composer-height);
    left: 0;
    right: 0;
    overflow-y: auto;
    padding: 20px;
    background: var(--content-bg);
}

.channel .channel-composer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--content-bg);
    display: flex;
    height: var(--composer-height);
    padding: 12px 20px;
    border-top: 1px solid var(--content-border);
    box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
    box-sizing: border-box;
    gap: 12px;
    z-index: 10;
}

.channel .channel-composer input[name="message"] {
    flex: 1;
    padding: 12px 16px;
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    border: 1px solid var(--content-border);
    border-radius: 6px;
    background: var(--content-bg);
    color: var(--content-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.channel .channel-composer input[name="message"]::placeholder {
    color: var(--content-text-muted);
}

.channel .channel-composer input[name="message"]:focus {
    outline: 2px solid var(--codefor-orange);
    outline-offset: 2px;
    border-color: var(--codefor-orange);
    box-shadow: 0 0 0 3px rgba(255, 102, 0, 0.1);
}

.channel .channel-composer button {
    min-width: 100px;
    padding: 12px 20px;
    background: var(--codefor-orange);
    border: none;
    color: white;
    font-weight: var(--font-weight-medium);
    font-family: var(--font-family);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.channel .channel-composer button:hover {
    background: var(--codefor-orange-dark);
}

.channel .channel-composer button:active {
    transform: translateY(1px);
}

/* Screen reader only class */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--codefor-orange);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: var(--font-weight-bold);
    z-index: 9999;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 6px;
}

/* Focus styles for better keyboard accessibility */
button:focus,
.channel-menu:focus,
.menu-toggle:focus {
    outline: 2px solid var(--codefor-orange);
    outline-offset: 2px;
}

/* Touch target size compliance - minimum 44px */
button,
.channel-menu,
.menu-toggle {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
    box-sizing: border-box;
}

.channel-menu {
    padding: 15px 20px; /* Override for better visual design while maintaining touch target */
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .channels-menu {
        transition: none;
    }
    
    .sidebar-overlay {
        transition: none;
    }
    
    .skip-link {
        transition: none;
    }
}

/* High contrast focus for better visibility */
@media (prefers-contrast: high) {
    button:focus,
    .channel-menu:focus,
    .menu-toggle:focus,
    input:focus {
        outline: 3px solid;
        outline-offset: 3px;
    }
}

/* Message navigation for screen readers */
.message-nav-hint {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.message-nav-hint:focus {
    position: static;
    width: auto;
    height: auto;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
    margin-bottom: 12px;
    border-radius: 12px;
    background: var(--card-bg);
    border: 1px solid var(--content-border);
    border-left: 4px solid var(--codefor-orange);
    box-shadow: var(--card-shadow);
    font-size: var(--font-size-base);
    line-height: 1.5;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.message:hover {
    background: var(--hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 102, 0, 0.1);
    border-left-color: var(--codefor-orange-light);
    border-color: var(--codefor-orange-light);
}

.message:focus {
    outline: 2px solid var(--codefor-orange);
    outline-offset: 2px;
    background: var(--hover-bg);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border-light);
    flex-shrink: 0;
    margin-top: 2px;
}

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

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

.message-username {
    font-size: var(--font-size-lg);
    color: var(--codefor-orange);
    font-weight: var(--font-weight-bold);
    margin: 0 0 2px 0; /* Reset h3 default margins */
}

.message-time {
    font-size: 12px;
    color: var(--content-text-muted);
    font-weight: var(--font-weight-normal);
    opacity: 0.8;
    white-space: nowrap;
}

.message-content {
    color: var(--content-text);
    word-wrap: break-word;
    line-height: 1.6;
}

.message-link {
    color: var(--codefor-orange);
    text-decoration: underline;
    transition: color 0.2s ease;
}

.message-link:hover {
    color: var(--codefor-orange-dark);
    text-decoration: none;
}

.message-link:visited {
    color: #cc5500;
}

.opendiensten-link {
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
    text-align: center;
}

.opendiensten-link a {
    color: var(--primary-orange);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    transition: color 0.2s ease;
    display: block;
    line-height: 1.4;
}

.opendiensten-link a small {
    color: var(--text-light);
    font-weight: var(--font-weight-normal);
}

.opendiensten-link a:hover {
    color: var(--codefor-orange-dark);
    text-decoration: underline;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 62, 80, 0.4);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    
}

/* Channel link styling - modern Code for NL style */
.channel-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--card-bg);
    color: var(--content-text-muted);
    text-decoration: none;
    padding: 4px 10px 4px 8px;
    border-radius: 16px;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid var(--content-border);
    box-shadow: var(--card-shadow);
    vertical-align: middle;
}

.channel-link:hover {
    background: var(--hover-bg);
    color: var(--codefor-orange);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 102, 0, 0.15);
    border-color: var(--codefor-orange-light);
}

.channel-link:active {
    transform: translateY(0);
    background: var(--active-bg);
}

.channel-link .channel-hash {
    font-weight: 600;
    opacity: 0.7;
    font-size: 0.9em;
    color: var(--content-text-muted);
}

.channel-link .channel-name {
    font-weight: 500;
}

/* Focus styles for accessibility */
.channel-link:focus {
    outline: 2px solid var(--codefor-orange);
    outline-offset: 2px;
    background: var(--hover-bg);
    color: var(--codefor-orange);
}

/* Mobile-first responsive design */
@media (min-width: 768px) {
    .channels-menu {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(0);
        transition: none;
    }
    
    .channels-container {
        margin-left: var(--sidebar-width);
    }
    
    .channel .channel-header .menu-toggle {
        display: none;
    }
}

@media (max-width: 767px) {
    :root {
        --sidebar-width: 280px;
    }
    
    .channels-container.sidebar-open {
        margin-left: 0;
    }
}

