/* ============================================================
   FONT DECLARATIONS — Emerald & Gold Design System
   Fonts are bundled in /fonts/ (offline-capable via SW cache)
   ============================================================ */

/* Tajawal — 5 weights, bilingual (Arabic + Latin) */
@font-face {
    font-family: 'Tajawal';
    font-weight: 300;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/tajawal/tajawal-300.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC;
}
@font-face {
    font-family: 'Tajawal';
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/tajawal/tajawal-400.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC;
}
@font-face {
    font-family: 'Tajawal';
    font-weight: 500;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/tajawal/tajawal-500.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC;
}
@font-face {
    font-family: 'Tajawal';
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/tajawal/tajawal-700.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC;
}
@font-face {
    font-family: 'Tajawal';
    font-weight: 900;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/tajawal/tajawal-900.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF, U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC;
}

/* Be Vietnam Pro — 4 files (400, 400-italic, 500, 700), Latin */
@font-face {
    font-family: 'Be Vietnam Pro';
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/be-vietnam-pro/be-vietnam-pro-400.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Be Vietnam Pro';
    font-weight: 400;
    font-style: italic;
    font-display: swap;
    src: url('/fonts/be-vietnam-pro/be-vietnam-pro-400-italic.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Be Vietnam Pro';
    font-weight: 500;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/be-vietnam-pro/be-vietnam-pro-500.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Be Vietnam Pro';
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    src: url('/fonts/be-vietnam-pro/be-vietnam-pro-700.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Material Symbols Outlined — single variable font (FILL 0..1, wght 100..700) */
@font-face {
    font-family: 'Material Symbols Outlined';
    font-weight: 100 700;
    font-style: normal;
    font-display: block;
    src: url('/fonts/material-symbols/material-symbols-outlined.woff2') format('woff2');
}

/* ============================================================
   MATERIAL SYMBOLS OUTLINED — Base class
   CRITICAL: direction: ltr prevents RTL glyph mirroring
   ============================================================ */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined', sans-serif;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;               /* CRITICAL: prevent RTL glyph mirroring */
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'liga';
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    transition: font-variation-settings 200ms ease;
}
.material-symbols-outlined.icon-sm {
    font-size: 20px;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
.material-symbols-outlined.icon-lg {
    font-size: 32px;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 32;
}
.material-symbols-outlined.icon-filled,
.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ============================================================
   RESET & BASE
   ============================================================ */

/* Reset & base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Eliminate iOS 300ms tap delay on all interactive elements */
button, a, [role="button"], input, select, textarea {
    touch-action: manipulation;
}

:root {
    /* === EMERALD & GOLD — Default Light Theme === */
    --bg-primary:       #faf9f5;
    --bg-secondary:     #ffffff;
    --bg-chat:          #efeeea;
    --text-primary:     #1b1c1a;
    --text-secondary:   #404945;
    --accent:           #2b695a;
    --accent-hover:     #003229;
    --accent-text:      #ffffff;
    --accent-rgb:       43, 105, 90;
    --accent-light:     #ffdea5;
    --border:           #bfc9c4;
    --msg-sent-bg:      #00574a;
    --msg-sent-text:    #ffffff;
    --msg-received-bg:  #eeedea;
    --msg-received-text: #1b1c1a;
    --nav-bg:           #003229;
    --nav-text:         #ffffff;
    --input-bg:         #f4f4f0;
    --input-border:     #bfc9c4;
    --card-bg:          #ffffff;
    --hover-bg:         #e9e8e4;
    --shadow:           0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md:        0 16px 32px rgba(43,105,90,0.06), 0 4px 8px rgba(0,0,0,0.06);
    --radius: 8px;

    /* New tokens — Emerald & Gold */
    --color-secondary:           #775a19;
    --color-secondary-fixed:     #ffdea5;
    --glass-bg:                  rgba(250, 249, 245, 0.70);
    --glass-blur:                blur(20px) saturate(1.4);
    --z-glass-bar:               100;
    --z-popups:                  200;
    --z-modals:                  1000;
    --z-toasts:                  9999;

    /* Bubble shape tokens */
    --bubble-radius-sent:          0.75rem;
    --bubble-radius-received-ltr:  0.75rem 0.75rem 0.75rem 0.5rem;
    --bubble-radius-received-rtl:  0.75rem 0.75rem 0.5rem 0.75rem;

    /* Call modal (default light) */
    --call-bg:          #003229;
    --call-text:        #ffffff;
    --call-btn-end:     #b91c1c;
    --call-btn-accept:  #2b695a;
    --call-pulse-color: rgba(255,255,255,0.25);

    /* Read receipt */
    --read-receipt-color: #3ba4d6;

    /* Utility palette (alerts, validation, etc.) */
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;

    /* Font stack */
    --font-family: 'Be Vietnam Pro', 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Responsive layout tokens */
    --keyboard-height: 0px;
    --chat-max-width: 1800px;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* RTL font override: Tajawal first for Arabic content */
:root[dir="rtl"] body,
body:lang(ar) {
    font-family: 'Tajawal', 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ============ Layout ============ */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-nav {
    background: var(--nav-bg);
    color: var(--nav-text);
    padding: 0 24px;
    padding-top: env(safe-area-inset-top, 0px);
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-nav .brand {
    font-size: 1.15em;
    font-weight: 600;
    color: var(--nav-text);
    letter-spacing: 0.5px;
}
.app-nav .brand:hover {
    text-decoration: none;
}

.app-nav .nav-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.app-nav .nav-links a {
    color: rgba(255,255,255,0.85);
    font-size: 0.9em;
    font-weight: 500;
    padding: 6px 0;
    transition: color 0.15s;
    white-space: nowrap;
}
.app-nav .nav-links a:hover {
    color: var(--nav-text);
    text-decoration: none;
}

/* Language Switcher (pill toggle) */
.app-nav .lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 100px;
    padding: 2px;
    cursor: pointer;
    transition: border-color 0.2s;
    outline: none;
    margin: 0 4px;
}
.app-nav .lang-switcher:hover {
    border-color: rgba(255,255,255,0.5);
}
.app-nav .lang-label {
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 100px;
    color: rgba(255,255,255,0.6);
    transition: all 0.2s;
    line-height: 1;
}
.app-nav .lang-label.lang-active {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Hamburger toggle — hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--nav-text);
    font-size: 1.5em;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* ============ Buttons ============ */
button, .btn {
    font-family: var(--font-family);
    font-size: 0.9em;
    font-weight: 500;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #003229 0%, #004b3e 100%);
    color: var(--accent-text);
    border: none;
    border-radius: 1.5rem;
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #004b3e 0%, #003229 100%);
    opacity: 0.92;
}

.btn-danger {
    background: #b91c1c;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: inherit;
}
.btn-danger:hover:not(:disabled) {
    background: #991b1b;
}

.btn-outline {
    background: var(--card-bg);
    color: var(--accent);
    border: none;
    border-radius: 8px;
    box-shadow: inset 0 0 0 1.5px rgba(43,105,90,0.30);
    font-family: inherit;
}
.btn-outline:hover:not(:disabled) {
    background: var(--hover-bg);
}

/* Glass surface — frosted glass for header, bottom nav, chat input */
.glass-surface {
    background: var(--glass-bg, rgba(250,249,245,0.70));
    -webkit-backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
            backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass-surface { background: var(--bg-primary); }
}

/* Gold section header labels */
.list-section-header {
    color: var(--color-secondary);
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* ============ Bento Grid Quick-Actions ============ */
.bento-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0.5rem 0;
}
.bento-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    border-radius: 1.5rem;
    padding: 1.25rem;
    border: none;
    cursor: pointer;
    transition: transform 200ms ease, box-shadow 200ms ease;
    text-decoration: none;
    text-align: start;
}
.bento-card:active { transform: scale(0.95); }
.bento-card:hover { box-shadow: var(--shadow-md); }
.bento-card-primary {
    background: var(--accent);
    color: var(--accent-text);
}
.bento-card-secondary {
    background: var(--hover-bg);
    color: var(--text-primary);
}
.bento-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: rgba(255,255,255,0.18);
}
.bento-card-primary .bento-card-icon { background: rgba(255,255,255,0.18); }
.bento-card-secondary .bento-card-icon { background: rgba(43,105,90,0.12); color: var(--accent); }
.bento-card-label {
    font-weight: 700;
    font-size: 0.95rem;
}
.bento-card-description {
    font-size: 0.8rem;
    opacity: 0.8;
}
@media (max-width: 480px) {
    .bento-grid { grid-template-columns: 1fr; }
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85em;
}

/* ============ Forms ============ */
input, select, textarea {
    font-family: var(--font-family);
    font-size: 0.95em;
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
    background: var(--input-bg);
    color: var(--text-primary);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

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

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

/* ============ Cards ============ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

/* ============ Alerts ============ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9em;
    margin-bottom: 16px;
    animation: fadeIn 0.25s ease-out;
}
.alert-error {
    background: #fce4ec;
    color: #c62828;
    border: 1px solid #ef9a9a;
}
.alert-success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}
.alert-info {
    background: var(--accent-light);
    color: var(--accent-hover);
    border: 1px solid #90caf9;
}
.auth-status-area {
    min-height: 48px;
}
.alert-hidden {
    visibility: hidden;
    height: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* ============ RTL Support ============ */
[dir="rtl"] .floating-label {
    left: auto;
    right: 16px;
    transform-origin: right top;
}
[dir="rtl"] .floating-input {
    text-align: right;
}
[dir="rtl"] .auth-hint {
    margin-left: 0;
    margin-right: 4px;
}
[dir="rtl"] .message-meta {
    flex-direction: row-reverse;
}
[dir="rtl"] .nav-links {
    flex-direction: row-reverse;
}
[dir="rtl"] .sidebar-item-body {
    text-align: right;
}
[dir="rtl"] .sidebar-item-time {
    margin-left: 0;
    margin-right: auto;
}
[dir="rtl"] .conversation-item-name,
[dir="rtl"] .conversation-item-preview {
    text-align: right;
}
[dir="rtl"] .conversation-item-meta {
    text-align: left;
}
[dir="rtl"] .auth-footer {
    text-align: center;
}
[dir="rtl"] .settings-page {
    direction: rtl;
    text-align: right;
}
[dir="rtl"] .toggle-row {
    direction: rtl;
}
[dir="rtl"] .device-card {
    direction: rtl;
    flex-direction: row-reverse;
}
[dir="rtl"] .device-name,
[dir="rtl"] .device-date,
[dir="rtl"] .device-lastseen {
    direction: rtl;
    unicode-bidi: plaintext;
    text-align: right;
}
[dir="rtl"] .settings-page h2,
[dir="rtl"] .settings-page h3,
[dir="rtl"] .settings-page h4,
[dir="rtl"] .settings-section-title {
    direction: rtl;
    text-align: right;
}
[dir="rtl"] .settings-logout-btn {
    direction: rtl;
    flex-direction: row-reverse;
}
[dir="rtl"] .device-current {
    margin-left: 0;
    margin-right: 8px;
}
[dir="rtl"] .device-role-badge {
    margin-left: 0;
    margin-right: 6px;
}
[dir="rtl"] .danger-zone,
[dir="rtl"] .danger-description {
    direction: rtl;
    text-align: start;
}
[dir="rtl"] .backup-status,
[dir="rtl"] .link-device-box,
[dir="rtl"] .font-size-selector,
[dir="rtl"] .theme-name,
[dir="rtl"] .wallpaper-name {
    direction: rtl;
}
[dir="rtl"] .page-header h2 {
    text-align: right;
}

/* ============ Home page ============ */
.hero {
    text-align: center;
    padding: 60px 24px;
}
.hero h1 {
    font-size: 2.2em;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.hero p {
    font-size: 1.1em;
    color: var(--text-secondary);
    margin-bottom: 32px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}
.hero-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}
.hero-actions a {
    display: inline-block;
    padding: 12px 32px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 1em;
    transition: background 0.15s;
}
.hero-actions .cta-primary {
    background: var(--accent);
    color: var(--accent-text);
}
.hero-actions .cta-primary:hover {
    background: var(--accent-hover);
    text-decoration: none;
}
.hero-actions .cta-secondary {
    background: var(--card-bg);
    color: var(--accent);
    border: 1px solid var(--accent);
}
.hero-actions .cta-secondary:hover {
    background: var(--accent-light);
    text-decoration: none;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 40px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}
.feature-item {
    text-align: center;
    padding: 20px;
}
.feature-item h3 {
    font-size: 1em;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.feature-item p {
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* ============ Auth pages ============ */
.auth-page {
    max-width: 400px;
    margin: 40px auto;
}
/* Auth inputs — ensure readable in all dark themes */
:root[data-theme="default-dark"] .auth-page .floating-input,
:root[data-theme="default-dark"] .auth-page input[type="text"],
:root[data-theme="default-dark"] .auth-page input[type="password"],
:root[data-theme="whatsapp-dark"] .auth-page .floating-input,
:root[data-theme="whatsapp-dark"] .auth-page input[type="text"],
:root[data-theme="whatsapp-dark"] .auth-page input[type="password"],
:root[data-theme="signal-dark"] .auth-page .floating-input,
:root[data-theme="signal-dark"] .auth-page input[type="text"],
:root[data-theme="signal-dark"] .auth-page input[type="password"],
:root[data-theme="telegram-dark"] .auth-page .floating-input,
:root[data-theme="telegram-dark"] .auth-page input[type="text"],
:root[data-theme="telegram-dark"] .auth-page input[type="password"] {
    color: #ffffff !important;
    background: rgba(255,255,255,0.08) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    caret-color: #fff !important;
    padding-top: 22px !important;
    padding-bottom: 8px !important;
    min-height: 52px !important;
    font-family: inherit;
}
:root[data-theme="default-dark"] .auth-page .floating-input::placeholder,
:root[data-theme="whatsapp-dark"] .auth-page .floating-input::placeholder,
:root[data-theme="signal-dark"] .auth-page .floating-input::placeholder,
:root[data-theme="telegram-dark"] .auth-page .floating-input::placeholder {
    color: rgba(255,255,255,0.4) !important;
}
:root[data-theme="default-dark"] .auth-page .floating-label,
:root[data-theme="whatsapp-dark"] .auth-page .floating-label,
:root[data-theme="signal-dark"] .auth-page .floating-label,
:root[data-theme="telegram-dark"] .auth-page .floating-label {
    color: rgba(255,255,255,0.7) !important;
}
:root[data-theme="default-dark"] .auth-page .floating-input:not(:placeholder-shown) + .floating-label,
:root[data-theme="default-dark"] .auth-page .floating-input:focus + .floating-label,
:root[data-theme="whatsapp-dark"] .auth-page .floating-input:not(:placeholder-shown) + .floating-label,
:root[data-theme="whatsapp-dark"] .auth-page .floating-input:focus + .floating-label,
:root[data-theme="signal-dark"] .auth-page .floating-input:not(:placeholder-shown) + .floating-label,
:root[data-theme="signal-dark"] .auth-page .floating-input:focus + .floating-label,
:root[data-theme="telegram-dark"] .auth-page .floating-input:not(:placeholder-shown) + .floating-label,
:root[data-theme="telegram-dark"] .auth-page .floating-input:focus + .floating-label {
    transform: translateY(-18px) scale(0.8) !important;
}
.auth-page h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.5em;
}
.auth-page .card {
    margin-bottom: 16px;
}
.auth-page .auth-footer {
    text-align: center;
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* App version footer */
.app-version-footer {
    text-align: center;
    font-size: 0.75em;
    color: var(--text-secondary);
    opacity: 0.6;
    padding: 24px 0 12px;
    letter-spacing: 0.3px;
}

/* ============ Conversations list ============ */
.conversation-list {
    display: flex;
    flex-direction: column;
}
.conversation-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.05);
    cursor: pointer;
    transition: background 0.15s;
    gap: 12px;
}
.conversation-item:hover {
    background: var(--hover-bg);
}
.conversation-item.active {
    background: var(--accent-light);
}
.conversation-item:last-child {
    box-shadow: none;
}
.conversation-item-content {
    flex: 1;
    min-width: 0;
}
.conversation-item-name {
    font-weight: 600;
    margin-bottom: 2px;
}
.conversation-item-preview {
    color: var(--text-secondary);
    font-size: 0.87em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-item-meta {
    text-align: end;
    margin-inline-start: 12px;
    flex-shrink: 0;
}
.conversation-item-time {
    color: var(--text-secondary);
    font-size: 0.8em;
    margin-bottom: 4px;
}
.conversation-item-badge {
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.78em;
    font-weight: 600;
    animation: badgePop 0.3s ease-out;
}

/* ============ Chat page ============ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px); /* default: with nav bar */
    height: calc(100dvh - 56px);
    max-width: 100%;
}
.chat-header {
    padding: 10px 16px;
    background: var(--glass-bg, var(--card-bg));
    -webkit-backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
            backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    position: relative;
    z-index: var(--z-glass-bar, 100);
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
}
.chat-header-info {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}
.chat-header-name-block {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}
.chat-header-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    position: relative;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .chat-header { background: var(--card-bg); }
}
.chat-header-title {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-header-subtitle {
    color: var(--text-secondary);
    font-size: 0.8em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-typing-indicator {
    color: var(--text-secondary);
    font-size: 0.85em;
    font-style: italic;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: var(--bg-chat);
    background-image: var(--chat-bg-image, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='%23003229' fill-opacity='0.05' fill-rule='evenodd'%3E%3Cpath d='M40 8L52 20L64 20L64 32L76 44L64 56L64 68L52 68L40 80L28 68L16 68L16 56L4 44L16 32L16 20L28 20Z' stroke='%23003229' stroke-width='1' fill='none' stroke-opacity='0.05'/%3E%3Cpolygon points='40,14 44,28 58,28 47,37 51,51 40,42 29,51 33,37 22,28 36,28'/%3E%3C/g%3E%3C/svg%3E"));
    background-repeat: repeat;
    background-size: 80px 80px;
}
.loading-older-indicator {
    text-align: center;
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 0.8em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-secondary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* chat-input-area: see refined version below */
.chat-empty-state {
    text-align: center;
    color: var(--text-secondary);
}

/* Participants panel */
.participants-panel {
    padding: 8px 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    max-height: 150px;
    overflow-y: auto;
}
.participants-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.participant-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--bg-secondary, var(--hover-bg));
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.85em;
    white-space: nowrap;
}
.participant-admin {
    color: var(--accent);
    font-size: 0.75em;
    font-weight: 700;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    padding: 1px 6px;
    border-radius: 4px;
    margin-inline-start: 2px;
}
.toggle-participants-btn {
    border: none;
    background: none;
    color: var(--accent);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85em;
    padding: 4px 0;
}
.toggle-participants-row {
    padding: 2px 16px;
    border-bottom: 1px solid var(--border);
    line-height: 1;
    text-align: start;
}
@media (max-width: 767px) {
    .toggle-participants-row {
        padding: 0 12px;
    }
    .toggle-participants-btn {
        font-size: 0.8em;
        padding: 2px 0;
    }
}

/* ============ Message bubbles ============ */
.message-row {
    /* T012: Message slide-in animations */

    display: flex;
    margin-bottom: 14px;
    position: relative;
}
.message-row.mine {
    justify-content: flex-end;
}
.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: var(--msg-bubble-radius, 16px);
    font-size: var(--msg-font-size, var(--app-font-size, 14.5px));
    line-height: 1.4;
    position: relative;
}
.message-bubble.mine {
    background: var(--msg-sent-bg);
    color: var(--msg-sent-text);
    border-radius: var(--bubble-radius-sent, 0.75rem);
}
/* Ensure all child elements inside sent bubbles inherit the bubble's text color
   instead of using global theme vars that assume a light page background. */
.message-bubble.mine .message-meta,
.message-bubble.mine .forwarded-label,
.message-bubble.mine .audio-duration,
.message-bubble.mine .message-media-placeholder,
.message-bubble.mine .message-file-meta {
    color: inherit;
    opacity: 0.7;
}
.message-bubble.mine .delivery-sending,
.message-bubble.mine .delivery-sent,
.message-bubble.mine .delivery-delivered {
    color: inherit;
    opacity: 0.7;
}
.message-bubble.mine .delivery-read {
    color: var(--read-receipt-color);
}
.message-bubble.mine .audio-play-btn {
    background: transparent;
    color: #fff;
}
.message-bubble.mine .audio-duration {
    color: rgba(255,255,255,0.6);
}
.message-bubble.mine .aw-bar {
    background: rgba(255,255,255,0.2);
}
.message-bubble.mine .aw-bar.played {
    background: #fff;
}
.message-bubble.mine .message-file-name {
    color: inherit;
}
.message-bubble.mine .message-file-action-btn {
    color: inherit;
}
.message-bubble.mine .reply-quote-text {
    color: inherit;
}
.message-bubble.theirs {
    background: var(--msg-received-bg);
    color: var(--msg-received-text);
    border-radius: var(--bubble-radius-received-ltr, 0.75rem 0.75rem 0.75rem 0.5rem);
    box-shadow: var(--shadow);
    position: relative;
}
.message-bubble.theirs::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -6px;
    border: 8px solid transparent;
    border-bottom-color: var(--msg-received-bg);
    border-left-width: 0;
}
[dir="rtl"] .message-bubble.theirs {
    border-radius: var(--bubble-radius-received-rtl, 0.75rem 0.75rem 0.5rem 0.75rem);
}
[dir="rtl"] .message-bubble.theirs::after {
    left: auto;
    right: -6px;
    border-bottom-color: var(--msg-received-bg);
    border-right-width: 0;
    border-left-width: 8px;
}
/* Ensure received bubble children also inherit for dark themes */
.message-bubble.theirs .message-meta,
.message-bubble.theirs .forwarded-label,
.message-bubble.theirs .audio-duration,
.message-bubble.theirs .message-media-placeholder,
.message-bubble.theirs .message-file-meta {
    color: inherit;
    opacity: 0.7;
}
.message-bubble.theirs .delivery-sending,
.message-bubble.theirs .delivery-sent,
.message-bubble.theirs .delivery-delivered {
    color: inherit;
    opacity: 0.7;
}
.message-bubble.theirs .audio-play-btn {
    color: inherit;
}
.message-bubble.theirs .audio-avatar {
    background: rgba(128,128,128,0.15);
    color: inherit;
}
.message-bubble.theirs .aw-bar {
    background: rgba(128,128,128,0.3);
}
.message-bubble.theirs .message-file-name {
    color: inherit;
}
.message-bubble.theirs .message-file-action-btn {
    color: inherit;
}
.message-bubble.theirs .reply-quote-text {
    color: inherit;
}
.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
    unicode-bidi: plaintext;
    text-align: start;
}
/* Big emoji - WhatsApp-style */
.message-text.emoji-only {
    font-size: 2.5rem;
    line-height: 1.1;
    text-align: center;
    padding: 8px 4px;
}
/* Transparent bubble for emoji-only messages */
.message-bubble:has(.emoji-only) {
    background: transparent !important;
    box-shadow: none;
    padding: 4px 8px;
}
.message-meta {
    font-size: 0.72em;
    margin-top: 4px;
    opacity: 0.85;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}
.message-timestamp {
    color: var(--color-secondary);
    font-size: 0.75rem;
}

/* ============ Message input ============ */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Attach button */
.attach-menu-wrapper {
    position: relative;
    flex-shrink: 0;
    z-index: 201;
}
.attach-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.attach-btn:hover {
    background: var(--hover-bg);
    color: var(--accent);
}

/* Attach popup menu — backdrop covers entire viewport to catch dismiss taps */
.attach-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: transparent;
    cursor: pointer;
}
.attach-menu-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 9001;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    min-width: 200px;
    overflow: hidden;
}
.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 18px;
    cursor: pointer;
    font-size: 0.93em;
    color: var(--text-primary);
    transition: background 0.12s;
    border-bottom: 1px solid var(--border);
}
.attach-menu-item:last-child {
    border-bottom: none;
}
.attach-menu-item:hover {
    background: var(--hover-bg);
}
.attach-menu-icon {
    font-size: 1.2em;
    line-height: 1;
    width: 24px;
    text-align: center;
}

