/* Faheem Chat - extra styling beyond Tailwind utilities */

#messages-container::-webkit-scrollbar,
#conversation-list::-webkit-scrollbar,
#user-search-results::-webkit-scrollbar {
    width: 6px;
}
#messages-container::-webkit-scrollbar-thumb,
#conversation-list::-webkit-scrollbar-thumb,
#user-search-results::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.15s ease;
}
.conversation-item:hover {
    background-color: #f9fafb;
}
.conversation-item.active {
    background-color: #eef2ff;
}

.msg-bubble {
    max-width: min(76%, 34rem);
    padding: 0.6rem 0.9rem;
    border-radius: 1.15rem;
    font-size: 0.875rem;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg-bubble.mine {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    border-bottom-right-radius: 0.25rem;
}
.msg-bubble.theirs {
    background-color: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 0.25rem;
}

.message-row {
    animation: message-in 0.18s ease-out;
}
.message-row-grouped {
    margin-top: -0.5rem;
}
.message-sender {
    color: #9ca3af;
    font-size: 0.6875rem;
    margin: 0 0 0.15rem 0.65rem;
}
.attachment-image {
    display: block;
    margin: 0.35rem -0.3rem -0.25rem;
    overflow: hidden;
    border-radius: 0.85rem;
}
.attachment-image img {
    display: block;
    width: min(18rem, 100%);
    max-height: 18rem;
    object-fit: cover;
}
.attachment-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 14rem;
    margin-top: 0.35rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.7rem;
    background: rgba(255, 255, 255, 0.14);
    text-decoration: none;
}
.theirs .attachment-file {
    background: #f3f4f6;
}
.attachment-file-icon {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.35rem 0.25rem;
    border-radius: 0.35rem;
    background: #dbeafe;
    color: #1d4ed8;
}
.attachment-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    font-size: 0.75rem;
}
.attachment-download {
    font-size: 0.65rem;
    opacity: 0.75;
}
@keyframes message-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.avatar-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background-color: #e0e7ff;
    color: #4338ca;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.online-dot {
    width: 9px;
    height: 9px;
    border-radius: 9999px;
    background-color: #22c55e;
    border: 2px solid white;
}
.offline-dot {
    width: 9px;
    height: 9px;
    border-radius: 9999px;
    background-color: #9ca3af;
    border: 2px solid white;
}

.unread-badge {
    background-color: #4f46e5;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 1.1rem;
    height: 1.1rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.3rem;
}

.user-search-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
}
.user-search-item:hover {
    background-color: #f9fafb;
}
.user-search-item.selected {
    background-color: #eef2ff;
}

/* WhatsApp-inspired application shell */
:root {
    --wa-app: #0b141a;
    --wa-panel: #111b21;
    --wa-header: #202c33;
    --wa-hover: #202c33;
    --wa-active: #2a3942;
    --wa-border: #27343b;
    --wa-text: #e9edef;
    --wa-muted: #8696a0;
    --wa-accent: #00a884;
    --wa-out: #005c4b;
    --wa-in: #202c33;
}

html,
body {
    background: var(--wa-app) !important;
    color: var(--wa-text);
}

#app {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--wa-app);
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.45);
}

@media (display-mode: standalone) {
    html,
    body,
    #app {
        width: 100%;
        min-width: 100%;
        min-height: 100%;
        margin: 0;
    }

    #app {
        box-shadow: none;
    }
}

#app > aside {
    width: 400px;
    min-width: 320px;
    background: var(--wa-panel) !important;
    border-color: var(--wa-border) !important;
}

#app > aside > div:first-child,
#chat-header,
#message-form,
#app > aside > div:last-child {
    background: var(--wa-header) !important;
    border-color: var(--wa-border) !important;
}

#app > aside > div:first-child {
    height: 60px;
}

#app > aside > div:first-child img {
    width: 190px;
    height: 47px;
    object-fit: contain;
    object-position: left center;
}

