/* --- Design System & CSS Variables --- */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary-color: #4b5563;
    --secondary-hover: #374151;
    --success-color: #10b981;
    --success-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-sidebar: #f1f5f9;
    --bg-input: #ffffff;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    
    --border-subtle: #e2e8f0;
    --border-focus: #3b82f6;
    
    --my-message-bg: #2563eb;
    --peer-message-bg: #f1f5f9;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-page);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* Views */
.view {
    display: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

.view.active-view {
    display: flex;
}

/* --- Welcome / Login Screen --- */
.login-container {
    margin: auto;
    background-color: var(--bg-surface);
    padding: 36px 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 440px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--border-subtle);
}

.brand-badge {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-lg);
    background: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.login-container h1 {
    font-size: 1.85rem;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--text-main);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.45;
    margin: 0 0 24px;
}

.form-group {
    text-align: left;
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
    background-color: var(--bg-input);
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--text-inverse);
}
.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-sidebar);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
}
.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--primary-color);
    font-size: 0.85rem;
    padding: 8px 12px;
    width: 100%;
}
.btn-outline:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
}

.btn-danger {
    background-color: #fee2e2;
    color: var(--danger-color);
    width: 100%;
}
.btn-danger:hover {
    background-color: #fecaca;
}

.error-message {
    color: var(--danger-color);
    font-size: 0.88rem;
    min-height: 20px;
    margin: 12px 0 0;
    font-weight: 500;
}

.network-notice {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding: 8px 14px;
    background-color: #f8fafc;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- App Layout --- */
.sidebar {
    width: 300px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 20px;
    flex-shrink: 0;
    height: 100%;
    overflow-y: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 16px;
    color: var(--text-main);
}

.room-card {
    background-color: var(--bg-surface);
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-bottom: 16px;
}

.room-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.room-code-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.room-code {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--primary-color);
}

.icon-btn-small {
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn-small:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background-color: var(--primary-light);
}

#qrCodeContainer {
    text-align: center;
    background-color: var(--bg-surface);
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-bottom: 16px;
}

.qr-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 500;
}

#roomQrCodeWrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    min-height: 140px;
}

#roomQrCodeWrapper img,
#roomQrCodeWrapper canvas {
    border-radius: var(--radius-sm);
    display: block;
    margin: 0 auto;
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 10px 0 16px;
}

.users-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0 0 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#userList {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
}

#userList li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background-color: var(--primary-light);
    color: var(--primary-color);
    font-weight: 700;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-footer {
    margin-top: 16px;
}

/* --- Main Content Area --- */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background-color: var(--bg-surface);
}

.main-header {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    gap: 14px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-main);
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-connected {
    background-color: #d1fae5;
    color: #065f46;
}
.status-connected::before {
    background-color: #10b981;
}

/* Messages Feed */
.messages-container {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background-color: var(--bg-page);
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 65%;
}

.message-wrapper.user-message {
    align-self: flex-start;
}

.message-wrapper.my-message {
    align-self: flex-end;
}

.sender-name {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 10px;
    font-weight: 500;
}

.message-content {
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.my-message .message-content {
    background-color: var(--my-message-bg);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
}

.user-message .message-content {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-subtle);
}

/* System Message */
.system {
    align-self: center;
    max-width: 90%;
    text-align: center;
}

.system .message-content {
    background-color: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    box-shadow: none;
    border: none;
}

/* --- File Transfer Card --- */
.file-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 240px;
}

.file-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-message .file-icon {
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.file-details {
    flex-grow: 1;
    overflow: hidden;
}

.file-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.78rem;
    opacity: 0.85;
}

/* Progress Bar */
.transfer-progress-box {
    margin-top: 4px;
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.my-message .progress-bar-bg {
    background-color: rgba(255, 255, 255, 0.3);
}

.progress-bar-fill {
    height: 100%;
    background-color: #ffffff;
    width: 0%;
    border-radius: var(--radius-full);
    transition: width 0.15s ease-out;
}

.user-message .progress-bar-fill {
    background-color: var(--primary-color);
}

.progress-label {
    font-size: 0.75rem;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
    opacity: 0.9;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    background-color: var(--success-color);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 4px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}
.download-btn:hover {
    background-color: var(--success-hover);
}

/* Drag & Drop Overlay */
.drop-zone-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(37, 99, 235, 0.9);
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    backdrop-filter: blur(2px);
    pointer-events: none;
}

.drop-zone-overlay.active {
    display: flex;
}

.drop-zone-content {
    text-align: center;
    padding: 30px;
    border: 3px dashed white;
    border-radius: var(--radius-lg);
}

.drop-zone-content p {
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 12px;
}

/* --- Input Area --- */
.input-area {
    padding: 14px 20px;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

#messageInput {
    flex-grow: 1;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-subtle);
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    height: 42px;
    max-height: 120px;
    background-color: var(--bg-input);
    color: var(--text-main);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: var(--border-focus);
}

.icon-button {
    background: none;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--secondary-color);
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.icon-button:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
}
.send-btn:hover {
    background-color: var(--primary-hover);
    color: white;
}

/* Overlay for Mobile Sidebar */
#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: #1e293b;
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

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

    #sidebar-overlay.active {
        display: block;
    }

    .message-wrapper {
        max-width: 85%;
    }

    .messages-container {
        padding: 16px;
    }

    .input-area {
        padding: 10px 14px;
    }
}

