:root {
    color-scheme: light;
    --primary: #4f6df5;
    --primary-strong: #3d5bea;
    --primary-soft: #eef1ff;
    --success: #25a66a;
    --warning: #d6922f;
    --danger: #d75555;
    --info: #3b82f6;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #f0f2f7;
    --text: #171a22;
    --muted: #747b8b;
    --subtle: #a0a6b2;
    --border: #e8eaf0;
    --focus: rgba(79, 109, 245, .25);
    --bubble-in: #f0f2f7;
    --bubble-out: #4f6df5;
    --bubble-out-text: #fff;
    --shadow-sm: 0 1px 2px rgba(20, 24, 35, .04);
    --shadow-md: 0 10px 35px rgba(27, 35, 59, .08);
    --r-sm: 10px;
    --r-md: 16px;
    --r-lg: 22px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1015;
    --surface: #13171e;
    --surface-2: #171c24;
    --surface-3: #1d232d;
    --text: #f2f4f8;
    --muted: #9ca5b5;
    --subtle: #697384;
    --border: #252c37;
    --primary-soft: #1c2548;
    --bubble-in: #202631;
    --shadow-md: 0 12px 40px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
html { background: var(--bg); }
body, button, input, textarea, select { font-family: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { border: 0; }
button:not(:disabled) { cursor: pointer; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

.boot-screen { height: 100dvh; display: grid; place-items: center; gap: 20px; align-content: center; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: -.5px; }
.boot-mark { width: 52px; height: 52px; border-radius: 16px; font-size: 16px; }
.boot-line { width: 110px; height: 3px; border-radius: 10px; background: var(--surface-3); overflow: hidden; }
.boot-line span { display: block; width: 45%; height: 100%; background: var(--primary); animation: boot 1s ease-in-out infinite alternate; }
@keyframes boot { from { transform: translateX(-20%); } to { transform: translateX(140%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; } }

.messenger { height: 100dvh; display: grid; grid-template-rows: 68px minmax(0, 1fr); background: var(--bg); }
.topbar { display: grid; grid-template-columns: 260px 1fr 260px; align-items: center; gap: 20px; padding: 0 24px; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-name { font-weight: 600; letter-spacing: -.25px; white-space: nowrap; }
.tabs { justify-self: center; display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 14px; background: var(--surface-2); }
.tab { display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 14px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; transition: background .16s ease, color .16s ease; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.theme-button { justify-self: end; }
.icon-button { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); background: transparent; transition: .15s ease; }
.icon-button:hover { background: var(--surface-2); color: var(--text); }

.chat-layout { min-height: 0; display: grid; grid-template-columns: minmax(300px, 370px) minmax(0, 1fr); max-width: 1500px; width: 100%; margin: 0 auto; background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.conversation-panel { min-width: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); border-right: 1px solid var(--border); background: var(--surface); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 12px; }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, p { margin-top: 0; }
.panel-heading h1, .content-heading h1, .profile-card h1 { margin: 3px 0 0; font-size: 26px; line-height: 1.2; letter-spacing: -.7px; }
.search-box { margin: 0 16px 10px; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid transparent; border-radius: 13px; background: var(--surface-2); color: var(--muted); }
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.search-box .icon { width: 18px; height: 18px; }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.search-box input::placeholder { color: var(--subtle); }
.conversation-list { min-height: 0; overflow-y: auto; padding: 2px 8px 18px; overscroll-behavior: contain; }
.conversation-row { width: 100%; min-height: 72px; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: transparent; text-align: left; }
.conversation-row:hover { background: var(--surface-2); }
.conversation-row.selected { background: var(--primary-soft); }
.conversation-copy { min-width: 0; flex: 1; display: grid; gap: 6px; }
.conversation-line { min-width: 0; display: flex; align-items: center; gap: 8px; }
.conversation-line strong { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conversation-line time { color: var(--subtle); font-size: 10.5px; }
.muted { color: var(--muted); font-size: 11.5px; }
.last-message { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { min-width: 19px; height: 19px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 20px; background: var(--primary); color: white; font-size: 10px; font-weight: 700; }
.empty-inline { padding: 28px 16px; color: var(--muted); text-align: center; font-size: 12px; }

.avatar-shell { --avatar: #4f7cff; position: relative; width: 46px; height: 46px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--avatar) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--avatar) 28%, var(--border)); color: var(--avatar); font-size: 12px; font-weight: 700; }
.avatar-shell.large { width: 76px; height: 76px; font-size: 18px; }
.avatar-shell.ring { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--avatar); }
.online-dot { position: absolute; right: -1px; bottom: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--success); border: 2px solid var(--surface); }

.chat-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 72px minmax(0, 1fr) auto; background: var(--surface); }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.chat-header > .icon-button:last-child { margin-left: auto; }
.chat-person { min-width: 0; display: grid; gap: 2px; }
.chat-person strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-person span { color: var(--success); font-size: 10.5px; }
.mobile-back { display: none; }
.messages { min-height: 0; overflow-y: auto; padding: 18px clamp(18px, 4vw, 54px) 24px; background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--primary) 4%, transparent), transparent 28%), var(--surface-2); overscroll-behavior: contain; scroll-behavior: smooth; }
.date-divider { display: flex; justify-content: center; margin: 4px 0 20px; }
.date-divider span { padding: 5px 10px; border: 1px solid var(--border); border-radius: 20px; background: color-mix(in srgb, var(--surface) 86%, transparent); color: var(--muted); font-size: 10px; }
.message-row { display: flex; margin: 7px 0; }
.message-row.mine { justify-content: flex-end; }
.bubble { max-width: min(72%, 620px); padding: 9px 12px 7px; border-radius: 16px 16px 16px 5px; background: var(--bubble-in); box-shadow: var(--shadow-sm); }
.mine .bubble { border-radius: 16px 16px 5px 16px; background: var(--bubble-out); color: var(--bubble-out-text); }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 13px; }
.message-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 3px; color: var(--muted); font-size: 9px; }
.mine .message-meta { color: rgba(255,255,255,.72); }
.checks { letter-spacing: -2px; padding-right: 2px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { flex: 1; min-height: 44px; max-height: 120px; resize: none; border: 1px solid var(--border); border-radius: 14px; padding: 11px 13px; outline: 0; background: var(--surface-2); color: var(--text); font-size: 13px; line-height: 1.45; }
.composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.send-button { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 14px; background: var(--primary); color: #fff; transition: transform .12s ease, opacity .12s ease; }
.send-button:hover:not(:disabled) { background: var(--primary-strong); transform: translateY(-1px); }
.send-button:disabled { opacity: .4; cursor: default; }
.empty-chat { min-height: 0; display: grid; place-items: center; align-content: center; padding: 30px; text-align: center; color: var(--muted); background: var(--surface-2); }
.empty-chat-icon { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); }
.empty-chat-icon .icon { width: 28px; height: 28px; }
.empty-chat h2 { margin: 0 0 8px; color: var(--text); font-size: 18px; }
.empty-chat p { margin: 0; font-size: 12px; }

.content-page { min-height: 0; overflow-y: auto; width: min(980px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
.content-heading { margin-bottom: 28px; }
.content-heading p { margin: 8px 0 0; color: var(--muted); }
.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.status-card, .settings-card, .profile-card { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.status-card { display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 20px; }
.status-card > div:nth-child(2) { display: grid; align-content: center; gap: 2px; }
.status-card strong { font-size: 13px; }
.status-card time { color: var(--muted); font-size: 10.5px; }
.status-card p { grid-column: 1 / -1; margin: 4px 0 0; color: var(--muted); line-height: 1.6; }
.contact-list { display: grid; gap: 8px; }
.contact-card { width: 100%; display: flex; align-items: center; gap: 14px; padding: 13px 16px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); text-align: left; }
.contact-card:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); background: var(--surface-2); }
.contact-card > span:nth-child(2) { min-width: 0; flex: 1; display: grid; gap: 3px; }
.contact-card strong { font-size: 13px; }
.contact-card small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; }
.contact-action { color: var(--primary); font-size: 11px; font-weight: 600; }
.profile-page { width: min(760px, calc(100% - 40px)); }
.profile-card { display: flex; align-items: center; gap: 18px; padding: 24px; }
.profile-card h1 { margin-top: 5px; }
.profile-card p { margin: 5px 0 0; color: var(--muted); }
.settings-card { margin-top: 14px; padding: 22px; }
.settings-card > div + div { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 18px; }
.settings-card p, .settings-card small { display: block; margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.secondary-button, .primary-button { min-height: 40px; padding: 0 15px; border-radius: 11px; font-weight: 600; font-size: 12px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.secondary-button { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.primary-button { background: var(--primary); color: #fff; }
.demo-switcher { display: grid; grid-template-columns: 1fr 220px; align-items: end; gap: 18px; }
.demo-switcher select { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 11px; padding: 0 11px; background: var(--surface-2); color: var(--text); }
.state-page { min-height: calc(100dvh - 68px); display: grid; place-items: center; align-content: center; gap: 12px; padding: 30px; text-align: center; }
.state-page h1 { margin: 0; font-size: 22px; }
.state-page p { color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#blazor-error-ui { display: none; position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 1000; padding: 14px 16px; border: 1px solid var(--danger); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-md); color: var(--text); }
#blazor-error-ui .dismiss { float: right; background: transparent; color: var(--muted); }

@media (max-width: 900px) {
    .topbar { grid-template-columns: auto 1fr auto; padding: 0 14px; gap: 10px; }
    .brand-name { display: none; }
    .tabs { gap: 2px; }
    .tab { padding: 0 11px; }
    .chat-layout { grid-template-columns: 320px minmax(0, 1fr); border: 0; }
}

@media (max-width: 700px) {
    body { overflow: hidden; }
    .messenger { grid-template-rows: 62px minmax(0, 1fr); }
    .topbar { padding: 0 10px; grid-template-columns: 36px 1fr 36px; }
    .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 11px; }
    .theme-button { width: 36px; height: 36px; }
    .tabs { width: 100%; justify-content: space-around; padding: 3px; background: transparent; }
    .tab { min-width: 0; min-height: 42px; flex: 1; justify-content: center; padding: 0 5px; border-radius: 10px; }
    .tab span { display: none; }
    .tab .icon { width: 21px; height: 21px; }
    .tab.active { background: var(--primary-soft); box-shadow: none; }
    .chat-layout { display: block; position: relative; height: 100%; overflow: hidden; }
    .conversation-panel, .chat-panel { position: absolute; inset: 0; width: 100%; height: 100%; transition: transform .2s ease; }
    .conversation-panel { transform: translateX(0); border: 0; }
    .chat-panel { transform: translateX(100%); }
    .conversation-open .conversation-panel { transform: translateX(-20%); pointer-events: none; }
    .conversation-open .chat-panel { transform: translateX(0); }
    .mobile-back { display: grid; margin-left: -6px; }
    .panel-heading { padding-top: 18px; }
    .panel-heading h1, .content-heading h1, .profile-card h1 { font-size: 23px; }
    .messages { padding: 16px 12px 20px; }
    .bubble { max-width: 84%; }
    .chat-header { padding: 0 12px; }
    .chat-header .avatar-shell { width: 40px; height: 40px; }
    .composer { padding-left: 10px; padding-right: 10px; }
    .content-page, .profile-page { width: 100%; padding: 28px 16px 70px; }
    .status-grid { grid-template-columns: 1fr; }
    .contact-card { padding: 12px; }
    .contact-action { display: none; }
    .profile-card { padding: 20px; }
    .demo-switcher { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
    .topbar { grid-template-columns: 32px 1fr 32px; gap: 4px; padding: 0 7px; }
    .brand-mark, .theme-button { width: 32px; height: 32px; }
    .tabs { gap: 0; }
    .conversation-row { padding-left: 8px; padding-right: 8px; }
}
