:root {
    --color-bg: #0e1621;
    --color-sidebar: #17212b;
    --color-surface: #17212b;
    --color-surface-hover: #202b36;
    --color-surface-active: #2b5278;
    --color-surface-active-text: #c8d6e0;
    --color-surface-active-text-strong: #ffffff;
    --color-badge-bg: #54a9eb;
    --color-badge-text: #0e1621;
    --color-badge-active-bg: #ffffff;
    --color-badge-active-text: #2b5278;
    --color-primary: #54a9eb;
    --color-primary-dark: #3d8fd1;
    --color-primary-light: #7ec1f5;
    --color-primary-ink: #0e1621;
    --color-accent: #54a9eb;
    --color-accent-dark: #3d8fd1;
    --color-text: #e4e7ea;
    --color-muted: #7c8a97;
    --color-muted-light: #536471;
    --color-border: #0e1621;
    --color-card-border: #223140;
    --color-input-bg: #242f3d;
    --color-input-bg-focus: #2b3946;
    --color-input-bg-solid: #101921;
    --color-input-border: #263543;
    --color-danger: #ef5350;
    --color-danger-text: #ff7b78;
    --color-danger-bg: rgba(239, 83, 80, 0.12);
    --color-danger-border: rgba(239, 83, 80, 0.3);
    --color-success-text: #7ec1f5;
    --color-success-bg: rgba(84, 169, 235, 0.12);
    --color-success-border: rgba(84, 169, 235, 0.3);
    --color-bubble-mine: #2b5278;
    --color-bubble-theirs: #1c2733;
    --color-scrollbar-thumb: #2b3946;
    --color-scrollbar-thumb-hover: #384856;
    --color-wallpaper-dot: rgba(255, 255, 255, 0.035);
    --color-header-shadow: rgba(0, 0, 0, 0.25);
    --color-file-chip-bg: rgba(255, 255, 255, 0.06);
    --color-file-chip-bg-hover: rgba(255, 255, 255, 0.1);
    --color-app-backdrop: #060a10;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 13px;
    --radius-lg: 18px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
    --color-bg: #f5f7fa;
    --color-sidebar: #ffffff;
    --color-surface: #ffffff;
    --color-surface-hover: #f0f3f6;
    --color-surface-active: #e4eef8;
    --color-surface-active-text: var(--color-text);
    --color-surface-active-text-strong: var(--color-text);
    --color-badge-bg: #1a9c6e;
    --color-badge-text: #ffffff;
    --color-badge-active-bg: #1a9c6e;
    --color-badge-active-text: #ffffff;
    --color-primary: #173a5e;
    --color-primary-dark: #0d2540;
    --color-primary-light: #2c5c8f;
    --color-primary-ink: #ffffff;
    --color-accent: #1a9c6e;
    --color-accent-dark: #147d58;
    --color-text: #16202b;
    --color-muted: #65727f;
    --color-muted-light: #93a0ac;
    --color-border: #e3e8ed;
    --color-card-border: #e3e8ed;
    --color-input-bg: #eef1f4;
    --color-input-bg-focus: #ffffff;
    --color-input-bg-solid: #ffffff;
    --color-input-border: #dfe4ea;
    --color-danger: #c0362c;
    --color-danger-text: #c0362c;
    --color-danger-bg: #fbeceb;
    --color-danger-border: #f2cdc9;
    --color-success-text: #147d58;
    --color-success-bg: #e8f6f0;
    --color-success-border: #c3e9d7;
    --color-bubble-mine: #173a5e;
    --color-bubble-theirs: #ffffff;
    --color-scrollbar-thumb: #d4dae0;
    --color-scrollbar-thumb-hover: #bcc4cc;
    --color-wallpaper-dot: rgba(0, 0, 0, 0.03);
    --color-header-shadow: rgba(16, 30, 45, 0.08);
    --color-file-chip-bg: rgba(0, 0, 0, 0.05);
    --color-file-chip-bg-hover: rgba(0, 0, 0, 0.09);
    --color-app-backdrop: #c3cad2;
    --shadow-sm: 0 1px 2px rgba(16, 30, 45, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 30, 45, 0.10);
    --shadow-lg: 0 16px 48px rgba(16, 30, 45, 0.16);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-app-backdrop);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: rgba(84, 169, 235, 0.3);
}

/* Scrollbars */
.contact-list::-webkit-scrollbar,
.messages::-webkit-scrollbar {
    width: 8px;
}

.contact-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: 8px;
}

.contact-list::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