/* File preview bar */
.file-preview-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--hover-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
}
.file-preview-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}
.file-preview-icon {
    font-size: 2em;
    flex-shrink: 0;
    width: 48px;
    text-align: center;
}
.file-preview-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.file-preview-name {
    font-size: 0.88em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-preview-size {
    font-size: 0.78em;
    color: var(--text-secondary);
}
/* WhatsApp-style media preview panel */
.media-preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, var(--hover-bg));
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    max-height: 360px;
}
.media-preview-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.media-preview-close {
    background: none;
    border: none;
    font-size: 1.4em;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.media-preview-close:hover {
    background: var(--border);
    color: var(--text-primary);
}
.media-preview-filename {
    flex: 1;
    font-size: 0.85em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}
.media-preview-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* HD toggle button — WhatsApp style */
.hd-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--hover-bg);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.hd-toggle-btn .hd-label {
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    transition: color 0.15s;
}
.hd-toggle-btn:hover {
    border-color: var(--accent);
}
.hd-toggle-btn.hd-active {
    background: var(--accent);
    border-color: var(--accent);
}
.hd-toggle-btn.hd-active .hd-label {
    color: var(--accent-text);
}

.media-preview-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-primary, #000);
    position: relative;
}
.media-preview-image {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
}
.media-preview-placeholder {
    color: var(--text-secondary, #aaa);
    font-size: 2em;
    padding: 40px 0;
}
.media-preview-video {
    max-width: 100%;
    max-height: 280px;
    border-radius: 6px;
    background: #000;
    outline: none;
}
.media-preview-video-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,0.65);
    color: var(--accent-text);
    font-size: 0.75em;
    padding: 2px 8px;
    border-radius: 4px;
}
.media-preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
}
.media-preview-size {
    font-size: 0.78em;
    color: var(--text-secondary);
}
.media-preview-savings {
    color: var(--accent);
}

