:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: #0d1015;
  --panel-raised: #12161d;
  --panel-soft: #161b23;
  --line: #232a35;
  --line-soft: #1a2029;
  --text: #f0f3f7;
  --muted: #818b99;
  --muted-strong: #aab3c0;
  --accent: #8ba7ff;
  --accent-strong: #6e91ff;
  --accent-soft: rgba(110, 145, 255, .12);
  --success: #58d39b;
  --danger: #ff7b83;
  --bubble: #171c24;
  --outgoing: #21345a;
  --shadow: 0 20px 60px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif; }
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

/* Вход */
.login-screen {
  position: relative;
  isolation: isolate;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(circle at 50% -20%, #213151 0, #10151e 30%, var(--bg) 68%);
}
.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  opacity: .32;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.login-orbit { position: absolute; z-index: -1; border: 1px solid rgba(139,167,255,.13); border-radius: 50%; }
.orbit-one { width: 620px; height: 620px; }
.orbit-two { width: 850px; height: 850px; opacity: .45; }
.login-card {
  width: min(460px, calc(100% - 32px));
  padding: 36px;
  border: 1px solid rgba(139, 167, 255, .18);
  border-radius: 22px;
  background: rgba(13, 16, 21, .9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 42px; }
.login-brand > div:last-child { display: grid; gap: 2px; letter-spacing: .16em; }
.login-brand strong { font-size: 14px; }
.login-brand span { color: var(--muted); font-size: 9px; }
.brand-mark, .brand-symbol {
  display: grid;
  place-items: center;
  flex: none;
  background: linear-gradient(145deg, #fff, #cbd7f5);
  color: #090b0f;
  font-weight: 900;
  box-shadow: 0 8px 25px rgba(139,167,255,.18);
}
.brand-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 20px; }
.login-copy h1 { margin: 0 0 9px; font-size: 29px; line-height: 1.15; letter-spacing: -.02em; }
.login-copy p { margin: 0 0 30px; color: var(--muted-strong); line-height: 1.65; }
.login-card label { display: block; margin-bottom: 8px; color: var(--muted-strong); font-size: 12px; font-weight: 600; }
.password-field { position: relative; }
.password-field input {
  width: 100%; height: 52px; padding: 0 92px 0 15px;
  border: 1px solid var(--line); border-radius: 11px; outline: 0;
  background: #090c11; color: var(--text); transition: border-color .18s, box-shadow .18s;
}
.password-field input:focus { border-color: #5874be; box-shadow: 0 0 0 3px rgba(110,145,255,.1); }
.password-field button { position: absolute; right: 7px; top: 7px; height: 38px; padding: 0 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.primary-button {
  width: 100%; height: 50px; margin-top: 14px; padding: 0 17px;
  display: flex; align-items: center; justify-content: space-between;
  border: 0; border-radius: 11px; cursor: pointer;
  background: linear-gradient(135deg, #f5f7fb, #d7e1fa); color: #0a0d12; font-weight: 800;
  transition: transform .15s, filter .15s;
}
.primary-button:hover { filter: brightness(1.05); transform: translateY(-1px); }
.primary-button:disabled { opacity: .65; cursor: wait; transform: none; }
.error { min-height: 20px; margin-top: 12px; color: var(--danger); text-align: center; font-size: 12px; }
.security-note { display: flex; justify-content: center; align-items: center; gap: 7px; margin-top: 16px; color: var(--muted); font-size: 10px; }
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(88,211,155,.1); }

/* Каркас */
.workspace {
  width: 100%; height: 100%; min-height: 0; overflow: hidden;
  display: grid; grid-template-columns: 244px 350px minmax(460px, 1fr);
  background: var(--bg);
}
.accounts-pane, .chats-pane, .messages-pane { min-width: 0; min-height: 0; overflow: hidden; }
.accounts-pane, .chats-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.accounts-pane { background: #0b0e13; }
.chats-pane { background: var(--panel); }
.messages-pane { position: relative; display: flex; flex-direction: column; background: #0c0f14; }
.brand { height: 72px; flex: none; padding: 0 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line-soft); }
.brand-symbol { width: 34px; height: 34px; border-radius: 10px; }
.brand > div { display: grid; gap: 2px; letter-spacing: .13em; }
.brand strong { font-size: 12px; }
.brand small { color: var(--muted); font-size: 8px; }
.sidebar-summary { padding: 20px 18px 9px; display: flex; justify-content: space-between; align-items: center; }
.eyebrow { color: #67717f; font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.sidebar-summary > strong { color: var(--muted-strong); font-size: 12px; }
.scroll-list { min-height: 0; overflow-y: auto; overflow-x: hidden; flex: 1; scrollbar-gutter: stable; }
.scroll-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.scroll-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: #29313d; border: 2px solid transparent; border-radius: 9px; background-clip: padding-box; }
.list-item { position: relative; display: flex; gap: 11px; margin: 2px 8px; padding: 11px 10px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; transition: background .15s, border-color .15s; }
.list-item:hover { background: rgba(255,255,255,.035); }
.list-item.active { background: var(--accent-soft); border-color: rgba(139,167,255,.14); }
.list-item.active::before { content: ""; position: absolute; left: -9px; top: 14px; bottom: 14px; width: 2px; border-radius: 3px; background: var(--accent); }
.avatar { position: relative; flex: none; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(145deg,#222a36,#181e27); color: #d5dce7; font-weight: 800; letter-spacing: -.02em; }
.avatar-image { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; opacity: 0; transition: opacity .18s ease; }
.avatar.has-image .avatar-image { opacity: 1; }
.avatar.online::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 8px; height: 8px; border: 2px solid var(--panel); border-radius: 50%; background: var(--success); }
.avatar.online::after { z-index: 2; }
.item-body { min-width: 0; flex: 1; align-self: center; }
.item-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.item-row strong, .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row strong { font-size: 13px; }
.item-row time { flex: none; color: #66717e; font-size: 9px; }
.preview { margin-top: 3px; color: var(--muted); font-size: 11px; }
.counter { align-self: center; min-width: 22px; padding: 2px 7px; border-radius: 10px; background: #202631; color: #9ea8b6; text-align: center; font-size: 9px; }
.list-item.active .counter { background: rgba(139,167,255,.14); color: #b8c8ff; }
.sidebar-footer { flex: none; padding: 12px; border-top: 1px solid var(--line-soft); }
.system-state { display: flex; align-items: center; gap: 10px; margin: 4px 5px 14px; }
.system-state > div { min-width: 0; display: grid; }
.system-state strong { color: var(--muted-strong); font-size: 10px; }
.system-state small { overflow: hidden; color: #5d6774; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.quiet-button { width: 100%; height: 37px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.quiet-button:hover { border-color: #3a4350; color: var(--text); }

/* Чаты и поиск */
.search-wrap { position: relative; flex: none; padding: 15px 14px; border-bottom: 1px solid var(--line-soft); }
.search-wrap input { width: 100%; height: 42px; padding: 0 64px 0 37px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: #090c11; color: var(--text); font-size: 12px; }
.search-wrap input:focus { border-color: #4c639f; box-shadow: 0 0 0 3px rgba(110,145,255,.08); }
.search-icon { position: absolute; left: 27px; top: 23px; color: var(--muted); font-size: 21px; line-height: 1; transform: rotate(-15deg); pointer-events: none; }
.search-wrap kbd { position: absolute; right: 25px; top: 26px; padding: 2px 5px; border: 1px solid #2b333f; border-radius: 5px; background: #151a21; color: #697381; font: 8px/1.4 inherit; }
.pane-context { min-height: 64px; flex: none; padding: 15px 16px 11px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.pane-context > div { min-width: 0; display: grid; gap: 5px; }
.pane-context strong { overflow: hidden; color: #c9d0da; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.count-pill { min-width: 24px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 10px; color: #77818e; text-align: center; font-size: 9px; }
.chat-list .list-item { padding-top: 10px; padding-bottom: 10px; }
.chat-list .avatar { border-radius: 50%; }
.list-status { flex: none; min-height: 38px; padding: 11px 16px; border-top: 1px solid var(--line-soft); color: #5e6875; font-size: 9px; text-align: center; }
.search-result .preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.search-result .account-label { margin-bottom: 3px; color: #7794ed; font-size: 9px; }
.search-mark { color: #dbe4ff; background: rgba(139,167,255,.16); border-radius: 2px; }

/* Сообщения */
.chat-header { height: 72px; flex: none; padding: 0 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line-soft); background: rgba(13,16,21,.94); backdrop-filter: blur(16px); }
.avatar.large { width: 42px; height: 42px; border-radius: 50%; }
.muted-avatar { color: #687280; }
.chat-identity { min-width: 0; flex: 1; display: grid; }
.chat-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-identity small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.header-actions { display: flex; gap: 7px; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: #11151b; color: #98a2af; cursor: pointer; font-size: 18px; }
.icon-button:hover:not(:disabled) { border-color: #405071; color: var(--text); }
.icon-button:disabled { opacity: .35; cursor: default; }
.icon-button.loading { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable;
  padding: 28px max(24px, calc((100% - 850px)/2)) 36px;
  background-color: #0c0f14;
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(to bottom, rgba(19,24,33,.35), transparent 180px);
  background-size: 24px 24px, 100% 100%;
  scroll-behavior: smooth;
}
.empty-state { display: grid; place-items: center; text-align: center; }
.empty-card { min-width: 260px; padding: 25px 28px; display: grid; justify-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 16px; background: rgba(15,19,25,.88); box-shadow: 0 18px 50px rgba(0,0,0,.18); }
.empty-card b { font-size: 12px; }
.empty-card > span:last-child { color: var(--muted); font-size: 10px; }
.empty-icon { width: 38px; height: 38px; margin-bottom: 6px; display: grid; place-items: center; border: 1px solid #313a48; border-radius: 12px; color: #8398d6; font-size: 19px; }
.date-separator { margin: 18px 0 13px; display: flex; align-items: center; gap: 12px; color: #687382; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.date-separator::before, .date-separator::after { content: ""; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, #202630); }
.date-separator::after { transform: rotate(180deg); }
.message-row { display: flex; margin: 6px 0; animation: reveal .16s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(3px); } }
.message-row.outgoing { justify-content: flex-end; }
.bubble { position: relative; max-width: min(72%, 680px); padding: 10px 12px 8px; border: 1px solid rgba(255,255,255,.035); border-radius: 14px 14px 14px 4px; background: var(--bubble); box-shadow: 0 2px 9px rgba(0,0,0,.18); }
.outgoing .bubble { border-color: rgba(139,167,255,.08); border-radius: 14px 14px 4px 14px; background: var(--outgoing); }
.bubble.deleted { border-color: rgba(255,123,131,.28); background: linear-gradient(135deg, rgba(87,35,42,.45), var(--bubble)); }
.sender { margin-bottom: 4px; color: #91aaf2; font-size: 10px; font-weight: 800; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
.meta { margin: 6px 0 0 14px; display: flex; justify-content: flex-end; align-items: center; gap: 7px; color: #7c8795; font-size: 8px; }
.deleted-label, .edited-label { padding: 1px 5px; border-radius: 5px; }
.deleted-label { background: rgba(255,123,131,.12); color: #ff9aa0; }
.edited-label { background: rgba(139,167,255,.1); color: #aabfff; }
.media { display: block; max-width: 100%; margin-bottom: 8px; border-radius: 10px; background: #080a0d; }
.media.photo, .media.video { max-height: 520px; object-fit: contain; }
.media.video-note { width: 250px; height: 250px; border-radius: 50%; object-fit: cover; }
.media.sticker { width: 170px; height: 170px; object-fit: contain; background: transparent; }
.sticker-stage { position: relative; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 10px; }
.sticker-stage canvas, .sticker-content { width: 100% !important; height: 100% !important; display: block; object-fit: contain; }
.sticker-video { pointer-events: none; }
.sticker-loading { opacity: .65; }
.sticker-failed { width: auto !important; height: auto !important; min-width: 145px; min-height: 54px; padding: 12px; border: 1px dashed #343d49; border-radius: 10px; background: rgba(255,255,255,.025); }
.audio { width: 320px; max-width: 100%; margin-bottom: 5px; }
.file-link { min-width: 250px; margin-bottom: 7px; padding: 11px; display: flex; align-items: center; gap: 10px; border: 1px solid rgba(255,255,255,.09); border-radius: 10px; color: #dae4ff; text-decoration: none; }
.file-link:hover { background: rgba(255,255,255,.035); }
.file-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 9px; background: rgba(139,167,255,.1); color: var(--accent); }
.jump-bottom { position: absolute; right: 24px; bottom: 22px; z-index: 3; height: 38px; padding: 0 13px; display: flex; align-items: center; gap: 7px; border: 1px solid #354158; border-radius: 20px; background: rgba(23,29,39,.94); box-shadow: 0 10px 30px rgba(0,0,0,.35); color: #cbd6f4; cursor: pointer; font-size: 10px; backdrop-filter: blur(12px); }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; background: #151a22; box-shadow: var(--shadow); color: var(--muted-strong); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .2s; font-size: 11px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.skeleton { position: relative; overflow: hidden; pointer-events: none; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg,transparent,rgba(255,255,255,.035),transparent); animation: shimmer 1.1s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 218px 310px minmax(390px, 1fr); }
  .bubble { max-width: 82%; }
  .search-wrap kbd { display: none; }
  .search-wrap input { padding-right: 13px; }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .workspace { width: 100%; min-width: 920px; }
  .login-card { padding: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
