*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root,
html[data-theme="light"] {
    --bg-deep: #f3f0f8;
    --bg-panel: #ffffff;
    --bg-elevated: #f7f4fc;
    --bg-hover: #ebe4f7;
    --border: rgba(124, 58, 237, 0.14);
    --text: #1f1630;
    --text-muted: #6b5f80;
    --accent: #7c3aed;
    --accent-strong: #6d28d9;
    --accent-glow: rgba(124, 58, 237, 0.22);
    --success: #059669;
    --error: #dc2626;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 18px 40px rgba(88, 60, 140, 0.12);
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --glow-1: rgba(124, 58, 237, 0.12);
    --glow-2: rgba(168, 85, 247, 0.1);
    --surface-glass: rgba(255, 255, 255, 0.88);
    --sidebar-bg: rgba(255, 255, 255, 0.94);
    --chat-main-bg: rgba(243, 240, 248, 0.85);
    --user-strip-bg: rgba(124, 58, 237, 0.06);
    --own-message-bg: linear-gradient(135deg, rgba(124, 58, 237, 0.16), rgba(168, 85, 247, 0.12));
    --own-message-border: rgba(124, 58, 237, 0.22);
    --brand-gradient: linear-gradient(135deg, #6d28d9, var(--accent));
    --alert-error-bg: rgba(220, 38, 38, 0.08);
    --alert-error-border: rgba(220, 38, 38, 0.22);
    --alert-error-text: #b91c1c;
    --alert-success-bg: rgba(5, 150, 105, 0.1);
    --alert-success-border: rgba(5, 150, 105, 0.25);
    --alert-success-text: #047857;
    --hint-bg: rgba(124, 58, 237, 0.08);
}

html[data-theme="dark"] {
    --bg-deep: #0f0a1a;
    --bg-panel: #1a1229;
    --bg-elevated: #241a35;
    --bg-hover: #2d2142;
    --border: rgba(168, 85, 247, 0.15);
    --text: #f3eef8;
    --text-muted: #a89bb8;
    --accent: #a855f7;
    --accent-strong: #7c3aed;
    --accent-glow: rgba(168, 85, 247, 0.35);
    --success: #10b981;
    --error: #f87171;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --glow-1: rgba(124, 58, 237, 0.18);
    --glow-2: rgba(168, 85, 247, 0.12);
    --surface-glass: rgba(26, 18, 41, 0.85);
    --sidebar-bg: rgba(26, 18, 41, 0.92);
    --chat-main-bg: rgba(15, 10, 26, 0.6);
    --user-strip-bg: rgba(124, 58, 237, 0.06);
    --own-message-bg: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(168, 85, 247, 0.25));
    --own-message-border: rgba(168, 85, 247, 0.3);
    --brand-gradient: linear-gradient(135deg, #e9d5ff, var(--accent));
    --alert-error-bg: rgba(248, 113, 113, 0.12);
    --alert-error-border: rgba(248, 113, 113, 0.3);
    --alert-error-text: #fca5a5;
    --alert-success-bg: rgba(16, 185, 129, 0.12);
    --alert-success-border: rgba(16, 185, 129, 0.3);
    --alert-success-text: #6ee7b7;
    --hint-bg: rgba(124, 58, 237, 0.12);
}

html[data-theme="ocean"] {
    --bg-deep: #07131f;
    --bg-panel: #0c1929;
    --bg-elevated: #12263a;
    --bg-hover: #18324a;
    --border: rgba(14, 165, 233, 0.18);
    --text: #e8f4fc;
    --text-muted: #8ab0c9;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --accent-glow: rgba(14, 165, 233, 0.3);
    --success: #34d399;
    --error: #fb7185;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --glow-1: rgba(14, 165, 233, 0.18);
    --glow-2: rgba(56, 189, 248, 0.1);
    --surface-glass: rgba(12, 25, 41, 0.88);
    --sidebar-bg: rgba(12, 25, 41, 0.94);
    --chat-main-bg: rgba(7, 19, 31, 0.7);
    --user-strip-bg: rgba(14, 165, 233, 0.08);
    --own-message-bg: linear-gradient(135deg, rgba(14, 165, 233, 0.32), rgba(56, 189, 248, 0.2));
    --own-message-border: rgba(56, 189, 248, 0.35);
    --brand-gradient: linear-gradient(135deg, #7dd3fc, var(--accent));
    --alert-error-bg: rgba(251, 113, 133, 0.12);
    --alert-error-border: rgba(251, 113, 133, 0.3);
    --alert-error-text: #fda4af;
    --alert-success-bg: rgba(52, 211, 153, 0.12);
    --alert-success-border: rgba(52, 211, 153, 0.3);
    --alert-success-text: #6ee7b7;
    --hint-bg: rgba(14, 165, 233, 0.12);
}

html[data-theme="forest"] {
    --bg-deep: #0a1610;
    --bg-panel: #0f1f17;
    --bg-elevated: #163026;
    --bg-hover: #1c3b2e;
    --border: rgba(16, 185, 129, 0.18);
    --text: #ecfdf5;
    --text-muted: #95b5a6;
    --accent: #34d399;
    --accent-strong: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.28);
    --success: #6ee7b7;
    --error: #f87171;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --glow-1: rgba(16, 185, 129, 0.16);
    --glow-2: rgba(52, 211, 153, 0.1);
    --surface-glass: rgba(15, 31, 23, 0.88);
    --sidebar-bg: rgba(15, 31, 23, 0.94);
    --chat-main-bg: rgba(10, 22, 16, 0.7);
    --user-strip-bg: rgba(16, 185, 129, 0.08);
    --own-message-bg: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(52, 211, 153, 0.18));
    --own-message-border: rgba(52, 211, 153, 0.3);
    --brand-gradient: linear-gradient(135deg, #a7f3d0, var(--accent));
    --alert-error-bg: rgba(248, 113, 113, 0.12);
    --alert-error-border: rgba(248, 113, 113, 0.3);
    --alert-error-text: #fca5a5;
    --alert-success-bg: rgba(52, 211, 153, 0.12);
    --alert-success-border: rgba(52, 211, 153, 0.3);
    --alert-success-text: #6ee7b7;
    --hint-bg: rgba(16, 185, 129, 0.12);
}

html[data-theme="sunset"] {
    --bg-deep: #1a0d0a;
    --bg-panel: #2a1410;
    --bg-elevated: #3a1d16;
    --bg-hover: #4a261c;
    --border: rgba(249, 115, 22, 0.2);
    --text: #fff7ed;
    --text-muted: #c4a090;
    --accent: #fb923c;
    --accent-strong: #f97316;
    --accent-glow: rgba(249, 115, 22, 0.3);
    --success: #34d399;
    --error: #f87171;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --glow-1: rgba(249, 115, 22, 0.18);
    --glow-2: rgba(251, 146, 60, 0.12);
    --surface-glass: rgba(42, 20, 16, 0.88);
    --sidebar-bg: rgba(42, 20, 16, 0.94);
    --chat-main-bg: rgba(26, 13, 10, 0.7);
    --user-strip-bg: rgba(249, 115, 22, 0.08);
    --own-message-bg: linear-gradient(135deg, rgba(249, 115, 22, 0.32), rgba(251, 146, 60, 0.2));
    --own-message-border: rgba(251, 146, 60, 0.35);
    --brand-gradient: linear-gradient(135deg, #fed7aa, var(--accent));
    --alert-error-bg: rgba(248, 113, 113, 0.12);
    --alert-error-border: rgba(248, 113, 113, 0.3);
    --alert-error-text: #fca5a5;
    --alert-success-bg: rgba(52, 211, 153, 0.12);
    --alert-success-border: rgba(52, 211, 153, 0.3);
    --alert-success-text: #6ee7b7;
    --hint-bg: rgba(249, 115, 22, 0.12);
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app-shell:has(.chat-layout) {
    height: 100dvh;
    overflow: hidden;
}

body {
    background:
        radial-gradient(ellipse 80% 60% at 10% 0%, var(--glow-1), transparent),
        radial-gradient(ellipse 60% 50% at 90% 100%, var(--glow-2), transparent),
        var(--bg-deep);
}

.app-shell {
    min-height: 100vh;
}

/* Auth */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px;
    box-shadow: var(--shadow);
}

.auth-brand {
    text-align: center;
    margin-bottom: 28px;
}

.brand-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.auth-brand h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-brand p {
    color: var(--text-muted);
    margin-top: 6px;
    font-size: 0.95rem;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-footer a,
a {
    color: var(--accent);
    text-decoration: none;
}

.auth-footer a:hover,
a:hover {
    text-decoration: underline;
}

.demo-hint {
    margin-top: 20px;
    padding: 10px 14px;
    background: var(--hint-bg);
    border-radius: var(--radius-sm);
    text-align: center;
    color: var(--text-muted);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-sm {
    padding: 8px 12px;
    font-size: 0.875rem;
}

select.input {
    cursor: pointer;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 28px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn-danger {
    background: #dc2626;
    color: white;
    border: 1px solid transparent;
}

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

.btn-block {
    width: 100%;
    padding: 13px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px 8px;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: var(--alert-error-bg);
    border: 1px solid var(--alert-error-border);
    color: var(--alert-error-text);
}

.alert-success {
    background: var(--alert-success-bg);
    border: 1px solid var(--alert-success-border);
    color: var(--alert-success-text);
}

/* Chat layout */
.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

/* Skeleton loading */
.skeleton {
    display: block;
    border-radius: 8px;
    background: linear-gradient(
        90deg,
        color-mix(in srgb, var(--text-muted) 12%, transparent) 0%,
        color-mix(in srgb, var(--text-muted) 22%, transparent) 45%,
        color-mix(in srgb, var(--text-muted) 12%, transparent) 90%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.35s ease-in-out infinite;
}

.skeleton-avatar,
.skeleton-avatar-sm {
    flex-shrink: 0;
    border-radius: 12px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
}

.skeleton-avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 10px;
}

.skeleton-text {
    height: 11px;
    margin-bottom: 8px;
}

.skeleton-text:last-child {
    margin-bottom: 0;
}

.skeleton-lg {
    height: 16px;
}

.skeleton-w-25 { width: 25%; }
.skeleton-w-30 { width: 30%; }
.skeleton-w-35 { width: 35%; }
.skeleton-w-40 { width: 40%; }
.skeleton-w-45 { width: 45%; }
.skeleton-w-50 { width: 50%; }
.skeleton-w-55 { width: 55%; }
.skeleton-w-60 { width: 60%; }
.skeleton-w-70 { width: 70%; }

.skeleton-chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin-bottom: 4px;
}

.skeleton-chat-item-body {
    flex: 1;
    min-width: 0;
}

.chat-main-skeleton {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.skeleton-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.skeleton-header-text {
    flex: 1;
}

.skeleton-btn {
    width: 84px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
}

.skeleton-messages {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.skeleton-message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 78%;
}

.skeleton-message.own {
    align-self: flex-end;
}

.skeleton-bubble {
    height: 44px;
    border-radius: 16px;
}

.skeleton-bubble-sm { width: 140px; }
.skeleton-bubble-md { width: 200px; }
.skeleton-bubble-lg { width: 260px; height: 58px; }

.skeleton-composer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid var(--border);
}

.skeleton-composer-input {
    flex: 1;
    height: 42px;
    border-radius: 12px;
}

@keyframes skeleton-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
    }
}

.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.brand-mini {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.05rem;
}

.brand-icon-sm {
    font-size: 1.2rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--user-strip-bg);
}

.sidebar-user-link {
    width: 100%;
    border: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.sidebar-user-link:hover {
    background: var(--bg-hover);
}

.sidebar-user-text {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

.sidebar-section {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
}

.sidebar-grow {
    flex: 1;
    min-height: 0;
}

.sidebar-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px 12px 0;
}

.sidebar-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.sidebar-tab:hover {
    color: var(--text);
    background: var(--user-strip-bg);
}

.sidebar-tab.active {
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.sidebar-tab-count {
    min-width: 1.25rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    line-height: 1.3;
}

.sidebar-empty {
    padding: 20px 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.45;
    text-align: center;
}

.chat-item-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.chat-item-row .chat-item {
    flex: 1;
    min-width: 0;
}

.favorite-btn {
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.75;
}

.favorite-btn:hover,
.favorite-btn.active {
    color: #eab308;
    opacity: 1;
}

.mute-btn {
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.75;
    font-size: 0.95rem;
}

.mute-btn:hover,
.mute-btn.active {
    color: var(--accent);
    opacity: 1;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.95rem;
    color: var(--text);
}

.toggle-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.user-search {
    padding: 0 4px 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--hint-bg);
    border: 1px solid var(--border);
}

.chat-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-item-icon.group {
    background: var(--hint-bg);
    color: var(--accent);
}

.chat-item-body {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.chat-item-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar-photo {
    background: transparent !important;
    padding: 0;
}

.avatar-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 0.75rem;
}

.badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 6px;
}

.badge-admin {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.badge-unread {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.chat-item.active .badge-unread {
    background: var(--bg-panel);
    color: var(--accent-strong);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6b7280;
    display: inline-block;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

/* Main chat */
.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--chat-main-bg);
}

.mobile-only {
    display: none;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.chat-header-left > div {
    min-width: 0;
}

.welcome-panel {
    flex: 1;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.7;
}

.welcome-panel h2 {
    color: var(--text);
    margin-bottom: 8px;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
}

.chat-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.chat-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 75%;
    align-self: flex-start;
}

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px 16px 16px 4px;
    padding: 10px 14px;
    min-width: 80px;
}

.message.own .message-bubble {
    background: var(--own-message-bg);
    border-color: var(--own-message-border);
    border-radius: 16px 16px 4px 16px;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
}

.message-text {
    font-size: 0.95rem;
    line-height: 1.45;
    word-break: break-word;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.message-receipt {
    font-size: 0.72rem;
    letter-spacing: -0.12em;
    opacity: 0.75;
    line-height: 1;
}

.message-receipt.read {
    color: var(--accent);
    opacity: 1;
}

.messages-load-older {
    display: flex;
    justify-content: center;
    padding: 8px 0 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.messages-start {
    text-align: center;
    padding: 8px 0 12px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}

.message-edited {
    margin-left: 4px;
    opacity: 0.8;
}

.message-deleted-text {
    font-style: italic;
    color: var(--text-muted);
}

.message-reply-quote {
    border-left: 3px solid var(--accent);
    padding: 4px 8px;
    margin-bottom: 8px;
    border-radius: 0 8px 8px 0;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message-reply-quote strong {
    color: var(--accent);
    font-size: 0.72rem;
}

.message-reply-quote span {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.message-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
    opacity: 1;
}

.msg-action {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    border-radius: 6px;
    color: var(--text-muted);
    line-height: 1;
}

.msg-action:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.reaction-picker {
    position: relative;
}

.reaction-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    box-shadow: var(--shadow);
    z-index: 5;
    gap: 2px;
}

.reaction-picker:hover .reaction-menu,
.reaction-picker:focus-within .reaction-menu {
    display: flex;
}

.reaction-menu button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 6px;
    border-radius: 8px;
}

.reaction-menu button:hover {
    background: var(--bg-hover);
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.reaction-chip {
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--text);
}

.reaction-chip.active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.typing-indicator {
    padding: 20px 24px 8px;
    font-size: 0.6rem;
    color: var(--text-muted);
    font-style: italic;
    min-height: 1.2em;
}

.composer-context {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--user-strip-bg);
}

.composer-context.edit {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.composer-context-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.82rem;
}

.composer-context-body span {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-wide {
    max-width: 480px;
}

.members-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    margin: 12px 0;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.member-info {
    flex: 1;
    min-width: 0;
}

.message-image-link {
    display: block;
    margin: 4px 0 6px;
}

.message-image {
    display: block;
    max-width: min(280px, 100%);
    max-height: 320px;
    border-radius: 12px;
    object-fit: cover;
}

.composer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-glass);
}

