/* ==========================================================
   Team Connect · Public Join Page
   File: /css/join.css
   Version: v3 · Tuesday/02/06/2026
   Owner: DadLink Technologies Limited
   ----------------------------------------------------------
   Changelog
   v3 · Tuesday/02/06/2026 · Mobile scrolling fix. The 720px
        and landscape breakpoints locked .in-call-shell to
        calc(100dvh - 100px) which crammed video + tabs +
        chat composer + controls into a single viewport,
        leaving the chat with just one row visible and no
        way to scroll. Now: shell is height: auto on mobile,
        overflow: visible so the page scrolls naturally, video
        stage gets a fixed 45dvh slice, sidebar gets a
        sensible min-height (380px) so chat has real room to
        breathe. Landscape phones same approach with stage
        at 70dvh.
   v2 · Tuesday/02/06/2026 · Mobile optimisation pass.
        Replaced the single 640px tweak block with a full
        responsive ladder: 720px (most phones - tighter header,
        meeting card slimmer, lobby form padding reduced,
        in-call topbar/controls compact, in-call title truncates
        with ellipsis, toast container goes full-width pinned
        bottom), 420px (small phones - bubbles + headings drop
        one more notch), and a height-constrained landscape
        block (max-height 500px - trims chrome to give video
        maximum vertical space).
   v1 · Tuesday/02/06/2026 · Initial stylesheet.
   ========================================================== */

/* ---------- Tokens (dark default for video context) ---------- */
:root {
    --primary-color:      #007aff;
    --primary-color-dark: #0056b3;
    --success-color:      #34c759;
    --warning-color:      #ff9500;
    --error-color:        #ff3b30;
    --live-color:         #ff3b30;

    --background:           #0a0a0c;
    --background-secondary: #1c1c1e;
    --background-elevated:  #2c2c2e;
    --background-muted:     #18181a;
    --background-overlay:   rgba(0, 0, 0, 0.6);

    --text-primary:   #ffffff;
    --text-secondary: #aeaeb2;
    --text-tertiary:  #8e8e93;

    --border-color:        #2c2c2e;
    --border-color-strong: #48484a;

    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 18px;

    --shadow:    0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);

    --font-stack: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --background:           #f5f5f7;
        --background-secondary: #ffffff;
        --background-elevated:  #ffffff;
        --background-muted:     #fafafa;
        --text-primary:         #1d1d1f;
        --text-secondary:       #6e6e73;
        --text-tertiary:        #8e8e93;
        --border-color:         #d2d2d7;
        --border-color-strong:  #c7c7cc;
        --shadow:    0 2px 8px rgba(0, 0, 0, 0.08);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.18);
    }
}

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

html, body {
    background: var(--background);
    color: var(--text-primary);
    font-family: var(--font-stack);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    display: flex;
    flex-direction: column;
}

/* ---------- Header ---------- */
.join-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-secondary);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary-color), #5856d6);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    letter-spacing: 0.5px;
}
.brand-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}
.help-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}
.help-link:hover { color: var(--text-primary); }

/* ---------- Main ---------- */
.join-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* States only show when active */
.state { display: none; width: 100%; }
.state-active { display: block; }

.state-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}
.state-hint {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    max-width: 460px;
    margin: 0 auto;
    line-height: 1.55;
}

/* ---------- State: Verifying ---------- */
.verify-card {
    max-width: 400px;
    margin: 60px auto;
    padding: 40px 28px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    text-align: center;
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 22px;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- State: Error / Ended ---------- */
.error-card, .ended-card {
    max-width: 480px;
    margin: 60px auto;
    padding: 36px 28px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    text-align: center;
}
.error-mark {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(255, 59, 48, 0.15);
    color: var(--error-color);
    margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 700;
}
.error-card .btn,
.ended-card .btn { margin-top: 22px; }

/* ---------- State: Lobby ---------- */
#stateLobby { max-width: 1100px; margin: 0 auto; }

.lobby-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 28px;
    align-items: start;
}
@media (max-width: 900px) {
    .lobby-grid { grid-template-columns: 1fr; gap: 18px; }
}

