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

:root {
    --accent-color: #ff772e;
    --bg-primary: #000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --text-primary: #fff;
    --text-secondary: #98989d;
    --border-color: #38383a;
    --message-in: #1c1c1e;
    --message-out: var(--accent-color);
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

[data-theme="light"] {
    --bg-primary: #fff;
    --bg-secondary: #f2f2f7;
    --bg-tertiary: #e5e5ea;
    --text-primary: #000;
    --text-secondary: #8e8e93;
    --border-color: #c6c6c8;
    --message-in: #e5e5ea;
}

@media (prefers-color-scheme: light) {
    [data-theme="system"] {
        --bg-primary: #fff;
        --bg-secondary: #f2f2f7;
        --bg-tertiary: #e5e5ea;
        --text-primary: #000;
        --text-secondary: #8e8e93;
        --border-color: #c6c6c8;
        --message-in: #e5e5ea;
    }
}

[data-font-size="small"] {
    font-size: 14px;
}

[data-font-size="medium"] {
    font-size: 16px;
}

[data-font-size="large"] {
    font-size: 18px;
}

[data-font-size="xlarge"] {
    font-size: 20px;
}

[data-font-family="system"] {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-font-family="sf"] {
    font-family: 'SF Pro Display', -apple-system, sans-serif;
}

[data-font-family="roboto"] {
    font-family: 'Roboto', sans-serif;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 100vw;
    min-height: 100vh;
    padding-bottom: calc(70px + var(--safe-area-bottom));
}

/* Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 calc(8px + var(--safe-area-bottom));
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.nav-item i {
    font-size: 24px;
}

.nav-item span {
    font-size: 11px;
    font-weight: 500;
}

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

/* Header */
.page-header {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: calc(12px + var(--safe-area-top)) 16px 12px;
    z-index: 50;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    gap: 16px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:active {
    background: var(--bg-tertiary);
}

/* Auth Pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 48px;
}

.auth-logo i {
    font-size: 64px;
    color: var(--accent-color);
    margin-bottom: 16px;
}

.auth-logo h1 {
    font-size: 32px;
    font-weight: 700;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-input {
    width: 100%;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--accent-color);
}

.form-input::placeholder {
    color: var(--text-secondary);
}

.btn {
    padding: 16px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:active {
    opacity: 0.8;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-secondary);
}

.form-footer a {
    color: var(--accent-color);
    text-decoration: none;
}

/* Chat List */
.chat-list {
    background: var(--bg-primary);
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: var(--text-primary);
}

.chat-item:active {
    background: var(--bg-secondary);
}

.chat-avatar {
    width: 56px;
    height: 56px;
    overflow: hidden;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--text-secondary);
}

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

.chat-info {
    flex: 1;
    min-width: 0;
}

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

.chat-name {
    font-weight: 600;
    font-size: 17px;
}

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

.chat-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.unread-badge {
    background: var(--accent-color);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

/* Chat Screen */
.chat-header {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: calc(12px + var(--safe-area-top)) 16px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 50;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 17px;
}

.chat-header-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.messages-container {
    padding: 16px;
    padding-bottom: 80px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: calc(100vh - 180px);
}

.message-row {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
    width: 100%;
}

.row-in {
    justify-content: flex-start;
}

.row-out {
    justify-content: flex-end;
}

.message-sender-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    align-self: flex-end;
}

.message-sender-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-column {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message-sender-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 2px;
    margin-left: 4px;
}

.message {
    padding: 10px 14px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message-in {
    background: var(--message-in);
    border-bottom-left-radius: 4px;
}

.message-out {
    background: var(--message-out);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-content {
    margin-bottom: 2px;
    font-size: 15px;
    line-height: 1.4;
}

.message-time {
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
}

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

.message-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    margin-bottom: 8px;
}

.voice-player {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.voice-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.voice-progress-container {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.voice-progress-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: #fff;
    width: 0%;
    transition: width 0.1s linear;
}

.voice-duration {
    font-size: 11px;
    opacity: 0.8;
    min-width: 30px;
    text-align: right;
}

/* Message Input */
.message-input-container {
    position: fixed;
    bottom: calc(0px + var(--safe-area-bottom));
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-input-wrapper {
    flex: 1;
    background: var(--bg-tertiary);
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    min-height: 24px;
    max-height: 100px;
    resize: none;
}

.send-btn {
    background: var(--accent-color);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s;
}

.send-btn:active {
    transform: scale(0.95);
}

/* Status */
.status-list {
    padding: 16px;
    display: flex;
    gap: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 80px;
    cursor: pointer;
}

.status-ring {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(45deg, var(--accent-color), #ff3b7e);
}

.status-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--bg-primary);
    object-fit: cover;
}

.status-name {
    font-size: 13px;
    text-align: center;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Feed */
.feed-post {
    background: var(--bg-secondary);
    margin-bottom: 12px;
    border-radius: 12px;
    overflow: hidden;
}

.post-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.post-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.post-user-info h4 {
    font-size: 15px;
    font-weight: 600;
}

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

.post-content {
    padding: 0 16px 12px;
    font-size: 15px;
    line-height: 1.5;
}

.post-media {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
}

.post-actions {
    display: flex;
    padding: 12px 16px;
    gap: 24px;
    border-top: 1px solid var(--border-color);
}

.post-action {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
}

.post-action:active {
    color: var(--accent-color);
}

/* Settings */
.settings-section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 12px 16px;
    letter-spacing: 0.5px;
}

.settings-list {
    background: var(--bg-secondary);
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.setting-item:active {
    background: var(--bg-tertiary);
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
}

.setting-label i {
    font-size: 20px;
    width: 28px;
    color: var(--text-secondary);
}

.setting-value {
    color: var(--text-secondary);
    font-size: 15px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

/* Utility */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.loading {
    text-align: center;
    padding: 24px;
}

.spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

.alert {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success {
    background: rgba(52, 199, 89, 0.2);
    color: #34c759;
}

.alert-error {
    background: rgba(255, 59, 48, 0.2);
    color: #ff3b30;
}

/* Responsive */
@media (min-width: 768px) {
    .app {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
    }
}




/* ====== CALL UI ====== */
.call-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 15, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: #fff;
    transition: opacity 0.3s ease;
}

.call-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 90%;
    max-width: 900px;
    padding: 10px 0;
    margin-bottom: 8px;
}

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

.call-header-info img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #555;
}

.sharesc-btn {
    background: #2b992d;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.end-call-btn {
    background: #e63946;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.end-call-btn:hover {
    background: #c91d2f;
}

.video-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 90%;
    max-width: 900px;
    flex: 1;
}

#remoteVideo {
    width: 100%;
    height: auto;
    border-radius: 12px;
    background: #000;
    object-fit: cover;
}

#localVideo {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 35%;
    max-width: 280px;
    border-radius: 10px;
    border: 2px solid #444;
    object-fit: cover;
    background: #111;
}