.composer-input {
    flex: 1;
    min-width: 120px;
}

.composer-attach {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
}

.composer-attach input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.composer-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    order: -1;
}

.composer-preview img {
    height: 64px;
    width: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
    object-fit: cover;
}

.composer-error {
    width: 100%;
    order: 2;
    font-size: 0.8rem;
    color: var(--alert-error-text);
    padding: 0 24px 12px;
}

.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(480px, calc(100vw - 24px));
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-panel);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 0.92rem;
    animation: toast-in 0.2s ease-out;
}

.toast-success {
    border-color: var(--alert-success-border);
    background: var(--alert-success-bg);
    color: var(--alert-success-text);
}

.toast-info {
    border-color: var(--border);
}

.toast-error {
    border-color: var(--alert-error-border);
    background: var(--alert-error-bg);
    color: var(--alert-error-text);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, -8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 28px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
}

.modal h3 {
    margin-bottom: 6px;
    font-size: 1.2rem;
}

.modal-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 18px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
}

.empty-state h1 {
    font-size: 3rem;
    color: var(--accent);
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    background: #450a0a;
    color: #fecaca;
    z-index: 9999;
}

@media (max-width: 768px) {
    .chat-layout {
        grid-template-columns: 1fr;
        position: relative;
    }

    .mobile-only {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar,
    .chat-main {
        grid-column: 1;
        grid-row: 1;
        height: 100dvh;
        max-height: 100dvh;
    }

    .chat-layout:not(.mobile-chat-open) .chat-main {
        display: none;
    }

    .chat-layout.mobile-chat-open .sidebar {
        display: none;
    }

    .chat-header {
        padding: 12px 14px;
        gap: 8px;
    }

    .chat-header h2 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-header .btn {
        flex-shrink: 0;
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .messages {
        padding: 14px 12px;
    }

    .message {
        max-width: 88%;
    }

    .composer {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }

    .composer .btn {
        padding: 12px 14px;
        white-space: nowrap;
    }

    .welcome-panel {
        padding: 24px 16px;
    }

    .welcome-icon {
        font-size: 3rem;
    }

    .modal {
        padding: 20px;
        max-height: calc(100dvh - 40px);
        overflow-y: auto;
    }

    .auth-card {
        padding: 28px 20px;
    }
}

/* Profile cabinet */
.profile-page {
    min-height: 100dvh;
    display: grid;
    place-items: start center;
    padding: 28px 16px 48px;
}

.profile-card {
    width: 100%;
    max-width: 720px;
    background: var(--surface-glass);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.profile-top {
    margin-bottom: 22px;
}

.profile-top h1 {
    margin-top: 14px;
    font-size: 1.6rem;
}

.profile-lead {
    color: var(--text-muted);
    margin-top: 6px;
}

.profile-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--user-strip-bg);
    border: 1px solid var(--border);
    margin-bottom: 22px;
}

.avatar-lg {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    font-size: 1.1rem;
}

.avatar-upload {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}

.avatar-upload .btn {
    position: relative;
    overflow: hidden;
}

.avatar-upload input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.avatar-hint {
    width: 100%;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.color-swatch {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.color-swatch.selected {
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.theme-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.theme-card:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
}

.theme-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.theme-preview {
    height: 64px;
    border-radius: 10px;
    border: 1px solid;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px;
}

.theme-preview span {
    display: block;
    width: 28%;
    height: 10px;
    border-radius: 999px;
}

.theme-card-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.theme-card-body small {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.profile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

@media (max-width: 768px) {
    .profile-card {
        padding: 20px 16px;
    }

    .profile-actions {
        flex-direction: column-reverse;
    }

    .profile-actions .btn {
        width: 100%;
    }
}
