/* =====================================================================
   TKI Meet — UI Styles
   ===================================================================== */

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

:root {
    --bg:        #0f1117;
    --surface:   #1a1d27;
    --surface2:  #232634;
    --border:    #2d3148;
    --accent:    #4f6ef7;
    --accent-h:  #3d5ce0;
    --red:       #e64f4f;
    --red-h:     #c43c3c;
    --green:     #2ecc71;
    --text:      #e8eaf6;
    --text-dim:  #8b8fa8;
    --radius:    12px;
    --radius-sm: 8px;
    --shadow:    0 8px 32px rgba(0,0,0,.45);
}

html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); }

/* ── Landing ─────────────────────────────────────────────────────── */
.landing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: radial-gradient(ellipse at 60% 0%, #1c2147 0%, var(--bg) 70%);
}

.landing-wrapper { width: 100%; max-width: 440px; }

.landing-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 32px;
}

.brand-icon {
    width: 48px; height: 48px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-icon svg { width: 26px; height: 26px; color: #fff; }
.brand-icon.small { width: 36px; height: 36px; border-radius: 8px; }
.brand-icon.small svg { width: 20px; height: 20px; }

.brand h1 { font-size: 22px; font-weight: 700; line-height: 1.2; }
.brand p  { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* Form */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-dim); margin-bottom: 6px; }

input[type="text"] {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}

input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-dim); }

/* Tabs */
.divider-tabs {
    display: flex;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
    gap: 4px;
}

.tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background .2s, color .2s;
}

.tab.active { background: var(--surface); color: var(--text); }
.tab:hover:not(.active) { color: var(--text); }

.tab-content { }
.tab-content.hidden { display: none; }
.tab-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; line-height: 1.5; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, transform .1s;
    text-decoration: none;
}

.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.98); }

.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover  { background: var(--accent-h); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost  { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-full { width: 100%; }

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 14px;
}
.alert-error { background: rgba(230,79,79,.15); border: 1px solid rgba(230,79,79,.3); color: #f99; }

.footer-note { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 24px; }

/* ── Room page ────────────────────────────────────────────────────── */
.room-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

/* Header */
.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

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

.room-title {
    font-size: 15px;
    font-weight: 600;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-id-badge {
    font-size: 12px;
    padding: 3px 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-dim);
    cursor: pointer;
    letter-spacing: 0.5px;
    user-select: all;
    transition: border-color .2s;
}
.room-id-badge:hover { border-color: var(--accent); color: var(--text); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.btn-icon {
    width: 36px; height: 36px;
    border: none;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .2s, color .2s;
}
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }

.participant-count {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--surface2);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
}
.participant-count svg { width: 16px; height: 16px; }

/* Video grid */
.video-grid {
    flex: 1;
    display: grid;
    gap: 8px;
    padding: 12px;
    overflow: hidden;
    align-content: center;
    justify-content: center;
}

/* 1 participant = full width */
.video-grid[data-count="1"] {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}
/* 2 participants = side by side */
.video-grid[data-count="2"] {
    grid-template-columns: 1fr 1fr;
}
/* 3-4 = 2×2 */
.video-grid[data-count="3"],
.video-grid[data-count="4"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
/* 5-6 = 3×2 */
.video-grid[data-count="5"],
.video-grid[data-count="6"] {
    grid-template-columns: 1fr 1fr 1fr;
}

.video-tile {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    min-height: 160px;
}

.video-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scaleX(-1); /* mirror for local */
}

/* Don't mirror remote videos */
.video-tile:not(.local-tile) video { transform: none; }

.video-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    max-width: calc(100% - 16px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.video-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
    pointer-events: none;
}

/* Controls bar */
.controls-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.controls-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ctrl-label {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 500;
}

.ctrl-btn {
    width: 52px; height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--surface2);
    color: var(--text-dim);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .2s, color .2s, transform .1s;
}

.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.active { background: var(--surface2); color: var(--text); }
.ctrl-btn:not(.active) { background: rgba(230,79,79,.15); color: var(--red); }
.ctrl-btn.hangup { background: var(--red); color: #fff; }
.ctrl-btn.hangup:hover { background: var(--red-h); }
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn .icon-on, .ctrl-btn .icon-off { pointer-events: none; }
.hidden { display: none !important; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 24px;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.modal p  { font-size: 14px; color: var(--text-dim); margin-bottom: 18px; }

.share-url-box {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.share-url-box input { flex: 1; font-size: 13px; }

.share-code-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 18px;
    letter-spacing: 0.5px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30,34,50,.95);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    z-index: 200;
    pointer-events: none;
    backdrop-filter: blur(8px);
    white-space: nowrap;
}

/* Error screen */
.error-screen {
    display: flex; align-items: center; justify-content: center;
    height: 100vh; padding: 24px;
}

.error-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 380px;
}

.error-icon { font-size: 48px; margin-bottom: 16px; }
.error-card h2 { font-size: 22px; margin-bottom: 8px; }
.error-card p  { font-size: 14px; color: var(--text-dim); margin-bottom: 24px; }

/* Responsive */
@media (max-width: 600px) {
    .landing-card { padding: 28px 22px; }
    .room-title { max-width: 120px; }
    .ctrl-btn { width: 44px; height: 44px; }
    .ctrl-btn svg { width: 19px; height: 19px; }
    .controls-bar { gap: 8px; padding: 12px; }
    .video-grid[data-count="2"] { grid-template-columns: 1fr; }
    .video-grid[data-count="3"],
    .video-grid[data-count="4"],
    .video-grid[data-count="5"],
    .video-grid[data-count="6"] { grid-template-columns: 1fr 1fr; }
}