.file-preview-remove {
    background: none;
    border: none;
    font-size: 1.3em;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.file-preview-remove:hover {
    background: var(--border);
    color: var(--text-primary);
}

/* Input error */
.input-error {
    font-size: 0.83em;
    color: var(--danger);
    padding: 4px 4px 0;
}

/* FR-002a: Rate limit warning */
.rate-limit-warning {
    font-size: 0.83em;
    color: var(--warning, #f59e0b);
    padding: 4px 4px 0;
    animation: pulse 1s infinite;
}

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

/* FR-026: Offline indicator */
.offline-indicator {
    background: var(--warning, #f59e0b);
    color: #000;
    padding: 6px 12px;
    font-size: 0.85em;
    text-align: center;
}
}

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

/* Textarea */
.msg-textarea {
    flex: 1 1 0;
    min-width: 0;
    padding: var(--input-padding, 10px 14px);
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius, 20px);
    resize: none;
    font-size: 0.95em;
    outline: none;
    font-family: var(--font-family);
    background: var(--input-bg);
    color: var(--text-primary);
    max-height: 150px;
    overflow-y: auto;
    line-height: 1.4;
}
.msg-textarea:focus {
    border-color: var(--accent);
}

/* Send button */
.send-btn {
    border-radius: 50%;
    width: 42px;
    height: 42px;
    min-width: 42px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.send-btn.send-btn-active {
    background: var(--accent);
    color: white;
}
.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.send-btn:not(:disabled):hover {
    filter: brightness(1.08);
}

/* ============ Media bubbles (WhatsApp/Telegram style) ============ */

/* Zero-padding bubble for image and video — image fills edge-to-edge */
.message-bubble:has(.message-image),
.message-bubble:has(.message-video) {
    padding: 0;
    max-width: 80%;
    min-width: 280px;
}
/* Compact padding for file card bubble — file card handles its own layout */
.message-bubble:has(.message-file-card) {
    padding: 4px;
}
/* Clip media to bubble's rounded corners without hiding the reply button */
.message-bubble:has(.message-image) > .message-media,
.message-bubble:has(.message-video) > .message-media {
    overflow: hidden;
    border-radius: inherit;
}

/* Image: fill bubble width, capped height for readability */
.message-image {
    display: block;
    width: 100%;
    max-height: 400px;
    min-width: 220px;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.04);
}

/* Thumbnail placeholder with blur effect */
.message-image-blur {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(8px);
    transform: scale(1.1);
    z-index: 1;
}

/* Actual image should be above blur */
.message-image-clickable > .message-image:not(.message-image-blur) {
    position: relative;
    z-index: 2;
}

/* Video thumbnail container — always show thumbnail, click opens fullscreen */
.message-video-container {
    position: relative;
    cursor: pointer;
    background: #000;
    min-height: 120px;
    max-width: 100%; /* FR-022: Responsive on mobile */
}

.message-video-thumb-img {
    display: block;
    width: 100%;
    max-height: 400px;
    min-height: 120px;
    object-fit: cover;
}

.message-video-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: background 0.15s;
}

.message-video-container:hover .message-video-play-btn {
    background: rgba(0, 0, 0, 0.7);
}

.message-video-play-btn::before {
    content: "";
    border-style: solid;
    border-width: 10px 0 10px 18px;
    border-color: transparent transparent transparent white;
    margin-left: 3px;
}

/* Caption text and timestamp get their own padding inside zero-padding bubble */
.message-bubble:has(.message-image) .message-text,
.message-bubble:has(.message-video) .message-text {
    padding: 6px 12px 0;
}
.message-bubble:has(.message-image) .message-meta,
.message-bubble:has(.message-video) .message-meta {
    padding: 2px 12px 8px;
    margin-top: 0;
}

/* Placeholder for media that couldn't be loaded */
.message-media-placeholder {
    padding: 12px 16px;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9em;
}

/* Audio stays compact (fallback) */
.message-audio {
    max-width: 100%;
    display: block;
}

/* WhatsApp-style audio message */
.audio-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    width: 100%;
    box-sizing: border-box;
}
/* All message bubbles: percentage-based responsive width */
.message-bubble {
    min-width: 0;
    max-width: 70%;
}
@media (max-width: 767px) {
    .message-bubble { max-width: 85%; }
}
.audio-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.audio-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
/* Play button — plain icon, no circle background */
.audio-play-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 0;
    border: none;
    background: transparent;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.15s;
    flex-shrink: 0;
    padding: 0;
}
.audio-play-btn:hover { opacity: 0.75; }
.message-bubble.theirs .audio-play-btn { color: var(--accent); }
.message-bubble.mine .audio-play-btn { color: #fff; }
/* Waveform — visible, clickable for seeking */
.audio-wave-track {
    display: flex;
    align-items: center;
    gap: 1.5px;
    height: 24px;
    flex: 1;
    overflow: hidden;
    cursor: pointer;
}
/* Waveform bars: played = bright, remaining = dim */
.aw-bar {
    width: 3px;
    min-height: 2px;
    border-radius: 1.5px;
    background: rgba(255,255,255,0.2);
    flex-shrink: 0;
    transition: background 0.1s;
}
.aw-bar.played { background: #fff; }
.message-bubble.theirs .aw-bar { background: rgba(0,0,0,0.1); }
.message-bubble.theirs .aw-bar.played { background: var(--accent); }
/* Duration — shows total or remaining */
.audio-duration {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.72em;
    color: rgba(255,255,255,0.6);
    flex-shrink: 0;
    min-width: 32px;
}
.message-bubble.theirs .audio-duration { color: var(--text-secondary); }
/* Waveform wrapper — positions range overlay on top */
.audio-wave-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}
/* Range input overlaid on waveform — transparent but supports drag seeking */
.voice-seek-overlay {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    outline: none;
    cursor: pointer;
    opacity: 0;
    z-index: 1;
}
.voice-seek-overlay::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 24px;
    background: transparent;
    cursor: pointer;
}
.voice-seek-overlay::-moz-range-thumb {
    width: 16px;
    height: 24px;
    background: transparent;
    cursor: pointer;
    border: none;
}
/* Hide old seek bar class */
.voice-seek-bar { display: none; }
/* Keep old thumb rules just in case (hidden element) */
.message-bubble.mine .voice-seek-bar { background: rgba(255,255,255,0.2); }
.message-bubble.mine .voice-seek-bar::-webkit-slider-thumb { background: #fff;
}
.message-bubble.mine .voice-seek-bar::-moz-range-thumb {
    background: #fff;
}
/* Telegram-style compact speed toggle */
.voice-speed-btn {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.65em;
    font-weight: 700;
    min-width: 30px;
    height: 18px;
    border-radius: 9px;
    border: 1px solid rgba(128,128,128,0.3);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.message-bubble.mine .voice-speed-btn {
    border-color: rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.7);
}
.voice-speed-btn:hover {
    background: var(--accent-light, rgba(var(--accent-rgb, 37, 99, 235), 0.15));
    color: var(--accent);
}
/* Audio message wraps seek bar below the main row */
.audio-message {
    flex-wrap: wrap;
}
/* File / Document card (WhatsApp-style) */
.message-file-card {
    display: flex;
    flex-direction: column;
    min-width: 240px;
    max-width: 320px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 2px;
}
.message-file-preview {
    background: #f8f8f8;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    max-height: 200px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}
.message-file-preview-img {
    width: 100%;
    object-fit: cover;
    object-position: top;
    max-height: 200px;
}
/* When preview exists, header loses top border-radius */
.message-file-card:has(.message-file-preview) .message-file-header {
    border-radius: 0;
}
.message-file-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.06);
    border-radius: 8px 8px 0 0;
}
.message-bubble.mine .message-file-header {
    background: rgba(0,0,0,0.1);
}
.message-file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-size: 1.5em;
    flex-shrink: 0;
    border-radius: 8px;
    background: rgba(128,128,128,0.1);
}
.message-file-icon.pdf-icon {
    background: #e74c3c18;
}
.message-file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.message-file-name {
    font-size: 0.85em;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-file-meta {
    font-size: 0.72em;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.message-file-actions {
    display: flex;
    border-top: 1px solid rgba(128,128,128,0.15);
}
.message-file-action-btn {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    font-size: 0.82em;
    font-weight: 500;
    color: inherit;
    opacity: 0.85;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s;
}
.message-file-action-btn:hover {
    background: rgba(128,128,128,0.1);
    opacity: 1;
}
.message-file-action-btn + .message-file-action-btn {
    border-left: 1px solid rgba(128,128,128,0.15);
}

/* ============ Enhanced Component Styles (WhatsApp/Telegram/Signal style) ============ */

/* Enhanced message bubbles */
.message-bubble {
    transition: background 0.15s;
}

/* Refined input area — glass treatment */
.chat-input-area {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 6px 10px 10px;
    background: var(--glass-bg, var(--card-bg));
    -webkit-backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
            backdrop-filter: var(--glass-blur, blur(20px) saturate(1.4));
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
    position: relative;
    z-index: var(--z-glass-bar, 100);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .chat-input-area { background: var(--card-bg); }
}
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--input-bg, var(--bg-secondary));
    border-radius: 24px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    min-width: 0;
}
.chat-input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb, 37, 99, 235), 0.1);
}

/* Enhanced attach button */
.attach-btn,
.emoji-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
}
.attach-btn:hover,
.emoji-btn:hover {
    background: var(--hover-bg);
    color: var(--accent);
    transform: scale(1.08);
}
.attach-btn:active,
.emoji-btn:active {
    transform: scale(0.95);
}

/* Enhanced textarea */
.msg-textarea {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 4px;
    border: none;
    border-radius: 0;
    resize: none;
    font-size: 0.95em;
    outline: none;
    font-family: var(--font-family);
    background: transparent;
    color: var(--text-primary);
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
}
.msg-textarea::placeholder {
    color: var(--text-secondary);
}

/* Enhanced send button - WhatsApp style */
.send-btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.send-btn.send-btn-active {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 2px 8px rgba(var(--accent-rgb, 37, 99, 235), 0.3);
    animation: btn-pop-in 0.15s ease-out;
}
@keyframes btn-pop-in {
    from { transform: scale(0.6); opacity: 0.5; }
    to { transform: scale(1); opacity: 1; }
}
.send-btn.send-btn-active:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(var(--accent-rgb, 37, 99, 235), 0.4);
}
.send-btn.send-btn-active:active {
    transform: scale(0.92);
}

/* Enhanced mic button - Telegram style */
.mic-btn {
    background: var(--accent);
    border: none;
    color: var(--accent-text);
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(var(--accent-rgb, 37, 99, 235), 0.25);
    animation: btn-pop-in 0.15s ease-out;
}
.mic-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 10px rgba(var(--accent-rgb, 37, 99, 235), 0.35);
}
.mic-btn:active {
    transform: scale(0.92);
}

/* Enhanced attach popup menu */
.attach-menu-popup {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    z-index: 9001;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 5px 24px rgba(0, 0, 0, 0.2);
    min-width: 240px;
    overflow: hidden;
    animation: slideUp 0.2s ease-out;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--text-primary);
    transition: background 0.15s;
}
.attach-menu-item:hover {
    background: var(--hover-bg);
}
.attach-menu-icon {
    font-size: 1.4em;
    width: 32px;
    text-align: center;
}

/* Enhanced file preview */
.file-preview-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: 14px;
    border: 1px solid var(--border);
    margin-bottom: 6px;
}
.file-preview-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}
.file-preview-icon {
    font-size: 2.2em;
    flex-shrink: 0;
    width: 52px;
    text-align: center;
}
.file-preview-name {
    font-size: 0.9em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}
.file-preview-size {
    font-size: 0.8em;
    color: var(--text-secondary);
}
.file-preview-remove {
    background: none;
    border: none;
    font-size: 1.4em;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: all 0.15s;
}
.file-preview-remove:hover {
    background: var(--border);
    color: var(--danger, #dc3545);
}

/* Enhanced emoji picker */
.emoji-picker-popup {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    z-index: 201;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.22);
    width: 340px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease-out;
}

/* Hide mobile-only emoji picker elements on desktop */
.emoji-sheet-backdrop { display: none; }
.sheet-drag-handle { display: none; }
.emoji-picker-close {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--bg-secondary);
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 16px;
    z-index: 10;
    transition: all 0.15s;
}
.emoji-picker-close:hover {
    background: var(--border);
    color: var(--text-primary);
}
.emoji-picker-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.emoji-picker-search input {
    width: 100%;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.9em;
    background: var(--hover-bg);
    border: 1px solid transparent;
    color: var(--text-primary);
    outline: none;
    transition: all 0.15s;
}
.emoji-picker-search input:focus {
    border-color: var(--accent);
    background: var(--input-bg);
}
.emoji-picker-search input::placeholder {
    color: var(--text-secondary);
}
.emoji-category-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    background: var(--bg-secondary);
}
.emoji-category-tab {
    flex: 1;
    min-width: 40px;
    padding: 10px 4px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1.2em;
    cursor: pointer;
    text-align: center;
    transition: all 0.12s;
}
.emoji-category-tab:hover {
    background: var(--hover-bg);
}
.emoji-category-tab.active {
    border-bottom-color: var(--accent);
    background: var(--hover-bg);
}
.emoji-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}
.emoji-item {
    font-size: 1.5rem;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.1s;
    line-height: 1;
}
.emoji-item:hover {
    background: var(--hover-bg);
    transform: scale(1.2);
}
.emoji-item:active {
    transform: scale(0.9);
}

/* Quick reply button (inside bubble, WhatsApp-style) */
.msg-quick-reply {
    position: absolute;
    top: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--card-bg);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 0;
    transition: opacity 0.15s, background 0.12s, transform 0.12s;
    z-index: 10;
    touch-action: manipulation;
}
/* Position: fully outside bubble edge so it never overlaps text */
.message-bubble.mine .msg-quick-reply { left: -32px; }
.message-bubble.theirs .msg-quick-reply { right: -32px; }
/* Desktop hover */
.message-row:hover .msg-quick-reply {
    opacity: 1;
    pointer-events: auto;
}
/* Mobile: show on tap (bubble touch) */
@media (hover: none) {
    .message-bubble:active .msg-quick-reply,
    .message-bubble:focus-within .msg-quick-reply {
        opacity: 1;
        pointer-events: auto;
    }
}
.msg-quick-reply:hover {
    background: var(--hover-bg);
    color: var(--accent);
    transform: scale(1.1);
}
.msg-quick-reply:active {
    transform: scale(0.95);
}

/* Header / toolbar action buttons (search, menu, close) */
.msg-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    cursor: pointer;
    font-size: 1.1em;
    border-radius: 50%;
    transition: background 0.12s, color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    touch-action: manipulation;
}
.msg-action-btn:hover {
    background: var(--hover-bg);
    color: var(--accent);
}
.msg-action-btn:active {
    transform: scale(0.93);
}

/* Enhanced message meta */
.message-meta {
    font-size: 0.7em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    justify-content: flex-end;
    opacity: 0.75;
}
.message-bubble:hover .message-meta {
    opacity: 1;
}