#new-chat-btn,
#attach-btn,
#close-modal-btn,
#notifications-btn,
#install-app-btn {
    color: var(--wa-muted) !important;
}
#new-chat-btn:hover,
#attach-btn:hover,
#notifications-btn:hover,
#install-app-btn:hover {
    background: var(--wa-hover) !important;
    color: var(--wa-text) !important;
}
.notifications-enabled {
    color: #25d366 !important;
}
.install-app-btn {
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}
.admin-invite-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    height: 2rem;
    padding: 0 0.55rem;
    border: 1px solid rgba(0, 168, 132, 0.45);
    border-radius: 0.45rem;
    background: rgba(0, 168, 132, 0.12);
    color: #25d366;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.admin-invite-btn:hover {
    background: rgba(0, 168, 132, 0.22);
}

#conversation-list,
#messages-container {
    background: var(--wa-panel) !important;
}
#messages-container {
    background-color: var(--wa-app) !important;
    background-image:
        radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.018), transparent 34%),
        radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.018), transparent 38%);
}
#app > main { background: var(--wa-app); }
#messages-container::-webkit-scrollbar-thumb,
#conversation-list::-webkit-scrollbar-thumb,
#user-search-results::-webkit-scrollbar-thumb {
    background: #2a3942;
}

.conversation-item {
    padding: 0.75rem 1rem;
    border-color: rgba(255, 255, 255, 0.035);
}
.conversation-item:hover,
#saved-messages-btn:hover {
    background: var(--wa-hover) !important;
}
.conversation-item.active {
    background: var(--wa-active) !important;
}
.conversation-item p,
#saved-messages-btn p,
#chat-header p {
    color: var(--wa-text) !important;
}
.conversation-item .text-gray-400,
.conversation-item .text-gray-500,
#saved-messages-btn .text-gray-500,
#chat-header .text-gray-400,
#typing-indicator {
    color: var(--wa-muted) !important;
}
#chat-header .text-green-600 { color: #25d366 !important; }
#saved-messages-btn {
    color: var(--wa-text);
    border-color: rgba(255, 255, 255, 0.035) !important;
}

.avatar-circle {
    background: linear-gradient(135deg, #667781, #3b4a54) !important;
    color: #d7e0e5 !important;
}
#saved-messages-btn .avatar-circle {
    background: rgba(0, 168, 132, 0.2) !important;
    color: #25d366 !important;
}
.online-dot { background: #25d366; border-color: var(--wa-panel); }
.offline-dot { background: #667781; border-color: var(--wa-panel); }
.unread-badge { background: #25d366; color: #0b141a; }

#empty-state {
    background: var(--wa-app);
    color: var(--wa-muted);
}
#empty-state .text-gray-400 { color: var(--wa-muted) !important; }

#chat-header {
    height: 60px;
}
#chat-header .avatar-circle {
    width: 40px;
    height: 40px;
}
.chat-back-btn {
    display: none;
    width: 2rem;
    height: 2rem;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--wa-muted);
    font-size: 1.35rem;
    cursor: pointer;
}
.chat-back-btn:hover { background: var(--wa-hover); color: var(--wa-text); }
#message-form {
    padding: 0.65rem 1rem;
}
#message-input {
    min-height: 42px;
    background: #2a3942 !important;
    border: 0 !important;
    border-radius: 1.5rem;
    color: var(--wa-text) !important;
    box-shadow: none !important;
}
#message-input::placeholder { color: var(--wa-muted); }
#message-input:focus { outline: 2px solid rgba(0, 168, 132, 0.3); }
#send-btn {
    background: var(--wa-accent) !important;
    color: #0b141a !important;
}
#send-btn:hover { background: #02c39a !important; }
#file-preview {
    background: #2a3942 !important;
    color: var(--wa-text) !important;
}
.upload-limit-hint {
    flex-shrink: 0;
    color: var(--wa-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}
.upload-progress {
    padding: 0.45rem 1rem 0.55rem;
    background: var(--wa-header);
    color: var(--wa-muted);
    font-size: 0.7rem;
}
.upload-progress-top {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.3rem;
}
.upload-progress-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.upload-spinner {
    width: 0.75rem;
    height: 0.75rem;
    flex-shrink: 0;
    border: 2px solid rgba(134, 150, 160, 0.35);
    border-top-color: var(--wa-accent);
    border-radius: 50%;
    animation: upload-spin 0.75s linear infinite;
}
.is-sending #attach-btn {
    cursor: wait;
    opacity: 0.5;
}
.upload-progress-track {
    height: 0.25rem;
    overflow: hidden;
    border-radius: 999px;
    background: #2a3942;
}
.upload-progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--wa-accent);
    transition: width 0.12s ease-out;
}
@keyframes upload-spin {
    to { transform: rotate(360deg); }
}

