:root {
    --bg-dark: #050508;
    --surface-dark: #0A0A12;
    --accent-blue: #6366F1; /* Indigo */
    --accent-glow: rgba(99, 102, 241, 0.4);
    --accent-secondary: #A855F7; /* Purple */
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --sidebar-width: 350px;
    --msg-sent: linear-gradient(135deg, #6366F1, #A855F7);
    --msg-received: #1E1E2E;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    color: white;
    font-family: 'Inter', sans-serif;
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

html {
    height: 100%;
    margin: 0;
    padding: 0;
}

h1, h2, h3, .sidebar-title {
    font-family: 'Space Grotesk', sans-serif;
}

.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;
    overflow: hidden;
}

.nebula-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.08), transparent 40%),
                radial-gradient(circle at 80% 70%, rgba(168, 85, 247, 0.08), transparent 40%);
    z-index: -1;
    pointer-events: none;
    filter: blur(80px);
}

/* Glassmorphism utility */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
}

/* Views */
.view {
    display: none;
    width: 100%;
    height: 100%;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Onboarding */
#onboarding-view {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.onboarding-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 30px;
    text-align: center;
}

.logo-shield {
    width: 80px;
    height: 80px;
    background: var(--accent-blue);
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--bg-dark);
    margin: 0 auto 20px;
    box-shadow: 0 0 30px var(--accent-glow);
}

.logo-container h1 {
    font-size: 32px;
    margin-bottom: 8px;
}

.logo-container p {
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.input-group {
    text-align: left;
    margin-bottom: 30px;
}

.input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    display: block;
}

.phone-input {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 4px;
}

.country-code {
    padding: 12px 16px;
    border-right: 1px solid var(--glass-border);
    font-weight: 600;
}

#phone-input {
    background: none;
    border: none;
    color: white;
    padding: 12px 16px;
    font-size: 16px;
    width: 100%;
    outline: none;
}

.btn-primary {
    width: 100%;
    background: var(--accent-blue);
    color: var(--bg-dark);
    border: none;
    padding: 16px;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.98);
}

.onboarding-note {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 20px;
}

/* OTP Specific */
.otp-input-group {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 20px auto 30px;
    width: 100%;
}

.otp-digit {
    width: 60px;
    height: 70px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    color: white;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.otp-digit:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Chrome, Safari, Edge, Opera - hide spin buttons */
.otp-digit::-webkit-outer-spin-button,
.otp-digit::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.otp-footer {
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.otp-footer .text-btn {
    color: var(--accent-blue);
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    background: rgba(5, 5, 5, 0.5);
    backdrop-filter: blur(10px);
}

.sidebar-header {
    padding: calc(24px + env(safe-area-inset-top, 0px)) 24px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.profile-thumb {
    position: relative;
    width: 44px;
    height: 44px;
}

.profile-thumb img {
    width: 100%;
    height: 100%;
    border-radius: 14px;
}

.status-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #4ADE80;
    border: 2px solid var(--bg-dark);
    border-radius: 50%;
}

.sidebar-title {
    flex: 1;
    font-size: 20px;
    font-weight: 700;
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.search-bar {
    padding: 0 24px 16px;
    position: relative;
}

.search-bar i {
    position: absolute;
    left: 40px;
    top: 12px;
    width: 18px;
    color: var(--text-secondary);
}

.search-bar input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 12px 12px 44px;
    color: white;
    font-size: 14px;
    outline: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.chat-item.active {
    background: rgba(99, 102, 241, 0.08);
    border-left: 3px solid var(--accent-blue);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
}

.chat-info {
    flex: 1;
    overflow: hidden;
}

.chat-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-top h4 {
    font-size: 15px;
    font-weight: 600;
}

.chat-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.chat-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Main */
.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    height: 100%;
}

.chat-header {
    padding: calc(16px + env(safe-area-inset-top, 0px)) 24px 16px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(5, 5, 8, 0.8);
    backdrop-filter: blur(20px);
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
}

.chat-contact-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    overflow: hidden;
}

.contact-avatar img {
    width: 100%;
    height: 100%;
}

.contact-meta h3 {
    font-size: 16px;
    font-weight: 600;
}

.status-text {
    font-size: 11px;
    color: var(--accent-blue);
    font-weight: 500;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.message-area {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: var(--bg-dark);
    background-image: radial-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
}

.empty-state {
    margin: auto;
    text-align: center;
    max-width: 280px;
}

.empty-state i {
    width: 48px;
    height: 48px;
    color: var(--accent-blue);
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 13px;
    color: var(--text-secondary);
}

.message {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    position: relative;
    line-height: 1.4;
}

.message.received {
    align-self: flex-start;
    background: var(--msg-received);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.sent {
    align-self: flex-end;
    background: var(--msg-sent);
    color: white;
    font-weight: 500;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 4px;
    display: block;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    opacity: 0.7;
}

.msg-time {
    font-size: 10px;
}

.status-icon {
    width: 14px;
    height: 14px;
}

.status-icon.read {
    color: var(--accent-blue);
}

.cipher-text {
    font-family: 'Space Grotesk', monospace;
    letter-spacing: 0.5px;
}

/* Input Area */
.message-input-area {
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--glass-border);
    background: rgba(5, 5, 5, 0.95);
    backdrop-filter: blur(20px);
}

.input-wrapper {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    display: flex;
    align-items: center;
    padding: 0 8px;
}

#message-input {
    flex: 1;
    background: none;
    border: none;
    color: white;
    padding: 12px;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 100px;
}

.send-btn {
    width: 50px;
    height: 50px;
    background: var(--accent-blue);
    border: none;
    border-radius: 50%;
    color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--accent-glow);
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.send-btn i {
    width: 22px;
    height: 22px;
}

/* Mobile Navigation (only mobile) */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px 24px;
    padding-bottom: env(safe-area-inset-bottom, 10px);
    border-top: 1px solid var(--glass-border);
    justify-content: space-around;
    background: #050508;
    z-index: 1000;
}