/* Enhanced forwarded label */
.forwarded-label {
    font-size: 0.72em;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Enhanced reaction badges */
.reaction-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}
.reaction-badge {
    /* T013: Reaction pop animation */
    transition: transform 0.15s ease;

    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.8em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: all 0.15s;
}
.reaction-badge:hover {
    background: var(--hover-bg);
    border-color: var(--accent);
}
.reaction-badge.mine {
    background: var(--accent-light);
    border-color: var(--accent);
}

/* ============ QR Device Linking ============ */
.qr-link-page {
    max-width: 400px;
    margin: 0 auto;
    padding: 24px;
    text-align: center;
}
.qr-link-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    text-align: start;
}
.qr-link-header h2 { margin: 0; }
.qr-code-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.qr-instructions {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin: 0;
}
.qr-code-wrapper {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    display: inline-block;
}
.qr-code-wrapper svg {
    width: 220px;
    height: 220px;
}
.qr-placeholder {
    width: 220px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qr-countdown {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.numeric-code-display {
    margin-top: 8px;
}
.numeric-code-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 4px;
}
.numeric-code-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 4px;
    font-family: monospace;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 8px 20px;
    border-radius: 8px;
    display: inline-block;
}
.qr-linking-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}
.btn-qr-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--accent);
    transition: background 0.15s;
}
.btn-qr-link:hover {
    background: var(--bg-hover, rgba(0,0,0,0.04));
}
.qr-link-login-btn {
    text-align: center;
    margin: 16px 0 8px;
}

/* QR Scanner overlay */
.qr-scanner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.qr-scanner-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1001;
}
.qr-scanner-instructions {
    color: #fff;
    font-size: 1rem;
    text-align: center;
    padding: 0 24px;
}
#qr-scanner-element {
    width: 300px;
    height: 300px;
    border-radius: 12px;
    overflow: hidden;
}
.link-confirm-dialog {
    background: var(--card-bg, #fff);
    border-radius: 16px;
    padding: 24px;
    max-width: 320px;
    text-align: center;
}
.link-confirm-dialog h3 { margin: 0 0 16px; }
.link-confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}
.manual-code-entry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px;
}
.manual-code-input {
    font-size: 1.5rem;
    letter-spacing: 4px;
    text-align: center;
    width: 200px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-family: monospace;
}

/* ============ New Chat FAB (WhatsApp/Telegram pattern) ============ */
.new-chat-fab {
    display: none; /* hidden on desktop — sidebar header has the button */
}
@media (max-width: 767px) {
    .new-chat-fab {
        display: flex;
        position: fixed;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 16px;
        border: none;
        background: var(--accent);
        color: var(--accent-text, #fff);
        cursor: pointer;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
        z-index: 15;
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .new-chat-fab .material-symbols-outlined {
        font-size: 26px;
    }
    .new-chat-fab:hover {
        transform: scale(1.05);
        box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    }
    .new-chat-fab:active {
        transform: scale(0.95);
    }
}

/* ============ Settings hub categories ============ */
.settings-hub-categories {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-secondary, #f0f0f0);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}
.settings-hub-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-primary, #fff);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
    border: none;
    width: 100%;
    text-align: start;
    font: inherit;
}
.settings-hub-item:hover {
    background: var(--bg-hover, #f5f5f5);
}
.settings-hub-item:active {
    background: var(--bg-active, #ebebeb);
}
.settings-hub-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent, #1976d2);
    color: #fff;
    flex-shrink: 0;
    font-size: 22px;
}
.settings-hub-item-text {
    flex: 1;
    min-width: 0;
}
.settings-hub-item-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary, #111);
    line-height: 1.3;
}
.settings-hub-item-subtitle {
    font-size: 13px;
    color: var(--text-secondary, #666);
    line-height: 1.3;
    margin-top: 1px;
}
.settings-hub-item-chevron {
    color: var(--text-secondary, #999);
    font-size: 20px;
    flex-shrink: 0;
}
[dir="rtl"] .settings-hub-item-chevron {
    transform: scaleX(-1);
}

.settings-hub-profile-card {
    cursor: pointer;
    transition: background 0.15s;
}
.settings-hub-profile-card:hover {
    background: var(--bg-hover, #f5f5f5);
}

/* ============ Settings page ============ */
.settings-page {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px;
}
.settings-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.settings-header h2 {
    margin: 0;
}
.back-link {
    text-decoration: none;
    font-size: 1.2em;
    color: var(--text-primary);
}
button.back-link {
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}
.section-title {
    margin-bottom: 12px;
}

/* ─── Settings Section Cards (global) ─── */
.settings-section-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 0;
    margin-bottom: 12px;
    overflow: hidden;
}
.settings-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 10px 16px 2px;
    margin: 0;
}

/* ─── Profile / Account Form (global) ─── */
.profile-form {
    padding: 8px 16px 12px;
}
.profile-field {
    margin-bottom: 16px;
}
.profile-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-align: start;
}
.profile-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg, var(--bg));
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}
.profile-input:focus {
    border-color: var(--accent, #1976d2);
}
.profile-field-error {
    display: block;
    font-size: 0.78rem;
    color: var(--danger, #ef4444);
    margin-top: 4px;
}
.btn-profile-save {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent, #1976d2);
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-profile-save:hover {
    opacity: 0.9;
}
.btn-profile-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─── Password / Username field wrappers (global) ─── */
.password-field-wrapper {
    position: relative;
}
.password-field-wrapper .profile-input {
    padding-inline-end: 44px;
}
.password-toggle-btn {
    position: absolute;
    top: 50%;
    inset-inline-end: 4px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.password-toggle-btn .material-symbols-outlined {
    font-size: 20px;
}

/* ─── Username input with @ prefix (global) ─── */
.username-at-prefix {
    position: absolute;
    top: 50%;
    inset-inline-start: 12px;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.95rem;
    pointer-events: none;
}
.username-input {
    padding-inline-start: 28px !important;
    direction: ltr;
    text-align: left;
}

/* ─── Settings logout button (global) ─── */
.settings-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--danger, #ef4444);
    background: transparent;
    border: 1px solid var(--danger, #ef4444);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 16px;
}
.settings-logout-btn:hover,
.settings-logout-btn:active {
    background: var(--danger, #ef4444);
    color: #fff;
}

/* ─── Password strength indicator ─── */
.password-strength {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 0.78rem;
    font-weight: 500;
}
.password-strength-bar {
    flex: 1;
    max-width: 120px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
}
.password-strength-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.25s, background 0.25s;
}
.password-strength-fill.weak {
    width: 33%;
    background: var(--danger, #ef4444);
}
.password-strength-fill.medium {
    width: 66%;
    background: var(--warning, #d97706);
}
.password-strength-fill.strong {
    width: 100%;
    background: var(--success, #16a34a);
}
.password-strength-label {
    color: var(--text-secondary);
}
.password-strength-label.weak { color: var(--danger, #ef4444); }
.password-strength-label.medium { color: var(--warning, #d97706); }
.password-strength-label.strong { color: var(--success, #16a34a); }

/* ─── Desktop settings form sizing ─── */
@media (min-width: 768px) {
    .settings-page {
        max-width: 600px;
        margin: 0 auto;
    }
    .profile-input, .password-input {
        max-width: 400px;
    }
    .btn-profile-save {
        max-width: 200px;
    }
}

/* Settings tonal card container — replaces 1px section borders */
.settings-category {
    background: var(--card-bg);
    border-radius: 0.75rem;
    overflow: hidden;
    margin-bottom: 1rem;
}
.settings-category .toggle-row {
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.05);
}
.settings-category .toggle-row:last-child {
    box-shadow: none;
}
.loading-text {
    color: var(--text-secondary);
}
.device-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.device-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
}
.device-name {
    font-weight: 600;
}
.device-current {
    font-size: 0.8em;
    color: var(--success);
    margin-left: 8px;
}
.device-role-badge {
    display: inline-block;
    font-size: 0.7em;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}
.role-master {
    background: var(--accent-bg, rgba(59, 130, 246, 0.12));
    color: var(--accent, #3b82f6);
}
.role-linked {
    background: var(--text-secondary-bg, rgba(107, 114, 128, 0.12));
    color: var(--text-secondary, #6b7280);
}
.device-date {
    font-size: 0.85em;
    color: var(--text-secondary);
}
.device-lastseen {
    font-size: 0.8em;
    color: var(--text-secondary);
}
.btn-unlink {
    padding: 6px 14px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}
.link-device-box {
    margin-top: 24px;
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
}
.link-device-box p {
    color: var(--text-secondary);
    margin: 0;
}
.link-device-box .link-device-sub {
    font-size: 0.85em;
    margin: 4px 0 0;
    opacity: 0.7;
}

/* ============ Security info page ============ */
.security-page {
    max-width: 480px;
    margin: 0 auto;
    padding: 24px;
}
.security-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.security-header h3 {
    margin: 0;
}
.safety-number-card {
    background: var(--hover-bg);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    margin-bottom: 24px;
}
.safety-number-label {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
}
.safety-number-value {
    font-family: monospace;
    font-size: 1.4em;
    letter-spacing: 2px;
    line-height: 1.8;
    word-spacing: 8px;
}
.verification-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 500;
}
.verification-badge.verified {
    background: #d4edda;
    color: #155724;
}
.verification-badge.unverified {
    background: #fff3cd;
    color: #856404;
}
.verify-actions {
    text-align: center;
    margin-bottom: 24px;
}
.btn-verify {
    padding: 10px 24px;
    border: none;
    background: var(--success);
    color: white;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1em;
}
.btn-unverify {
    padding: 10px 24px;
    border: 1px solid var(--danger);
    background: var(--card-bg);
    color: var(--danger);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1em;
}
.security-info-box {
    background: var(--hover-bg);
    border-radius: var(--radius);
    padding: 16px;
    color: var(--text-secondary);
    font-size: 0.9em;
    line-height: 1.5;
}
.security-info-box p {
    margin: 0;
}

/* ============ Key change warning ============ */
.key-change-warning {
    padding: 12px 16px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius);
    margin: 8px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.key-change-content {
    flex: 1;
}
.key-change-title {
    margin: 0 0 4px 0;
    font-weight: 600;
    color: #856404;
}
.key-change-text {
    margin: 0;
    color: #856404;
    font-size: 0.9em;
    line-height: 1.4;
}
.key-change-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    color: #856404;
    padding: 0;
    line-height: 1;
}

/* ============ Disappearing timer ============ */
.disappearing-section {
    padding: 12px 0;
}
.disappearing-section h4 {
    margin: 0 0 8px;
}
.disappearing-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.disappearing-select {
    padding: 6px 10px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 0.9em;
    background: var(--input-bg);
    color: var(--text-primary);
    width: auto;
}
.disappearing-save {
    padding: 6px 14px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}
.disappearing-status {
    margin: 6px 0 0;
    font-size: 0.85em;
}
.disappearing-status.is-error {
    color: var(--danger);
}
.disappearing-status.is-success {
    color: var(--success);
}

/* ============ New conversation / search results ============ */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header h2 {
    margin: 0;
}
.page-header-spacer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.page-header-spacer h2 {
    margin: 0;
}
.search-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
.search-result-item.selected {
    background: var(--hover);
}
.search-result-label {
    flex: 1;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}
.search-result-name {
    font-weight: 600;
}
.search-result-meta {
    color: var(--text-secondary);
    font-size: 0.85em;
}

/* ============ New Conversation — WhatsApp/Telegram style ============ */
.nc-mode-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 12px;
}
.nc-mode-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: background 0.12s;
    text-align: start;
}
.nc-mode-item:active,
.nc-mode-item.active {
    background: var(--hover-bg);
}
.nc-mode-item.active {
    color: var(--accent);
    font-weight: 600;
}
.nc-mode-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    flex-shrink: 0;
}
.nc-mode-item.active .nc-mode-icon {
    background: var(--accent);
    color: var(--accent-text);
}
.nc-input-wrap {
    position: relative;
    padding: 8px 16px;
}
.nc-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--input-bg, var(--bg-secondary));
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.nc-input:focus {
    border-color: var(--accent);
}
.nc-search {
    padding-inline-start: 42px;
}
.nc-search-icon {
    position: absolute;
    top: 50%;
    inset-inline-start: 30px;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 1.2rem;
    pointer-events: none;
}
.nc-results {
    display: flex;
    flex-direction: column;
}
.nc-user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.12s;
    text-align: start;
    width: 100%;
}
.nc-user-item:active {
    background: var(--hover-bg);
}
.nc-user-item.selected {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.nc-user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nc-user-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nc-user-meta {
    font-size: 0.82rem;
    color: var(--text-secondary);
    direction: ltr;
    unicode-bidi: embed;
}
.nc-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.nc-check.checked {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.nc-check .material-symbols-outlined {
    font-size: 16px;
}

/* ============ Mode tabs (New Conversation — legacy) ============ */
.tabs {
    display: flex;
    gap: 8px;
}
.tab-btn {
    flex: 1;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ============ Group creation footer ============ */
.group-create-footer {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 0 4px;
    background: var(--bg);
}
.selected-count {
    color: var(--text-secondary);
    font-size: 0.9em;
}
.empty-state {
    padding: 48px 24px;
    text-align: center;
}
.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.centered-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 24px;
}

/* ============ Theme picker ============ */
.theme-section {
    margin-top: 32px;
}
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.theme-card {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--card-bg);
}
.theme-card:hover {
    border-color: var(--accent);
}
.theme-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}
.theme-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin: 0 auto 8px;
    border: 2px solid rgba(0,0,0,0.1);
}
.theme-name {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text-primary);
}

/* ============ Wallpaper picker ============ */
.wallpaper-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.wallpaper-card {
    border: 2px solid var(--border);
    border-radius: var(--radius, 8px);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    text-align: center;
}
.wallpaper-card:hover {
    border-color: var(--accent);
}
.wallpaper-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}
.wallpaper-swatch {
    width: 100%;
    height: 72px;
}
.wallpaper-name {
    font-size: 0.78em;
    font-weight: 500;
    color: var(--text-primary);
    padding: 5px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============ Delivery status icons (WhatsApp-style) ============ */
.delivery-status {
    font-size: 1.15em;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1;
    display: inline-block;
    min-width: 20px;
    text-align: right;
}
.delivery-sending { 
    color: var(--text-secondary); 
    font-size: 0.85em;
    font-weight: 400;
}
.delivery-sent { 
    color: var(--text-secondary); 
    font-weight: 600;
}
.delivery-delivered { 
    color: var(--text-secondary);
    font-weight: 700;
    letter-spacing: -1px;
}
.delivery-read {
    color: var(--read-receipt-color);
    font-weight: 700;
    letter-spacing: -1px;
}

/* ============ Animations & Transitions ============ */
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {    to { opacity: 1; transform: translateX(0); }
}

/* Message slide-in animations (T002) */
@keyframes message-slide-in-left {
    from { opacity: 0; transform: translateX(-20px) translateY(6px); }
    to { opacity: 1; transform: translateX(0) translateY(0); }
}
@keyframes message-slide-in-right {
    from { opacity: 0; transform: translateX(20px) translateY(6px); }
    to { opacity: 1; transform: translateX(0) translateY(0); }
}

/* Reaction pop animation (T003) */
@keyframes reaction-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* Context menu enter animation (T004) */
@keyframes context-menu-enter {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
@keyframes badgePop {
    0% { transform: scale(0.6); }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}
.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

.fade-in {
    animation: fadeIn 0.25s ease-out;
}
.msg-slide-in-right {
    animation: slideInRight 0.2s ease-out;
}
.msg-slide-in-left {
    animation: slideInLeft 0.2s ease-out;
}

/* Smooth theme transitions */
html[data-theme] body,
html[data-theme] .app-nav,
html[data-theme] .card,
html[data-theme] .message-bubble,
html[data-theme] input,
html[data-theme] select,
html[data-theme] textarea {
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Focus ring utility */
.focus-ring:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Typing indicator dots */
.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    margin: 0 1px;
    animation: pulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============ Password strength ============ */
.password-wrapper {
    position: relative;
}
.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 0.85em;
}
.strength-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin-top: 6px;
    overflow: hidden;
}
.strength-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease, background-color 0.3s ease;
}
.strength-bar-fill.weak { width: 33%; background: var(--danger); }
.strength-bar-fill.medium { width: 66%; background: var(--warning); }
.strength-bar-fill.strong { width: 100%; background: var(--success); }
.strength-text {
    font-size: 0.78em;
    margin-top: 2px;
}

/* ============ Logout button ============ */
.btn-logout {
    background: none;
    border: 1px solid rgba(255,255,255,0.4);
    color: rgba(255,255,255,0.85);
    padding: 4px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.15s, border-color 0.15s;
}
.btn-logout:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.7);
}

/* ============ Active nav link ============ */
.app-nav .nav-links a.active {
    color: var(--nav-text);
    border-bottom: 2px solid var(--nav-text);
}

/* ============ Mobile nav backdrop ============ */
.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0,0,0,0.4);
    z-index: 98;
}
.nav-backdrop.open {
    display: block;
}

