:root {
    --primary-color: #4F46E5;
    --primary-dark: #4338CA;
    --secondary-color: #7C3AED;
    --success-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --dark-color: #1F2937;
    --light-color: #F3F4F6;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* O atributo hidden precisa vencer as classes que declaram display:
   grid ou flex (.grade, .call-controls, .painel-inferior), senão o
   elemento continua visível mesmo marcado como escondido. */
[hidden] {
    display: none !important;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    min-height: 100vh;
    color: var(--gray-800);
}

/* Container Principal */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Cards */
.card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    padding: 30px;
    margin-bottom: 20px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.15);
}

/* Formulários */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: var(--gray-50);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
    background: white;
}

/* Botões */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: #D97706;
}

.btn-gradient {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-gradient:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
}

/* Video Container */
.video-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.video-box {
    position: relative;
    background: var(--dark-color);
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16/9;
}

.video-box video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-box .video-label {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.video-box.local {
    border: 2px solid var(--primary-color);
}

.video-box.remote {
    border: 2px solid var(--success-color);
}

/* Controles de Chamada */
.call-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.call-controls .btn {
    min-width: 120px;
}

/* Participantes */
.participants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.participant-card {
    background: var(--gray-50);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.participant-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.participant-card .avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: bold;
    margin: 0 auto 12px;
}

.participant-card .name {
    font-weight: 500;
    color: var(--gray-800);
}

.participant-card .status {
    font-size: 12px;
    color: var(--gray-500);
}

.participant-card .status.active {
    color: var(--success-color);
}

/* Chat */
.chat-container {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    height: 400px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-message {
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 80%;
}

.chat-message.sent {
    background: var(--primary-color);
    color: white;
    margin-left: auto;
}

.chat-message.received {
    background: var(--gray-100);
    color: var(--gray-800);
}

.chat-message .sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-message .time {
    font-size: 10px;
    opacity: 0.7;
    margin-left: 8px;
}

.chat-input {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--gray-200);
}

.chat-input input {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
}

.chat-input input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Grid de Salas */
.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.room-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    border: 2px solid var(--gray-200);
    transition: all 0.3s ease;
}

.room-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}

.room-card .room-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.room-card .room-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-800);
}

.room-card .room-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.room-card .room-status.active {
    background: #D1FAE5;
    color: #065F46;
}

.room-card .room-status.ended {
    background: #FEE2E2;
    color: #991B1B;
}

.room-card .room-meta {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    font-size: 14px;
    color: var(--gray-500);
}

.room-card .room-actions {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

/* Notificações */
/* No rodapé, não no topo: ali o aviso cobria o botão "Sair" do cabeçalho
   e dava para clicar nele sem querer. */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 16px 24px;
    border-radius: 12px;
    color: white;
    font-weight: 500;
    z-index: 1000;
    max-width: 380px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
    animation: slideIn 0.3s ease;
}

.notification.success {
    background: var(--success-color);
}

.notification.error {
    background: var(--danger-color);
}

.notification.warning {
    background: var(--warning-color);
}

.notification.info {
    background: var(--primary-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.modal {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 24px;
    color: var(--gray-800);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-400);
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: var(--gray-800);
}

/* Responsivo */
@media (max-width: 768px) {
    .video-container {
        grid-template-columns: 1fr;
    }
    
    .rooms-grid {
        grid-template-columns: 1fr;
    }
    
    .container {
        padding: 12px;
    }
    
    .card {
        padding: 20px;
    }
    
    .call-controls .btn {
        min-width: 80px;
        padding: 10px 16px;
        font-size: 14px;
    }
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Badge */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-primary {
    background: #DBEAFE;
    color: #1E40AF;
}

.badge-success {
    background: #D1FAE5;
    color: #065F46;
}

.badge-danger {
    background: #FEE2E2;
    color: #991B1B;
}

/* ============================================================
   Grade de vídeos da malha (até 6 participantes)
   O número de colunas vem de data-total, definido pelo sala.js.
   ============================================================ */

.grade {
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
    margin-bottom: 16px;
}

.grade[data-total="2"],
.grade[data-total="3"],
.grade[data-total="4"] {
    grid-template-columns: repeat(2, 1fr);
}

.grade[data-total="5"],
.grade[data-total="6"] {
    grid-template-columns: repeat(3, 1fr);
}

.tile {
    position: relative;
    background: #111827;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border: 2px solid transparent;
}

.tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #111827;
}

.tile.local {
    border-color: var(--primary-color);
}

.tile.local video {
    /* Espelha a própria imagem, como o usuário espera se ver. */
    transform: scaleX(-1);
}

.tile.problema {
    border-color: var(--danger-color);
}

.tile .rotulo {
    position: absolute;
    left: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tile .estado {
    position: absolute;
    right: 10px;
    top: 10px;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, .65);
    color: #FCD34D;
    font-size: 11px;
}

.tile .estado:empty {
    display: none;
}

/* Barra superior da sala */
.barra-sala {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    color: #fff;
    margin-bottom: 16px;
}

.barra-sala h1 {
    font-size: 22px;
    margin-bottom: 2px;
}

.barra-sala .meta {
    font-size: 13px;
    opacity: .85;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.codigo-sala {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 15px;
    letter-spacing: 2px;
    background: rgba(255, 255, 255, .18);
    padding: 3px 12px;
    border-radius: 6px;
}

.btn-ghost {
    background: rgba(255, 255, 255, .18);
    color: #fff;
    padding: 6px 14px;
    font-size: 13px;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, .3);
}

.btn.desligado {
    background: var(--danger-color);
    color: #fff;
}

/* Chat */
.chat-sistema {
    text-align: center;
    font-size: 12px;
    color: var(--gray-500);
    margin: 10px 0;
    font-style: italic;
}

.painel-inferior {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    align-items: start;
}

/* Painel do administrador */
.lista-salas {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sala-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 2px solid var(--gray-200);
    border-radius: 12px;
    flex-wrap: wrap;
}

.sala-item.encerrada {
    opacity: .6;
}

.sala-item .titulo {
    font-weight: 600;
    font-size: 16px;
}

.sala-item .detalhes {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.sala-item .acoes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sala-item .codigo {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 18px;
    letter-spacing: 3px;
    color: var(--primary-color);
    font-weight: 700;
}

.aviso-caixa {
    background: #FEF3C7;
    border: 1px solid #FCD34D;
    color: #92400E;
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 16px;
}

.aviso-caixa.erro {
    background: #FEE2E2;
    border-color: #FCA5A5;
    color: #991B1B;
}

.vazio {
    text-align: center;
    color: var(--gray-400);
    padding: 32px 16px;
}

.link-discreto {
    display: inline-block;
    margin-top: 18px;
    color: var(--gray-500);
    font-size: 14px;
    text-decoration: none;
}

.link-discreto:hover {
    color: var(--primary-color);
}

@media (max-width: 900px) {
    .painel-inferior {
        grid-template-columns: 1fr;
    }

    .grade[data-total="5"],
    .grade[data-total="6"] {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .grade[data-total] {
        grid-template-columns: 1fr;
    }
}