:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-secondary: #64748b;
    --color-secondary-hover: #475569;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-background: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --sidebar-width: 320px;
    --header-height: 64px;
    --input-height: 44px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

/* Login view: margin-auto centers when content fits, top-aligns with
   scroll when it overflows (never clips the headline). */
#auth-container {
    overflow-y: auto;
    align-items: stretch;
}
#auth-container .auth-layout {
    margin: auto;
    min-height: auto;
    width: 100%;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    width: 48px;
    height: 48px;
    color: var(--color-primary);
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: 14px;
}

.auth-form h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    height: var(--input-height);
    padding: 0 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-group input::placeholder {
    color: var(--color-text-muted);
}

/* Password visibility toggle */
.pw-field {
    position: relative;
}

.pw-field input {
    width: 100%;
    padding-right: 44px;
}

.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.pw-toggle:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.pw-toggle:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.pw-toggle svg {
    width: 18px;
    height: 18px;
}

.form-hint {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--input-height);
    padding: 0 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-hover);
}

.btn-full {
    width: 100%;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-icon:hover:not(:disabled) {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn:focus-visible,
.btn-icon:focus-visible,
.tab-btn:focus-visible,
.mobile-tab:focus-visible,
.request-btn:focus-visible,
.modal-close:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.auth-switch {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--color-text-secondary);
}

.auth-switch a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-top: 16px;
    font-size: 13px;
}

.badge {
    background: var(--color-primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--color-border);
}

.avatar-sm {
    width: 32px;
    height: 32px;
}

.avatar-lg {
    width: 56px;
    height: 56px;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-text-secondary);
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--color-text-muted);
}

.status.online::before {
    background: var(--color-success);
}

.status.offline::before {
    background: var(--color-text-muted);
}

.status.away::before {
    background: var(--color-warning);
}

.status.busy::before {
    background: var(--color-danger);
}

.chat-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
}
.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.user-details {
    min-width: 0;
}

.user-details h3 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color var(--transition-fast);
}

.tab-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.tab-btn.active {
    color: var(--color-primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-primary);
    border-radius: 2px 2px 0 0;
}

.tab-btn svg {
    width: 20px;
    height: 20px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.search-box {
    position: relative;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--color-text-muted);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    height: var(--input-height);
    padding: 0 14px 0 44px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--color-background);
    transition: border-color var(--transition-fast);
}

.search-box input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-surface);
}

.conversations-list, .friends-list, .requests-list {
    padding: 8px;
}

.conversation-item, .friend-item, .request-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.conversation-item:hover, .friend-item:hover, .request-item:hover {
    background: var(--color-surface-hover);
}

.conversation-item.active {
    background: var(--color-primary-light);
}

.conversation-item.active .conversation-name {
    color: var(--color-primary);
}

.conversation-avatar, .friend-avatar, .request-avatar {
    flex-shrink: 0;
}

.conversation-info, .friend-info, .request-info {
    flex: 1;
    min-width: 0;
}

.conversation-name, .friend-name, .request-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Online-now strip at the top of the Chats tab. */
.online-strip {
    padding: 4px 12px 10px;
    border-bottom: 1px solid var(--color-border);
}

.online-strip-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin: 4px 4px 8px;
}

.online-strip-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.online-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 56px;
    max-width: 64px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.online-chip-avatar {
    position: relative;
    width: 44px;
    height: 44px;
}

.online-chip-avatar .avatar {
    width: 44px;
    height: 44px;
}

.online-chip-avatar i {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-success);
    border: 2px solid var(--color-surface);
}