/* ============ Copy button ============ */
.btn-copy {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.15s, color 0.15s;
}
.btn-copy:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}
.btn-copy.copied {
    color: var(--success);
    border-color: var(--success);
}

/* ============ Confirm dialog ============ */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.15s ease-out;
}
.confirm-dialog {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 380px;
    width: 90%;
    box-shadow: var(--shadow-md);
}
.confirm-dialog h4 { margin: 0 0 8px; }
.confirm-dialog p { margin: 0 0 20px; color: var(--text-secondary); font-size: 0.93em; }
.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ============ Card flush (no padding) ============ */
.card-flush {
    padding: 0;
    overflow: hidden;
}

/* ============ Inline margin utilities ============ */
.mx-chat { margin: 8px 16px; }
.mb-md { margin-bottom: 16px; }
.mt-lg { margin-top: 32px; }
.mb-0 { margin-bottom: 0; }

/* ============ Loading skeleton ============ */
.skeleton {
    background: linear-gradient(90deg, var(--hover-bg) 25%, var(--border) 50%, var(--hover-bg) 75%);
    background-size: 200% 100%;
    animation: pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius);
}
.skeleton-line {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-line.w-40 { width: 40%; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 3px;
}

/* ============ Blazor defaults ============ */
h1:focus { outline: none; }
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}
.blazor-error-boundary::after {
    content: "An error has occurred."
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    text-align: center;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ============ Chat App Shell (two-panel) ============ */
.chat-app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg-primary);
    touch-action: pan-x pan-y; /* prevent pinch-zoom on mobile */
}

.chat-sidebar {
    width: var(--sidebar-width, 340px);
    min-width: 280px;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
    overflow: hidden;
}

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-chat);
}

/* ============ Sidebar header ============ */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--nav-bg);
    color: var(--nav-text);
    min-height: 60px;
    gap: 12px;
    flex-shrink: 0;
}
.sidebar-header-actions {
    margin-inline-start: auto;
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.sidebar-icon-btn {
    background: none;
    border: none;
    color: var(--nav-text);
    opacity: 0.75;
    padding: 6px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-icon-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.1);
}
.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}
.sidebar-user-name {
    font-weight: 600;
    font-size: 0.95em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    display: block;
    text-align: start;
}

/* ============ Sidebar search ============ */
.sidebar-search {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-search input {
    border-radius: 20px;
    background: var(--hover-bg);
    border-color: transparent;
    padding: 8px 16px;
    font-size: 0.9em;
}
.sidebar-search input:focus {
    border-color: var(--accent);
    background: var(--input-bg);
}

/* Sidebar footer — app name and version at bottom */
.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-footer-name {
    font-size: 0.72em;
    color: var(--text-secondary);
    opacity: 0.6;
    font-weight: 500;
}
.sidebar-footer-version {
    font-size: 0.68em;
    color: var(--text-secondary);
    opacity: 0.45;
}

/* ============ Sidebar conversation list ============ */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
}
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.05);
    gap: 12px;
    transition: background 0.12s;
}
.sidebar-item:hover {
    background: var(--hover-bg);
}
.sidebar-item.active {
    background: var(--accent-light);
}
.sidebar-item-body {
    flex: 1;
    min-width: 0;
}
.sidebar-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 2px;
}
.sidebar-item-name {
    font-weight: 600;
    font-size: 0.95em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    margin-inline-end: 8px;
    unicode-bidi: plaintext;
    text-align: start;
}
.sidebar-item-time {
    font-size: 0.75em;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.sidebar-item-preview {
    font-size: 0.84em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============ Chat Bottom Navigation (mobile tab bar) ============ */
.chat-bottom-nav {
    display: none; /* hidden on desktop — shown via mobile media query */
    align-items: center;
    justify-content: space-around;
    padding: 8px 16px max(8px, env(safe-area-inset-bottom));
    border-radius: 2rem 2rem 0 0;
    border-top: none;
    box-shadow: 0 -4px 16px rgba(43,105,90,0.04);
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    position: relative;
    z-index: var(--z-glass-bar);
    flex-shrink: 0;
}
@supports not (backdrop-filter: blur(1px)) {
    .chat-bottom-nav { background: var(--bg-primary); }
}
.chat-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 16px;
    border-radius: 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.6;
    transition: background 200ms ease, color 200ms ease, opacity 200ms ease;
    text-decoration: none;
}
.chat-bottom-nav-item .material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    font-size: 1.375rem;
}
.chat-bottom-nav-item.active {
    background: rgba(43,105,90,0.12);
    color: var(--accent);
    opacity: 1;
    font-weight: 700;
}
.chat-bottom-nav-item.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 24;
}
@media (max-width: 767px) {
    .chat-app-shell { flex-direction: column; }
    .chat-app-shell .chat-sidebar { flex-direction: column; padding-bottom: 0; }
    .chat-bottom-nav {
        display: flex;
        flex-shrink: 0;
        z-index: 20;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-radius: 0;
        box-shadow: 0 -1px 8px rgba(0,0,0,0.08);
    }
}

/* ============ Avatar ============ */
.avatar {
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
    user-select: none;
    letter-spacing: 0;
}

.avatar.avatar-photo {
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.btn-text-sm {
    background: none;
    border: none;
    color: var(--color-primary, #00574a);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 500;
}

.btn-text-sm:hover {
    background: var(--bg-hover, rgba(0, 87, 74, 0.08));
}

/* ============ Welcome state (right panel, no conversation selected) ============ */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 12px;
    background: var(--bg-chat);
}
.chat-welcome-icon {
    font-size: 4em;
    opacity: 0.3;
}
.chat-welcome h3 {
    font-weight: 400;
    color: var(--text-primary);
}
.chat-welcome p {
    font-size: 0.9em;
    max-width: 320px;
    text-align: center;
    margin: 0;
}

/* ============ Panel content wrapper for non-chat pages ============ */
.panel-content-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
}

/* Chat container inside chat-panel: fill the panel height via flex */
.chat-panel .chat-container {
    flex: 1;
    height: unset;
    overflow: hidden;
}

