 /* All CSS styles here */
        * { margin:0; padding:0; box-sizing:border-box; }
        body {
            height: 100vh; /* Fallback for older browsers */
            height: 100dvh; /* Perfectly fits mobile screens dynamically */
            width: 100vw; overflow: hidden;
            -webkit-tap-highlight-color: transparent;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #f0f2f5;
        }
        .app-view {
            position: absolute; inset:0;
            display: flex; flex-direction: column;
            opacity:0; pointer-events:none;
            transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
            transform: scale(0.97);
            z-index:0;
            overflow:hidden;
            background: #f0f2f5;
        }
        .app-view.active { opacity:1; pointer-events:auto; transform:scale(1); z-index:10; }
        
        .app-header {
            background: #ffffff;
            padding: 12px 16px;
            border-bottom: 1px solid #e8ecf0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-shrink: 0;
            z-index: 50;
        }
        .app-header .brand {
            font-weight: 600;
            font-size: 16px;
            color: #1a2634;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .app-header .brand i { color: #2563eb; font-size: 18px; }
        .app-header .status {
            font-size: 13px;
            color: #4b5563;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .app-header .status .dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #22c55e;
            display: inline-block;
        }
        .app-header .status .dot.disconnected { background: #dc2626; }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .header-btn {
            position: relative;
            background: transparent;
            border: none;
            font-size: 18px;
            color: #4b5563;
            cursor: pointer;
            padding: 4px 6px;
            transition: color 0.2s;
            -webkit-tap-highlight-color: transparent;
        }
        .header-btn:active { transform: scale(0.92); }
        .header-btn .badge {
            position: absolute;
            top: -4px;
            right: -4px;
            background: #dc2626;
            color: white;
            border-radius: 50%;
            padding: 1px 6px;
            font-size: 9px;
            font-weight: 600;
            min-width: 18px;
            text-align: center;
        }
        
        .key-btn {
            width: clamp(55px, min(18vw, 9vh), 72px);
            height: clamp(55px, min(18vw, 9vh), 72px);
            border-radius: 50%;
            font-size: clamp(22px, 4vh, 26px);
            font-weight: 400;
            background: #ffffff;
            color: #1a2634;
            border: none;
            box-shadow: 0 2px 8px rgba(0,0,0,0.06);
            transition: all 0.12s ease;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            margin: 0 auto;
        }
        .key-btn:active { background: #e8ecf0; transform: scale(0.94); box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
        .key-btn .sub {
            position: absolute;
            bottom: 12%;
            font-size: 9px;
            color: #9ca3af;
            font-weight: 400;
            letter-spacing: 0.04em;
        }
        .key-btn-sub { color: #6b7280; font-size: 20px; }
        
        #dial-display {
            font-size: clamp(28px, 6vh, 38px);
            letter-spacing: 8px;
            font-weight: 300;
            background: transparent;
            border: none;
            text-align: center;
            width: 100%;
            outline: none;
            color: #1a2634;
            font-family: 'SF Mono', 'Menlo', monospace;
            padding: 8px 0;
            caret-color: #2563eb;
        }
        #dial-display::placeholder {
            color: #9ca3af;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            letter-spacing: 1px;
            font-size: 16px;
        }
        #dial-contact-name {
            font-size: 15px;
            font-weight: 500;
            color: #2563eb;
            min-height: 28px;
            text-align: center;
        }
        
        .call-btn {
            width: clamp(55px, min(18vw, 9vh), 72px);
            height: clamp(55px, min(18vw, 9vh), 72px);
            border-radius: 50%;
            border: none;
            font-size: clamp(22px, 4vh, 26px);
            cursor: pointer;
            transition: all 0.15s ease;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 16px rgba(0,0,0,0.12);
        }
        .call-btn:active { transform: scale(0.92); }
        .call-btn-audio { background: #22c55e; color: white; }
        .call-btn-video { background: #2563eb; color: white; }
        .call-btn-sms { background: #6b7280; color: white; }
        
        #view-call, #view-video-call {
            background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
            color: white;
        }
        .avatar-glow {
            width: 120px;
            height: 120px;
            background: rgba(255,255,255,0.05);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 40px;
            color: white;
            position: relative;
            border: 1px solid rgba(255,255,255,0.06);
        }
        .avatar-glow::after {
            content: '';
            position: absolute;
            inset: -10px;
            border-radius: 50%;
            border: 1.5px solid rgba(255,255,255,0.04);
            animation: pulse-ring 2.6s infinite;
        }
        @keyframes pulse-ring { 0% { transform:scale(1); opacity:0.5; } 100% { transform:scale(1.35); opacity:0; } }
        .ringing-indicator { animation: pulse 1s infinite; }
        @keyframes pulse { 0% { opacity:0.6; } 50% { opacity:1; } 100% { opacity:0.6; } }
        
        .control-bar {
            background: rgba(255,255,255,0.06);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-radius: 48px;
            padding: 14px 18px;
            display: flex;
            justify-content: space-around;
            width: 100%;
            max-width: 380px;
            margin: 0 auto;
        }
        .ctrl-btn {
            width: 54px;
            height: 54px;
            border-radius: 50%;
            border: none;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 20px;
            transition: all 0.15s ease;
            color: white;
            background: rgba(255,255,255,0.08);
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
        }
        .ctrl-btn:active { transform: scale(0.90); }
        .ctrl-btn.bg-red { background: #dc2626; color: white; }
        .ctrl-btn.bg-green { background: #22c55e; color: white; }
        .ctrl-btn.active-mute { background: white; color: #1a2634; }
        .ctrl-btn.speaker-on { background: #2563eb; color: white; }
        
        .video-container { 
            position: relative; 
            width: 100%; 
            height: 100%; 
            background: #0f172a;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .remote-video { 
            width: 100%; 
            height: 100%; 
            object-fit: cover; 
            background: #1e293b;
        }
        .remote-video.visible { display: block; }
        .remote-video.hidden { display: none; }
        
        .local-video {
            position: absolute;
            bottom: 120px;
            right: 16px;
            width: 110px;
            height: 150px;
            object-fit: cover;
            border-radius: 14px;
            border: 2px solid rgba(255,255,255,0.15);
            background: #1e293b;
            z-index: 5;
            box-shadow: 0 8px 24px rgba(0,0,0,0.4);
        }
        .local-video.visible { display: block; }
        .local-video.hidden { display: none; }
        
        .video-controls {
            position: absolute;
            bottom: max(env(safe-area-inset-bottom), 40px);
            left: 0;
            right: 0;
            display: flex;
            justify-content: center;
            gap: 20px;
            padding: 0 20px;
            z-index: 10;
        }
        .call-timer {
            font-variant-numeric: tabular-nums;
            letter-spacing: 2px;
            font-weight: 300;
            font-size: 32px;
        }
        
        .sms-message.sent {
            background: #2563eb;
            color: white;
            align-self: flex-end;
            border-bottom-right-radius: 4px;
        }
        .sms-message.received {
            background: #f1f3f5;
            color: #1a2634;
            align-self: flex-start;
            border-bottom-left-radius: 4px;
        }
        .sms-message {
            max-width: 80%;
            padding: 10px 16px;
            border-radius: 18px;
            word-wrap: break-word;
            font-size: 14px;
            line-height: 1.5;
        }
        .sms-input-bar {
            display: flex;
            padding: 12px 16px;
            padding-bottom: max(env(safe-area-inset-bottom), 12px);
            background: white;
            border-top: 1px solid #e8ecf0;
            gap: 10px;
            flex-shrink: 0;
        }
        .sms-input {
            flex: 1;
            border: 1px solid #d1d5db;
            border-radius: 24px;
            padding: 10px 18px;
            font-size: 15px;
            outline: none;
            transition: border 0.2s;
            background: #f8f9fa;
            color: #1a2634;
            font-family: inherit;
        }
        .sms-input:focus { border-color: #2563eb; background: white; }
        .sms-input::placeholder { color: #9ca3af; }
        .sms-send-btn {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            border: none;
            background: #2563eb;
            color: white;
            font-size: 18px;
            cursor: pointer;
            transition: background 0.2s;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
            flex-shrink: 0;
        }
        .sms-send-btn:active { background: #1d4ed8; transform: scale(0.92); }
        
        .history-item {
            background: white;
            border-radius: 14px;
            padding: 14px 16px;
            margin-bottom: 8px;
            box-shadow: 0 1px 4px rgba(0,0,0,0.04);
            border-left: 4px solid #2563eb;
        }
        .history-item.missed { border-left-color: #dc2626; }
        .history-item.ended { border-left-color: #9ca3af; }
        
        .toast-custom {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(15, 23, 42, 0.92);
            color: white;
            padding: 10px 24px;
            border-radius: 40px;
            font-size: 14px;
            z-index: 9999;
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            display: none;
            font-weight: 500;
            box-shadow: 0 8px 32px rgba(0,0,0,0.2);
            font-family: inherit;
            pointer-events: none;
            white-space: nowrap;
        }
        
        .register-container {
            max-width: 380px;
            width: 100%;
            padding: 0 20px;
        }
        .register-container h1 {
            font-size: 24px;
            font-weight: 700;
            color: #1a2634;
            margin-bottom: 4px;
        }
        .register-container p {
            color: #6b7280;
            font-size: 14px;
        }
        .register-input {
            border: none;
            border-bottom: 2px solid #d1d5db;
            border-radius: 0;
            padding: 12px 0 8px;
            background: transparent;
            font-size: 16px;
            width: 100%;
            transition: border-color 0.2s;
            font-weight: 500;
            color: #1a2634;
            font-family: inherit;
            outline: none;
        }
        .register-input:focus { border-bottom-color: #2563eb; }
        .register-input::placeholder { color: #9ca3af; font-weight: 400; }
        .register-label {
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            color: #6b7280;
            display: block;
            margin-bottom: 4px;
            letter-spacing: 0.04em;
        }
        .btn-primary-custom {
            background: #1a2634;
            color: white;
            border: none;
            border-radius: 50px;
            padding: 16px 24px;
            font-size: 16px;
            font-weight: 600;
            width: 100%;
            cursor: pointer;
            transition: background 0.2s;
            font-family: inherit;
        }
        .btn-primary-custom:active { background: #0f172a; transform: scale(0.98); }
        
        .bg-surface { background: #ffffff; }
        .rounded-top-3xl { border-radius: 32px 32px 0 0; }
        .text-muted { color: #6b7280; }
        .border-light { border-color: #e8ecf0; }
        input, textarea, button { -webkit-appearance: none; appearance: none; }
        
        #sms-messages {
            flex: 1;
            overflow-y: auto;
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            background: #f8f9fa;
        }
        #sms-messages::-webkit-scrollbar { width: 4px; }
        #sms-messages::-webkit-scrollbar-track { background: transparent; }
        #sms-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }
        
        .spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid rgba(255,255,255,0.3);
            border-radius: 50%;
            border-top-color: #fff;
            animation: spin 0.8s ease-in-out infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        
        input[type="tel"] {
            -webkit-user-select: text !important;
            user-select: text !important;
        }
        
        .reconnect-btn {
            background: #2563eb;
            color: white;
            border: none;
            padding: 6px 16px;
            border-radius: 20px;
            font-size: 12px;
            cursor: pointer;
            transition: background 0.2s;
            font-family: inherit;
            font-weight: 500;
        }
        .reconnect-btn:hover { background: #1d4ed8; }
        .reconnect-btn:active { transform: scale(0.95); }

        .video-incoming-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(0,0,0,0.7);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            z-index: 20;
        }
        .video-incoming-overlay .avatar-glow {
            width: 100px;
            height: 100px;
            font-size: 32px;
            border-color: rgba(255,255,255,0.2);
        }
        .video-incoming-overlay .caller-name {
            font-size: 24px;
            font-weight: 300;
            margin-top: 16px;
            color: white;
        }
        .video-incoming-overlay .caller-status {
            font-size: 14px;
            color: rgba(255,255,255,0.6);
            margin-top: 4px;
        }
        .video-incoming-controls {
            display: flex;
            gap: 30px;
            margin-top: 30px;
        }
        .video-incoming-controls .ctrl-btn {
            width: clamp(50px, 12vh, 70px);
            height: clamp(50px, 12vh, 70px);
            font-size: clamp(22px, 4vh, 28px);
            border-radius: 50%;
            border: none;
            cursor: pointer;
            transition: all 0.15s ease;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
        }
        .video-incoming-controls .ctrl-btn:active { transform: scale(0.90); }
        .video-incoming-controls .ctrl-btn.bg-red { background: #dc2626; color: white; }
        .video-incoming-controls .ctrl-btn.bg-green { background: #22c55e; color: white; }
        
        .error-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(8px);
            z-index: 30;
            padding: 20px;
        }
        .error-overlay .error-icon { font-size: 48px; color: #dc2626; margin-bottom: 16px; }
        .error-overlay .error-title { font-size: 20px; font-weight: 600; color: white; margin-bottom: 8px; }
        .error-overlay .error-message {
            font-size: 14px;
            color: rgba(255,255,255,0.7);
            text-align: center;
            max-width: 300px;
            margin-bottom: 20px;
        }
        .error-overlay .error-btn {
            background: #2563eb;
            color: white;
            border: none;
            padding: 10px 30px;
            border-radius: 25px;
            font-size: 14px;
            cursor: pointer;
            font-family: inherit;
            font-weight: 500;
            transition: background 0.2s;
        }
        .error-overlay .error-btn:hover { background: #1d4ed8; }
        .error-overlay .error-btn:active { transform: scale(0.95); }

        .video-status-debug {
            position: absolute;
            top: 80px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.7);
            color: #00ff88;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 11px;
            font-family: monospace;
            z-index: 15;
            pointer-events: none;
        }

        .sms-popup {
            position: fixed;
            bottom: 90px;
            left: 50%;
            transform: translateX(-50%);
            background: #1a2634;
            color: white;
            padding: 14px 20px;
            border-radius: 16px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.3);
            z-index: 200;
            max-width: 90%;
            min-width: 280px;
            display: none;
            animation: slideUp 0.3s ease;
            cursor: pointer;
        }
        .sms-popup.show { display: block; }
        @keyframes slideUp {
            from { opacity: 0; transform: translateX(-50%) translateY(20px); }
            to { opacity: 1; transform: translateX(-50%) translateY(0); }
        }
        .sms-popup .popup-sender { font-weight: 600; font-size: 14px; color: #60a5fa; }
        .sms-popup .popup-message { font-size: 13px; color: #e5e7eb; margin-top: 2px; }
        .sms-popup .popup-time { font-size: 10px; color: #9ca3af; margin-top: 4px; }
        .sms-popup .popup-close {
            position: absolute;
            top: 6px;
            right: 10px;
            background: none;
            border: none;
            color: #9ca3af;
            font-size: 16px;
            cursor: pointer;
        }

        .sms-contact-list {
            flex: 1;
            overflow-y: auto;
            padding: 8px 12px;
            background: #f8f9fa;
        }
        .sms-contact-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            background: white;
            border-radius: 12px;
            margin-bottom: 6px;
            cursor: pointer;
            transition: background 0.2s;
            border: 1px solid #f0f2f5;
        }
        .sms-contact-item:active { background: #e8ecf0; }
        .sms-contact-item .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #e8ecf0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            color: #1a2634;
            margin-right: 12px;
            flex-shrink: 0;
        }
        .sms-contact-item .info { flex: 1; min-width: 0; }
        .sms-contact-item .info .name { font-weight: 500; font-size: 14px; color: #1a2634; }
        .sms-contact-item .info .preview { font-size: 12px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .sms-contact-item .info .time { font-size: 10px; color: #9ca3af; }
        .sms-contact-item .unread-badge {
            background: #2563eb;
            color: white;
            border-radius: 50%;
            padding: 2px 8px;
            font-size: 11px;
            font-weight: 600;
            flex-shrink: 0;
        }

        /* User Preferences Panel */
        .settings-panel {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            border-radius: 24px 24px 0 0;
            padding: 20px;
            box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
            z-index: 200;
            transform: translateY(100%);
            transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
            max-height: 70vh;
            overflow-y: auto;
        }
        .settings-panel.show { transform: translateY(0); }
        .settings-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.4);
            z-index: 199;
            display: none;
            backdrop-filter: blur(4px);
        }
        .settings-overlay.show { display: block; }
        .settings-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 14px 0;
            border-bottom: 1px solid #f0f2f5;
        }
        .settings-item:last-child { border-bottom: none; }
        .settings-item .info .title { font-weight: 500; font-size: 15px; color: #1a2634; }
        .settings-item .info .desc { font-size: 12px; color: #6b7280; }
        .toggle-switch {
            width: 48px;
            height: 28px;
            border-radius: 14px;
            background: #d1d5db;
            cursor: pointer;
            transition: background 0.3s;
            position: relative;
            flex-shrink: 0;
        }
        .toggle-switch.active { background: #2563eb; }
        .toggle-switch .toggle-knob {
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background: white;
            position: absolute;
            top: 3px;
            left: 3px;
            transition: transform 0.3s;
            box-shadow: 0 2px 4px rgba(0,0,0,0.15);
        }
        .toggle-switch.active .toggle-knob { transform: translateX(20px); }
        .settings-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 12px;
            border-bottom: 2px solid #e8ecf0;
            margin-bottom: 8px;
        }
        .settings-header h3 { font-size: 18px; font-weight: 600; color: #1a2634; }
        .settings-header .close-btn {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #6b7280;
        }
        .settings-header .close-btn:active { transform: scale(0.92); }
        .status-badge-offline {
            background: #dc2626;
            color: white;
            font-size: 10px;
            padding: 2px 10px;
            border-radius: 12px;
            font-weight: 600;
        }