:root {
    --bg-app: #111b21;
    --bg-nav: #202c33;
    --bg-panel: #111b21;
    --bg-chat: #0b141a;
    --bg-hover: #202c33;
    --bg-search: #202c33;
    --bg-bubble: #202c33;
    --bg-bubble-mine: #005c4b;
    --border-color: #222d34;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-icon: #aebac1;
    --accent: #00a884;
    --danger: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.8);
}

[data-theme="light"] {
    --bg-app: #f0f2f5; --bg-nav: #f0f2f5; --bg-panel: #ffffff; --bg-chat: #efeae2;
    --bg-hover: #f5f6f6; --bg-search: #f0f2f5; --bg-bubble: #ffffff; --bg-bubble-mine: #d9fdd3;
    --border-color: #e9edef; --text-primary: #111b21; --text-secondary: #667781;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Outfit', sans-serif; transition: background 0.3s ease; }
body { background: var(--bg-app); color: var(--text-primary); height: 100vh; overflow: hidden; display: flex; align-items: center; justify-content: center; }

.d-none { display: none !important; }

/* ---- Auth Flow ---- */
.auth-screen { position: fixed; inset: 0; background: var(--bg-app); z-index: 10000; display: flex; align-items: center; justify-content: center; }
.auth-container { width: 100%; max-width: 380px; padding: 20px; text-align: center; }
.auth-logo-img { width: 120px; height: 120px; border-radius: 25px; box-shadow: var(--shadow-sm); margin-bottom: 25px; }
.input-group { display: flex; gap: 10px; margin: 25px 0; border-bottom: 2px solid var(--accent); padding: 8px; }
.input-group input, .input-group select { background: transparent; border: none; font-size: 1.1rem; color: var(--text-primary); outline: none; }
.primary-btn { width: 100%; background: var(--accent); color: white; border: none; padding: 14px; border-radius: 30px; font-weight: 600; cursor: pointer; transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.primary-btn:hover { transform: scale(1.02); filter: brightness(1.1); }
.otp-input { text-align: center; font-size: 2.5rem; letter-spacing: 12px; }

/* ---- Main UI Layout ---- */
.app-container { display: flex; width: 100vw; height: 100vh; }

/* Nav Bar */
.app-nav { width: 65px; background: var(--bg-nav); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 15px 0; z-index: 100; }
.nav-btn { background: transparent; border: none; color: var(--text-icon); width: 48px; height: 48px; border-radius: 14px; cursor: pointer; font-size: 1.5rem; position: relative; transition: 0.2s; display: flex; align-items: center; justify-content: center; }
.nav-btn.active { background: var(--bg-hover); color: var(--accent); }
.badge { position: absolute; top: 3px; right: 3px; background: var(--accent); color: white; font-size: 0.65rem; border-radius: 10px; padding: 1px 5px; border: 2px solid var(--bg-nav); }

/* Sidebar */
.sidebar-panel { width: 380px; background: var(--bg-panel); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; position: relative; }
.panel-header { padding: 30px 20px 10px; display: flex; justify-content: space-between; align-items: center; }
.panel-header h2 { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }

.search-container { padding: 10px 20px; }
.search-box { background: var(--bg-search); border-radius: 12px; display: flex; align-items: center; padding: 12px 15px; gap: 15px; }
.search-box input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 0.95rem; }

.story-carousel { display: flex; padding: 15px 20px; gap: 18px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border-color); }
.story-item { min-width: 65px; text-align: center; cursor: pointer; }
.story-avatar { position: relative; width: 58px; height: 58px; border-radius: 50%; border: 2.5px solid var(--accent); padding: 2px; }
.story-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.add-icon { position: absolute; bottom: 0; right: 0; background: var(--accent); color: white; border-radius: 50%; width: 20px; height: 20px; font-size: 1rem; border: 2px solid var(--bg-panel); display: flex; align-items: center; justify-content: center; }

.list-container { flex: 1; overflow-y: auto; scrollbar-width: thin; }
.list-item { display: flex; align-items: center; padding: 16px 20px; gap: 15px; cursor: pointer; transition: 0.2s; border-left: 3px solid transparent; }
.list-item:hover, .list-item.active { background: var(--bg-hover); }
.list-item.active { border-left-color: var(--accent); }
.item-avatar img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; }
.item-content { flex: 1; min-width: 0; padding-bottom: 12px; border-bottom: 1px solid var(--border-color); }
.item-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.item-name { font-weight: 600; font-size: 1.1rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 0.75rem; color: var(--text-secondary); }
.item-msg { font-size: 0.88rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Workspace & Welcome Screen */
.chat-workspace { flex: 1; display: flex; background: var(--bg-chat); position: relative; }
.welcome-screen { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
.welcome-logo-img { width: 140px; height: 140px; border-radius: 35px; box-shadow: var(--shadow-lg); margin-bottom: 30px; animation: float 3s infinite ease-in-out; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-15px); } }

/* Active Chat */
.active-chat { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { height: 65px; background: var(--bg-nav); padding: 0 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); }
.chat-user-info { display: flex; align-items: center; gap: 15px; cursor: pointer; }
.chat-avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.user-status.typing { color: var(--accent); font-weight: 600; }

