/* ============================================================
   Nova Chat — Stylesheet
   Nova Net Visual System v1.0
   RTL | Vazirmatn Font | Dark/Light Mode
   ============================================================ */

/* ── Vazirmatn Font (Self-hosted) ─────────────────────────── */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Thin.woff2') format('woff2');
    font-weight: 100; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-ExtraLight.woff2') format('woff2');
    font-weight: 200; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Light.woff2') format('woff2');
    font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Regular.woff2') format('woff2');
    font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Medium.woff2') format('woff2');
    font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-SemiBold.woff2') format('woff2');
    font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Bold.woff2') format('woff2');
    font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-ExtraBold.woff2') format('woff2');
    font-weight: 800; font-style: normal; font-display: swap;
}
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn/Vazirmatn-Black.woff2') format('woff2');
    font-weight: 900; font-style: normal; font-display: swap;
}

/* ── Design Tokens ────────────────────────────────────────── */
:root {
    /* Dark Mode (default) */
    --bg-primary:    #0A0E1A;
    --bg-secondary:  #111827;
    --bg-card:       #151E2E;
    --bg-hover:      #1A2540;
    --bg-input:      #0F1929;
    --border:        #1E2D45;
    --border-light:  #253552;

    --accent:        #00C9A7;
    --accent-hover:  #00B596;
    --accent-dim:    rgba(0, 201, 167, 0.12);
    --accent-glow:   rgba(0, 201, 167, 0.25);

    --text-primary:  #F0F5FF;
    --text-secondary:#8B9DC3;
    --text-muted:    #4E6080;

    --msg-sent-bg:   #00C9A7;
    --msg-sent-text: #0A1A15;
    --msg-recv-bg:   #1A2540;
    --msg-recv-text: #E8F0FF;

    --online-color:  #10B981;
    --danger:        #EF4444;
    --warning:       #F59E0B;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    --sidebar-width: 320px;
    --header-height: 60px;
    --transition: 0.2s ease;
}

html.light {
    --bg-primary:    #F0F4F8;
    --bg-secondary:  #FFFFFF;
    --bg-card:       #FFFFFF;
    --bg-hover:      #E8EEF6;
    --bg-input:      #F5F8FC;
    --border:        #DDE5F0;
    --border-light:  #C8D5E8;

    --text-primary:  #0D1627;
    --text-secondary:#5A6E8A;
    --text-muted:    #9EB0C8;

    --msg-sent-bg:   #00C9A7;
    --msg-sent-text: #0A1A15;
    --msg-recv-bg:   #EDF2FA;
    --msg-recv-text: #0D1627;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.14);
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-family: 'Vazirmatn', 'Tahoma', 'Arial', sans-serif;
    font-size: 15px;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; outline: none; }

/* ── Theme Toggle ─────────────────────────────────────────── */
.theme-toggle,
.theme-toggle-auth {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border: 1px solid var(--border);
    transition: all var(--transition);
}
.theme-toggle:hover,
.theme-toggle-auth:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}

html:not(.light) .icon-moon,
html.light      .icon-sun  { display: block; }
html:not(.light) .icon-sun,
html.light      .icon-moon { display: none; }

/* ============================================================
   AUTH PAGES (Login / Register)
   ============================================================ */
.auth-page {
    display: flex;
    min-height: 100dvh;
    overflow: auto;
    background: var(--bg-primary);
}

.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    width: 100%;
    padding: 24px 16px;
    position: relative;
}

.theme-toggle-auth {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 10;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.35s ease;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo-img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 16px var(--accent-glow));
}

.auth-brand {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.auth-brand span {
    color: var(--accent);
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 20px;
    font-weight: 500;
}
.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: #FCA5A5;
    border: 1px solid rgba(239, 68, 68, 0.25);
}
.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: #6EE7B7;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

