/* 
    Minimalist Black & White Theme for ChatApp
    Focuses on typography, whitespace, and micro-animations.
*/

:root {
    /* Color Palette - Minimalist B&W */
    --bg-main: #f9f9f9;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f0f0f0;
    
    --text-primary: #111111;
    --text-secondary: #666666;
    --text-muted: #999999;
    
    --border-color: #e5e5e5;
    
    --accent: #000000;
    --accent-hover: #333333;
    --accent-text: #ffffff;
    
    --danger: #ff3333;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.12);
    
    /* Layout */
    --sidebar-width: 320px;
    --header-height: 60px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-pill: 9999px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.2, 0, 0, 1);
}

/* Dark Theme Variables */
[data-theme="dark"] {
    --bg-main: #111111;
    --bg-surface: #1e1e1e;
    --bg-surface-hover: #2a2a2a;
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    
    --border-color: #333333;
    
    --accent: #ffffff;
    --accent-hover: #e0e0e0;
    --accent-text: #000000;
    
    --danger: #ff5555;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.5);
}
[data-theme="dark"] .auth-error {
    background: #3a1111;
    border-color: #5a2222;
}
[data-theme="dark"] .message-wrapper.theirs .message-bubble {
    background: var(--bg-surface);
    border-color: var(--border-color);
}

/* Smooth theme transition */
body, .sidebar, .chat-main, .chat-header, .message-input-bar,
.glass-card, .auth-container, .message-bubble, .profile-panel,
.dropdown-menu, .modal-overlay {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Material Symbols Adjustments */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

/* Utilities */
.hidden { display: none !important; }

/* Global Loader */
.global-loader {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: var(--text-primary);
    transition: opacity var(--transition-normal);
}
.global-loader .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.glass-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-lg);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-normal);
    border: none;
    outline: none;
    gap: 0.5rem;
}
.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
}
.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn-secondary {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: #e0e0e0;
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}
.btn-full { width: 100%; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}
.icon-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* Forms & Inputs */
.input-group {
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition-fast);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

/* AUTH SCREENS */
.auth-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    animation: fadeScale 0.4s var(--transition-normal);
}
.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.logo-icon-large {
    font-size: 48px;
    color: var(--accent);
    margin-bottom: 1rem;
}
.auth-logo h1 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}
.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}
.auth-links {
    margin-top: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.auth-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: var(--transition-fast);
}
.auth-links a:hover {
    color: var(--accent);
}
.auth-error {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #fff0f0;
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    text-align: center;
    border: 1px solid #ffcccc;
}

/* MAIN APP LAYOUT */
.chat-app {
    display: flex;
    height: 100vh;
    background: var(--bg-main);
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    position: relative;
}
.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}
.sidebar-user-text {
    display: flex;
    flex-direction: column;
}
.sidebar-username {
    font-weight: 600;
    font-size: 0.95rem;
}
.sidebar-status-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.avatar {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    flex-shrink: 0;
}
.avatar img, img.avatar {
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.avatar-sm { width: 36px; height: 36px; font-size: 1rem; }
.avatar-md { width: 48px; height: 48px; font-size: 1.25rem; }
.avatar-lg { width: 100px; height: 100px; font-size: 2.5rem; }
img.avatar-sm { width: 36px; height: 36px; }
img.avatar-md { width: 48px; height: 48px; }
img.avatar-lg { width: 100px; height: 100px; }

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 60px;
    right: 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    min-width: 200px;
    z-index: 1000;
    padding: 0.5rem 0;
}
.dropdown-item {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: var(--transition-fast);
}
.dropdown-item:hover {
    background: var(--bg-surface-hover);
}
.dropdown-item.danger {
    color: var(--danger);
}
.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

.sidebar-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}
.search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.search-input-wrap .search-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    font-size: 18px;
}
.search-input-wrap input {
    padding-left: 2.5rem;
    background: var(--bg-main);
    border-radius: var(--radius-pill);
    border: none;
}
.search-input-wrap input:focus {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}
.contact-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 1rem;
    cursor: pointer;
    transition: var(--transition-fast);
    border-bottom: 1px solid transparent;
}
.contact-item:hover {
    background: var(--bg-main);
}
.contact-item.active {
    background: var(--bg-surface-hover);
}
.contact-info {
    flex: 1;
    overflow: hidden;
}
.contact-name {
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.contact-status-indicator {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.unread-badge {
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-pill);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}
.empty-state p { margin-top: 1rem; font-weight: 500; color: var(--text-secondary); }
.empty-state span { font-size: 0.85rem; }

/* MAIN CHAT AREA */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    position: relative;
}
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
}
.empty-chat-icon {
    font-size: 64px;
    color: var(--border-color);
    margin-bottom: 1.5rem;
}

