:root {
    --spacing: 12px;
    --border-radius-large: 8px;
    --border-radius-small: 4px;
}

* {
    box-sizing: border-box;
}

body { /* wraps header and main */
    display: grid;
    grid-template-rows: auto 1fr;
    grid-row-gap: var(--spacing);
    height: 100vh;
    padding: var(--spacing);
    margin: 0;
    font-family: 'Roboto', sans-serif;
}

header {
    display: flex;
    align-items: center;
    padding: 2px 0; /* Ajusta el padding superior e inferior */
    height: 30px; /* Establece una altura específica si es necesario */
}

header img {
    margin-left: var(--spacing); /* Añade un margen a la izquierda */
    max-height: 35px;
}

main { /* wraps video-panel and chat-panel */
    display: grid;
    grid-template-columns: 640px 3fr;
    grid-column-gap: var(--spacing);
    overflow: hidden; /* Cambiado de auto a hidden */
}

.video-panel {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-row-gap: var(--spacing);
    overflow: auto;

    & section {
        overflow: auto;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #f2f2f2;
        border-radius: var(--border-radius-large);

        & video {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }

        &.local video {
            transform: scaleX(-1);
        }
    }
}

.chat-panel {
    display: grid;
    grid-template-rows: 1fr auto;
    grid-row-gap: var(--spacing);
    padding: var(--spacing);
    background: #f2f2f2;
    border-radius: var(--border-radius-large);
    height: 100%;

    .chat-log {
        padding: var(--spacing);
        background: #fff;
        overflow-y: auto; /* Asegura que el área de mensajes tenga su propio scroll */
        border-radius: var(--border-radius-small);
        line-height: 1.4;
        max-height: calc(100vh - 142px);

        .message.local::before {
            font-weight: bold;
            color: blue;
            content: "You: ";
        }

        .message.remote::before {
            font-weight: bold;
            color: red;
            content: "Stranger: ";
        }

        .message.server {
            color: #999;
            font-style: italic;
        }

        .message.typing {
            color: #666;
            font-style: italic;
        }
    }

    .chat-controls {
        display: flex;

        .messaging {
            display: flex;
            flex-grow: 1;

            & input {
                margin: 0 16px;
                width: 100%;
                height: 40px;
                padding: 16px;
                border: 0;
                border-radius: var(--border-radius-small);
                font-size: 16px;

                &:focus {
                    outline: none;
                }
            }
        }

        .pairing button {
            width: 80px;
        }
    }
}

button {
    background: #1e88e5;
    color: #fff;
    border: 0;
    border-radius: var(--border-radius-small);
    height: 40px;
    line-height: 1;
    padding: 0 16px;
    cursor: pointer;

    &:hover {
        background: #1976d2;
    }
}

/* Conditional styles for buttons */
.chat-controls .pairing button {
    display: none;
}

[data-state=NOT_CONNECTED] button#startPairing,
[data-state=DISCONNECTED_LOCAL] button#startPairing,
[data-state=DISCONNECTED_REMOTE] button#startPairing,
[data-state=CONNECTING] button#abortPairing,
[data-state=CONNECTED] button#leavePairing {
    display: block;
}

/* Conditional styles for spinner */
.spinner {
    display: none;
}

[data-state=CONNECTING] .spinner {
    display: block;
}

/* Conditional styles for remote video */
body:not([data-state=CONNECTED]) .remote video {
    display: none;
}

/* Conditional styles for chat */
body:not([data-state=CONNECTED]) .chat-controls .messaging {
    filter: grayscale(1);
    opacity: 0.6;
    pointer-events: none;
}

@media (max-width: 767px) {
    main { /* put video panel on top of chat panel */
        grid-template-columns: none;
        grid-template-rows: 2fr 1fr; /* Adjust the height ratio between video and chat */
        grid-row-gap: var(--spacing);
    }

    .video-panel {
        position: relative;
        grid-template-columns: none;
        grid-template-rows: 1fr;
    }

        .video-panel .remote {
            grid-row: 1 / 2;
        }

        .video-panel .local {
            position: absolute;
            top: var(--spacing);
            right: var(--spacing);
            width: 25%;
            height: auto;
            border: 2px solid white;
            border-radius: var(--border-radius-large); /* Ensure rounded corners */
            overflow: hidden;
            transition: all 3s ease; /* Add transition for smooth changes */
        }

            .video-panel .local video {
                width: 100%;
                height: 100%;
                object-fit: cover;
                border-radius: var(--border-radius-large); /* Ensure rounded corners */
                transition: all 0.3s ease; /* Add transition for smooth changes */
            }

    .chat-panel {
        height: auto; /* Ensure chat panel takes the remaining space */

        .chat-log
            {
                max-height: 168px;
            }
    }

    /* Need this to show all UI because the browser navigation bar is taking space */
    body {
        max-height: 92vh;
    }

}