.online-chip span:last-child {
    font-size: 11px;
    color: var(--color-text-secondary);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.online-chip:hover span:last-child {
    color: var(--color-text);
}

/* Username shown under the display name (never an email). */
.username-sub {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.user-details .username-sub {
    margin-top: 1px;
}

.chat-username {
    font-size: 11px;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-left: 6px;
    white-space: nowrap;
}

.conversation-preview, .friend-status {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time, .request-time {
    font-size: 11px;
    color: var(--color-text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.conversation-unread {
    flex-shrink: 0;
}

.request-actions {
    display: flex;
    gap: 8px;
    margin-left: 8px;
}

.request-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--color-primary-light);
    color: var(--color-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.request-btn:hover {
    background: var(--color-primary);
    color: white;
}

.request-btn.reject {
    background: #fef2f2;
    color: var(--color-danger);
}

.request-btn.reject:hover {
    background: var(--color-danger);
    color: white;
}

.request-btn svg {
    width: 16px;
    height: 16px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 16px;
    font-size: 14px;
}

.divider {
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer .btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Desktop sidebar collapse (hamburger). Mobile uses .open slide-over. */
#chat-container.sidebar-hidden .sidebar {
    display: none;
}
@media (max-width: 768px) {
    #menu-toggle { display: inline-flex; }
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
}

.chat-back {
    display: none;
    margin-right: 4px;
}

.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    color: var(--color-text-secondary);
}

.chat-welcome svg {
    width: 80px;
    height: 80px;
    margin-bottom: 24px;
    opacity: 0.3;
}

.chat-welcome h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.chat-welcome p {
    font-size: 14px;
}

.chat-area {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    height: var(--header-height);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.chat-header-info h3 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--color-background);
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 700px;
    margin: 0 auto;
}

.message {
    display: flex;
    gap: 8px;
    max-width: 75%;
    animation: fadeIn 0.2s ease;
}

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

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.other {
    align-self: flex-start;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.message-sender {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.message-time {
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
}

.message.own .message-bubble {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.other .message-bubble {
    background: var(--color-surface);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--color-background);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

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

.message-file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-file-size {
    font-size: 11px;
    color: var(--color-text-muted);
}

.message-file-download {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.message-reactions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-left: 4px;
}

.reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.reaction:hover {
    background: var(--color-surface-hover);
}

.reaction.own {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--color-text-secondary);
    font-size: 13px;
    max-width: 700px;
    margin: 0 auto;
}

.typing-indicator span:first-child,
.typing-indicator span:nth-child(2),
.typing-indicator span:nth-child(3) {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--color-text-muted);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

.message-form {
    padding: 16px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

.message-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 700px;
    margin: 0 auto;
}

.input-wrapper {
    flex: 1;
}

#message-input {
    width: 100%;
    min-height: 44px;
    max-height: 150px;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    background: var(--color-background);
    transition: border-color var(--transition-fast);
}

#message-input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-surface);
}

.mobile-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 8px 0;
    z-index: 100;
}

.mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 11px;
    cursor: pointer;
}

.mobile-tab.active {
    color: var(--color-primary);
}

.mobile-tab svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 768px) {
    /* Master-detail: list OR chat, full width. No off-canvas. */
    #chat-container {
        height: 100dvh;
    }
    .sidebar {
        position: static;
        transform: none;
        width: 100%;
        box-shadow: none;
    }
    #main-content {
        display: none;
        width: 100%;
    }
    body.mobile-chat-open #sidebar {
        display: none;
    }
    body.mobile-chat-open #main-content {
        display: flex;
    }
    .chat-back {
        display: inline-flex !important;
    }
    .sidebar-overlay {
        display: none;
    }

    .mobile-tabs {
        display: flex;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    /* Inside an individual chat the bottom bar is hidden so the
       conversation + composer use the freed space (no blank gap). */
    body.mobile-chat-open #mobile-tabs {
        display: none;
    }

    /* Fixed bottom tabs overlay content: keep composer reachable.
       No compensation while the bar is hidden inside a chat. */
    body.mobile-chat-open #main-content {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .chat-header {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .message {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 24px;
    }

    .chat-header {
        padding: 10px 12px;
    }

    .messages-container {
        padding: 12px;
    }

    .message-form {
        padding: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
/* ---- Deliberate dark theme (layered surfaces, not inverted) ---- */
[data-theme="dark"] {
    --color-primary: #60a5fa;
    --color-primary-hover: #93c5fd;
    --color-primary-light: #1e3a8a;
    --color-secondary: #94a3b8;
    --color-secondary-hover: #cbd5e1;
    --color-danger: #f87171;
    --color-danger-hover: #ef4444;
    --color-success: #4ade80;
    --color-warning: #fbbf24;
    --color-background: #0b1220;
    --color-surface: #111c33;
    --color-surface-hover: #1a2947;
    --color-border: #24365c;
    --color-text: #e6edf7;
    --color-text-secondary: #a9bad2;
    --color-text-muted: #64748f;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}
[data-theme="dark"] .reply-quote { background: rgba(255, 255, 255, 0.07); }
[data-theme="dark"] img { opacity: 0.92; }

/* ---- Theme toggle (next to bell) ---- */
#theme-btn .theme-sun { display: none; }
#theme-btn .theme-moon { display: block; }
[data-theme="dark"] #theme-btn .theme-sun { display: block; }
[data-theme="dark"] #theme-btn .theme-moon { display: none; }
#theme-btn svg { width: 20px; height: 20px; }

/* ---- Notification bell + center ---- */
.icon-btn-wrap { position: relative; flex-shrink: 0; }
#notif-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 280px;
    max-width: min(280px, calc(100vw - 24px));
    max-height: 380px;
    overflow-y: auto;
    overflow-x: hidden;
    word-break: break-word;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 600;
}
.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
}
.notif-panel-header button {
    background: transparent;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: 12px;
}
.notif-item { padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--color-primary-light); }
[data-theme="dark"] .notif-item.unread { background: rgba(96, 165, 250, 0.12); }
.notif-item .notif-title { font-weight: 600; }
.notif-item .notif-time { font-size: 11px; color: var(--color-text-muted); }