/* Meeting card */
.meeting-card {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.meeting-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.meeting-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.meta-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Camera preview */
.preview-wrap {
    position: relative;
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--border-color);
}
.preview-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
    transform: scaleX(-1); /* mirror for natural preview */
    background: #000;
}
.preview-placeholder {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #1c1c1e, #2c2c2e);
    color: #fff;
}
.placeholder-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}
.placeholder-hint {
    font-size: 13px;
    color: #aeaeb2;
    margin-bottom: 20px;
    max-width: 320px;
}
.preview-controls {
    position: absolute;
    bottom: 16px; left: 50%;
    transform: translateX(-50%);
    display: flex; gap: 10px;
    z-index: 2;
}
.ctrl-bubble {
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 9px 16px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, transform 0.05s;
}
.ctrl-bubble:hover { background: rgba(58, 58, 60, 0.9); }
.ctrl-bubble:active { transform: scale(0.96); }
.ctrl-bubble[data-on="false"] { background: rgba(255, 59, 48, 0.85); }
.ctrl-bubble[data-on="false"]:hover { background: rgba(255, 59, 48, 1); }
.ctrl-bubble-dark { background: #2c2c2e; border-color: #38383a; }
.ctrl-bubble-leave { background: var(--error-color); padding: 9px 22px; }
.ctrl-bubble-leave:hover { background: #d33027; }

/* Right side form */
.lobby-right {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-input {
    background: var(--background-muted);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}
.form-input:focus { border-color: var(--primary-color); }

/* Device settings (accordion) */
.device-settings {
    background: var(--background-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.device-settings summary {
    padding: 11px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    user-select: none;
    list-style: none;
    position: relative;
    padding-right: 36px;
}
.device-settings summary::-webkit-details-marker { display: none; }
.device-settings summary::after {
    content: '+';
    position: absolute;
    right: 14px; top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-secondary);
    font-weight: 400;
    transition: transform 0.2s;
}
.device-settings[open] summary::after { content: '−'; }
.device-body {
    padding: 14px;
    border-top: 1px solid var(--border-color);
    display: flex; flex-direction: column; gap: 14px;
}

/* Mic meter */
.mic-meter {
    height: 6px;
    background: var(--background-elevated);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}
.mic-meter-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--success-color), var(--warning-color), var(--error-color));
    transition: width 0.05s linear;
}
.mic-meter-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Host status */
.host-status {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: var(--background-muted);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}
.status-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--text-tertiary);
    display: inline-block;
    flex-shrink: 0;
}
.status-dot-pulse {
    background: var(--warning-color);
    animation: pulse-dot 1.6s ease-in-out infinite;
}
.status-dot-live {
    background: var(--success-color);
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 149, 0, 0.5); }
    50%      { box-shadow: 0 0 0 8px rgba(255, 149, 0, 0); }
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.98); }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-secondary {
    background: var(--background-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-large {
    padding: 14px 22px;
    font-size: 15px;
    border-radius: var(--radius);
}

.link-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.audio-only-row {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}
.audio-only-row .link-btn { margin-left: 6px; }

/* ---------- State: In-call ---------- */
#stateInCall { padding: 0; }
.in-call-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: calc(100vh - 130px);
    height: calc(100dvh - 130px);
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.in-call-topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 18px;
    background: rgba(28, 28, 30, 0.95);
    border-bottom: 1px solid #2c2c2e;
}
.in-call-title { font-size: 15px; font-weight: 600; color: #fff; }
.in-call-status {
    display: flex; align-items: center; gap: 8px;
    font-family: monospace;
    font-size: 13px;
    color: #aeaeb2;
}
.in-call-stage {
    background: #0a0a0a;
    display: flex; align-items: center; justify-content: center;
}
.stage-placeholder {
    text-align: center;
    color: #aeaeb2;
    padding: 20px;
}
.stage-placeholder .placeholder-title { color: #fff; font-size: 20px; margin-bottom: 10px; }
.stage-placeholder code {
    background: #2c2c2e;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--primary-color);
}
.in-call-controls {
    display: flex; justify-content: center; align-items: center;
    gap: 10px;
    padding: 14px;
    background: rgba(28, 28, 30, 0.95);
    border-top: 1px solid #2c2c2e;
}

/* ---------- Footer ---------- */
.join-footer {
    padding: 14px 22px;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border-color);
    background: var(--background-secondary);
}
.join-footer strong { color: var(--text-secondary); font-weight: 600; }

/* ---------- Toast ---------- */
.toast-container {
    position: fixed; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 9500;
    pointer-events: none;
}
.toast {
    background: var(--background-elevated);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border-left: 3px solid var(--primary-color);
    min-width: 220px;
    font-size: 14px;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: auto;
}
.toast-success { border-left-color: var(--success-color); }
.toast-warning { border-left-color: var(--warning-color); }
.toast-error   { border-left-color: var(--error-color); }
.toast-out { opacity: 0; transform: translateX(20px); }

/* ==========================================================
   Mobile optimisations
   - 720px:  most phones (portrait + landscape) - tighten everything
   - 420px:  small phones portrait
   - landscape + height-constrained: trim chrome to give video room
   ========================================================== */
@media (max-width: 720px) {
    /* Header — slimmer brand + smaller mark */
    .join-header { padding: 10px 14px; }
    .brand { gap: 10px; }
    .brand-mark { width: 30px; height: 30px; font-size: 12px; border-radius: 8px; }
    .brand-name { font-size: 14px; }
    .help-link { font-size: 12px; }

    /* Main padding — give content more room */
    .join-main { padding: 14px; }

    /* State titles */
    .state-title { font-size: 18px; }
    .state-hint  { font-size: 13px; }

    /* Verify / error / ended cards */
    .verify-card,
    .error-card,
    .ended-card {
        margin: 24px auto;
        padding: 28px 20px;
    }
    .error-mark { width: 48px; height: 48px; font-size: 24px; margin-bottom: 16px; }

    /* Lobby — meeting card slimmer */
    .meeting-card { padding: 14px 16px; margin-bottom: 14px; }
    .meeting-title { font-size: 17px; margin-bottom: 8px; }
    .meeting-meta { gap: 12px; }
    .meta-label { font-size: 10px; }
    .meta-value { font-size: 12px; }

    /* Right-side form tighter */
    .lobby-right { padding: 16px; gap: 12px; }
    .form-input { padding: 10px 12px; font-size: 14px; }

    /* Preview controls — bottom bubbles tighter on small screens */
    .preview-controls { bottom: 12px; gap: 8px; }
    .ctrl-bubble {
        padding: 8px 14px;
        font-size: 12px;
    }
    .ctrl-bubble-leave { padding: 8px 18px; }

    /* Device settings smaller heading */
    .device-settings summary { padding: 10px 12px; padding-right: 32px; font-size: 12px; }
    .device-body { padding: 12px; gap: 12px; }

    /* Buttons — keep tap targets but reduce font */
    .btn { padding: 10px 16px; font-size: 13px; }
    .btn-large { padding: 12px 18px; font-size: 14px; }

    /* In-call shell on mobile: stop forcing everything into viewport
       height. Let the page scroll so the sidebar (chat + notes) can
       breathe instead of being squashed into one row. The video stage
       takes a fixed slice of viewport, the sidebar takes its natural
       height with internal scroll on messages/notes lists. */
    .in-call-shell {
        height: auto;
        min-height: auto;
        border-radius: var(--radius);
        overflow: visible;
    }
    .in-call-body {
        overflow: visible;
        grid-template-columns: 1fr !important;
        grid-template-rows: auto auto !important;
    }
    .in-call-stage {
        height: 45vh;
        height: 45dvh;
        min-height: 240px;
        max-height: 56vh;
    }
    .in-call-sidebar {
        min-height: 380px;
        max-height: 70vh;
        max-height: 70dvh;
    }
    .in-call-topbar { padding: 10px 14px; }
    .in-call-title  { font-size: 13px; max-width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .in-call-status { font-size: 12px; gap: 6px; }
    .in-call-controls { padding: 10px 8px; gap: 6px; }

    /* In-call controls — shrink bubbles, hide auxiliary text where possible */
    .in-call-controls .ctrl-bubble {
        padding: 8px 12px;
        font-size: 11px;
    }
    .in-call-controls .ctrl-bubble-leave { padding: 8px 16px; }

    /* Footer slimmer */
    .join-footer { padding: 10px 14px; font-size: 11px; }

    /* Toast — full-width bottom on mobile */
    .toast-container {
        left: 12px; right: 12px; bottom: 80px;
        align-items: stretch;
    }
    .toast { min-width: 0; width: 100%; }
}

@media (max-width: 420px) {
    /* Small phones — one more notch tighter for in-call buttons */
    .in-call-controls .ctrl-bubble {
        padding: 7px 10px;
        font-size: 10px;
    }
    .in-call-controls .ctrl-bubble-leave { padding: 7px 14px; }

    /* Lobby preview controls */
    .preview-controls { bottom: 10px; gap: 6px; }
    .ctrl-bubble { padding: 7px 12px; font-size: 11px; }

    /* Headings */
    .state-title { font-size: 17px; }
    .meeting-title { font-size: 16px; }
}

/* Landscape phones — give video as much vertical as possible */
@media (max-width: 920px) and (orientation: landscape) and (max-height: 500px) {
    .join-header { padding: 6px 14px; }
    .join-main   { padding: 10px; }
    .in-call-shell {
        height: auto;
        min-height: auto;
        overflow: visible;
    }
    .in-call-stage {
        height: 70vh;
        height: 70dvh;
        min-height: 200px;
    }
    .in-call-sidebar {
        min-height: 320px;
    }
    .in-call-topbar { padding: 6px 12px; }
    .in-call-controls { padding: 6px 10px; }
    .in-call-controls .ctrl-bubble { padding: 6px 10px; font-size: 11px; }
    .lobby-grid { gap: 12px; }
    .preview-controls { bottom: 8px; }
}
