:root {
    --primary-bg: #fff;
    --secondary-bg: #f0f2f5;
    --primary-text: #1c1e21;
    --secondary-text: #666;
    --accent-color: #007bff;
    --accent-hover: #0056b3;
    --border-color: #ddd;
    --header-height: 60px;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--secondary-bg);
    color: var(--primary-text);
    margin: 0;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    display: flex;
    align-items: center;
    background-color: var(--primary-bg);
    height: var(--header-height);
    padding: 0 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

.menu-button {
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    min-width: 44px;
    min-height: 44px;
}

.app-title {
    font-size: 1.2rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100%;
    background: var(--primary-bg);
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    z-index: 100;
    overflow-y: auto;
    box-shadow: 4px 0 6px rgba(0,0,0,0.1);
    padding-top: var(--header-height);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}

.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-content {
    padding: 1rem;
}

.sidebar h2 {
    font-size: 1rem;
    color: var(--secondary-text);
    text-transform: uppercase;
    margin: 1.5rem 0 0.5rem;
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding-top: var(--header-height);
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    padding: 0.8rem;
    border-radius: 12px;
    background-color: var(--primary-bg);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    max-width: 80%;
}

.message .meta {
    font-size: 0.75rem;
    color: var(--secondary-text);
    margin-bottom: 0.3rem;
}

.message p {
    margin: 0;
    word-wrap: break-word;
}

.message-footer {
    background: var(--primary-bg);
    box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
    z-index: 5;
}

#send-message-form {
    display: flex;
    align-items: flex-start;
    padding: 0.75rem;
    gap: 0.5rem;
}

textarea, select, button {
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

select {
    min-height: 44px;
}

#message-content {
    flex: 1;
    resize: none;
    padding: 0.6rem;
    min-height: 24px;
    max-height: 100px;
    line-height: 1.4;
}

#send-message-form button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-message-form button:hover, #send-message-form button:focus {
    background-color: var(--accent-hover);
}

#connect-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#connect-form textarea {
    height: 80px;
    font-size: 0.9rem;
}

#connect-form button {
    min-height: 44px;
    background: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
}
#connect-form button:hover {
    background-color: var(--accent-hover);
}


#peers, #status {
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    max-height: 150px;
    overflow-y: auto;
    word-break: break-all;
    font-size: 0.9rem;
}

/* Tablet and larger */
@media (min-width: 768px) {
    .menu-button, .sidebar-overlay {
        display: none;
    }

    .app-container {
        display: grid;
        grid-template-columns: var(--sidebar-width) 1fr;
        grid-template-rows: var(--header-height) 1fr;
        grid-template-areas:
            "header header"
            "sidebar content";
    }

    .app-header {
        position: static;
        grid-area: header;
    }

    .sidebar {
        position: static;
        transform: none;
        box-shadow: none;
        border-right: 1px solid var(--border-color);
        height: 100%;
        padding-top: 0;
    }

    .sidebar-content {
        padding: 1.5rem;
    }

    .content-wrapper {
        grid-area: content;
        padding-top: 0;
        height: calc(100vh - var(--header-height));
    }

    .main-content {
        padding: 1.5rem;
    }

    .message-footer {
        box-shadow: none;
        border-top: 1px solid var(--border-color);
    }
    
    #send-message-form {
        padding: 1rem;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .main-content {
        padding: 2rem;
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
    }
    .message-footer {
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
}