/* Form */
.auth-form { display: flex; flex-direction: column; gap: 18px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-hint {
    font-size: 0.775rem;
    color: var(--text-muted);
    margin-top: -2px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    right: 14px;
    color: var(--text-muted);
    display: flex;
    pointer-events: none;
    z-index: 1;
}

.form-input {
    width: 100%;
    padding: 12px 44px 12px 14px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input::placeholder { color: var(--text-muted); }

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.toggle-password {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    display: flex;
    padding: 4px;
    transition: color var(--transition);
}
.toggle-password:hover,
.toggle-password.active { color: var(--accent); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    transition: all var(--transition);
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: var(--accent);
    color: #0A1A15;
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-block { width: 100%; margin-top: 4px; }

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-link {
    color: var(--accent);
    font-weight: 600;
}
.auth-link:hover { text-decoration: underline; }

/* ============================================================
   CHAT APP LAYOUT
   ============================================================ */
/* ── Site Announcement Ticker ─────────────────────────────── */
.site-announcement {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    height: 40px;
    display: flex;
    align-items: stretch;
    direction: ltr;
    background: #06100d;
    border-bottom: 1px solid rgba(0,201,167,.18);
    box-shadow: 0 1px 16px rgba(0,201,167,.07);
    overflow: hidden;
}

.announcement-badge {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 18px 0 12px;
    background: var(--accent);
    color: #06100d;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .6px;
    text-transform: uppercase;
    white-space: nowrap;
    clip-path: polygon(0 0, calc(100% - 11px) 0, 100% 50%, calc(100% - 11px) 100%, 0 100%);
}

.announcement-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #06100d;
    opacity: .6;
    animation: ann-pulse 1.6s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes ann-pulse {
    0%, 100% { transform: scale(1); opacity: .6; }
    50%       { transform: scale(1.5); opacity: 1; }
}

.announcement-ticker {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    -webkit-mask-image: linear-gradient(to right, transparent 0%, #000 5%, #000 95%, transparent 100%);
    mask-image: linear-gradient(to right, transparent 0%, #000 5%, #000 95%, transparent 100%);
}

.announcement-track {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    color: rgba(195,230,222,.85);
    font-size: .8rem;
    font-weight: 400;
    letter-spacing: .1px;
    animation: ann-ticker 28s linear infinite;
}

.announcement-track span { direction: rtl; }

@keyframes ann-ticker {
    0%   { transform: translateX(-50%); }
    100% { transform: translateX(0); }
}

.announcement-close {
    flex-shrink: 0;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-right: 1px solid rgba(0,201,167,.12);
    cursor: pointer;
    color: rgba(195,230,222,.35);
    transition: color .2s, background .2s;
    padding: 0;
}
.announcement-close:hover {
    color: rgba(195,230,222,.85);
    background: rgba(0,201,167,.07);
}

.chat-page { overflow: hidden; }
.chat-page:has(.site-announcement) .app-shell {
    margin-top: var(--announce-h, 40px);
    height: calc(100dvh - var(--announce-h, 40px));
}

.app-shell {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    height: 100%;
    overflow: hidden;
    transition: transform var(--transition);
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.sidebar-logo-text {
    font-size: 1.125rem;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.sidebar-logo-text strong { color: var(--accent); }

/* Current User */
.current-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: #0A1A15;
    position: relative;
    flex-shrink: 0;
    letter-spacing: 0;
}

.avatar.lg {
    width: 44px;
    height: 44px;
    font-size: 1rem;
}

.online-dot {
    position: absolute;
    bottom: 1px;
    left: 1px;
    width: 10px;
    height: 10px;
    background: var(--online-color);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.current-user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    min-width: 0;
}

.current-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.current-user-id {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.logout-btn {
    color: var(--text-muted);
    display: flex;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.logout-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    text-decoration: none;
}

/* Search */
.search-box {
    padding: 12px 12px 0;
    flex-shrink: 0;
    position: relative;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 9px 36px 9px 36px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color var(--transition);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); }

.search-clear {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
    display: flex;
    padding: 4px;
    transition: color var(--transition);
}
.search-clear:hover { color: var(--text-primary); }

/* Search Results */
.search-results {
    position: absolute;
    top: calc(100% + 4px);
    right: 12px;
    left: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}
.search-result-item:hover { background: var(--bg-hover); }

.search-no-result {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Conversations */
.conversations-label {
    padding: 14px 16px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.conversations-list::-webkit-scrollbar { width: 4px; }
.conversations-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.empty-conversations {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--text-muted);
    text-align: center;
}
.empty-conversations svg { opacity: 0.4; }
.empty-conversations p { font-size: 0.875rem; }
.empty-conversations .hint { font-size: 0.775rem; opacity: 0.7; }

/* Conversation Item */
.conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
    position: relative;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active {
    background: var(--accent-dim);
    border: 1px solid rgba(0, 201, 167, 0.2);
}

.conv-item-body {
    flex: 1;
    min-width: 0;
}

.conv-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin-bottom: 3px;
}

.conv-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.conv-item-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    background: var(--accent);
    color: #0A1A15;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    flex-shrink: 0;
}

/* ── Chat Main ────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
    height: 100%;
    overflow: hidden;
}

/* Empty / Welcome */
.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
    max-width: 360px;
}

.chat-empty-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    opacity: 0.6;
    filter: drop-shadow(0 0 20px var(--accent-glow));
    margin-bottom: 4px;
}

.chat-empty-content h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}
.chat-empty-content p {
    font-size: 0.875rem;
    line-height: 1.6;
}

/* Active Chat */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    display: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.back-btn:hover { color: var(--accent); background: var(--accent-dim); }

.chat-header-avatar {
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.chat-header-status.online { color: var(--online-color); }

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 12px;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.messages-loading {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
}

/* Load More */
.load-more-btn {
    align-self: center;
    padding: 7px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 12px;
}
.load-more-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Date Divider */
.date-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}
.date-divider::before,
.date-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Message Bubbles */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 75%;
    animation: msgIn 0.18s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message-row.sent {
    flex-direction: row-reverse;
    margin-right: auto;
    margin-left: 0;
    align-self: flex-end;
}

.message-row.received {
    margin-left: auto;
    margin-right: 0;
    align-self: flex-start;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #0A1A15;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.msg-avatar.hidden { visibility: hidden; }

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
    max-width: 100%;
}

.message-row.sent .message-bubble {
    background: var(--msg-sent-bg);
    color: var(--msg-sent-text);
    border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
    background: var(--msg-recv-bg);
    color: var(--msg-recv-text);
    border-bottom-left-radius: 4px;
}

/* Group consecutive messages */
.message-row.sent.grouped .message-bubble  { border-top-right-radius: var(--radius-md); }
.message-row.received.grouped .message-bubble { border-top-left-radius: var(--radius-md); }

.msg-time {
    font-size: 0.65rem;
    opacity: 0.65;
    display: block;
    text-align: left;
    margin-top: 4px;
    white-space: nowrap;
}
.message-row.received .msg-time { text-align: right; }

/* System Message */
.message-system {
    align-self: center;
    font-size: 0.775rem;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 5px 14px;
    border-radius: 999px;
    margin: 6px 0;
}

/* Message Input */
.message-input-area {
    padding: 12px 16px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 8px;
    transition: border-color var(--transition);
}
.message-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    max-height: 140px;
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 7px 4px;
    align-self: center;
}
.message-input::placeholder { color: var(--text-muted); }

.send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #0A1A15;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    opacity: 0.5;
    pointer-events: none;
}
.send-btn:not(:disabled):not([disabled]) {
    opacity: 1;
    pointer-events: auto;
}
.send-btn:not(:disabled):not([disabled]):hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 12px var(--accent-glow);
    transform: scale(1.05);
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── User Info (search result / conv item) ────────────────── */
.user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-id {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.user-online {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--online-color);
}
.user-online::before {
    content: '';
    width: 7px;
    height: 7px;
    background: var(--online-color);
    border-radius: 50%;
    flex-shrink: 0;
}
.user-offline { color: var(--text-muted); font-size: 0.75rem; }