body.nav-hidden .mobile-nav {
    display: none !important;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
}

.nav-btn.active {
    color: var(--accent-blue);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: 100%;
        border-right: none;
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    }
    
    .chat-view {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.4s cubic-bezier(0.1, 0.7, 0.1, 1), opacity 0.3s ease;
        background: var(--bg-dark);
        padding-bottom: 0; /* Tight fit for bottom input */
    }
    
    .chat-view.active {
        transform: translateX(0);
        opacity: 1;
    }
    
    .sidebar.hidden-mobile {
        display: none;
    }
    
    .back-btn {
        display: block;
    }
    
    .mobile-nav {
        display: flex;
    }
}

/* Modal Base */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 20px;
}

.modal.active {
    display: flex;
}

/* Settings Modal (Telegram Style) */
.settings-modal {
    max-width: 500px;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.settings-header {
    padding: calc(20px + env(safe-area-inset-top, 0px)) 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.settings-profile-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    background: none;
}

.profile-banner-wrapper {
    position: relative;
    width: 100%;
    height: 150px;
}

.profile-banner {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-edit-banner {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.profile-main-info {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 24px;
    margin-top: -30px;
    z-index: 2;
}

.profile-avatar-wrapper {
    position: relative;
    width: 90px;
    height: 90px;
    flex-shrink: 0;
}

.large-avatar {
    width: 100%;
    height: 100%;
    border-radius: 35%;
    object-fit: cover;
    border: 2px solid var(--accent-blue);
}

.btn-edit-avatar {
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 32px;
    height: 32px;
    background: var(--accent-blue);
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--bg-dark);
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.profile-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#display-name-input {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    font-weight: 700;
    font-family: 'Space Grotesk';
    outline: none;
    padding: 0;
}

#profile-phone {
    font-size: 14px;
    color: var(--text-secondary);
}

#username-input {
    background: none;
    border: none;
    color: var(--accent-blue);
    font-size: 14px;
    outline: none;
    padding: 0;
}

.settings-list {
    padding: 20px 0;
    flex: 1;
    overflow-y: auto;
}

.settings-section-title {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-blue);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.settings-item {
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-blue);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--accent-blue);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

.settings-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.settings-item i:not(.arrow) {
    width: 20px;
    height: 20px;
}

.settings-item span {
    flex: 1;
    font-size: 15px;
}

.settings-item .value {
    color: var(--text-secondary);
    font-size: 14px;
    margin-right: 8px;
}

.settings-item .arrow {
    width: 16px;
    color: var(--text-secondary);
}

.icon-orange { color: #FF9500; }
.icon-blue { color: #007AFF; }
.icon-green { color: #34C759; }
.icon-purple { color: #AF52DE; }

.btn-logout, .btn-update {
    width: 100%;
    padding: 16px;
    background: none;
    border: none;
    border-top: 1px solid var(--glass-border);
    color: #FF4B4B;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
}

.btn-update {
    color: var(--accent-blue);
    border-top: 1px solid rgba(0, 243, 255, 0.1);
}

/* Responsive Tweaks */
@media (max-width: 768px) {
    .modal {
        padding: 0;
    }
    .settings-modal {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }
}

/* Standalone PWA Optimizations */
@media (display-mode: standalone) {
    body, html, .app-container, .view {
        height: 100% !important;
        height: -webkit-fill-available !important;
    }
    
    .mobile-nav {
        padding-bottom: 5px;
    }
    
    .message-input-area {
        padding-bottom: 5px;
    }
}

/* Typing Indicator */
.status-container {
    display: flex;
    flex-direction: column;
}

.typing-indicator {
    font-size: 11px;
    color: var(--accent-secondary);
    font-weight: 600;
    display: none;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Call Modal */
.call-modal {
    background: radial-gradient(circle at center, #1E1E2E, #050508);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.call-modal.active {
    display: flex;
}

.call-content {
    text-align: center;
    width: 100%;
}

.call-avatar-pulse {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 30px;
}

.call-avatar-pulse img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--accent-blue);
    z-index: 2;
    position: relative;
}

.call-avatar-pulse::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    background: var(--accent-blue);
    animation: ripple 2s infinite;
    z-index: 1;
}

@keyframes ripple {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.5); opacity: 0; }
}

.call-actions {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 60px;
}

.call-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: white;
}

.call-btn.end { background: #FF3B30; box-shadow: 0 0 20px rgba(255, 59, 48, 0.4); }
.call-btn.accept { background: #34C759; box-shadow: 0 0 20px rgba(52, 199, 89, 0.4); }


/* Functional UI Tweaks */
.empty-chat-list {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-chat-list .text-btn {
    margin-top: 12px;
    color: var(--accent-blue);
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
}