/* ============ Mobile responsive for chat shell ============ */
@media (max-width: 767px) {
    .chat-app-shell {
        position: relative;
    }
    .chat-sidebar {
        width: 100%;
        max-width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        /* Stop above the bottom nav; nav is flex-shrink:0 so its height is stable */
        bottom: var(--bottom-nav-h, 72px);
        z-index: 10;
        transform: translateX(0);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
    }
    .chat-sidebar.hide-mobile {
        transform: translateX(-100%);
        pointer-events: none;
    }
    .chat-panel {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: var(--bottom-nav-h, 72px);
        z-index: 5;
        transform: translateX(100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
    }
    .chat-panel.show-mobile {
        transform: translateX(0);
    }
    /* On mobile, show back button in chat header */
    .back-link-desktop-hidden {
        display: inline-flex;
    }
}
@media (min-width: 768px) {
    /* Hide back button on desktop in chat header */
    .back-link-desktop-hidden {
        display: none;
    }
}

/* ============ Responsive breakpoints ============ */

/* Mobile (< 768px) */
@media (max-width: 767px) {
    /* Hide settings/new buttons on mobile — already in bottom nav */
    .sidebar-desktop-only {
        display: none;
    }
    /* Sidebar icon buttons — larger touch targets on mobile */
    .sidebar-icon-btn {
        width: 40px;
        height: 40px;
        opacity: 0.85;
    }
    .sidebar-icon-btn.sidebar-logout-btn {
        color: var(--danger, #ef4444);
        opacity: 1;
    }
    .app-nav {
        padding: 0 12px;
    }
    .nav-toggle {
        display: block;
    }
    .app-nav .nav-links {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--nav-bg);
        flex-direction: column;
        padding: 8px 0;
        box-shadow: var(--shadow-md);
        z-index: 99;
    }
    .app-nav .nav-links.open {
        display: flex;
    }
    .app-nav .nav-links a {
        padding: 12px 24px;
        width: 100%;
    }
    .app-content {
        padding: 16px 12px;
    }
    .hero {
        padding: 32px 16px;
    }
    .hero h1 {
        font-size: 1.6em;
    }
    .hero p {
        font-size: 0.95em;
    }
    .auth-page {
        margin: 24px auto;
        padding: 0 16px;
        max-width: 100%;
    }
    .auth-page input,
    .auth-page select,
    .auth-page textarea,
    .auth-page .floating-input {
        min-height: 48px;
        font-size: 16px;
    }
    .auth-page .btn-primary,
    .auth-page .btn-full {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }
    .settings-page {
        padding: 8px 12px;
        padding-bottom: env(safe-area-inset-bottom, 24px);
    }
    /* Mobile settings section card adjustments */
    .settings-section-card .section-title,
    .settings-section-card .subsection-title {
        padding: 6px 16px 2px;
        margin: 0;
        font-size: 0.82rem;
    }
    .settings-section-card .settings-category {
        margin-bottom: 0;
        border-radius: 0;
        background: transparent;
    }
    .settings-section-card .toggle-row {
        padding: 10px 16px;
        min-height: 52px;
    }
    .settings-section-card .theme-grid {
        padding: 8px 12px 12px;
    }
    .settings-section-card .font-size-slider-container {
        margin: 0;
        padding: 8px 12px 12px;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
    .settings-section-card .font-size-preview {
        padding: 10px;
        margin-bottom: 12px;
        border-radius: 8px;
    }
    .settings-section-card .font-size-preview-label {
        display: none;
    }
    .settings-section-card .font-size-slider-row {
        gap: 10px;
    }
    .settings-section-card .font-size-selector {
        padding: 4px 12px 12px;
    }
    .settings-section-card .font-size-btn {
        flex: 1;
        min-height: 44px;
        justify-content: center;
    }
    .settings-section-card .wallpaper-grid {
        padding: 8px 12px 12px;
    }
    .settings-section-card .device-list {
        padding: 4px 12px 12px;
    }
    .settings-section-card .device-card {
        padding: 10px 12px;
        border-radius: 8px;
        font-size: 0.88rem;
    }
    .settings-section-card .device-name {
        font-size: 0.92rem;
    }
    .settings-section-card .device-date,
    .settings-section-card .device-lastseen {
        font-size: 0.78rem;
    }
    .settings-section-card .link-device-box {
        margin: 0 12px 12px;
        padding: 12px;
        font-size: 0.88rem;
    }
    .settings-section-card .danger-zone {
        padding: 12px 16px;
    }
    .settings-section-card .backup-status-row {
        padding: 4px 16px 12px;
    }
    .settings-section-card .backup-status {
        font-size: 0.82rem;
    }
    .toggle-label {
        font-size: 0.92rem;
    }
    .toggle-desc {
        font-size: 0.76rem;
    }
    /* ─── Profile Card (mobile) ─── */
    .settings-profile-card {
        display: flex;
        align-items: center;
        gap: 14px;
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
    }
    .settings-profile-info {
        min-width: 0;
    }
    .settings-profile-name {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .settings-profile-username {
        font-size: 0.85rem;
        color: var(--text-secondary);
        margin-top: 2px;
        direction: ltr;
        unicode-bidi: embed;
        text-align: start;
    }
    [dir="rtl"] .settings-profile-card {
        flex-direction: row-reverse;
        text-align: right;
    }
    /* Mobile: tighter field spacing */
    .profile-field {
        margin-bottom: 14px;
    }
    .toggle-row {
        min-height: 48px;
        padding: 10px 0;
    }
    .toggle-switch {
        min-width: 52px;
        width: 52px;
        height: 30px;
        min-height: 30px;
        display: inline-flex;
        align-items: center;
    }
    .theme-card {
        min-height: 60px;
    }
    .theme-grid {
        gap: 10px;
        grid-template-columns: repeat(2, 1fr);
    }
    .wallpaper-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .font-size-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    .font-size-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    .font-size-selector {
        flex-wrap: wrap;
    }
    .font-size-selector .font-size-btn {
        min-height: 44px;
        flex: 1 1 calc(50% - 6px);
    }
    .device-card {
        padding: 12px;
    }
    .btn-unlink {
        min-height: 40px;
        min-width: 70px;
    }
    .btn-danger,
    .btn-secondary {
        min-height: 44px;
        font-size: 16px;
    }
    .danger-zone {
        padding: 16px 0;
    }
    .security-page {
        padding: 16px 12px;
    }
    .security-page .btn-verify,
    .security-page .btn-unverify,
    .security-page .btn-copy {
        min-height: 44px;
        font-size: 16px;
        padding: 12px 24px;
    }
    .safety-number-value {
        font-size: 1.2em;
        letter-spacing: 1px;
        word-spacing: 4px;
    }
    .message-bubble {
        max-width: 85%;
    }
    .theme-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    .emoji-picker-popup {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 50vh;
        border-radius: 16px 16px 0 0;
        z-index: 900;
        border: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .emoji-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 899;
    }
    .sheet-drag-handle {
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--border);
        margin: 8px auto 4px;
    }
    .emoji-grid { grid-template-columns: repeat(7, 1fr); }
    .forward-dialog {
        max-width: calc(100vw - 32px);
        max-height: 80vh;
    }
    .message-image {
        width: 100%;
        max-height: 280px;
        height: auto;
    }
    .lightbox-image {
        max-width: 95vw;
        max-height: 85vh;
    }
    .video-lightbox-content {
        width: 100vw;
        max-width: 100vw;
    }
    .video-lightbox-player {
        max-height: 90vh;
        border-radius: 0;
    }
    .lightbox-close {
        top: 8px;
        right: 8px;
    }
    .lightbox-nav {
        width: 44px;
        height: 60px;
    }
    .lightbox-toolbar-btn {
        min-width: 44px;
        min-height: 44px;
    }
    .toast-container {
        top: 64px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: calc(100% - 32px);
        max-width: 400px;
    }
    /* T001 — chat input row: prevent flex overflow on mobile */
    .chat-input-row {
        gap: 6px;
        min-width: 0;
    }
    /* T005 — textarea: shrink properly in flex */
    .msg-textarea {
        flex: 1 1 0;
        min-width: 0;
    }
    /* T001 — send/mic always visible */
    .send-btn, .mic-btn {
        flex-shrink: 0;
    }
    /* T002 — emoji picker: constrain to viewport */
    .emoji-picker-popup {
        max-width: calc(100vw - 16px);
        max-height: 50vh;
    }
    /* Chat header: compact on mobile, single row */
    .chat-header {
        padding: 8px 8px;
        gap: 6px;
    }
    .chat-header-info {
        gap: 8px;
    }
    .chat-header-actions {
        gap: 2px;
    }
    .msg-action-btn {
        padding: 6px;
        min-width: 36px;
        min-height: 36px;
        background: color-mix(in srgb, var(--text-secondary) 8%, transparent);
        border-radius: 50%;
    }
    .msg-action-btn svg {
        width: 20px;
        height: 20px;
    }
    .msg-action-btn:active {
        background: color-mix(in srgb, var(--text-secondary) 18%, transparent);
    }
    .chat-header-call-btn {
        padding: 6px;
        min-width: 36px;
        min-height: 36px;
        background: color-mix(in srgb, var(--accent) 15%, transparent);
        color: var(--accent);
    }
    /* T004 — voice recorder: ensure it fits mobile width */
    .vr-bar {
        gap: 6px;
        min-width: 0;
    }
    .vr-track {
        min-width: 0;
        flex: 1 1 0;
    }
    .vr-wave-live {
        min-width: 0;
        flex: 1 1 0;
    }
    /* M-10 — quick reply: contain inside message area on mobile */
    .message-bubble.mine .msg-quick-reply { left: 0; }
    .message-bubble.theirs .msg-quick-reply { right: 0; }
    /* M-14 — chat header subtitle: enforce minimum readable size */
    .chat-header-subtitle { font-size: max(12px, 0.8em); }
}

/* Tablet (768px — 1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
    .app-content {
        max-width: 720px;
    }
    .message-bubble {
        max-width: 75%;
    }
    .chat-sidebar {
        width: 35%;
        min-width: 260px;
        max-width: 360px;
        position: relative;
        transform: none !important;
        pointer-events: auto !important;
    }
    .chat-panel {
        position: relative;
        transform: none !important;
        width: 65%;
    }
}
/* M-04 — Small tablets / iPad portrait (768–1023px): tighter sidebar */
@media (min-width: 768px) and (max-width: 1023px) {
    .chat-sidebar {
        width: 280px;
        min-width: 240px;
        max-width: 300px;
    }
    .app-nav .nav-links { gap: 12px; }
}

/* Desktop (1200px+) */
@media (min-width: 1200px) {
    .app-content {
        max-width: 800px;
    }
    .chat-app-shell {
        max-width: var(--chat-max-width);
        margin: 0 auto;
        box-shadow: -1px 0 0 var(--border), 1px 0 0 var(--border);
    }
}

/* Small phone (320px-480px) */
@media (max-width: 480px) {
    /* T005 — textarea */
    .msg-textarea { max-height: 100px; flex: 1 1 0; min-width: 0; }
    /* T001 — send/mic buttons sized for touch, never pushed off-screen */
    .send-btn, .mic-btn { width: 38px; height: 38px; min-width: 38px; flex-shrink: 0; }
    /* T001 — input row: tight gap, no overflow */
    .chat-input-row { gap: 4px; padding: 3px 4px; }
    .chat-input-area { padding: 4px 6px 6px; }
    /* Attach/emoji buttons: comfortably tappable now that bottom nav hides in conversation */
    .attach-btn, .emoji-btn { width: 36px; height: 36px; min-width: 36px; padding: 7px; }
    /* T002 — emoji picker: fit viewport with margin */
    .emoji-picker-popup {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        left: 8px;
        right: 8px;
        border-radius: 12px 12px 0 0;
        max-height: 50vh;
    }
    /* Chat header: extra compact on small screens */
    .chat-header { padding: 6px 6px; gap: 4px; }
    .chat-header-actions { gap: 1px; }
    .msg-action-btn { min-width: 34px; min-height: 34px; padding: 5px; }
    .chat-header-call-btn { padding: 5px; min-width: 36px; min-height: 36px; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
    /* T004 — voice recorder: reduce gaps, smaller buttons to fit */
    .vr-bar { gap: 4px; padding: 3px 4px; }
    .vr-btn-trash { width: 32px; height: 32px; min-width: 32px; }
    .vr-btn-stop { width: 34px; height: 34px; min-width: 34px; }
    .vr-btn-play { width: 32px; height: 32px; min-width: 32px; }
    .vr-btn-send { width: 36px; height: 36px; min-width: 36px; }
    .vr-time { font-size: 0.68em; min-width: 24px; }
    .message-text.emoji-only { font-size: 1.8rem; }
    /* M-05 — media bubbles: prevent overflow on narrow phones */
    .message-bubble:has(.message-image),
    .message-bubble:has(.message-video) { min-width: auto; max-width: 90%; }
    /* M-11 — input row: prevent content push-out on narrow phones */
    .chat-input-row { min-width: 0; }
}

/* Very narrow phones (foldables, 320px) */
@media (max-width: 380px) {
    .message-bubble { max-width: 90%; }
    .chat-input-row { gap: 3px; padding: 2px 3px; }
    .vr-time { display: none; }
}

/* Landscape orientation */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-header { padding: 4px 8px; gap: 6px; }
    .msg-textarea { max-height: 60px; }
    .emoji-picker-popup { max-height: 200px; }
    .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); }
}

/* Touch device target sizes (minimum 44×44 CSS px) */
@media (hover: none) {
    .send-btn, .mic-btn, .attach-btn, .emoji-btn,
    .msg-quick-reply,
    .audio-play-btn, .forward-btn, .reply-close-btn,
    .vr-btn-trash, .vr-btn-stop, .vr-btn-play, .vr-btn-send,
    .emoji-item, .emoji-category-tab, .reaction-badge,
    .theme-swatch,
    .nav-toggle, .btn-logout {
        min-width: 44px;
        min-height: 44px;
    }
    .app-nav .lang-switcher {
        min-height: 36px;
    }
    .conversation-item, .sidebar-item {
        min-height: 56px;
    }
    input[type="text"], input[type="password"], input[type="email"],
    input[type="tel"], input[type="url"], input[type="search"],
    select, textarea {
        min-height: 44px;
    }
    .chat-sidebar a, .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Small phone touch override — keep buttons compact to prevent overflow */
@media (max-width: 480px) and (hover: none) {
    .send-btn, .mic-btn { min-width: 38px; min-height: 38px; }
    .attach-btn, .emoji-btn { min-width: 36px; min-height: 36px; }
    .vr-btn-trash { min-width: 32px; min-height: 32px; }
    .vr-btn-stop { min-width: 34px; min-height: 34px; }
    .vr-btn-play { min-width: 32px; min-height: 32px; }
    .vr-btn-send { min-width: 36px; min-height: 36px; }
}

/* Mobile overflow protection */
@media (max-width: 767px) {
    /* Prevent iOS Safari auto-zoom on input focus (triggers at font-size < 16px) */
    input, textarea, select { font-size: 16px !important; }

    .auth-page { max-width: 100vw; box-sizing: border-box; }
    .modal, .dialog { max-width: 100vw; }

    /* Attach menu: bottom sheet on mobile */
    .attach-menu-popup {
        position: fixed;
        bottom: calc(var(--keyboard-height, 0px) + env(safe-area-inset-bottom, 0px) + 60px);
        left: 12px;
        right: 12px;
        max-width: none;
        border-radius: 16px;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    }
    .attach-menu-backdrop {
        background: rgba(0,0,0,0.3);
    }
    .attach-menu-item {
        min-height: 48px;
        padding: 14px 18px;
    }
}

/* ============ Mobile Action Sheet ============ */
.action-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
}

.action-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: 16px 16px 0 0;
    padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 1001;
    transform: translateY(100%);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
}

.action-sheet-enter {
    transform: translateY(0);
    transition: transform 0.25s ease-out;
}

.action-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 4px auto 8px;
}

.action-sheet-actions {
    display: flex;
    flex-direction: column;
}

.action-sheet-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    min-height: 48px;
    text-align: start;
}

.action-sheet-btn:active {
    background: var(--hover-bg);
}

.action-sheet-btn-danger {
    color: var(--danger);
}

.action-sheet-icon {
    font-size: 1.25rem;
    width: 28px;
    text-align: center;
}

/* ============ Conversation Placeholder ============ */
.conversation-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex: 1;
    background: var(--bg-chat);
}

.conversation-placeholder-content {
    text-align: center;
    color: var(--text-secondary);
}

.conversation-placeholder-icon {
    margin-bottom: 16px;
    color: var(--text-secondary);
    opacity: 0.6;
}

.conversation-placeholder-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px;
}

.conversation-placeholder-text {
    font-size: 1rem;
    margin: 0;
    color: var(--text-secondary);
}

/* ============ Hide bottom nav in conversation (WhatsApp/Telegram/Signal pattern) ============ */
@media (max-width: 767px) {
    .in-conversation .chat-bottom-nav {
        display: none;
    }
    .in-conversation .chat-container {
        height: 100vh;
        height: 100dvh;
    }
}

/* ============ Keyboard Height Offset ============ */
@media (max-width: 767px) {
    .chat-input-area {
        padding-bottom: max(var(--keyboard-height, 0px), env(safe-area-inset-bottom, 0px));
        max-width: 100vw;
        box-sizing: border-box;
    }
}

/* ─── Font Size Scaling (CSS custom property driven) ─── */
html {
    --app-font-size: 15px;
    font-size: var(--app-font-size);
}
body { font-size: var(--app-font-size); }