/* ---------- Auth pages ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 10%, rgba(84, 169, 235, 0.08), transparent 45%),
        radial-gradient(circle at 85% 90%, rgba(84, 169, 235, 0.06), transparent 45%),
        var(--color-bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: var(--shadow-md);
    animation: auth-card-in 0.35s ease-out;
}

@keyframes auth-card-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-topbar {
    position: fixed;
    top: 18px;
    right: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.theme-slice {
    display: flex;
    align-items: center;
    padding: 3px;
    border-radius: 20px;
    background: var(--color-input-bg);
    gap: 2px;
}

.theme-slice-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--color-muted);
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.theme-slice-option:hover {
    color: var(--color-text);
}

.theme-slice-option.active {
    background: var(--color-primary);
    color: var(--color-primary-ink);
}

.auth-footer {
    width: 100%;
    max-width: 400px;
    font-size: 11.5px;
    text-align: center;
    color: var(--color-muted-light);
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(84, 169, 235, 0.3);
}

.brand-logo svg {
    width: 20px;
    height: 20px;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-muted);
    margin-bottom: 26px;
}

.field {
    margin-bottom: 18px;
}

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 7px;
    color: var(--color-text);
}

.field input {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-input-bg-solid);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(84, 169, 235, 0.18);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 16px;
    background: var(--color-primary);
    color: var(--color-primary-ink);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

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

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

.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}

.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: var(--color-input-bg-solid);
    color: var(--color-text);
    border: 1.5px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-oauth:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}

.btn-oauth svg {
    flex-shrink: 0;
}

.oauth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    color: var(--color-muted);
    font-size: 12px;
}

.oauth-divider::before,
.oauth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.45;
    margin-bottom: 18px;
}

.alert svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.alert-error {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
    border: 1px solid var(--color-danger-border);
}

.alert-success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
    border: 1px solid var(--color-success-border);
}

.password-strength {
    margin-top: 8px;
    display: none;
    align-items: center;
    gap: 8px;
}

.password-strength.is-visible {
    display: flex;
}

.password-strength-bar {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--color-input-border);
    overflow: hidden;
}

.password-strength-fill {
    height: 100%;
    width: 0;
    border-radius: 2px;
    transition: width 0.2s ease, background 0.2s ease;
}

.password-strength-fill.very-weak { width: 12%; background: #ef5350; }
.password-strength-fill.weak { width: 32%; background: #f2994a; }
.password-strength-fill.fair { width: 58%; background: #f2c94c; }
.password-strength-fill.strong { width: 82%; background: #6fcf73; }
.password-strength-fill.very-strong { width: 100%; background: #27ae60; }

.password-strength-label {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    color: var(--color-muted);
}

.password-strength-label.very-weak,
.password-strength-label.weak { color: #ef5350; }
.password-strength-label.fair { color: #c9960a; }
.password-strength-label.strong,
.password-strength-label.very-strong { color: #219653; }

.auth-links {
    margin-top: 20px;
    font-size: 13px;
    text-align: center;
    color: var(--color-muted);
}

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

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

/* ---------- Chat layout ---------- */

.app-shell {
    display: flex;
    height: calc(100vh - 32px);
    margin: 16px;
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.sidebar {
    width: 320px;
    background: var(--color-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
}

.sidebar-header {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.menu-btn,
.add-contact-toggle-btn {
    color: var(--color-muted);
    background: transparent;
}

.menu-btn:hover,
.add-contact-toggle-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.search-bar {
    position: relative;
    flex: 1;
    min-width: 0;
}

.search-bar .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-muted);
    display: flex;
    pointer-events: none;
}

.search-bar input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: none;
    border-radius: 20px;
    font-size: 13.5px;
    font-family: inherit;
    background: var(--color-input-bg);
    color: var(--color-text);
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.search-bar input::placeholder {
    color: var(--color-muted);
}

.search-bar input:focus {
    outline: none;
    background: var(--color-input-bg-focus);
    box-shadow: 0 0 0 2px rgba(84, 169, 235, 0.3);
}

/* Account menu & add-contact popover */

.popover-backdrop {
    position: fixed;
    inset: 0;
    z-index: 39;
    background: transparent;
}

.account-menu,
.add-contact-popover {
    position: absolute;
    top: 54px;
    z-index: 40;
    background: var(--color-surface);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: popover-in 0.12s ease-out;
}

@keyframes popover-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.account-menu {
    left: 10px;
    width: 240px;
    padding: 6px;
}

.account-menu-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
}

.account-menu-user .avatar {
    width: 38px;
    height: 38px;
    font-size: 14px;
}

.account-menu-user-meta {
    min-width: 0;
}

.account-menu-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-menu-email {
    font-size: 12px;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: 4px 4px;
}

.account-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font-size: 13.5px;
    font-family: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s ease;
}

.account-menu-item:hover {
    background: var(--color-surface-hover);
}

.account-menu-item.account-menu-danger {
    color: var(--color-danger);
}

.account-menu-icon {
    display: flex;
    color: var(--color-muted);
    flex-shrink: 0;
}