.chat-messages { flex: 1; padding: 25px 8%; overflow-y: auto; 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='%23ffffff' fill-opacity='0.03'%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"); display: flex; flex-direction: column; gap: 10px; }

/* Bubbles */
.msg-row { display: flex; margin-bottom: 2px; perspective: 1000px; }
.sent { justify-content: flex-end; }
.received { justify-content: flex-start; }
.msg-bubble { max-width: 70%; padding: 10px 14px; border-radius: 12px; font-size: 0.98rem; position: relative; box-shadow: var(--shadow-sm); animation: bubblePop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes bubblePop { from { transform: scale(0.9) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.sent .msg-bubble { background: var(--bg-bubble-mine); border-top-right-radius: 0; }
.received .msg-bubble { background: var(--bg-bubble); border-top-left-radius: 0; }
.read { color: #53bdeb; }

/* Media Bubbles */
.media-bubble { padding: 5px !important; }
.media-bubble img { max-width: 320px; border-radius: 10px; display: block; cursor: zoom-in; }

/* Footer */
.chat-footer { background: var(--bg-nav); padding: 12px 20px; display: flex; align-items: flex-end; gap: 12px; }
.message-input-wrapper { flex: 1; background: var(--bg-search); border-radius: 25px; padding: 6px 18px; display: flex; align-items: center; gap: 12px; box-shadow: inset 0 2px 5px rgba(0,0,0,0.1); }
.message-input-wrapper textarea { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 1rem; padding: 8px 0; resize: none; max-height: 150px; }
.action-btn { width: 50px; height: 50px; background: var(--accent); color: white; border-radius: 50%; border: none; font-size: 1.4rem; cursor: pointer; transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.action-btn:hover { transform: scale(1.1) rotate(-10deg); }

/* Overlays & Drawers */
.emoji-drawer { position: absolute; bottom: 85px; left: 20px; width: 320px; height: 260px; background: var(--bg-panel); border-radius: 20px; padding: 20px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; font-size: 1.6rem; overflow-y: auto; border: 1px solid var(--border-color); box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease; }
.emoji-drawer span { cursor: pointer; transition: 0.2s; }
.emoji-drawer span:hover { transform: scale(1.4); }

.attachment-menu { position: absolute; bottom: 85px; left: 60px; background: var(--bg-panel); border-radius: 20px; padding: 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; box-shadow: var(--shadow-lg); border: 1px solid var(--border-color); animation: slideUp 0.3s ease; }
.attach-item { cursor: pointer; text-align: center; }
.attach-item i { width: 60px; height: 60px; border-radius: 50%; background: var(--btn-color); color: white; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; transition: 0.2s; margin-bottom: 8px; }
.attach-item:hover i { transform: scale(1.1); }

/* Story Viewer */
.story-viewer { position: fixed; inset: 0; background: #000; z-index: 30000; display: flex; flex-direction: column; }
.story-progress-container { position: absolute; top: 12px; left: 10px; right: 10px; height: 3px; background: rgba(255,255,255,0.2); }
.story-progress-bar { height: 100%; background: #fff; width: 0; }
.story-header { padding: 40px 20px 20px; display: flex; justify-content: space-between; align-items: center; color: white; }
.story-user { display: flex; align-items: center; gap: 12px; }
.story-user img { width: 45px; height: 45px; border-radius: 50%; border: 2px solid var(--accent); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 50000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(5px); }
.modal-card { width: 340px; background: var(--bg-nav); padding: 25px; border-radius: 20px; border: 1px solid var(--border-color); text-align: center; }
.modal-btns { display: flex; gap: 10px; margin-top: 25px; }

/* Call Card */
.call-overlay { position: fixed; inset: 0; background: rgba(11, 20, 26, 0.9); z-index: 60000; display: flex; align-items: center; justify-content: center; }
.call-card { width: 360px; border-radius: 40px; padding: 60px 20px; text-align: center; background: linear-gradient(145deg, var(--bg-nav), #0b141a); box-shadow: 20px 20px 60px #050a0d, -20px -20px 60px #0f1c24; }
.call-card img { width: 160px; height: 160px; border-radius: 50%; border: 3px solid var(--accent); margin-bottom: 25px; }

/* Mobile Adaptations */
@media (max-width: 768px) {
    .sidebar-panel { width: 100%; }
    .app-nav { position: fixed; bottom: 0; width: 100%; height: 65px; flex-direction: row; padding: 0; }
    .nav-btn { flex: 1; height: 100%; flex-direction: column; }
    .chat-workspace { position: fixed; inset: 0; transform: translateX(100%); transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 500; }
    .chat-workspace.active { transform: translateX(0); }
    .attachment-menu, .emoji-drawer { width: 94%; left: 3%; bottom: 85px; }
}

@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- PWA Install Banner ---- */
.install-banner { position: fixed; bottom: 85px; left: 50%; transform: translateX(-50%); z-index: 100000; background: var(--bg-nav); padding: 10px 20px; border-radius: 20px; border: 1px solid var(--border-color); box-shadow: var(--shadow-lg); width: 92%; max-width: 450px; animation: slideUp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.install-content { display: flex; align-items: center; gap: 15px; }
.install-content img { width: 50px; height: 50px; border-radius: 12px; }
.install-text { flex: 1; }
.install-text h3 { font-size: 1rem; color: var(--text-primary); }
.install-text p { font-size: 0.75rem; color: var(--text-secondary); }
.install-actions { display: flex; align-items: center; gap: 10px; }
.primary-btn.sm { padding: 8px 15px; font-size: 0.85rem; border-radius: 15px; width: auto; }
.icon-btn.sm { width: 30px; height: 30px; font-size: 1rem; }

@media (max-width: 768px) {
    .install-banner { bottom: 80px; }
}