/* ─── Font Size Slider ─── */
.font-size-slider-container {
    margin-top: 12px;
    padding: 20px 24px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
}
.font-size-preview {
    text-align: center;
    margin-bottom: 20px;
    padding: 16px;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    transition: font-size 0.15s ease-out;
    color: var(--text-primary);
    line-height: 1.5;
}
.font-size-preview-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.font-size-slider-row {
    display: flex;
    align-items: center;
    gap: 16px;
}
.font-size-slider-row .slider-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
    font-weight: 700;
    user-select: none;
}
.font-size-slider-row .slider-icon-sm {
    font-size: 12px;
}
.font-size-slider-row .slider-icon-lg {
    font-size: 22px;
}
.font-size-slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    transition: background 0.2s;
    cursor: pointer;
}
.font-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 3px solid var(--bg-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}
.font-size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}
.font-size-slider::-webkit-slider-thumb:active {
    transform: scale(1.25);
    box-shadow: 0 2px 16px color-mix(in srgb, var(--accent) 50%, transparent);
}
.font-size-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 3px solid var(--bg-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}
.font-size-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
}
.font-size-slider::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: var(--border);
}
.font-size-value {
    text-align: center;
    margin-top: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.5px;
}
.font-size-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 12px;
    margin-top: 4px;
}
.font-size-ticks span {
    font-size: 0.65rem;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* ─── Settings Toggles ─── */
.settings-toggles {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.toggle-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.05);
}
.toggle-row:last-child {
    box-shadow: none;
}
.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.toggle-label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    text-align: start;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.toggle-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: start;
    line-height: 1.4;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
/* Backup status row */
.backup-status-row {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    gap: 10px;
}
.backup-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}
.backup-status.backup-ok {
    color: var(--success);
}
.backup-status.backup-none {
    color: var(--warning);
}
.btn-backup {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    align-self: flex-start;
}
.btn-backup:hover:not(:disabled) {
    background: var(--accent);
    color: var(--accent-text);
}
.btn-backup:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.backup-password-prompt {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}
.backup-password-prompt .password-field-wrapper {
    max-width: 300px;
}
.backup-password-prompt .backup-password-input {
    padding: 10px 12px;
    font-size: 0.9rem;
}
.backup-prompt-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.backup-prompt-actions .btn-backup,
.backup-prompt-actions .btn-secondary {
    width: 100%;
    max-width: 300px;
}
.btn-sm {
    padding: 6px 14px !important;
    font-size: 0.82rem !important;
}

.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 30px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 30px;
    transition: background 0.25s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 24px;
    width: 24px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* ─── Subsection Title ─── */
.subsection-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.mt-md { margin-top: 16px; }

/* ─── Language Selector (reuses font-size-btn styling) ─── */
.font-size-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ─── Date Separator ─── */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
    gap: 12px;
}
.date-separator::before, .date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.date-separator-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-chat);
    padding: 4px 12px;
    border-radius: 12px;
    white-space: nowrap;
}

/* ─── Message Grouping ─── */
.message-row.group-first { margin-bottom: 2px; }
.message-row.group-middle { margin-top: 2px; margin-bottom: 2px; }
.message-row.group-last { margin-top: 2px; }

.message-row.group-first .message-bubble.mine,
.message-row.group-middle .message-bubble.mine {
    border-bottom-right-radius: 4px;
}
.message-row.group-middle .message-bubble.mine,
.message-row.group-last .message-bubble.mine {
    border-top-right-radius: 4px;
}
.message-row.group-first .message-bubble.theirs,
.message-row.group-middle .message-bubble.theirs {
    border-bottom-left-radius: 4px;
}
.message-row.group-middle .message-bubble.theirs,
.message-row.group-last .message-bubble.theirs {
    border-top-left-radius: 4px;
}

/* ─── Scroll to Bottom ─── */
.scroll-to-bottom {
    position: absolute;
    bottom: 80px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}
.scroll-to-bottom.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}
.scroll-arrow {
    font-size: 1.2rem;
    font-weight: bold;
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    opacity: 0.3;
    margin-bottom: 16px;
    color: var(--text-secondary);
}
.empty-state h3 {
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}
.empty-state p {
    font-size: 0.9rem;
}

/* ─── Skeleton Loader ─── */
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}
.skeleton-shimmer {
    background: linear-gradient(90deg, var(--hover-bg) 25%, var(--border) 50%, var(--hover-bg) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s infinite ease-in-out;
}

.skeleton-conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}
.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
}
.skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.skeleton-line {
    height: 12px;
    border-radius: 6px;
}
.skeleton-line-short { width: 40%; }
.skeleton-line-long { width: 75%; }

.skeleton-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 24px 16px;
}
.skeleton-msg {
    height: 36px;
    border-radius: var(--radius);
    width: 45%;
}
.skeleton-msg-left { align-self: flex-start; }
.skeleton-msg-right { align-self: flex-end; }
.skeleton-msg-wide { width: 65%; }

/* ─── Toast Notifications ─── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    transition: opacity 0.3s, transform 0.3s;

    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    min-width: 280px;
    max-width: 420px;
    border-left: 4px solid var(--accent);
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }
.toast-message {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
}
.toast-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
}
.toast-close:hover {
    color: var(--text-primary);
}

@keyframes toast-slide-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-slide-out {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}
.toast-enter {
    animation: toast-slide-in 0.3s ease-out;
}
.toast-exit {
    animation: toast-slide-out 0.3s ease-in forwards;
}

/* ─── Unread Divider ─── */
.unread-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    color: var(--accent);
}
.unread-divider::before, .unread-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--accent);
}
.unread-divider span {
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
}

/* ─── Load Earlier Messages ─── */
.load-earlier-messages {
    text-align: center;
    padding: 8px 0 4px;
}
.load-earlier-messages .btn-link {
    font-size: 0.82rem;
    color: var(--accent);
    opacity: 0.8;
    transition: opacity 0.15s;
}
.load-earlier-messages .btn-link:hover {
    opacity: 1;
}

/* ============ Image Lightbox ============ */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}
.lightbox-toolbar {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1002;
    display: flex;
    align-items: center;
    gap: 8px;
}
.lightbox-toolbar-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}
.lightbox-toolbar-btn:hover {
    background: rgba(255,255,255,0.3);
}
.lightbox-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 2em;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    line-height: 1;
    padding: 0;
}
.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}
.lightbox-counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.8);
    font-size: 0.9em;
    z-index: 1002;
    background: rgba(0,0,0,0.4);
    padding: 4px 14px;
    border-radius: 12px;
}
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1002;
    background: rgba(255,255,255,0.12);
    border: none;
    color: white;
    font-size: 2.5em;
    width: 48px;
    height: 72px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}
.lightbox-nav:hover {
    background: rgba(255,255,255,0.25);
}
.lightbox-nav-left { left: 16px; }
.lightbox-nav-right { right: 16px; }
.lightbox-image-wrapper {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: grab;
}
.lightbox-image {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    transform-origin: center center;
}
/* ============ Video Lightbox (fullscreen player) ============ */
.video-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}
.video-lightbox-content {
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.video-lightbox-player {
    width: 100%;
    max-height: 85vh;
    border-radius: 8px;
    background: #000;
    outline: none;
}

.message-image-clickable {
    cursor: pointer;
    position: relative;
    display: block;
}

/* ============ Emoji Picker ============ */
.emoji-picker-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 201;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    width: 320px;
    max-height: 380px;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.15s ease-out;
}
.emoji-picker-close {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    z-index: 10;
}
.emoji-picker-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}
.emoji-picker-search {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}
.emoji-picker-search input {
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 0.85em;
    background: var(--hover-bg);
    border-color: transparent;
}
.emoji-picker-search input:focus {
    border-color: var(--accent);
    background: var(--input-bg);
}
.emoji-category-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
}
.emoji-category-tab {
    flex: 1;
    min-width: 36px;
    padding: 6px 2px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 1.1em;
    cursor: pointer;
    text-align: center;
    transition: background 0.12s;
}
.emoji-category-tab:hover {
    background: var(--hover-bg);
}
.emoji-category-tab.active {
    border-bottom-color: var(--accent);
}
.emoji-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.emoji-category-label {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    padding: 4px 4px 6px;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}
.emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    transition: background 0.1s;
}
.emoji-item:hover {
    background: var(--hover-bg);
}
.emoji-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.emoji-btn:hover {
    background: var(--hover-bg);
    color: var(--accent);
}

/* ============ Reply Quote ============ */
.reply-quote-block {
    border-left: 3px solid var(--accent);
    background: rgba(0,0,0,0.06);
    border-radius: 6px;
    padding: 4px 8px;
    margin-bottom: 4px;
    cursor: pointer;
    max-height: 64px;
    overflow: hidden;
    display: flex;
    gap: 8px;
    align-items: center;
}
.reply-quote-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.message-bubble.mine .reply-quote-block {
    background: rgba(128,128,128,0.15);
    border-left-color: currentColor;
    border-left-width: 3px;
    border-left-style: solid;
}
.reply-media-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}
.reply-sender-name {
    font-size: 0.78em;
    font-weight: 600;
    color: inherit;
    opacity: 0.85;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}
.message-bubble.mine .reply-sender-name {
    color: inherit;
    opacity: 0.9;
}
.reply-quote-text {
    font-size: 0.83em;
    opacity: 0.8;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}
/* ============ Reply Preview Bar (above message input — WhatsApp style) ============ */
.reply-preview-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 0;
    max-height: 52px;
    overflow: hidden;
    background: var(--bg-secondary, rgba(0,0,0,0.04));
    border-radius: 8px 8px 0 0;
    margin: 0 4px;
    position: relative;
}
.reply-preview-bar::before {
    content: '';
    width: 4px;
    align-self: stretch;
    background: var(--accent);
    border-radius: 4px 0 0 4px;
    flex-shrink: 0;
}
.reply-preview-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    padding: 2px 0;
}
.reply-preview-bar .reply-sender-name {
    font-weight: 600;
    font-size: 0.75em;
    color: var(--accent);
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-preview-bar .reply-quote-text {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.reply-preview-bar .reply-media-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}
.reply-preview-close {
    background: none;
    border: none;
    font-size: 1.1em;
    color: var(--text-secondary);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
    position: relative;
    transition: background 0.15s;
}
/* 44px touch target via pseudo-element */
.reply-preview-close::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
}
.reply-preview-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

/* ============ Context Menu ============ */
.context-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: transparent;
}
.context-menu {
    /* T014: Context menu enter animation */
    animation: context-menu-enter 0.15s ease-out;

    position: fixed;
    z-index: 501;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.18);
    min-width: 170px;
    max-width: calc(100vw - 16px);
    overflow: hidden;
    animation: fadeIn 0.12s ease-out;
    padding: 4px 0;
    transform-origin: top left;
}
/* Flip context menu upward when near bottom of viewport */
.context-menu.flip-up {
    transform-origin: bottom left;
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.88em;
    color: var(--text-primary);
    transition: background 0.1s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.context-menu-item:hover {
    background: var(--hover-bg);
}
.context-menu-item.danger {
    color: var(--danger);
}
.context-menu-icon {
    font-size: 1.1em;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* message-actions: replaced by .msg-quick-reply inside bubble */

/* ============ Presence / Online Status ============ */
.presence-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--card-bg);
    position: absolute;
    bottom: 0;
    right: 0;
}
.avatar-wrapper {
    position: relative;
    display: inline-flex;
}
.presence-text {
    font-size: 0.78em;
    color: var(--text-secondary);
}
.presence-online {
    color: var(--success);
}

/* ============ Voice Recorder (WhatsApp-style) ============ */

/* Mic button (in message input) */
.mic-btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    touch-action: manipulation;
}
.mic-btn:hover {
    color: var(--accent);
    background: var(--hover-bg);
}

/* --- Bar (shared base for recording & preview) --- */
.vr-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    background: var(--input-bg, var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: 24px;
    flex: 1;
    min-height: 46px;
    max-height: 52px;
}

/* --- Shared button base --- */
.vr-btn {
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    touch-action: manipulation;
    padding: 0;
}
.vr-btn:active { transform: scale(0.9); }

/* Trash/cancel */
.vr-btn-trash {
    width: 34px; height: 34px; min-width: 34px;
    background: transparent;
    color: var(--text-secondary);
}
.vr-btn-trash:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

/* Stop recording */
.vr-btn-stop {
    width: 38px; height: 38px; min-width: 38px;
    background: #ef4444;
    color: var(--accent-text);
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}
.vr-btn-stop:hover { background: #dc2626; }

/* Play/pause — outlined style to distinguish from filled Send button */
.vr-btn-play {
    width: 34px; height: 34px; min-width: 34px;
    background: transparent;
    color: var(--accent);
    border: 2px solid var(--accent) !important;
}
.vr-btn-play:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Send — WhatsApp green filled circle, visually distinct from outlined Play */
.vr-btn-send {
    width: 42px; height: 42px; min-width: 42px;
    background: var(--waveform-played, var(--accent));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.35);
    border: none !important;
}
.vr-btn-send:hover { background: #008f72; }

/* Timer */
.vr-time {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.78em;
    color: var(--text-secondary);
    min-width: 32px;
    text-align: center;
    flex-shrink: 0;
    white-space: nowrap;
}

/* --- Recording phase --- */
.vr-rec-indicator {
    width: 10px; height: 10px;
    flex-shrink: 0;
    position: relative;
}
.vr-rec-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #ef4444;
    display: block;
    animation: vr-pulse 1.4s ease-in-out infinite;
}
@keyframes vr-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

/* Live waveform */
.vr-wave-live {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 28px;
    flex: 1;
    overflow: hidden;
}
.vr-bar-live {
    width: 2.5px;
    background: var(--accent);
    border-radius: 2px;
    min-height: 2px;
    opacity: 0.65;
    transition: height 0.08s ease-out;
}