/* ---- Landing hero (logged-out view, desktop) ---- */
.auth-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    padding: 20px;
    width: 100%;
    max-width: 1024px;
}
.auth-hero-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 48px;
    flex-wrap: wrap;
    width: 100%;
}
.landing-sections { width: 100%; }
.landing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}
.landing-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.landing-card .pt-icon { font-size: 22px; }
.landing-card b { font-size: 14px; }
.landing-card span { color: var(--color-text-secondary); }
.landing-cta {
    margin-top: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.landing-cta b { display: block; }
.landing-cta span { color: var(--color-text-secondary); font-size: 13px; }
.landing-footer {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
    padding: 20px 0 8px;
}
.landing-hero { max-width: 440px; }
.landing-hero .brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.landing-hero .logo { width: 40px; height: 40px; color: var(--color-primary); }
.landing-hero h1 { font-size: 32px; line-height: 1.15; margin-bottom: 12px; }
.landing-hero p.lead { color: var(--color-text-secondary); font-size: 16px; margin-bottom: 20px; }
.landing-points { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.landing-points li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.landing-points .pt-icon { color: var(--color-primary); font-size: 18px; line-height: 1.4; }
.landing-points b { display: block; }
.landing-points span { color: var(--color-text-secondary); }
@media (max-width: 900px) {
    .landing-hero { display: none; }
}
/* Security status rows */
.sec-status { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 14px; }
.sec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-text-muted); flex-shrink: 0; }
.sec-dot.ok { background: var(--color-success); }
.sec-dot.warn { background: var(--color-warning); }
.sec-note { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

/* ---- Connection banner, conv actions, setting select ---- */
.conn-banner {
    background: var(--color-warning);
    color: #1e293b;
    text-align: center;
    font-size: 13px;
    padding: 6px 12px;
}
.conv-actions { display: inline-flex; gap: 2px; margin-left: 6px; }
.mini-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
}
.mini-btn:hover { background: var(--color-surface-hover); color: var(--color-text); }
.setting-select {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-background);
    color: var(--color-text);
}

