:root {
  --bg: #0a0e1a;
  --panel: #101625;
  --panel-2: #151c2d;
  --panel-3: #1b2438;
  --text: #f5f7fb;
  --muted: #8f9bb1;
  --line: rgba(255,255,255,.075);
  --accent: #7c5cff;
  --accent-2: #5b3df4;
  --incoming: #1a2234;
  --outgoing: linear-gradient(135deg,#7558ff,#5c3bf2);
  --danger: #ff657a;
  --success: #46d7a7;
  --shadow: 0 20px 55px rgba(0,0,0,.35);
}

body.light {
  --bg: #eef2f8;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --panel-3: #edf1f7;
  --text: #172033;
  --muted: #768196;
  --line: rgba(27,37,59,.09);
  --incoming: #eef2f8;
  --shadow: 0 20px 55px rgba(35,49,78,.13);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: #8f7cff; font-size: 11px; font-weight: 800; letter-spacing: .16em; }

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(124,92,255,.22), transparent 33%),
    radial-gradient(circle at 85% 80%, rgba(66,195,255,.11), transparent 30%),
    var(--bg);
}
.login-card {
  width: min(430px, 100%);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.brand-mark, .rail-logo {
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  background: linear-gradient(145deg,#8d74ff,#5c3bef);
  box-shadow: 0 10px 25px rgba(102,68,242,.35);
}
.brand-mark { width: 54px; height: 54px; border-radius: 18px; margin-bottom: 26px; font-size: 24px; }
.login-card h1 { margin: 0; font-size: clamp(34px, 7vw, 50px); line-height: 1.02; letter-spacing: -.045em; }
.login-copy { color: var(--muted); line-height: 1.6; margin: 18px 0 28px; }
.login-card label { display: block; color: var(--muted); font-size: 13px; margin: 15px 0; }
.login-card input {
  width: 100%;
  margin-top: 8px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--panel-2);
  outline: none;
}
.login-card input:focus { border-color: rgba(124,92,255,.7); box-shadow: 0 0 0 3px rgba(124,92,255,.12); }
.primary-button, .secondary-button {
  width: 100%; border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 800;
}
.primary-button { margin-top: 12px; color: white; background: linear-gradient(135deg,#8268ff,#5b3df1); box-shadow: 0 12px 30px rgba(93,61,241,.3); }
.secondary-button { color: var(--text); background: var(--panel-3); border: 1px solid var(--line); }
.form-error { min-height: 18px; color: var(--danger); font-size: 13px; text-align: center; }

.app-shell { height: 100%; display: grid; grid-template-columns: 74px 360px minmax(420px,1fr) 340px; }
.rail { display: flex; align-items: center; flex-direction: column; gap: 12px; padding: 18px 12px; border-right: 1px solid var(--line); background: #080c15; }
body.light .rail { background: #172033; }
.rail-logo { width: 42px; height: 42px; border-radius: 14px; margin-bottom: 18px; }
.rail-button { width: 44px; height: 44px; border: 0; border-radius: 13px; background: transparent; color: #8390a6; font-size: 19px; }
.rail-button:hover, .rail-button.active { color: white; background: rgba(124,92,255,.18); }
.rail-bottom { margin-top: auto; }

.inbox-panel, .details-panel { background: var(--panel); }
.inbox-panel { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.inbox-header { display: flex; align-items: center; justify-content: space-between; padding: 24px 22px 15px; }
.inbox-header h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: #647088; box-shadow: 0 0 0 4px rgba(100,112,136,.12); }
.connection-dot.online { background: var(--success); box-shadow: 0 0 0 4px rgba(70,215,167,.12); }
.search-box { display: flex; gap: 9px; align-items: center; margin: 0 18px 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-2); color: var(--muted); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.channel-filters { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; padding: 0 14px 12px; border-bottom: 1px solid var(--line); }
.channel-filters button, .subfilters button, .subfilters select { border: 0; color: var(--muted); background: transparent; border-radius: 10px; padding: 8px 5px; font-size: 12px; font-weight: 700; }
.channel-filters button { min-width: 0; height: 42px; display: flex; align-items: center; justify-content: center; gap: 3px; }
.channel-filters button img { width: 25px; height: 25px; object-fit: contain; display: block; }
.all-channels-icon { font-size: 19px; line-height: 1; }
.channel-filters button.active { background: var(--panel-3); color: var(--text); }
.channel-filters b, .subfilters b { font-size: 10px; padding-left: 3px; }
.channel-icon { display: inline-grid; place-items: center; width: 21px; height: 21px; flex: 0 0 21px; }
.channel-icon img { width: 100%; height: 100%; display: block; object-fit: contain; }
.subfilters { display: flex; justify-content: space-between; align-items: center; padding: 9px 16px; }
.subfilters button.active { color: white; background: var(--accent); }
.subfilters select { outline: none; }
.conversation-list { overflow-y: auto; flex: 1; padding: 4px 8px 14px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 46px 1fr auto; gap: 11px; align-items: center; padding: 12px; border: 0; border-radius: 15px; text-align: left; background: transparent; color: var(--text); }
.conversation-item:hover { background: var(--panel-2); }
.conversation-item.active { background: var(--panel-3); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; font-weight: 900; background: linear-gradient(145deg,#5a6b85,#334158); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.conversation-item .avatar { width: 46px; height: 46px; }
.avatar.large { width: 44px; height: 44px; }
.conversation-copy { min-width: 0; }
.conversation-top { display: flex; gap: 8px; align-items: center; }
.conversation-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-copy p { margin: 5px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.conversation-meta { display: flex; align-items: flex-end; flex-direction: column; gap: 8px; color: var(--muted); font-size: 10px; }
.unread-badge { display: grid; place-items: center; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; color: white; background: var(--accent); font-weight: 800; }
.empty-list { padding: 34px 20px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.6; }

.chat-panel { min-width: 0; position: relative; background: var(--panel-2); }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.empty-state h3 { margin: 20px 0 8px; font-size: 24px; }
.empty-state p { max-width: 400px; margin: 0; color: var(--muted); line-height: 1.6; }
.empty-orbit { width: 90px; height: 90px; display: grid; place-items: center; border: 1px solid rgba(124,92,255,.35); border-radius: 50%; box-shadow: 0 0 50px rgba(124,92,255,.18); }
.empty-orbit:before { content: ''; position: absolute; width: 130px; height: 44px; border: 1px solid rgba(124,92,255,.25); border-radius: 50%; transform: rotate(-20deg); }
.empty-orbit span { color: #9b8aff; font-size: 33px; }
.chat-view { height: 100%; display: grid; grid-template-rows: 74px 1fr auto; }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb,var(--panel) 87%,transparent); backdrop-filter: blur(16px); }
.chat-title-wrap { min-width: 0; flex: 1; }
.chat-title-wrap h3 { margin: 0; font-size: 16px; }
.chat-title-wrap p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.channel-badge { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 7px; vertical-align: middle; }
.channel-badge img { width: 22px; height: 22px; object-fit: contain; display: block; }
.ghost-button, .icon-button { border: 1px solid var(--line); color: var(--text); background: var(--panel-2); border-radius: 11px; }
.ghost-button { padding: 9px 12px; font-size: 12px; font-weight: 750; }
.icon-button { width: 37px; height: 37px; }
.mobile-back { display: none; border: 0; background: transparent; color: var(--text); font-size: 32px; }
.message-list { overflow-y: auto; padding: 25px clamp(18px,4vw,55px); }
.day-divider { display: flex; align-items: center; gap: 12px; margin: 12px 0 22px; color: var(--muted); font-size: 11px; }
.day-divider:before, .day-divider:after { content: ''; height: 1px; flex: 1; background: var(--line); }
.message-row { display: flex; margin: 8px 0; }
.message-row.outbound { justify-content: flex-end; }
.message-bubble { max-width: min(680px,80%); padding: 11px 14px 8px; border-radius: 17px; background: var(--incoming); box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.message-row.inbound .message-bubble { border-bottom-left-radius: 5px; }
.message-row.outbound .message-bubble { color: white; background: var(--outgoing); border-bottom-right-radius: 5px; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.48; font-size: 14px; }
.message-meta { display: flex; justify-content: flex-end; gap: 5px; margin-top: 5px; color: color-mix(in srgb,currentColor 70%,transparent); font-size: 9px; }
.attachments { display: grid; gap: 8px; margin-bottom: 8px; }
.attachment-photo { max-width: 330px; width: 100%; max-height: 330px; border-radius: 12px; object-fit: cover; background: rgba(0,0,0,.12); }
.attachment-file { display: flex; gap: 9px; align-items: center; padding: 9px 10px; border: 1px solid rgba(255,255,255,.12); border-radius: 11px; color: inherit; text-decoration: none; }
.composer { display: flex; gap: 10px; align-items: flex-end; padding: 14px 18px max(14px,env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { width: 100%; min-height: 45px; max-height: 140px; resize: none; border: 1px solid var(--line); border-radius: 15px; padding: 12px 14px; outline: none; color: var(--text); background: var(--panel-2); line-height: 1.4; }
.composer textarea:focus { border-color: rgba(124,92,255,.55); }
.send-button { flex: 0 0 auto; width: 45px; height: 45px; border: 0; border-radius: 15px; color: white; background: linear-gradient(135deg,#8268ff,#5b3df1); font-size: 18px; }
.send-button:disabled { opacity: .45; cursor: not-allowed; }

.details-panel { overflow-y: auto; padding: 28px 20px; border-left: 1px solid var(--line); text-align: center; }
.details-empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; line-height: 1.6; }
.details-avatar { width: 74px; height: 74px; margin: 0 auto 12px; font-size: 24px; }
.details-panel h3 { margin: 0; }
.details-card { margin: 25px 0; padding: 4px 14px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel-2); text-align: left; }
.details-card div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.details-card div:last-child { border: 0; }
.details-card span { color: var(--muted); }
.details-card strong { max-width: 190px; overflow-wrap: anywhere; text-align: right; }
.note-label { display: block; color: var(--muted); text-align: left; font-size: 12px; }
.note-label textarea { width: 100%; margin: 8px 0 10px; padding: 12px; resize: vertical; border: 1px solid var(--line); border-radius: 13px; outline: none; color: var(--text); background: var(--panel-2); }
.toast { position: fixed; z-index: 999; right: 20px; bottom: 20px; max-width: 360px; padding: 12px 15px; border-radius: 13px; color: white; background: #1b2438; box-shadow: var(--shadow); transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #9b3345; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(139,151,173,.25); border-radius: 10px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 68px 330px minmax(380px,1fr); }
  .details-panel { position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; width: 310px; transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .details-panel.open { transform: translateX(0); }
}
@media (max-width: 820px) {
  .app-shell { display: block; }
  .rail { display: none; }
  .inbox-panel { height: 100%; }
  .chat-panel { position: fixed; z-index: 10; inset: 0; transform: translateX(100%); transition: transform .2s ease; }
  .chat-panel.mobile-open { transform: translateX(0); }
  .mobile-back { display: block; }
  .ghost-button { display: none; }
  .message-bubble { max-width: 88%; }
}
@media (max-width: 480px) {
  .login-card { padding: 30px 22px; border-radius: 22px; }
  .channel-filters { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .channel-filters button { font-size: 10px; padding-inline: 2px; }
  .channel-filters button img { width: 23px; height: 23px; }
  .chat-header { padding-inline: 10px; }
  .message-list { padding-inline: 12px; }
  .composer { padding-inline: 10px; }
}

/* Клиентская карточка 1.2 */
.details-drawer-header { display: none; align-items: center; justify-content: space-between; position: sticky; z-index: 2; top: -28px; margin: -28px -20px 20px; padding: 16px 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb,var(--panel) 94%,transparent); backdrop-filter: blur(16px); text-align: left; }
.details-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--panel-2); font-size: 26px; line-height: 1; }
.details-backdrop { display: none; position: fixed; z-index: 19; inset: 0; background: rgba(3,7,15,.62); opacity: 0; transition: opacity .2s ease; }
.details-backdrop.open { opacity: 1; }
.details-toolbar { display: grid; gap: 7px; margin: 16px 0 4px; }
.compact-button { padding: 10px 12px; }
.compact-button:disabled { opacity: .55; }
.details-section { margin-top: 22px; text-align: left; }
.details-section h4 { margin: 0 0 9px; color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.details-card { margin: 0; padding: 2px 14px; }
.details-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.details-row:last-child { border-bottom: 0; }
.details-row > span:first-child { flex: 0 0 42%; color: var(--muted); }
.details-value { display: flex; min-width: 0; flex: 1; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; text-align: right; overflow-wrap: anywhere; }
.details-value strong { max-width: 100%; font-weight: 750; overflow-wrap: anywhere; }
.details-value a { color: #9f8cff; font-weight: 750; text-decoration: none; overflow-wrap: anywhere; }
.details-value a:hover { text-decoration: underline; }
.details-value small { width: 100%; color: var(--muted); font-size: 9px; }
.copy-detail { flex: 0 0 auto; width: 27px; height: 27px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--panel-3); }
.copy-detail:hover { color: var(--text); }
.note-label { margin-top: 24px; }
body.details-open { overflow: hidden; }

@media (max-width: 1180px) {
  .details-drawer-header { display: flex; }
  .details-backdrop { display: block; pointer-events: none; }
  .details-backdrop.open { pointer-events: auto; }
  .details-panel { z-index: 20; width: min(380px,92vw); padding-top: 28px; }
}

@media (max-width: 820px) {
  .details-backdrop { z-index: 29; }
  .details-panel { z-index: 30; width: min(390px,94vw); }
}

@media (max-width: 480px) {
  .channel-filters { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .details-panel { width: 100%; }
  .details-row { gap: 10px; }
  .details-row > span:first-child { flex-basis: 39%; }
}

/* Вложения, мобильная карточка и Android-контейнер 1.4 */
.channel-filters { grid-template-columns: repeat(4,minmax(0,1fr)); }
.channel-filters button { padding-inline: 2px; }
.channel-filters button img { width: 24px; height: 24px; }
.composer { align-items: flex-end; }
.composer-main { min-width: 0; flex: 1; display: grid; gap: 7px; }
.composer-main textarea { width: 100%; }
.attach-button { flex: 0 0 auto; width: 45px; height: 45px; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: var(--panel-2); font-size: 26px; line-height: 1; }
.attach-button:disabled { opacity: .45; }
.selected-file { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-3); font-size: 11px; }
.selected-file span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-file strong { font-weight: 750; }
.selected-file small { color: var(--muted); }
.selected-file button { flex: 0 0 auto; width: 25px; height: 25px; border: 0; border-radius: 8px; color: var(--text); background: transparent; font-size: 20px; }
.attachment-video { width: min(360px,100%); max-height: 360px; border-radius: 12px; background: #000; }
.attachment-audio { display: grid; gap: 6px; min-width: min(310px,70vw); }
.attachment-audio span { font-size: 11px; }
.attachment-audio audio { width: 100%; height: 38px; }

@media (max-width: 480px) {
  .channel-filters { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 2px; padding-inline: 8px; }
  .channel-filters button { height: 39px; }
  .channel-filters button img { width: 21px; height: 21px; }
  .channel-filters .all-channels-icon { font-size: 15px; }
  .channel-filters b { display: none; }
  .attach-button, .send-button { width: 43px; height: 43px; }
  .composer { gap: 7px; }
}

/* Безопасные отступы Android WebView */
@supports (padding: max(0px)) {
  .inbox-header, .chat-header { padding-top: max(18px, env(safe-area-inset-top)); }
}