.chat-active {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.chat-header {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}
.back-btn { display: none; }
.chat-header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}
.chat-header-info h3 { font-size: 1rem; font-weight: 600; }
.chat-status { font-size: 0.75rem; color: var(--text-secondary); }

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto; /* Push to bottom */
}
.message-wrapper {
    display: flex;
    max-width: 75%;
    animation: fadeUp 0.3s var(--transition-normal);
}
.message-wrapper.mine {
    align-self: flex-end;
}
.message-wrapper.theirs {
    align-self: flex-start;
}
.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    position: relative;
    font-size: 0.95rem;
}
.message-wrapper.theirs .message-bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 2px;
}
.message-wrapper.mine .message-bubble {
    background: var(--accent);
    color: var(--accent-text);
    border-bottom-right-radius: 2px;
}

/* Media in Messages */
.message-media-img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    cursor: pointer;
}
.message-media-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0,0,0,0.05);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: inherit;
}
.message-wrapper.mine .message-media-file {
    background: rgba(255,255,255,0.1);
}

/* Polls in Messages */
.message-poll {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 200px;
}
.poll-question {
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.poll-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.05);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.message-wrapper.mine .poll-option {
    background: rgba(255,255,255,0.1);
}
.poll-option:hover {
    filter: brightness(0.95);
}
.poll-progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: rgba(0,0,0,0.1);
    z-index: 0;
}
.message-wrapper.mine .poll-progress {
    background: rgba(255,255,255,0.2);
}
.poll-label, .poll-votes {
    position: relative;
    z-index: 1;
    font-size: 0.85rem;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    margin-top: 0.25rem;
    opacity: 0.7;
    justify-content: flex-end;
}
.message-wrapper.theirs .message-meta {
    justify-content: flex-start;
}

/* Message Input Area */
.media-preview-container {
    padding: 0.5rem 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.media-preview-img {
    height: 40px;
    border-radius: var(--radius-sm);
}
.media-preview-filename {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.message-input-bar {
    padding: 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}
.message-input-wrap {
    flex: 1;
    background: var(--bg-main);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
}
.message-input-wrap textarea {
    width: 100%;
    border: none;
    background: transparent;
    resize: none;
    max-height: 120px;
    padding: 0;
}
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}
.send-btn:disabled {
    background: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    width: 100%;
    max-width: 400px;
    animation: fadeScale 0.3s var(--transition-normal);
}
.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h2 { font-size: 1.25rem; }
.modal-body { padding: 1.5rem; }

/* Search Results & Sessions */
.search-results, .sessions-list {
    margin-top: 1rem;
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.search-result-item, .session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: var(--bg-main);
    border: 1px solid var(--border-color);
}
.search-result-info, .session-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
}
.session-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.session-device {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.session-badge {
    background: var(--accent);
    color: var(--accent-text);
    padding: 2px 6px;
    border-radius: var(--radius-pill);
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Profile Panel */
.profile-panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: 340px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    z-index: 100;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
    transform: translateX(0);
}
.profile-panel.hidden {
    transform: translateX(100%);
    display: flex !important; /* Keep flex for transition */
}
.profile-panel-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}
.profile-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
}
.profile-pfp-wrapper {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 2rem auto;
}
.profile-avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 2.5rem;
    text-transform: uppercase;
    overflow: hidden;
    flex-shrink: 0;
}
img.profile-avatar-large {
    display: block;
}
.edit-pfp-btn {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: var(--accent);
    color: white;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}
.edit-pfp-btn:hover {
    background: var(--accent-hover);
    color: white;
}
.profile-field {
    margin-bottom: 1.25rem;
}
.profile-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}
.profile-readonly {
    display: block;
    padding: 0.75rem;
    background: var(--bg-main);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    user-select: all;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}
.toast {
    padding: 12px 20px;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
    animation: slideIn 0.3s ease forwards;
}
.toast.toast-error { background: var(--danger); }

/* Animations */
@keyframes fadeScale {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.typing-dots {
    display: flex;
    gap: 3px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        height: 100%;
    }
    .sidebar.hidden-mobile { display: none; }
    .chat-main.active-mobile {
        display: flex;
        z-index: 20;
        position: absolute;
        width: 100%;
        height: 100%;
    }
    .back-btn { display: inline-flex; }
    .profile-panel { width: 100%; }
    .auth-card {
        margin: 1rem;
        padding: 1.5rem;
    }
    .modal {
        max-width: calc(100% - 2rem);
        margin: 1rem;
    }
    .message-wrapper {
        max-width: 88%;
    }
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .message-input-bar {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
    .icon-btn {
        width: 44px;
        height: 44px;
    }
    .contact-item {
        padding: 0.875rem 1rem;
    }
}