/* ---- Landing 3D flow visual ---- */
.landing-visual { margin: 20px 0 4px; perspective: 900px; }
.flow-scene {
    position: relative;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background:
        radial-gradient(120px 120px at 15% 20%, rgba(96,165,250,0.16), transparent 70%),
        radial-gradient(140px 140px at 85% 80%, rgba(34,197,94,0.14), transparent 70%),
        var(--color-surface);
    padding: 10px 6px 14px;
    transform-style: preserve-3d;
    animation: sceneFloat 7s ease-in-out infinite;
    overflow: hidden;
}
@keyframes sceneFloat {
    0%, 100% { transform: rotateX(4deg) rotateY(-5deg) translateY(0); }
    50% { transform: rotateX(-3deg) rotateY(5deg) translateY(-6px); }
}
.flow-svg { width: 100%; height: auto; display: block; }
.flow-line {
    stroke-dasharray: 6 8;
    animation: flowDash 1.1s linear infinite;
    opacity: 0.9;
}
.flow-line-2 { animation-duration: 1.5s; opacity: 0.65; }
.flow-line-3 { stroke-dasharray: 3 7; animation-duration: 0.8s; opacity: 0.45; }
@keyframes flowDash { to { stroke-dashoffset: -28; } }
.flow-node circle { fill: var(--color-surface); stroke: var(--color-primary); stroke-width: 2.5; }
.flow-node text { fill: var(--color-text); font-size: 15px; font-weight: 700; }
.flow-node { animation: nodePulse 2.6s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes nodePulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.flow-packet { fill: #22c55e; offset-path: path('M70 110 C 150 40, 250 40, 330 110'); animation: packetMove 2.4s linear infinite; }
.flow-packet-2 { fill: #60a5fa; offset-path: path('M70 110 C 150 180, 250 180, 330 110'); animation-duration: 3s; animation-delay: 0.7s; }
.flow-packet-3 { fill: #f59e0b; offset-path: path('M70 110 L330 110'); animation-duration: 1.8s; animation-delay: 1.2s; }
@keyframes packetMove { from { offset-distance: 0%; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } to { offset-distance: 100%; opacity: 0; } }
.flow-bubble {
    position: absolute;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 9999px;
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    animation: bubbleFloat 4.5s ease-in-out infinite;
}
.flow-bubble-1 { top: 8px; left: 8px; }
.flow-bubble-2 { bottom: 10px; right: 10px; background: #16a34a; animation-delay: 1.4s; }
@keyframes bubbleFloat { 0%, 100% { transform: translateY(0) translateZ(30px); } 50% { transform: translateY(-8px) translateZ(46px); } }
.flow-lock {
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 700;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border-radius: 9999px;
    padding: 3px 10px;
    animation: lockFloat 3.2s ease-in-out infinite;
}
@keyframes lockFloat { 0%, 100% { transform: translate(-50%,-50%) translateZ(60px); } 50% { transform: translate(-50%,-62%) translateZ(80px); } }
/* Scroll reveals */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 500ms ease, transform 500ms ease; }
.reveal.revealed { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
    .flow-scene, .flow-line, .flow-packet, .flow-node, .flow-bubble, .flow-lock { animation: none !important; }
    .reveal { opacity: 1; transform: none; transition: none; }
}

/* ── Premium chat theme (matches landing product mock) ──
   Airy panels, card rows, dark outgoing bubbles, pill composer.
   Visual-only: no layout/display/position changes. */
:root {
    --chat-bg: #f3f6fb;
    --chat-panel: #ffffff;
    --chat-soft: #edf1f7;
    --chat-border: #e3e9f2;
    --chat-ink: #101c33;
    --chat-own-bg: #101c33;
    --chat-own-fg: #ffffff;
    --chat-badge-bg: #101c33;
    --chat-badge-fg: #ffffff;
    --chat-green: #16a34a;
}
[data-theme="dark"] {
    --chat-bg: #0b1220;
    --chat-panel: #111c33;
    --chat-soft: #182747;
    --chat-border: #24365c;
    --chat-ink: #e6edf7;
    --chat-own-bg: #60a5fa;
    --chat-own-fg: #0b1220;
    --chat-badge-bg: #e6edf7;
    --chat-badge-fg: #0b1220;
    --chat-green: #4ade80;
}

/* Sidebar panel + search pill */
.sidebar { background: var(--chat-panel); }
.search-box { border-bottom: 1px solid var(--chat-border); }
.search-box input {
    border-radius: 9999px;
    background: var(--chat-soft);
    border-color: var(--chat-border);
    height: 40px;
}
.search-box input:focus { background: var(--chat-panel); }

/* Conversation rows: soft cards, active row pops like the mock */
.conversation-item,
.friend-item,
.request-item { border-radius: 12px; border: 1px solid transparent; }
.conversation-item:hover,
.friend-item:hover { background: var(--chat-soft); }
.conversation-item.active {
    background: var(--chat-panel);
    border-color: var(--chat-border);
    box-shadow: var(--shadow-md);
}
.conversation-item.active .conversation-name { color: var(--chat-ink); }
.conversation-preview { color: var(--color-text-muted); }
.conversation-time { color: var(--color-text-muted); font-size: 11px; }
#conversations-list .badge {
    background: var(--chat-badge-bg);
    color: var(--chat-badge-fg);
}

/* Chat header: bordered circular action buttons, green presence */
.chat-header { background: var(--chat-panel); border-bottom: 1px solid var(--chat-border); }
.chat-header-actions .btn-icon {
    border: 1px solid var(--chat-border);
    background: var(--chat-panel);
    width: 36px;
    height: 36px;
    color: var(--color-text-secondary);
}
.chat-header-actions .btn-icon:hover:not(:disabled) {
    background: var(--chat-soft);
    color: var(--chat-ink);
    border-color: var(--chat-border);
}
.chat-header-actions .btn-icon svg { width: 17px; height: 17px; }
#chat-status.online { color: var(--chat-green); font-weight: 500; }

/* E2EE lock badge in chat header */
.e2ee-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--chat-green);
    background: color-mix(in srgb, var(--chat-green) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--chat-green) 30%, transparent);
    padding: 1px 7px;
    border-radius: 9999px;
    margin-left: 6px;
    white-space: nowrap;
}