.call-modal.minimized {
    width: 260px;
    height: 150px;
    right: 15px;
    bottom: 15px;
    left: auto;
    top: auto;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.call-modal.minimized video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Incoming Call Modal */
.incoming-call-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.incoming-card {
    background: #1a1a1a;
    border-radius: 12px;
    padding: 30px 40px;
    text-align: center;
    color: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.3s ease;
}

.incoming-card img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 15px;
}

.call-buttons {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.accept-btn {
    background: #06d6a0;
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.reject-btn {
    background: #ef233c;
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Screen share layout */
.screen-share-active #remoteVideo {
    width: 90%;
    height: auto;
    max-height: 90vh;
    object-fit: contain;
}

.screen-share-active #localVideo {
    width: 25% !important;
    height: auto;
}

.screen-share-active .screen-video {
    width: 70%;
    height: auto;
    border-radius: 12px;
    margin: 0 2%;
}

.hidden {
    display: none !important;
}

.call-controls {
    position: absolute;
    bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.ctrl-btn,
.end-call-btn {
    background: rgba(30, 30, 30, 0.8);
    color: #fff;
    border: none;
    padding: 12px 15px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s ease;
}

.ctrl-btn:hover {
    background: rgba(50, 50, 50, 0.9);
}

.end-call-btn {
    background: #e63946;
    border-radius: 50%;
    padding: 14px 16px;
}

.end-call-btn:hover {
    background: #c91d2f;
}

.screen-share-active #localVideo {
    display: none;
}

.ongoing-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1a1a1a;
    color: #fff;
    padding: 12px 18px;
    border-radius: 25px;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
}