/* Base Styles */
:root {
    --primary-color: #4a90e2;
    --primary-dark: #357abd;
    --secondary-color: #f5f6fa;
    --text-color: #2f3640;
    --border-color: #dcdde1;
    --modal-bg: #ffffff;
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --panel-width: 260px;
    --header-height: 56px;
    --danger-color: #e74c3c;
    --success-color: #27ae60;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--secondary-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
}

/* ─── Header ─── */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    height: var(--header-height);
    min-height: var(--header-height);
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.header-right {
    position: relative;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}

.icon-btn:hover {
    background-color: var(--secondary-color);
    color: var(--primary-color);
}

.icon-btn.active-toggle {
    color: var(--primary-color);
    background-color: rgba(74, 144, 226, 0.12);
}

.header-center h1 {
    font-size: 1.4rem;
    color: var(--primary-color);
}

/* ─── Media Buttons ─── */
.media-separator {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 0.25rem;
}

.media-btn {
    position: relative;
}

.media-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.media-btn:disabled:hover {
    background: none;
    color: var(--text-color);
}

.media-btn.active {
    color: var(--success-color);
    background-color: rgba(39, 174, 96, 0.12);
}

.media-btn.not-permitted {
    opacity: 0.35;
    cursor: not-allowed;
}

.media-btn.not-permitted::after {
    content: '🔒';
    font-size: 0.55rem;
    position: absolute;
    bottom: 2px;
    right: 2px;
}

/* ─── App Content (2-column: Main + Sidebar) ─── */
.app-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    width: 100%;
}

/* ─── Right Sidebar Wrapper ─── */
.right-sidebar {
    width: 0;
    min-width: 0;
    background: #fff;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease;
    overflow: hidden;
}

.right-sidebar.open {
    width: var(--panel-width);
    min-width: var(--panel-width);
}

/* ─── Sidebar Panels (Internal) ─── */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-panel:last-child {
    border-bottom: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--secondary-color);
    min-height: 40px;
}

.panel-header h3 {
    font-size: 0.9rem;
    color: var(--text-color);
    white-space: nowrap;
}

.panel-header h3 i {
    margin-right: 0.4rem;
    color: var(--primary-color);
}

.panel-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: #999;
    padding: 0.2rem;
    border-radius: 4px;
    transition: color 0.2s;
}

.panel-close-btn:hover {
    color: var(--text-color);
}

/* ─── Permission Controls (Professor) ─── */
.permission-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid var(--border-color);
    background: #fefce8;
}

.perm-btn {
    flex: 1;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    background: #fff;
    color: var(--text-color);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.perm-btn:hover {
    border-color: var(--primary-color);
}

.perm-btn.perm-allow:hover {
    background-color: rgba(39, 174, 96, 0.1);
    color: var(--success-color);
    border-color: var(--success-color);
}

.perm-btn.perm-mute:hover {
    background-color: rgba(231, 76, 60, 0.1);
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.perm-btn.active-perm {
    font-weight: 600;
}

.perm-btn.perm-allow.active-perm {
    background-color: rgba(39, 174, 96, 0.15);
    color: var(--success-color);
    border-color: var(--success-color);
}

.perm-btn.perm-mute.active-perm {
    background-color: rgba(231, 76, 60, 0.15);
    color: var(--danger-color);
    border-color: var(--danger-color);
}

/* ─── Attendants Panel ─── */
.attendants-list {
    list-style: none;
    padding: 0.5rem 0;
    overflow-y: auto;
    flex: 1;
}

.attendant-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.attendant-item:hover {
    background-color: var(--secondary-color);
}

.attendant-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    flex-shrink: 0;
}

.attendant-name {
    font-size: 0.85rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background-color: #27ae60;
}

.status-dot.offline {
    background-color: #bdc3c7;
}

/* Per-user permission toggle */
.perm-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2rem 0.35rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: #999;
    transition: all 0.2s;
    flex-shrink: 0;
}

.perm-toggle:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.perm-toggle.allowed {
    color: var(--success-color);
    border-color: var(--success-color);
    background-color: rgba(39, 174, 96, 0.08);
}

/* ─── Presentation Area ─── */
.presentation-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #eaecef;
    position: relative;
    overflow: hidden;
    width: 0;
}

.presentation-placeholder {
    text-align: center;
}

.placeholder-open-btn {
    background: none;
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 3rem 4rem;
    cursor: pointer;
    color: #aaa;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.placeholder-open-btn i {
    font-size: 4rem;
}

.placeholder-open-btn span {
    font-size: 1.1rem;
}

.placeholder-open-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: rgba(74, 144, 226, 0.05);
}

.pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

/* ─── Remote Video Streams ─── */
.remote-streams {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    align-content: flex-start;
    z-index: 5;
    pointer-events: none;
}

.remote-streams:empty {
    display: none;
}

.remote-tile {
    position: relative;
    width: 200px;
    height: 150px;
    background: #222;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

.remote-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remote-tile .remote-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    text-align: center;
}