/* Message area + bubbles */
.messages-container {
    background:
        radial-gradient(560px 220px at 70% 0%, rgba(37,99,235,0.06), transparent 60%),
        var(--chat-bg);
}
.message-bubble {
    border-radius: 14px;
    border: 1px solid var(--chat-border);
    box-shadow: 0 1px 2px rgba(15,23,42,0.05);
    font-size: 13.5px;
}
.message.other .message-bubble {
    background: var(--chat-panel);
    color: var(--chat-ink);
    border-bottom-left-radius: 4px;
}
.message.own .message-bubble {
    background: var(--chat-own-bg);
    color: var(--chat-own-fg);
    border-color: transparent;
    border-bottom-right-radius: 4px;
}
.message-sender { color: var(--color-text-secondary); }
.message-time { color: var(--color-text-muted); font-size: 11px; }
.message-status { color: var(--color-text-muted); font-size: 11px; }

/* Typing pill */
.typing-indicator {
    background: var(--chat-panel);
    border: 1px solid var(--chat-border);
    border-radius: 9999px;
    padding: 8px 14px;
    box-shadow: var(--shadow-sm);
}

/* Composer: pill input + dark circular send */
.message-form { background: var(--chat-panel); border-top: 1px solid var(--chat-border); }
#message-input {
    border-radius: 9999px;
    background: var(--chat-soft);
    border-color: var(--chat-border);
    padding: 10px 16px;
}
#message-input:focus { background: var(--chat-panel); }
#send-btn:not(:disabled) {
    background: var(--chat-ink);
    color: var(--chat-panel);
    width: 40px;
    height: 40px;
    box-shadow: var(--shadow-sm);
}
#send-btn:hover:not(:disabled) { background: var(--chat-ink); filter: brightness(1.25); }
#send-btn svg { width: 18px; height: 18px; }

/* Sidebar footer buttons match the softer radius */
.sidebar-footer .btn { border-radius: 12px; }