/* --- Preview phase --- */
.vr-track {
    flex: 1;
    position: relative;
    min-width: 0;
    height: 28px;
    display: flex;
    align-items: center;
}
.vr-seek {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
}
.vr-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 28px;
    background: transparent;
    cursor: pointer;
}
.vr-seek::-moz-range-thumb {
    width: 14px; height: 28px;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* Static waveform */
.vr-wave-static {
    display: flex;
    align-items: center;
    gap: 1.5px;
    height: 28px;
    width: 100%;
    overflow: hidden;
}
.vr-bar-static {
    width: 2.5px;
    min-height: 3px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.12s;
    flex-shrink: 0;
}
.vr-bar-static.played {
    background: var(--accent);
}

/* --- Mobile (<=480px) --- */
@media (max-width: 480px) {
    .vr-bar {
        gap: 4px;
        padding: 3px 4px;
        min-height: 40px;
        border-radius: 20px;
        min-width: 0;
    }
    .vr-btn-trash { width: 32px; height: 32px; min-width: 32px; }
    .vr-btn-stop { width: 34px; height: 34px; min-width: 34px; }
    .vr-btn-play { width: 32px; height: 32px; min-width: 32px; }
    .vr-btn-send { width: 36px; height: 36px; min-width: 36px; }
    .vr-time { font-size: 0.68em; min-width: 24px; }
    .vr-wave-live { gap: 1.5px; height: 24px; min-width: 0; flex: 1 1 0; }
    .vr-bar-live { width: 2px; }
    .vr-wave-static { gap: 1px; height: 24px; min-width: 0; }
    .vr-bar-static { width: 2px; }
    .vr-track { min-width: 0; flex: 1 1 0; }
}

/* --- Tablet (481-1199px) --- */
@media (min-width: 481px) and (max-width: 1199px) {
    .vr-bar { gap: 8px; }
}

/* --- Landscape phones --- */
@media (max-height: 500px) and (orientation: landscape) {
    .vr-bar {
        min-height: 38px;
        max-height: 42px;
        padding: 3px 6px;
    }
    .vr-wave-live, .vr-wave-static { height: 20px; }
}

/* ============ Link Preview ============ */
.link-preview-card {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 6px;
    background: var(--card-bg);
    text-decoration: none;
    color: inherit;
    max-width: 100%;
    transition: background 0.12s;
}
.link-preview-card:hover {
    background: var(--hover-bg);
    text-decoration: none;
}
.link-preview-image {
    width: 80px;
    min-height: 80px;
    object-fit: cover;
    flex-shrink: 0;
}
.link-preview-info {
    padding: 8px 10px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.link-preview-title {
    font-size: 0.85em;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.link-preview-desc {
    font-size: 0.78em;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.link-preview-domain {
    font-size: 0.72em;
    color: var(--text-secondary);
    text-transform: lowercase;
}
.link-preview-loading {
    padding: 8px;
    font-size: 0.8em;
    color: var(--text-secondary);
}

/* ============ Message Reactions ============ */
.reaction-picker {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: fadeIn 0.12s ease-out;
}
.reaction-picker-item {
    font-size: 1.3em;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    transition: background 0.1s, transform 0.1s;
}
.reaction-picker-item:hover {
    background: var(--hover-bg);
    transform: scale(1.2);
}
.reaction-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    background: var(--hover-bg);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}
.reaction-badge:hover {
    background: var(--accent-light);
}
.reaction-badge.mine {
    border-color: var(--accent);
    background: var(--accent-light);
}
.reaction-badge-emoji {
    font-size: 1.1em;
}
.reaction-badge-count {
    font-size: 0.78em;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============ Chat Header Menu ============ */
.chat-header-menu {
    position: absolute;
    inset-inline-end: 12px;
    top: 52px;
    z-index: 501;
}

/* ============ Clear Chat Dialog ============ */
.clear-chat-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    z-index: 1100;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    min-width: 280px;
    max-width: 360px;
    text-align: center;
}
.clear-chat-dialog h4 {
    margin: 0 0 8px;
    color: var(--text-primary);
}
.clear-chat-dialog p {
    margin: 0 0 16px;
    color: var(--text-secondary);
    font-size: 0.9em;
}
.clear-chat-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.clear-chat-option {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--hover-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.95em;
    transition: background 0.15s;
}
.clear-chat-option:hover {
    background: var(--border);
}
.clear-chat-option.danger {
    border-color: var(--danger);
    color: var(--danger);
}
.clear-chat-option.danger:hover {
    background: var(--danger);
    color: var(--accent-text);
}
.clear-chat-cancel {
    padding: 8px 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9em;
}
.clear-chat-cancel:hover {
    color: var(--text-primary);
}

/* ============ Message Search Bar ============ */
.chat-search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.chat-search-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9em;
    outline: none;
}
.chat-search-input:focus {
    border-color: var(--accent);
}
.chat-search-count {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 40px;
    text-align: center;
}

/* Search results panel */
.chat-search-results {
    max-height: 240px;
    overflow-y: auto;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.chat-search-result-item {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 2px 8px;
    width: 100%;
    padding: 8px 16px;
    border: none;
    background: transparent;
    text-align: start;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}
.chat-search-result-item:hover,
.chat-search-result-item.active {
    background: var(--hover-bg, rgba(0,0,0,0.05));
}
.chat-search-result-sender {
    grid-column: 1;
    grid-row: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-search-result-time {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.chat-search-result-text {
    grid-column: 1 / span 2;
    grid-row: 2;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search highlight on currently focused match */
.message-highlight {
    animation: search-highlight-flash 1.5s ease;
}
@keyframes search-highlight-flash {
    0%, 30% { background-color: var(--accent-light); }
    100% { background-color: transparent; }
}

/* ============ Forward Dialog ============ */
.forward-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.forward-dialog {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 420px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.forward-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.forward-dialog-header h4 {
    margin: 0;
    font-size: 1em;
}
.forward-search-input {
    margin: 10px 12px;
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9em;
    outline: none;
}
.forward-search-input:focus {
    border-color: var(--accent);
}
.forward-conversation-list {
    flex: 1;
    overflow-y: auto;
}
.forward-conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    font-size: 0.95em;
}
.forward-conversation-item:hover {
    background: var(--hover-bg);
}

/* ============ Forwarded Label ============ */
.forwarded-label {
    font-size: 0.75em;
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: 2px;
    opacity: 0.8;
}



/* T011: Mobile timestamps - full opacity on touch devices */
@media (hover: none) {
    .message-meta, .msg-meta {
        opacity: 1 !important;
    }
}
/* T016: Skeleton shimmer effect */
@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton-line, .skeleton-avatar, .skeleton-message {
    background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-shimmer) 50%, var(--skeleton-base) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
}
/* T020: Forward dialog styling */
.forward-dialog {
    background: var(--card-bg);
    border-radius: var(--input-radius);
    box-shadow: var(--shadow-md);
}
/* T021: Clear chat dialog styling */
.clear-chat-dialog {
    background: var(--card-bg);
    border-radius: var(--input-radius);
    box-shadow: var(--shadow-md);
}
/* T022: Search counter styling */
.chat-search-count {
    color: var(--text-secondary);
    font-size: 0.85em;
}
/* T023: Focus rings for accessibility */
button:focus-visible, input:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
/* T024: Touch targets - minimum 44px (excluding chat header buttons which size via their own rules) */
.context-menu-item, .clear-chat-option, .forward-conversation-item {
    min-height: 44px;
    min-width: 44px;
}
/* T025: Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
/* T005: Reduced motion preference - disable all animations */
@media (prefers-reduced-motion: reduce) {
    .message-row,
    .toast,
    .context-menu,
    .reaction-badge,
    .skeleton-line,
    .skeleton-avatar,
    .skeleton-conversation-item,
    .skeleton-message,
    .action-sheet,
    .action-sheet-backdrop,
    .emoji-sheet-backdrop,
    .emoji-picker-popup,
    .chat-sidebar,
    .chat-panel {
        animation: none !important;
        transition: none !important;
    }
}

/* ============ Group Info Page ============ */
.chat-header-group-info-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    text-align: start;
    min-width: 0;
    flex: 1;
}
.chat-header-group-info-btn:hover {
    opacity: 0.85;
}
.chat-header-group-info-btn .chat-header-title {
    margin: 0;
}

.group-info-page .panel-content-scroll {
    padding: 0 0 48px;
}

.group-info-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px 20px;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.group-info-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.group-info-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.group-info-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

.group-info-edit-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 320px;
}

.group-info-section {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.group-info-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.group-info-section-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.group-info-section-value {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.group-info-desc-section { }

.group-info-desc-text {
    margin: 4px 0 0;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.group-desc-textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
    box-sizing: border-box;
}

.group-info-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.add-member-btn {
    font-size: 1.1rem;
    line-height: 1;
}

.add-member-panel {
    margin-top: 8px;
}

.search-results-list {
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.group-info-actions {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.leave-confirm-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    width: 100%;
    box-sizing: border-box;
}

.leave-confirm-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ============ Shared utility classes ============ */
.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    font-family: inherit;
}
.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-icon {
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
    border-radius: 4px;
}
.btn-icon:hover {
    color: var(--accent);
    background: var(--accent-light, rgba(0,0,0,0.05));
}

.settings-input {
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: var(--input-bg, var(--bg-secondary));
    font-family: inherit;
    color: var(--text-primary);
    font-size: 0.95rem;
    box-sizing: border-box;
    outline: none;
    transition: background 0.15s, box-shadow 0.15s;
}
.settings-input:focus {
    background: var(--bg-secondary);
    box-shadow: 0 0 0 2px rgba(119, 90, 25, 0.30);
}

.field-error {
    color: var(--danger);
    font-size: 0.82rem;
    margin: 4px 0 0;
}

/* ============ System Message Bubble ============ */
.system-message-bubble {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 12px;
    margin: 6px auto;
    max-width: 80%;
    text-align: center;
    user-select: none;
    pointer-events: none;
}

.system-message-text {
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 3px 10px;
    line-height: 1.4;
}

.system-message-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.7;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============ Invite Link Panel ============ */
.invite-link-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
}
.invite-link-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
}
.invite-link-text {
    flex: 1;
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.invite-link-expiry {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}
.invite-link-generate {
    display: flex;
    align-items: center;
    gap: 8px;
}
.invite-expiry-select {
    flex: 1;
}
.invite-link-copied {
    color: var(--success, #28a745);
    font-size: 0.82rem;
    margin: 0;
}

/* ============ Invite Page ============ */
.invite-page-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
}
.invite-card, .invite-invalid-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
}
.invite-group-name {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0;
}
.invite-member-count {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9rem;
}
.invite-join-btn {
    width: 100%;
    margin-top: 8px;
}

/* ============ Muted Notice ============ */
.muted-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--warning-light, #fff3cd);
    color: var(--warning, #856404);
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

/* ============ Group Member List ============ */
.member-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
}
.member-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.member-list-item:last-child {
    border-bottom: none;
}
.member-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.member-name {
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.member-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.member-role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--primary-light, #e3f2fd);
    color: var(--primary, #1976d2);
}
.member-muted-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--warning-light, #fff3cd);
    color: var(--warning, #856404);
}
.member-actions {
    position: relative;
}
.member-context-menu {
    right: 0;
    left: auto;
}
.mute-duration-popup {
    position: absolute;
    right: 0;
    top: 32px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 200;
    min-width: 140px;
    padding: 4px 0;
    display: flex;
    flex-direction: column;
}

/* ============ Responsive — New Group Chat Components ============ */
@media (max-width: 767px) {
    /* Group Info page */
    .group-info-header { padding: 16px 0 8px; }
    .group-info-name { font-size: 1.2rem; }
    .panel-content-scroll { padding: 16px 12px; }

    /* Invite page */
    .invite-card, .invite-invalid-card {
        padding: 24px 16px;
        max-width: 100%;
        border-radius: 12px;
    }
    .invite-page-container { padding: 16px; }

    /* Media gallery */
    .media-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Group member list */
    .member-list-item { padding: 8px 10px; }

    /* Search results */
    .chat-search-results { max-height: 200px; }
    .chat-search-result-item { padding: 6px 12px; }

    /* Mute duration popup */
    .mute-duration-popup { right: 0; min-width: 120px; }
}

/* RTL layout support (Arabic) */
[dir="rtl"] .member-context-menu { right: auto; left: 0; }
[dir="rtl"] .mute-duration-popup { right: auto; left: 0; }
[dir="rtl"] .invite-link-copy { flex-direction: row-reverse; }
[dir="rtl"] .group-info-name-row { flex-direction: row-reverse; }
[dir="rtl"] .media-gallery-tabs { flex-direction: row-reverse; }
[dir="rtl"] .chat-search-result-sender { text-align: end; }
[dir="rtl"] .chat-search-result-time { text-align: start; }

/* ── Chat header call button ─────────────────────────────────────────────── */

.chat-header-call-btn {
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

.chat-header-call-btn:hover {
    color: var(--accent-hover, var(--accent));
    background: var(--hover-bg);
}

.chat-header-call-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--text-secondary);
}

/* ── Call record rows in thread ──────────────────────────────────────────── */

.call-record-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin: 4px auto;
    max-width: 280px;
    border-radius: 8px;
    background: var(--card-bg, rgba(0,0,0,0.05));
    font-size: 13px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.call-record-icon {
    font-size: 15px;
    flex-shrink: 0;
}

.call-record-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

.call-record-direction {
    font-size: 11px;
    font-weight: 700;
}

.call-record-label {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.call-record-duration {
    color: var(--text-secondary);
    font-size: 11px;
    white-space: nowrap;
}

.call-record-time {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.call-record-completed .call-record-icon { color: var(--call-btn-accept, #43a047); }
.call-record-missed .call-record-icon    { color: #e53935; }
.call-record-cancelled .call-record-icon { color: var(--text-secondary); }

.call-record-missed .call-record-label   { color: #e53935; }