.account-menu-danger .account-menu-icon {
    color: var(--color-danger);
}

.add-contact-popover {
    right: 10px;
    width: 260px;
    padding: 14px;
}

.add-contact-popover-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 10px;
}

.add-contact-popover input {
    width: 100%;
    padding: 9px 12px;
    margin-bottom: 10px;
    border: 1.5px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    background: var(--color-input-bg-solid);
    color: var(--color-text);
}

.add-contact-popover input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.filter-tabs {
    display: flex;
    gap: 6px;
    padding: 4px 12px 10px;
}

.filter-tab {
    padding: 6px 14px;
    border: none;
    border-radius: 16px;
    background: var(--color-input-bg);
    color: var(--color-muted);
    font-size: 12.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.filter-tab:hover {
    color: var(--color-text);
}

.filter-tab.active {
    background: var(--color-primary);
    color: var(--color-primary-ink);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 2px 0 8px;
}

.contact-list-empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
    line-height: 1.6;
}

.contact-item {
    padding: 9px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    position: relative;
    transition: background 0.12s ease;
}

.contact-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.contact-preview {
    font-size: 13px;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-item.has-unread .contact-preview {
    color: var(--color-text);
    font-weight: 500;
}

.unread-badge {
    flex-shrink: 0;
    background: var(--color-badge-bg);
    color: var(--color-badge-text);
    font-size: 11.5px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

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

.contact-item.active {
    background: var(--color-surface-active);
}

.contact-item.active .contact-preview,
.contact-item.active .contact-email {
    color: var(--color-surface-active-text);
}

.contact-item.active.has-unread .contact-preview {
    color: var(--color-surface-active-text-strong);
}

.contact-item.active .unread-badge {
    background: var(--color-badge-active-bg);
    color: var(--color-badge-active-text);
}

.contact-item.active .preview-status {
    color: var(--color-surface-active-text);
}

.contact-item.active .preview-status.read {
    color: var(--color-surface-active-text-strong);
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-0 { background: linear-gradient(135deg, #6690f2, #497ae8); }
.avatar-1 { background: linear-gradient(135deg, #4fd170, #2fb852); }
.avatar-2 { background: linear-gradient(135deg, #ffa85c, #f3823a); }
.avatar-3 { background: linear-gradient(135deg, #a684f5, #8c62ec); }
.avatar-4 { background: linear-gradient(135deg, #ff6f88, #f04d6b); }
.avatar-5 { background: linear-gradient(135deg, #3dd1c6, #22b3a8); }
.avatar-6 { background: linear-gradient(135deg, #f5c343, #e8a920); }
.avatar-7 { background: linear-gradient(135deg, #ec6fd8, #d94cc2); }

.chat-header .avatar,
#chat-avatar {
    width: 40px;
    height: 40px;
}

.contact-meta {
    min-width: 0;
    flex: 1;
}

.contact-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--color-text);
}

.contact-email {
    font-size: 12.5px;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.verified-badge {
    color: var(--color-primary);
    flex-shrink: 0;
    display: inline-flex;
}

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg);
    background-image:
        radial-gradient(circle, var(--color-wallpaper-dot) 1px, transparent 1px);
    background-size: 22px 22px;
    min-width: 0;
    position: relative;
}

.chat-header {
    padding: 11px 22px;
    background: var(--color-surface);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 0 var(--color-header-shadow);
}

.chat-header-meta {
    flex: 1;
    min-width: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.header-action-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    color: var(--color-muted);
}

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

.chat-header .contact-name {
    font-size: 15px;
}

.chat-header .contact-email {
    font-size: 12px;
}

.conv-search-bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--color-surface);
    box-shadow: 0 1px 0 var(--color-header-shadow);
}

.conv-search-bar .search-icon {
    color: var(--color-muted);
    display: flex;
    flex-shrink: 0;
}

.conv-search-bar input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    background: var(--color-input-bg);
    color: var(--color-text);
}

.conv-search-bar input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(84, 169, 235, 0.3);
}

.conv-search-count {
    font-size: 12px;
    color: var(--color-muted);
    white-space: nowrap;
    min-width: 32px;
    text-align: center;
}

.conv-search-nav {
    width: 30px;
    height: 30px;
    background: transparent;
    color: var(--color-muted);
}

.conv-search-nav:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.more-options-menu {
    position: absolute;
    top: 54px;
    right: 12px;
    z-index: 40;
    background: var(--color-surface);
    border: 1px solid var(--color-card-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    min-width: 180px;
    animation: popover-in 0.12s ease-out;
}

.bubble.search-match-active {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.contact-status {
    font-size: 12.5px;
    color: var(--color-muted);
    margin-top: 1px;
}

.contact-status.online {
    color: var(--color-primary);
}

.contact-status.typing {
    color: var(--color-accent);
}

.preview-status {
    display: inline-flex;
    flex-shrink: 0;
    margin-right: 3px;
    color: var(--color-muted);
    position: relative;
    top: 1px;
}

.preview-status.read {
    color: var(--color-primary);
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-muted-light);
    gap: 14px;
}

.chat-empty svg {
    opacity: 0.5;
}

.chat-empty p {
    font-size: 14px;
    margin: 0;
    max-width: 240px;
    text-align: center;
    line-height: 1.5;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.date-separator {
    align-self: center;
    background: var(--color-surface);
    color: var(--color-muted);
    font-size: 11.5px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 20px;
    margin: 14px 0 10px;
    box-shadow: var(--shadow-sm);
    text-transform: capitalize;
}

.bubble {
    max-width: 58%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 14.5px;
    line-height: 1.45;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    margin-top: 5px;
    animation: bubble-in 0.18s ease-out;
}

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.bubble .time {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    font-size: 10.5px;
    margin-top: 4px;
    opacity: 0.6;
}

.msg-status {
    display: inline-flex;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.6);
}

.msg-status.read {
    color: #7ec1f5;
}

.bubble.mine {
    align-self: flex-end;
    background: var(--color-bubble-mine);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.bubble.theirs {
    align-self: flex-start;
    background: var(--color-bubble-theirs);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}

.composer {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    background: var(--color-surface);
}

.composer-bar {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--color-input-bg);
    border-radius: 20px;
    padding: 2px;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.composer-bar:focus-within {
    background: var(--color-input-bg-focus);
    box-shadow: 0 0 0 2px rgba(84, 169, 235, 0.3);
}

.composer-bar .attach-btn,
.composer-bar .send-btn {
    width: 36px;
    height: 36px;
}

.composer input {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    border: none;
    font-size: 14.5px;
    font-family: inherit;
    background: transparent;
    color: var(--color-text);
}

.composer input::placeholder {
    color: var(--color-muted);
}

.composer input:focus {
    outline: none;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease;
    padding: 0;
}

.icon-btn:active {
    transform: scale(0.92);
}

.send-btn.recording {
    background: var(--color-danger);
    color: #fff;
}

.recording-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px;
}

.recording-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--color-danger);
    animation: pulse 1.1s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.recording-timer {
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

.recording-hint {
    font-size: 13px;
    color: var(--color-muted);
}

.attach-btn {
    background: transparent;
    color: var(--color-muted);
}

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

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

.send-btn:hover {
    background: var(--color-primary-light);
}

.upload-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 22px;
    font-size: 12.5px;
    color: var(--color-muted);
    background: var(--color-surface);
}

.spinner {
    width: 13px;
    height: 13px;
    border: 2px solid var(--color-scrollbar-thumb);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.bubble img.attachment-image {
    max-width: 260px;
    max-height: 260px;
    border-radius: 10px;
    display: block;
    cursor: pointer;
}

.bubble video.attachment-video {
    max-width: 280px;
    border-radius: 10px;
    display: block;
}

.bubble audio.attachment-audio {
    width: 240px;
    height: 36px;
}

.bubble .attachment-caption {
    display: block;
    margin-top: 6px;
}

.attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    background: var(--color-file-chip-bg);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    max-width: 240px;
    transition: background 0.15s ease;
}

.attachment-file:hover {
    background: var(--color-file-chip-bg-hover);
}

.bubble.mine .attachment-file {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.bubble.mine .attachment-file:hover {
    background: rgba(255, 255, 255, 0.22);
}

.attachment-file-icon {
    flex-shrink: 0;
    display: flex;
}

.attachment-file-meta {
    min-width: 0;
}

.attachment-file-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.attachment-file-size {
    font-size: 11px;
    opacity: 0.75;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 40px;
    animation: lightbox-in 0.15s ease-out;
}

@keyframes lightbox-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.scroll-bottom-btn {
    position: absolute;
    right: 22px;
    bottom: 84px;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 5;
    animation: popover-in 0.12s ease-out;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.scroll-bottom-btn:hover {
    color: var(--color-text);
}

.scroll-bottom-btn:active {
    transform: scale(0.92);
}

.scroll-bottom-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--color-primary);
    color: var(--color-primary-ink);
    font-size: 10.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-card-border);
    border-radius: 20px;
    padding: 10px 18px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    animation: toast-in 0.15s ease-out;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(6px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
    .sidebar {
        width: 100%;
        position: absolute;
        inset: 0;
        z-index: 2;
        transition: transform 0.2s ease;
    }

    .app-shell.chat-open .sidebar {
        transform: translateX(-100%);
    }

    .chat-panel {
        width: 100%;
    }

    .bubble {
        max-width: 82%;
    }
}