/* ── Mobile Sidebar Overlay ───────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

/* ============================================================
   RESPONSIVE — Mobile
   ============================================================ */
@media (max-width: 768px) {
    :root { --sidebar-width: 100vw; }

    .app-shell { position: relative; }

    .sidebar {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        transform: translateX(100%);
        border-left: none;
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }

    /* Bug fix: sidebar must start below the announcement banner */
    .chat-page:has(.site-announcement) .sidebar {
        top: var(--announce-h, 40px);
        height: calc(100dvh - var(--announce-h, 40px));
    }
    .chat-page:has(.site-announcement) .sidebar-overlay {
        top: var(--announce-h, 40px);
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay.visible { display: block; }

    .chat-main { width: 100%; }

    .back-btn { display: flex; }

    .message-row { max-width: 88%; }

    .auth-card { padding: 28px 24px; }
}

/* ── Scrollbar global ──────────────────────────────────────── */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================================================
   PAPERCLIP / FILE ATTACHMENT
   ============================================================ */

/* Paperclip button */
.attach-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}
.attach-btn:hover { color: var(--accent); background: var(--accent-dim); }
.attach-btn.uploading { color: var(--accent); pointer-events: none; }

/* Upload Progress Bar */
.upload-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--accent-dim);
    border: 1px solid rgba(0,201,167,0.2);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    animation: fadeUp 0.2s ease;
}
.upload-progress-track {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    width: 0%;
    transition: width 0.15s ease;
}
.upload-progress-text {
    font-size: 0.775rem;
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
    min-width: 100px;
    text-align: left;
}

