* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f23;
    color: white;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Login / Dashboard ---------- */

#login-section, #dashboard-section {
    background: #1a1a2e;
    padding: 40px;
    border-radius: 12px;
    width: 400px;
    max-width: 90%;
}

h1 {
    margin-bottom: 24px;
    font-size: 24px;
    text-align: center;
}

form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

input {
    padding: 12px;
    border: 1px solid #333;
    border-radius: 6px;
    background: #16213e;
    color: white;
    font-size: 16px;
    outline: none;
}

input:focus {
    border-color: #4e8cff;
}

button {
    padding: 12px 24px;
    background: #0f3460;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: #1a4f8e;
}

.small-btn {
    padding: 8px 16px;
    font-size: 14px;
}

.hidden {
    display: none !important;
}

.error {
    color: #ff6b6b;
    font-size: 14px;
}

.hint {
    margin-top: 16px;
    color: #666;
    font-size: 12px;
    text-align: center;
}

.join-section {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.join-section input {
    flex: 1;
}

#dashboard-section p {
    text-align: center;
    margin-bottom: 16px;
    color: #aaa;
}

#room-error {
    margin-top: 12px;
    text-align: center;
}

/* ---------- Room Layout ---------- */

#room-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

#top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #1a1a2e;
    border-bottom: 1px solid #333;
}

#top-bar span {
    flex: 1;
    font-size: 14px;
}

#main-area {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ---------- Video Grid ---------- */

#video-grid {
    position: relative;
    flex: 1;
    overflow: hidden;
}

/* ---------- Tile Windows (draggable + resizable) ---------- */

.tile-window {
    position: absolute;
    background: #1a1a2e;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #333;
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
    min-width: 160px;
    min-height: 120px;
}

.tile-window:hover {
    border-color: #555;
}

.tile-window.screen-share-active {
    border-color: #e94560;
}

.tile-window.local-tile {
    border-color: #4e8cff;
}

/* Drag header */
.tile-header {
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 12px;
    cursor: grab;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tile-header:active,
.tile-header.dragging {
    cursor: grabbing;
}

.tile-window video {
    width: 100%;
    height: calc(100% - 28px);
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.video-label {
    position: absolute;
    bottom: 30px;
    left: 8px;
    padding: 3px 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    white-space: nowrap;
}

/* Resize handle (bottom-right) */
.resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 24px;
    height: 24px;
    cursor: nwse-resize;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.15s;
    background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.3) 50%);
    border-radius: 0 0 6px 0;
}

.tile-window:hover .resize-handle,
.tile-window:active .resize-handle,
.resize-handle.active {
    opacity: 1;
}

.resize-handle.active {
    background: linear-gradient(135deg, transparent 50%, rgba(78,140,255,0.6) 50%);
}

.screen-share-badge {
    position: absolute;
    top: 32px;
    right: 8px;
    padding: 3px 8px;
    background: #e94560;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    pointer-events: none;
}

/* ---------- Chat Bottom Panel ---------- */

#chat-panel {
    display: flex;
    flex-direction: column;
    background: #1a1a2e;
    border-top: 1px solid #333;
    max-height: 40vh;
}

#chat-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: bold;
    border-bottom: 1px solid #333;
    cursor: pointer;
}

#chat-close-btn {
    cursor: pointer;
    opacity: 0.6;
    font-size: 16px;
}

#chat-close-btn:hover {
    opacity: 1;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 80px;
    max-height: 30vh;
}

.chat-msg {
    margin-bottom: 12px;
}

.chat-msg .chat-user {
    font-weight: bold;
    font-size: 13px;
    color: #4e8cff;
    margin-right: 6px;
}

.chat-msg .chat-time {
    font-size: 11px;
    color: #666;
}

.chat-msg .chat-text {
    font-size: 14px;
    word-break: break-word;
    margin-top: 2px;
}

#chat-input-area {
    display: flex;
    padding: 8px;
    gap: 8px;
    border-top: 1px solid #333;
}

#chat-input-area input {
    flex: 1;
}

#chat-input-area button {
    padding: 12px 16px;
}

/* ---------- Controls Bar ---------- */

#controls-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #1a1a2e;
    border-top: 1px solid #333;
}

.control-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: #16213e;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.control-btn:hover {
    background: #1a4f8e;
}

.control-btn.active {
    background: #0f3460;
}

.control-btn.muted {
    background: #c0392b;
}

.control-btn.sharing {
    background: #27ae60;
}

.danger {
    background: #c0392b !important;
}

.danger:hover {
    background: #e74c3c !important;
}

/* ---------- Join Overlay ---------- */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#join-box {
    background: #1a1a2e;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

#join-box h1 {
    font-size: 22px;
    margin-bottom: 16px;
}

#join-box p {
    margin-bottom: 8px;
    color: #ccc;
    font-size: 14px;
}

#join-room-id {
    color: #4e8cff;
}

.big-btn {
    display: block;
    width: 100%;
    padding: 16px;
    margin-top: 20px;
    background: #0f3460;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.big-btn:hover {
    background: #1a4f8e;
}

.big-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.secondary-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    background: transparent;
    border: 1px solid #333;
    border-radius: 8px;
    color: #aaa;
    font-size: 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.secondary-btn:hover {
    background: #16213e;
    color: white;
}

.secondary-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
    #join-box {
        padding: 24px;
    }
    .control-btn {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
    #controls-bar {
        gap: 12px;
        padding: 12px;
    }

    /* Mobile: stack tiles vertically in the grid area */
    #video-grid {
        overflow-y: auto;
    }

    .tile-window {
        position: relative !important;
        left: 8px !important;
        top: auto !important;
        width: calc(100% - 16px) !important;
        height: 25vh !important;
        min-height: 140px;
        margin-bottom: 8px;
    }

    .tile-window:first-of-type {
        margin-top: 8px;
    }

    .resize-handle {
        width: 32px;
        height: 32px;
        opacity: 0.4;
    }
}

/* ---------- Error Overlay ---------- */

#error-box {
    background: #1a1a2e;
    padding: 32px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

#error-box p {
    margin-bottom: 20px;
    font-size: 18px;
}
