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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    overflow: hidden;
}

.auth-page {
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #075E54 0%, #128C7E 100%);
}
.auth-container {
    background: white; border-radius: 12px; padding: 40px;
    width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.auth-header { text-align: center; margin-bottom: 30px; }
.auth-header h1 { color: #075E54; font-size: 28px; margin-bottom: 8px; }
.auth-header p { color: #666; font-size: 14px; }
.tabs { display: flex; margin-bottom: 20px; border-bottom: 2px solid #eee; }
.tab { flex: 1; padding: 12px; border: none; background: none; cursor: pointer; font-size: 16px; color: #666; }
.tab.active { color: #075E54; border-bottom: 2px solid #075E54; margin-bottom: -2px; }
.auth-form input { width: 100%; padding: 14px; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 8px; font-size: 15px; }
.auth-form button { width: 100%; padding: 14px; background: #075E54; color: white; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; }
.auth-form button:hover { background: #128C7E; }
.hidden { display: none !important; }
.alert { padding: 12px; border-radius: 8px; margin-bottom: 15px; font-size: 14px; }
.alert.error { background: #ffebee; color: #c62828; }
.alert.success { background: #e8f5e9; color: #2e7d32; }

.app-container { display: flex; height: 100vh; max-width: 1400px; margin: 0 auto; background: white; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
.sidebar { width: 350px; border-right: 1px solid #e0e0e0; display: flex; flex-direction: column; background: white; }
.sidebar-header { background: #075E54; color: white; padding: 15px; display: flex; justify-content: space-between; align-items: center; }
.user-info { display: flex; align-items: center; gap: 12px; }
.user-info small { display: block; opacity: 0.8; font-size: 12px; }
.logout-btn { color: white; text-decoration: none; font-size: 13px; padding: 6px 12px; border: 1px solid rgba(255,255,255,0.3); border-radius: 4px; }
.search-box { padding: 12px; display: flex; gap: 8px; background: #f8f8f8; border-bottom: 1px solid #e0e0e0; }
.search-box input { flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 20px; outline: none; }
.search-box button { padding: 10px 16px; background: #075E54; color: white; border: none; border-radius: 20px; cursor: pointer; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { display: flex; align-items: center; padding: 12px 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; }
.chat-item:hover, .chat-item.active { background: #f5f5f5; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: #128C7E; color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; margin-right: 12px; flex-shrink: 0; }
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 500; margin-bottom: 4px; }
.chat-preview { font-size: 13px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 12px; color: #999; margin-left: 8px; }
.no-chats { padding: 30px; text-align: center; color: #999; }

.chat-area {
    flex: 1; display: flex; flex-direction: column; position: relative;
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.chat-header { background: #075E54; color: white; padding: 12px 20px; display: flex; align-items: center; }
.chat-user { display: flex; align-items: center; gap: 12px; }
.chat-user small { display: block; opacity: 0.8; font-size: 12px; }
.no-chat { color: rgba(255,255,255,0.7); font-style: italic; }

.messages-container {
    flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 80px;
    display: flex; flex-direction: column; gap: 8px;
}

.message { display: flex; flex-direction: column; max-width: 70%; min-width: 0; }
.message.sent { align-self: flex-end; align-items: flex-end; }
.message.received { align-self: flex-start; align-items: flex-start; }

.message-bubble {
    padding: 8px 12px; border-radius: 8px; line-height: 1.4; max-width: 100%;
    white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
    position: relative;
}
.message-bubble a { color: #4fc3f7; text-decoration: underline; overflow-wrap: anywhere; word-break: break-all; }
.message.sent .message-bubble { background: #dcf8c6; border-top-right-radius: 0; }
.message.received .message-bubble { background: white; border-top-left-radius: 0; }

.message-time {
    font-size: 11px; color: #999; margin-top: 4px;
    display: flex; align-items: center; justify-content: flex-end; gap: 3px;
}
.ticks { font-size: 14px; line-height: 1; margin-left: 2px; }
.ticks.sent, .ticks.delivered { color: #999; }
.ticks.read { color: #34b7f1; }

.media-bubble {
    padding: 4px !important;
    overflow: hidden;
    max-width: 100%;
}

.msg-media {
    max-width: 220px; max-height: 200px; border-radius: 6px;
    display: block; cursor: pointer;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none; -webkit-user-drag: none;
}

.media-grid {
    display: grid;
    gap: 4px;
    max-width: 340px;
    width: 100%;
}
.media-grid.grid-2, .media-grid.grid-3, .media-grid.grid-4 { grid-template-columns: 1fr 1fr; }

.grid-item {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    cursor: pointer;
    aspect-ratio: 1;
    background: #222;
    max-width: 100%;
    min-height: 150px;
}
.grid-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid-more {
    position: absolute; inset: 0; background: rgba(0,0,0,0.5);
    color: white; display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: bold;
}

.video-thumb {
    width: 200px; min-height: 250px; height: 120px; background: #333; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    position: relative; overflow: hidden;
}
.video-thumb.small {
    width: 100%;
    height: 100%;
    min-height: 150px;
    max-width: 100%;
    border-radius: 6px;
    overflow: hidden;
}
.play-icon { font-size: 40px; color: white; position: relative; z-index: 2; }

.video-poster {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: inherit;
    pointer-events: none;
}

.doc-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    max-width: 260px;
}
.doc-card:hover { background: #eee; }
.doc-icon { font-size: 28px; }
.doc-name { font-size: 14px; color: #333; word-break: break-all; }

.doc-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    background: #f5f5f5;
}
.doc-name-small {
    font-size: 11px;
    color: #333;
    text-align: center;
    word-break: break-all;
    max-height: 32px;
    overflow: hidden;
}

.doc-text-view {
    background: white;
    color: #333;
    padding: 16px;
    max-height: 75vh;
    overflow-y: auto;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: monospace;
    font-size: 14px;
    border-radius: 8px;
}

.doc-preview-card {
    background: white;
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    max-width: 320px;
}
.doc-icon-large { font-size: 64px; margin-bottom: 12px; }
.doc-name-large { font-size: 16px; color: #333; margin-bottom: 16px; word-break: break-all; }
.doc-open-btn {
    display: inline-block;
    background: #075E54;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
}
.doc-open-btn:hover { background: #128C7E; }

.message-input {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex; align-items: flex-end; padding: 8px 10px;
    background: #f0f0f0; gap: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 50;
}
.message-input .input-wrapper {
    flex: 1; display: flex; align-items: flex-end; background: white;
    border-radius: 24px; padding: 6px 10px; gap: 6px; min-height: 48px;
}
.message-input .emoji-btn, .message-input .attach-btn {
    background: none; border: none; font-size: 22px; cursor: pointer;
    padding: 4px; color: #54656f; flex-shrink: 0; line-height: 1;
}
.message-input textarea {
    flex: 1; border: none; outline: none; font-size: 15px; font-family: inherit;
    resize: none; max-height: 120px; overflow: hidden; line-height: 1.4;
    padding: 8px 0; background: transparent; scrollbar-width: none; -ms-overflow-style: none;
}
.message-input textarea::-webkit-scrollbar { display: none; }
.message-input .send-btn {
    width: 48px; height: 48px; border-radius: 50%; background: #00a884;
    border: none; color: white; font-size: 20px; cursor: pointer;
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.message-input .send-btn:hover { background: #008f72; }

.emoji-picker {
    position: absolute; bottom: 70px; left: 8px; right: 8px; max-width: 360px;
    background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 100; padding: 8px; max-height: 260px; overflow: hidden;
    display: flex; flex-direction: column;
}
.emoji-categories { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; border-bottom: 1px solid #eee; flex-shrink: 0; }
.emoji-cat-btn { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.emoji-cat-btn:hover { background: #f0f0f0; }
.emoji-list { display: flex; flex-wrap: wrap; gap: 2px; overflow-y: auto; padding-top: 6px; flex: 1; }
.emoji-item { font-size: 22px; cursor: pointer; padding: 4px; border-radius: 4px; line-height: 1; }
.emoji-item:hover { background: #f0f0f0; }

.attach-panel {
    position: absolute; bottom: 70px; left: 8px; right: 8px; max-width: 280px;
    background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 90; padding: 12px; display: flex; gap: 12px; justify-content: space-around;
}
.attach-option {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    background: none; border: none; cursor: pointer; font-size: 13px; color: #333;
    padding: 8px; border-radius: 8px;
}
.attach-option:hover { background: #f5f5f5; }
.attach-icon { font-size: 28px; }

.media-viewer {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.media-viewer-content { position: relative; max-width: 95%; max-height: 90%; text-align: center; }
.media-close {
    position: absolute; top: -40px; right: 0;
    background: none; border: none; color: white; font-size: 28px; cursor: pointer; z-index: 10;
}

.media-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    border: none;
    color: white;
    font-size: 36px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
.media-prev { left: 10px; }
.media-next { right: 10px; }
.media-nav:hover { background: rgba(0,0,0,0.7); }

#media-container { overflow: auto; max-height: 75vh; }
.media-viewer video::-webkit-media-controls,
.media-viewer video::-webkit-media-controls-enclosure,
.media-viewer video::-webkit-media-controls-panel,
.media-viewer video::-webkit-media-controls-play-button,
.media-viewer video::-webkit-media-controls-start-playback-button {
    display: none !important; opacity: 0 !important; pointer-events: none !important;
}
.media-controls { display: none !important; }

.back-btn { display: none; background: none; border: none; color: white; font-size: 22px; margin-right: 8px; cursor: pointer; padding: 4px 8px; }

@media (max-width: 768px) {
    html, body { height: 100%; height: 100dvh; }
    .app-container { max-width: 100%; height: 100%; height: 100dvh; }
    .sidebar { width: 100%; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 10; }
    .chat-area { width: 100%; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 20; display: none; }
    .chat-area.active { display: flex; }
    .sidebar.hidden-mobile { display: none; }
    .back-btn { display: inline-block; }
    .chat-header { padding: 10px 12px; }
    .message { max-width: 80%; }
    .messages-container { padding-bottom: 90px; }
    .message-input {
        position: fixed; bottom: 0; left: 0; right: 0;
        padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); z-index: 60;
    }
    .emoji-picker, .attach-panel {
        position: fixed; bottom: 70px; left: 8px; right: 8px; z-index: 70;
    }
    .sidebar-header { padding: 12px; }
    .search-box { padding: 10px; }
}

.pdf-wrapper {
    width: 100%;
    height: 80vh;
    position: relative;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}
.pdf-wrapper embed {
    width: 100%;
    height: 100%;
}
.pdf-fallback {
    display: none;
    padding: 24px;
    text-align: center;
}

.ms-icon {
    width: 36px;
    height: 36px;
    display: block;
    flex-shrink: 0;
}
.doc-icon-large .ms-icon {
    width: 64px;
    height: 64px;
}
.doc-icon .ms-icon,
.doc-grid-item .ms-icon {
    width: 32px;
    height: 32px;
}

.audio-card {
    display: flex;
    flex-direction: column;
    min-width: 220px;
    max-width: 280px;
    padding: 8px;
    background: #f0f0f0;
    border-radius: 8px;
}
.audio-icon {
    font-size: 28px;
    text-align: center;
}
.audio-name {
    font-size: 12px;
    color: #333;
    text-align: center;
    margin: 4px 0;
    word-break: break-all;
}

.voice-bubble {
    padding: 6px 8px !important;
    background: #dcf8c6 !important;
    min-width: 260px;
    max-width: 300px;
}
.message.received .voice-bubble {
    background: #fff !important;
}
.voice-note {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}
.voice-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #075E54;
    color: white;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.voice-wave {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2px;
    height: 32px;
    cursor: pointer;
}
.voice-bar {
    flex: 1;
    background: #b0b0b0;
    border-radius: 1px;
    min-width: 2px;
    transition: background 0.1s;
}
.voice-bar.played {
    background: #34b7f1;
}
.voice-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 11px;
    color: #666;
    min-width: 50px;
}
.voice-dur {
    font-weight: 500;
}
.voice-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #075E54;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
    font-size: 14px;
}

.upload-status {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #075E54;
    color: white;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 80;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.msg-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}
.msg-modal.hidden { display: none !important; }
.msg-modal-box {
    background: white;
    width: 100%;
    max-width: 420px;
    border-radius: 16px 16px 0 0;
    padding: 8px 0 20px;
    animation: slideUp 0.2s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.msg-modal-title {
    text-align: center;
    font-size: 13px;
    color: #666;
    padding: 10px 16px 6px;
    border-bottom: 1px solid #eee;
}
.msg-modal-btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    border: none;
    background: none;
    text-align: left;
    font-size: 16px;
    color: #111;
    cursor: pointer;
}
.msg-modal-btn:active { background: #f5f5f5; }
.msg-modal-btn.danger { color: #e53935; }
.msg-modal-btn.cancel {
    text-align: center;
    color: #075E54;
    font-weight: 500;
    border-top: 8px solid #f0f0f0;
    margin-top: 4px;
}

/* Thin dark bar with bold dots */
.message-bubble {
    position: relative !important;
    padding-top: 8px !important;
    padding-right: 4px !important;
}
.msg-menu-btn {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    width: auto !important;
    min-width: 22px !important;
    height: 10px !important;
    line-height: 10px !important;
    font-size: 11px !important;
    font-weight: 900 !important;
    letter-spacing: 1px !important;
    background: rgba(0,0,0,0.25) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 0 5px 0 5px !important;
    padding: 0 4px !important;
    margin: 0 !important;
    opacity: 1 !important;
    z-index: 5 !important;
    cursor: pointer !important;
    text-shadow: 0 0 1px #000 !important;
}
.media-bubble {
    padding-top: 8px !important;
    padding-right: 2px !important;
}
.media-bubble .msg-menu-btn {
    top: 0 !important;
    right: 0 !important;
    background: rgba(0,0,0,0.4) !important;
    color: #fff !important;
}