/* Attachment Preview */
.attachment-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    animation: fadeUp 0.2s ease;
}
.attachment-thumb {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    color: var(--accent);
}
.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.attachment-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.attachment-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.attachment-size {
    font-size: 0.72rem;
    color: var(--text-muted);
}
.attachment-remove {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}
.attachment-remove:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ── File Messages ────────────────────────────────────────── */
.msg-text {
    word-break: break-word;
    white-space: pre-wrap;
}

/* Image message */
.msg-image-wrap {
    display: block;
    border-radius: calc(var(--radius-lg) - 4px);
    overflow: hidden;
    max-width: 280px;
    cursor: zoom-in;
    margin-bottom: 2px;
    line-height: 0;
}
.msg-image-wrap img {
    width: 100%;
    max-width: 280px;
    max-height: 320px;
    object-fit: cover;
    display: block;
    transition: opacity var(--transition);
}
.msg-image-wrap img:hover { opacity: 0.92; }

/* Image-only bubble: minimal padding */
.message-bubble.bubble-image {
    padding: 4px;
    background: transparent !important;
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.message-bubble.bubble-image .msg-time {
    padding: 0 6px 4px;
    display: block;
}

/* File download bubble */
.msg-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.12);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background var(--transition);
    margin-bottom: 4px;
    max-width: 280px;
    color: inherit;
}
.message-row.sent .msg-file { background: rgba(0,0,0,0.15); }
.message-row.received .msg-file { background: var(--bg-hover); }
.msg-file:hover { opacity: 0.85; text-decoration: none; }

.msg-file-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    color: inherit;
}
.msg-file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.msg-file-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}
.msg-file-size {
    font-size: 0.7rem;
    opacity: 0.7;
}
.msg-file-dl {
    flex-shrink: 0;
    opacity: 0.7;
}

/* ── Lightbox ─────────────────────────────────────────────── */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(6px);
    animation: fadeIn 0.2s ease;
}
.lightbox.active { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.lightbox-img {
    max-width: 100%;
    max-height: 90dvh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 60px rgba(0,0,0,0.8);
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.94); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.lightbox-close {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 50%;
    transition: background var(--transition);
    z-index: 10000;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   RESPONSIVE IMPROVEMENTS
   ============================================================ */

/* Prevent iOS zoom on input focus (font-size must be ≥ 16px) */
@media (max-width: 768px) {
    .form-input,
    .message-input,
    .search-input { font-size: 16px !important; }

    /* Better touch targets */
    .attach-btn,
    .send-btn,
    .toggle-password,
    .logout-btn { min-width: 44px; min-height: 44px; }

    /* Upload progress text shorter */
    .upload-progress-text { min-width: 70px; font-size: 0.72rem; }

    /* Image messages smaller on mobile */
    .msg-image-wrap,
    .msg-image-wrap img { max-width: 220px; }

    /* Auth card very small screens */
    .auth-card { padding: 24px 18px; }

    /* Search box — prevent overflow */
    .search-results { max-height: 200px; }

    /* Message input area padding */
    .message-input-area { padding: 8px 10px 12px; }

    /* Sidebar search padding */
    .search-box { padding: 8px 8px 0; }

    /* Lightbox close — easier to tap */
    .lightbox-close { top: env(safe-area-inset-top, 12px); left: 12px; }
}

/* Safe area insets (iPhone notch / home indicator) */
@supports (padding: env(safe-area-inset-bottom)) {
    .message-input-area {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Tablet (768–1024px): sidebar narrower */
@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-width: 260px; }
    .message-row { max-width: 80%; }
}

/* Very small screens (< 380px) */
@media (max-width: 380px) {
    .auth-brand { font-size: 1.4rem; }
    .auth-logo-img { width: 56px; height: 56px; }
    .message-row { max-width: 94%; }
    .msg-image-wrap,
    .msg-image-wrap img { max-width: 190px; }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .auth-container { padding: 12px 16px; }
    .auth-card { padding: 20px 24px; }
    .auth-logo { margin-bottom: 16px; }
    .auth-logo-img { width: 48px; height: 48px; }
}