/* Audio-only remote tile */
.remote-tile.audio-only {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 80px;
}

.remote-tile.audio-only .audio-icon {
    color: var(--success-color);
    font-size: 1.5rem;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

/* ─── Local Video Preview (PIP) ─── */
.local-preview {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    width: 160px;
    height: 120px;
    background: #222;
    border-radius: 8px;
    overflow: hidden;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    cursor: grab;
}

.local-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.local-preview #local-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    font-size: 0.7rem;
    padding: 0.3rem;
    text-align: center;
}

/* ─── Chat Panel ─── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.chat-msg {
    max-width: 90%;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    font-size: 0.8rem;
    position: relative;
}

.chat-msg.incoming {
    background-color: var(--secondary-color);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-msg.outgoing {
    background-color: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-sender {
    font-weight: 600;
    font-size: 0.75rem;
    display: block;
    margin-bottom: 0.15rem;
}

.chat-msg.outgoing .chat-sender {
    color: rgba(255, 255, 255, 0.8);
}

.chat-time {
    font-size: 0.65rem;
    display: block;
    text-align: right;
    margin-top: 0.2rem;
    opacity: 0.6;
}

.chat-input-area {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    border-top: 1px solid var(--border-color);
    gap: 0.25rem;
    background: #fff;
}

.chat-input-area input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--primary-color);
}

/* ─── Files Modal ─── */
.files-modal-content {
    max-width: 500px;
}

/* ─── Lectures Modal ─── */
.lectures-modal-content {
    max-width: 500px;
}

.lectures-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 1rem;
}

.lecture-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.lecture-item:last-child {
    border-bottom: none;
}

.lecture-info {
    flex: 1;
}

.lecture-name {
    font-weight: 600;
    color: var(--primary-color);
    display: block;
}

.lecture-detail {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-top: 0.2rem;
}

.lecture-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    color: var(--text-color);
}

.action-btn:hover {
    background-color: var(--secondary-color);
    border-color: #aaa;
}

.action-btn.edit:hover {
    color: #f39c12;
}

.action-btn.delete:hover {
    color: #e74c3c;
}

.action-btn.select:hover {
    color: #27ae60;
    border-color: #27ae60;
    background-color: rgba(39, 174, 96, 0.1);
}

.lecture-item.active {
    background-color: rgba(74, 144, 226, 0.08);
    border-left: 3px solid var(--primary-color);
}

.files-modal-content .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.files-modal-content .modal-header h2 {
    margin-bottom: 0;
    font-size: 1.2rem;
}

.files-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 1rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.file-item:last-child {
    border-bottom: none;
}

.file-item:hover {
    background-color: var(--secondary-color);
}

.file-item.selected {
    background-color: rgba(74, 144, 226, 0.1);
    color: var(--primary-color);
    font-weight: 600;
}

.file-item i {
    color: #e74c3c;
    font-size: 1.1rem;
}

.file-empty-msg {
    padding: 2rem;
    text-align: center;
    color: #aaa;
    font-size: 0.9rem;
}

.files-modal-actions {
    display: flex;
    justify-content: flex-end;
}

/* ─── Modal (shared) ─── */
.modal {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--modal-bg);
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

/* Tabs */
.tab-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.8rem 2rem;
    cursor: pointer;
    font-size: 1rem;
    color: #7f8c8d;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    font-weight: bold;
}

/* Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"] {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

/* Role Selector */
.role-selector {
    margin-bottom: 1rem;
    text-align: center;
}

.radio-group {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0.5rem;
}

.role-selector input[type="radio"] {
    width: auto;
    margin-right: 0.3rem;
    cursor: pointer;
}

/* Submit Button */
.submit-btn {
    width: 100%;
    padding: 0.8rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.submit-btn:hover {
    background-color: var(--primary-dark);
}

/* ─── User Menu ─── */
.user-menu-container {
    position: relative;
    cursor: pointer;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s;
}

.user-avatar:hover {
    transform: scale(1.05);
    background-color: var(--primary-dark);
}

.user-dropdown {
    display: none;
    position: absolute;
    top: 46px;
    right: 0;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 150px;
    z-index: 200;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.user-dropdown.show {
    display: block;
    animation: fadeInDropdown 0.2s ease-out;
}

@keyframes fadeInDropdown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-dropdown ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.user-dropdown li:last-child {
    border-top: 1px solid var(--border-color);
}

.user-dropdown li a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1rem;
    text-decoration: none;
    color: var(--text-color);
    transition: background-color 0.2s;
    font-size: 0.9rem;
}

.user-dropdown li a:hover {
    background-color: var(--secondary-color);
    color: var(--primary-color);
}

.user-dropdown hr {
    display: none;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .side-panel.open {
        position: absolute;
        z-index: 50;
        height: 100%;
        width: 80%;
        min-width: 80%;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    .chat-panel.open {
        right: 0;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
    }

    .remote-tile {
        width: 140px;
        height: 105px;
    }

    .local-preview {
        width: 120px;
        height: 90px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }
}