/* ============================================================
   NEST — Chat Page Styles
   WhatsApp-style dark theme messaging interface
   ============================================================ */

:root {
    --nest-primary: #075E54;
    --nest-primary-light: #128C7E;
    --nest-accent: #25D366;
    --nest-bg: #0B141A;
    --nest-bg-light: #1F2C34;
    --nest-card: #202C33;
    --nest-text: #E9EDEF;
    --nest-text-secondary: #8696A0;
    --nest-border: #2A3942;
    --nest-sent-bubble: #005C4B;
    --nest-received-bubble: #202C33;
    --nest-error: #EA4335;
    --nest-info: #53BDEB;
    --nest-header-height: 60px;
    --nest-input-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--nest-bg);
    color: var(--nest-text);
    height: 100vh;
    overflow: hidden;
}

/* ============================================================
   Chat Container Layout
   ============================================================ */
.chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    background: var(--nest-bg);
}

/* ============================================================
   Header
   ============================================================ */
.chat-header {
    height: var(--nest-header-height);
    background: var(--nest-card);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--nest-border);
    position: relative;
    z-index: 10;
    /* Panic exit tap target */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--nest-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

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

.header-name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.header-status.online {
    color: var(--nest-accent);
}

.header-status.typing {
    color: var(--nest-accent);
    font-style: italic;
}

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

.header-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--nest-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

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

/* ============================================================
   Messages Area
   ============================================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
    /* Chat background pattern */
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(7, 94, 84, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(7, 94, 84, 0.03) 0%, transparent 50%);
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--nest-border);
    border-radius: 3px;
}

/* Date separator */
.date-separator {
    text-align: center;
    padding: 8px 0;
}

.date-separator span {
    background: var(--nest-bg-light);
    color: var(--nest-text-secondary);
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 12px;
}

/* Message bubble */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    padding: 6px 10px 4px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.sent {
    align-self: flex-end;
    background: var(--nest-sent-bubble);
    border-top-right-radius: 2px;
}

.message.received {
    align-self: flex-start;
    background: var(--nest-received-bubble);
    border-top-left-radius: 2px;
}

.message-text {
    font-size: 14.5px;
    white-space: pre-wrap;
}

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

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

/* Read receipts */
.message-status {
    font-size: 14px;
    line-height: 1;
}

.message-status.sent { color: rgba(255, 255, 255, 0.4); }
.message-status.delivered { color: rgba(255, 255, 255, 0.5); }
.message-status.seen { color: var(--nest-info); }

/* System message */
.message.system {
    align-self: center;
    max-width: 90%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    text-align: center;
    padding: 6px 16px;
}

.message.system .message-text {
    font-size: 12px;
    color: var(--nest-text-secondary);
}

/* Media in messages */
.message-media {
    max-width: 300px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 4px;
}

.message-media img,
.message-media video {
    max-width: 100%;
    display: block;
    border-radius: 6px;
}

.message-media audio {
    width: 100%;
    min-width: 200px;
}

/* Reply preview */
.reply-preview {
    background: rgba(0, 0, 0, 0.15);
    border-left: 3px solid var(--nest-accent);
    padding: 4px 8px;
    margin-bottom: 4px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--nest-text-secondary);
    cursor: pointer;
}

/* ============================================================
   Input Area
   ============================================================ */
.chat-input-container {
    flex-shrink: 0;
    padding: 8px 12px;
    background: var(--nest-card);
    border-top: 1px solid var(--nest-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.input-actions {
    display: flex;
    gap: 4px;
}

.input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--nest-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.input-btn:hover {
    color: var(--nest-text);
}

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

.message-input-wrapper {
    flex: 1;
    position: relative;
}

#messageInput {
    width: 100%;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 14px;
    background: var(--nest-bg-light);
    border: none;
    border-radius: 20px;
    color: var(--nest-text);
    font-size: 15px;
    resize: none;
    outline: none;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

#messageInput::placeholder {
    color: var(--nest-text-secondary);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--nest-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--nest-primary-light);
}

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

.send-btn svg {
    width: 20px;
    height: 20px;
    margin-left: 2px;
}

/* Voice record button */
.record-btn {
    background: var(--nest-primary);
    color: white;
}

.record-btn.recording {
    background: var(--nest-error);
    animation: pulse 1.2s infinite;
}

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

/* ============================================================
   Call Overlay
   ============================================================ */
.call-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.call-overlay.hidden {
    display: none;
}

.call-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--nest-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    color: white;
    margin-bottom: 16px;
}

.call-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.call-status {
    font-size: 14px;
    color: var(--nest-text-secondary);
    margin-bottom: 48px;
}

.call-actions {
    display: flex;
    gap: 32px;
}

.call-action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

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

.call-action-btn.hangup {
    background: var(--nest-error);
    color: white;
}

.call-action-btn.accept {
    background: var(--nest-accent);
    color: white;
}

.call-action-btn.toggle {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.call-action-btn.toggle.active {
    background: white;
    color: var(--nest-bg);
}

.call-action-btn svg {
    width: 28px;
    height: 28px;
}

/* Video container */
#remoteVideo {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 99;
}

#localVideo {
    position: fixed;
    bottom: 100px;
    right: 16px;
    width: 120px;
    height: 160px;
    border-radius: 12px;
    object-fit: cover;
    z-index: 101;
    border: 2px solid white;
}

/* ============================================================
   Panic Exit Screen
   ============================================================ */
.panic-screen {
    position: fixed;
    inset: 0;
    background: white;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-size: 16px;
}

.panic-screen.hidden {
    display: none;
}

/* ============================================================
   File Upload Preview
   ============================================================ */
.upload-preview {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--nest-card);
    border-top: 1px solid var(--nest-border);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.upload-preview.hidden {
    display: none;
}

.upload-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
}

.upload-preview .file-info {
    flex: 1;
    min-width: 0;
}

.upload-preview .file-name {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-preview .file-size {
    font-size: 12px;
    color: var(--nest-text-secondary);
}

.upload-preview .cancel-upload {
    background: none;
    border: none;
    color: var(--nest-text-secondary);
    cursor: pointer;
    font-size: 20px;
}

/* ============================================================
   Typing indicator
   ============================================================ */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 8px 16px;
    background: var(--nest-received-bubble);
    border-radius: 8px;
    gap: 4px;
    align-items: center;
}

.typing-indicator.visible {
    display: flex;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--nest-text-secondary);
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   Loading state
   ============================================================ */
.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    flex-direction: column;
    gap: 16px;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--nest-border);
    border-top-color: var(--nest-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 480px) {
    .chat-messages {
        padding: 6px 10px;
    }
    
    .message {
        max-width: 85%;
    }
}
