:root {
    --bg-main: #000000;
    --bg-chat: #000000;
    --bg-header: #1c1c1e;
    --bg-input: #1c1c1e;
    --bg-sent: #0b84fe;
    --bg-received: #2c2c2e;
    --text-main: #ffffff;
    --text-muted: #8e8e93;
    --border-color: #38383a;
    --border-radius: 18px;
    --app-blue: #0b84fe;
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --accent-color: #0b84fe;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Login Page */
.login-container {
    background: var(--bg-header);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-container h2 {
    margin-bottom: 2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

#login-form input {
    padding: 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
}

#login-form input:focus {
    border-color: var(--app-blue);
}

#login-form button {
    padding: 1rem;
    background-color: var(--app-blue);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: background-color 0.2s;
}

#login-form button:hover {
    background-color: #0070e0;
}

.error {
    color: #ff453a;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Chat App */
.chat-container {
    background: var(--bg-chat);
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh; /* Account for iOS Safari address bar */
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--bg-header);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.header-info h2 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

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

.connection-status {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-pill {
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.2px;
    border: 1px solid transparent;
}

.status-online {
    color: #2dd36f;
    border-color: rgba(45, 211, 111, 0.35);
    background: rgba(45, 211, 111, 0.12);
}

.status-offline {
    color: #ff453a;
    border-color: rgba(255, 69, 58, 0.35);
    background: rgba(255, 69, 58, 0.12);
}

.header-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.typing {
    font-size: 0.8rem;
    color: var(--text-muted);
    height: 1rem;
}

#logout-btn {
    background: transparent;
    border: none;
    color: var(--app-blue);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#set-pin-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#set-pin-btn:hover,
#set-pin-btn:focus,
#logout-btn:hover,
#logout-btn:focus {
    color: var(--app-blue);
}

.clear-timer {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 64px;
    text-align: right;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: slideUp 0.3s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.message-wrapper.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message-wrapper.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-left: 4px;
    margin-right: 4px;
}

.message {
    padding: 0.6rem 1rem;
    position: relative;
    word-wrap: break-word;
    font-size: 1rem;
    line-height: 1.4;
}

.message-wrapper.sent .message {
    background-color: var(--bg-sent);
    border-radius: var(--border-radius);
    border-bottom-right-radius: 4px;
}

.message-wrapper.received .message {
    background-color: var(--bg-received);
    border-radius: var(--border-radius);
    border-bottom-left-radius: 4px;
}

/* Animations */
@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-file img, .msg-file video {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 5px;
}

.file-attachment {
    background: rgba(0,0,0,0.2);
    padding: 0.8rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-main);
}

.file-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.file-name {
    font-size: 0.85rem;
    word-break: break-all;
    text-align: center;
}

.msg-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.timestamp {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
}

.message-wrapper.received .timestamp {
    color: var(--text-muted);
}


/* Fade-out for deleted messages */
.message-wrapper.deleting {
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 180ms ease, transform 180ms ease;
}

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

.action-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 0.9rem;
}
.action-btn:hover {
    color: #fff;
}

/* Input Area */
.typing-container {
    background-color: var(--bg-chat);
    padding: 0 1.5rem;
    height: 1.5rem;
    margin-bottom: 0.5rem;
}

.typing {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.typing-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-received);
    padding: 0.5rem 0.8rem;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    animation: slideUp 0.3s ease forwards;
    height: 1.5rem;
}

.typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    margin: 0 2px;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-count {
    margin-left: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.input-area {
    display: flex;
    padding: 0.8rem 1rem;
    padding-bottom: calc(0.8rem + env(safe-area-inset-bottom));
    background-color: var(--bg-header);
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    width: 100%;
}

#attach-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-wrapper {
    flex: 1;
    background-color: var(--bg-chat);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    overflow: hidden;
}

#message-input {
    width: 100%;
    padding: 0.6rem 0;
    border: none;
    background: transparent;
    color: var(--text-main);
    outline: none;
    font-size: 1rem;
}

#message-input::placeholder {
    color: var(--text-muted);
}

#send-btn {
    background: transparent;
    color: var(--app-blue);
    border: none;
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#upload-preview {
    background: var(--bg-header);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

#cancel-upload {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-header);
    padding: 1.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 350px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.modal-content h3 {
    margin-bottom: 1rem;
}

.pin-modal-content {
    text-align: left;
    padding: 1.75rem;
    box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}

.pin-modal-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
    text-align: left;
}

.pin-modal-content p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.35;
    margin-bottom: 1rem;
}

.pin-modal-content #pin-input {
    width: 100%;
    padding: 0.85rem 0.9rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-chat);
    color: var(--text-main);
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.pin-modal-content #pin-input:focus {
    border-color: var(--app-blue);
    outline: none;
}

.pin-modal-content .modal-actions {
    justify-content: space-between;
}

.pin-modal-content .modal-actions button {
    flex: 1;
}

.pin-modal-content .modal-actions button + button {
    margin-left: 0.75rem;
}


.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.modal-actions button {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
}

/* Lock Screen */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}
.lock-screen.hidden {
    display: none;
}
.lock-box {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 400px;
}
.lock-box h2 {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.lock-box p {
    color: var(--text-secondary);
}
.lock-box input {
    width: 100%;
    padding: 12px;
    margin: 15px 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
}
.lock-box button {
    width: 100%;
    padding: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    margin-bottom: 10px;
}
.lock-box button.secondary-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.danger-btn {
    background: #ff453a !important;
    color: white !important;
}

.incoming-call-content {
    max-width: 350px;
    text-align: center;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
}

.caller-info {
    margin-bottom: 30px;
}

.caller-avatar {
    font-size: 5rem;
    color: #0a84ff;
    margin-bottom: 10px;
}

#caller-name {
    font-size: 1.5rem;
    font-weight: 500;
}

.success-btn {
    background: #34c759;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.success-btn:hover {
    background: #28a745;
}

/* Video Call Styling (WhatsApp-like) */
.video-call-modal {
    padding: 0;
    background: #000;
}

.video-call-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.remote-video {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Changed from cover to show full resolution without cropping */
    background: #000;
}

.local-video {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 120px;
    aspect-ratio: 9/16;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.2);
    background: #000;
    z-index: 10;
}

.call-controls {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 20;
    background: rgba(0,0,0,0.4);
    padding: 15px 25px;
    border-radius: 40px;
    backdrop-filter: blur(10px);
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn.off {
    background: white;
    color: #1c1c1e;
}

.control-btn.danger-btn {
    background: #ff453a;
    transform: rotate(135deg); /* Make it look like a hangup button */
}

.control-btn.danger-btn:active {
    transform: rotate(135deg) scale(0.9);
}

@media (max-width: 600px) {
    .local-video {
        width: 100px;
        top: 15px;
        right: 15px;
    }
    
    .call-controls {
        bottom: 30px;
        gap: 15px;
        padding: 12px 20px;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
}

#call-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#call-btn:hover {
    color: var(--accent-color);
}