.msg-bubble {
    max-width: min(65%, 34rem);
    padding: 0.4rem 0.6rem 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.25);
}
.msg-bubble.mine {
    background: var(--wa-out);
    border-bottom-right-radius: 0;
}
.msg-bubble.theirs {
    background: var(--wa-in);
    color: var(--wa-text);
    border: 0;
    border-bottom-left-radius: 0;
}
.message-row { margin: 0.125rem 0; }
.message-row-grouped { margin-top: -0.125rem; }
.message-sender { color: #53bdeb; }
.attachment-file { background: rgba(0, 0, 0, 0.16); }
.theirs .attachment-file { background: rgba(255, 255, 255, 0.06); }
.attachment-file-icon { background: rgba(0, 168, 132, 0.22); color: #25d366; }
.attachment-download { color: var(--wa-muted); }

#new-chat-modal {
    background: rgba(0, 0, 0, 0.65) !important;
}
#new-chat-modal > div {
    background: var(--wa-panel) !important;
    color: var(--wa-text);
    border: 1px solid var(--wa-border);
}
#new-chat-modal input,
#new-chat-modal .user-search-item,
#new-chat-modal .border-gray-100 {
    background: var(--wa-header) !important;
    border-color: var(--wa-border) !important;
    color: var(--wa-text) !important;
}
#new-chat-modal input::placeholder { color: var(--wa-muted); }
#new-chat-modal .text-gray-800,
#new-chat-modal .text-gray-600,
#new-chat-modal .text-gray-400 { color: var(--wa-text) !important; }
#new-chat-modal .text-gray-400 { color: var(--wa-muted) !important; }
#create-chat-btn,
.chat-mode-btn.bg-indigo-600 { background: var(--wa-accent) !important; border-color: var(--wa-accent) !important; color: #0b141a !important; }
.admin-invite-modal-btn {
    width: 100%;
    margin: -0.35rem 0 0.75rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(0, 168, 132, 0.45);
    border-radius: 0.5rem;
    background: rgba(0, 168, 132, 0.12);
    color: #25d366;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.admin-invite-modal-btn:hover { background: rgba(0, 168, 132, 0.22); }

@media (max-width: 760px) {
    html,
    body { width: 100%; min-width: 0; overflow: hidden; }
    #app { width: 100vw; max-width: 100vw; min-height: 100svh; height: 100svh; }
    #app > aside {
        width: 100%;
        min-width: 0;
    }
    #app > main { display: none !important; width: 100%; min-width: 0; min-height: 0; }
    #app.chat-open > aside { display: none; }
    #app.chat-open > main { display: flex !important; width: 100%; height: 100%; }
    #app.chat-open #chat-panel { display: flex !important; width: 100%; height: 100%; }
    .chat-back-btn { display: inline-flex; }
    #chat-header { padding: 0 0.75rem; gap: 0.5rem; }
    #messages-container { padding: 0.75rem; }
    #message-form {
        padding: 0.5rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        gap: 0.35rem;
    }
    #message-input { min-width: 0; }
    .upload-limit-hint { display: none; }
    .msg-bubble { max-width: 82%; }
}

@media (min-width: 761px) and (max-width: 1100px) {
    #app > aside { width: 300px; min-width: 280px; }
    #app > aside > div:first-child img { width: 155px; }
    #messages-container { padding-left: 1.25rem; padding-right: 1.25rem; }
    .msg-bubble { max-width: 74%; }
}

@media (max-width: 420px) {
    #app > aside > div:first-child img { width: 145px; }
    #app > aside > div:last-child { padding-left: 0.75rem; padding-right: 0.75rem; }
    #app > aside > div:last-child form button { font-size: 0.7rem; }
    #file-preview { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
