/* ============================================
   VoiceLink – WhatsApp-Inspired Voice Call UI
   Mobile-First Dark Theme
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #0b141a;
    --bg-secondary: #111b21;
    --bg-tertiary: #1f2c34;
    --bg-input: #2a3942;
    --bg-hover: #374955;

    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-hint: #667781;

    --accent-green: #00a884;
    --accent-green-hover: #00c49a;
    --accent-green-glow: rgba(0, 168, 132, 0.3);
    --accent-red: #ef4444;
    --accent-red-hover: #f87171;
    --accent-red-glow: rgba(239, 68, 68, 0.3);
    --accent-blue: #53bdeb;

    --border-color: #2a3942;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 50%;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* --- Screen Management --- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease, transform 0.4s ease;
    transform: scale(0.96);
}

.screen.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* ============================================
   JOIN SCREEN
   ============================================ */
.join-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
}

.logo-section {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 80px;
    height: 80px;
    animation: logoFloat 3s ease-in-out infinite;
}

.logo-icon svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 20px var(--accent-green-glow));
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.logo-section h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #00a884, #00d4aa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 300;
}

/* --- Join Form --- */
.join-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.input-group input {
    width: 100%;
    height: 52px;
    padding: 0 1rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 400;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-group input::placeholder {
    color: var(--text-hint);
}

.input-group input:focus {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px var(--accent-green-glow);
}

.input-hint {
    font-size: 0.75rem;
    color: var(--text-hint);
}

/* --- Buttons --- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 52px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, #00a884, #00c49a);
    color: #fff;
    box-shadow: 0 4px 16px var(--accent-green-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px var(--accent-green-glow);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

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

.btn-loader {
    display: flex;
    align-items: center;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Error Toast --- */
.error-toast {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: var(--accent-red);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   CALL SCREEN
   ============================================ */
.call-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0b141a 0%, #0d1a22 50%, #0b141a 100%);
}

/* --- Call Header --- */
.call-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    padding-top: max(1rem, env(safe-area-inset-top));
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.call-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.room-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.call-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.call-status.connected {
    color: var(--accent-green);
}

.call-status.calling {
    color: var(--accent-blue);
}

.call-status.ended {
    color: var(--accent-red);
}

.call-timer {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

/* --- Call Visual --- */
.call-visual {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    position: relative;
}

.avatar-ring {
    width: 140px;
    height: 140px;
    border-radius: var(--radius-full);
    border: 3px solid var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.5s ease;
}

.avatar-ring.calling {
    border-color: var(--accent-blue);
    animation: ringPulse 2s ease-in-out infinite;
}

.avatar-ring.connected {
    border-color: var(--accent-green);
    box-shadow: 0 0 40px var(--accent-green-glow);
}

@keyframes ringPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(83, 189, 235, 0.3); }
    50% { box-shadow: 0 0 0 20px rgba(83, 189, 235, 0); }
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-hint);
}

.avatar svg {
    width: 56px;
    height: 56px;
}

/* --- Signal Waves --- */
.signal-waves {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    bottom: calc(50% - 100px);
}

.wave {
    width: 4px;
    border-radius: 2px;
    background: var(--accent-green);
    animation: waveAnim 1s ease-in-out infinite;
}

.wave:nth-child(1) { height: 16px; animation-delay: 0s; }
.wave:nth-child(2) { height: 28px; animation-delay: 0.15s; }
.wave:nth-child(3) { height: 20px; animation-delay: 0.3s; }

@keyframes waveAnim {
    0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* --- Call Controls --- */
.call-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    padding: 1.5rem;
    padding-bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1rem));
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.control-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.control-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.control-icon svg {
    width: 28px;
    height: 28px;
}

.control-btn:not(:disabled):hover .control-icon {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.control-btn:not(:disabled):active .control-icon {
    transform: scale(0.95);
}

.control-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- Call Action Button (Green) --- */
.call-action .control-icon {
    background: var(--accent-green);
    color: #fff;
    width: 68px;
    height: 68px;
    box-shadow: 0 4px 20px var(--accent-green-glow);
}

.call-action .control-icon svg {
    width: 32px;
    height: 32px;
}

.call-action:not(:disabled):hover .control-icon {
    background: var(--accent-green-hover);
    box-shadow: 0 6px 28px var(--accent-green-glow);
}

/* --- Hangup Action Button (Red) --- */
.hangup-action .control-icon {
    background: var(--accent-red);
    color: #fff;
    width: 68px;
    height: 68px;
    box-shadow: 0 4px 20px var(--accent-red-glow);
}

.hangup-action .control-icon svg {
    width: 32px;
    height: 32px;
}

.hangup-action:not(:disabled):hover .control-icon {
    background: var(--accent-red-hover);
    box-shadow: 0 6px 28px var(--accent-red-glow);
}

/* --- Muted State --- */
.control-btn.muted .control-icon {
    background: var(--accent-red);
    color: #fff;
}

/* --- Active Speaker --- */
.control-btn.speaker-active .control-icon {
    background: var(--accent-blue);
    color: #fff;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pulseGreen {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-green-glow); }
    50% { box-shadow: 0 0 0 12px rgba(0, 168, 132, 0); }
}

/* ============================================
   RESPONSIVE - TABLET & DESKTOP
   ============================================ */
@media (min-width: 768px) {
    .join-container {
        padding: 3rem;
        gap: 3rem;
    }

    .logo-icon {
        width: 100px;
        height: 100px;
    }

    .logo-section h1 {
        font-size: 2.5rem;
    }

    .avatar-ring {
        width: 180px;
        height: 180px;
    }

    .avatar {
        width: 160px;
        height: 160px;
    }

    .avatar svg {
        width: 72px;
        height: 72px;
    }

    .control-icon {
        width: 68px;
        height: 68px;
    }

    .call-action .control-icon,
    .hangup-action .control-icon {
        width: 76px;
        height: 76px;
    }

    .call-controls {
        gap: 2rem;
    }
}

/* --- Landscape Mobile --- */
@media (max-height: 480px) and (orientation: landscape) {
    .call-visual {
        padding: 0.5rem 0;
    }

    .avatar-ring {
        width: 100px;
        height: 100px;
    }

    .avatar {
        width: 86px;
        height: 86px;
    }

    .call-controls {
        padding: 0.75rem;
    }

    .control-icon {
        width: 50px;
        height: 50px;
    }

    .call-action .control-icon,
    .hangup-action .control-icon {
        width: 56px;
        height: 56px;
    }

    .control-label {
        display: none;
    }
}

/* --- Prevent text selection on buttons --- */
button {
    user-select: none;
    -webkit-user-select: none;
}

/* --- Scrollbar (for desktop) --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}
