:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0e1822;
  --surface: #142331;
  --surface-2: #192c3c;
  --surface-3: #20394d;
  --text: #eef5fa;
  --muted: #8fa4b5;
  --border: #263c4c;
  --accent: #51a7f8;
  --accent-strong: #2f91e9;
  --bubble: #1b3041;
  --bubble-out: #24503f;
  --danger: #ff6b78;
  --shadow: 0 18px 60px #0006;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f8;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --surface-3: #e7f2fd;
  --text: #17212b;
  --muted: #71808f;
  --border: #dce5ec;
  --accent: #3390ec;
  --accent-strong: #227ed5;
  --bubble: #ffffff;
  --bubble-out: #dcf8cd;
  --shadow: 0 18px 60px #20466d18;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.app { min-height: 100svh; height: 100dvh; }

.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; z-index: 50; background: var(--bg); color: var(--text); }
.boot-name { font-size: 25px; font-weight: 800; letter-spacing: -.6px; }
.boot-bar { width: 112px; height: 4px; overflow: hidden; border-radius: 9px; background: var(--border); }
.boot-bar i { display: block; width: 42%; height: 100%; border-radius: inherit; background: var(--accent); animation: load 1.1s infinite; }
@keyframes load { to { transform: translateX(275%); } }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% -15%, #235578, transparent 48%), var(--bg); }
.auth-card, .onboard { width: min(440px, 100%); padding: 32px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.brand { text-align: center; margin-bottom: 26px; }
.brand img { width: 68px; height: 68px; }
.brand h1 { margin: 13px 0 5px; font-size: 26px; letter-spacing: -.5px; }
.brand p, .hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.field { display: grid; gap: 7px; margin: 16px 0; }
.field label { color: var(--muted); font-size: 13px; font-weight: 700; }
.field input, .field textarea, .search-input, .field select { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; outline: 0; background: var(--surface-2); color: var(--text); transition: border-color .16s, box-shadow .16s; }
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field textarea:focus, .search-input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #51a7f826; }
.code-input { font-size: 26px; letter-spacing: 9px; text-align: center; }
.btn { min-height: 44px; padding: 11px 16px; border-radius: 12px; font-weight: 750; transition: transform .15s, background .15s; }
.btn:active { transform: scale(.97); }
.btn-primary { width: 100%; background: var(--accent-strong); color: white; }
.btn-secondary { background: var(--surface-3); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--accent); }
.error { margin: 12px 0; padding: 11px 13px; border-radius: 12px; background: #ff536218; color: var(--danger); font-size: 13px; }
.rules { max-height: 330px; overflow: auto; margin: 20px 0; padding: 15px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.rules h3 { margin: 15px 0 5px; font-size: 14px; }
.rules p { margin: 5px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.shell { display: grid; grid-template-columns: 360px minmax(0, 1fr); height: 100%; min-height: 0; background: var(--surface); }
.sidebar { display: flex; min-width: 0; min-height: 0; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); }
.side-head, .chat-head { display: flex; align-items: center; gap: 11px; min-height: 68px; padding: 10px 15px; border-bottom: 1px solid var(--border); }
.side-head { padding-top: max(10px, env(safe-area-inset-top)); }
.side-head h2 { flex: 1; margin: 0; font-size: 20px; letter-spacing: -.3px; }
.icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: transparent; color: var(--muted); font-size: 22px; }
.icon svg, .send svg, .msg-more svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon svg circle { fill: currentColor; stroke: none; }
.accent-icon { color: var(--accent); }
.icon:hover { background: var(--surface-3); color: var(--text); }
.search { position: relative; padding: 10px 14px; }
.search-input { border: 0; border-radius: 20px; background: var(--surface-2); }
.search .search-input { padding-left: 41px; }
.search-glyph { position: absolute; z-index: 1; left: 28px; top: 18px; color: var(--muted); font-size: 22px; line-height: 1; pointer-events: none; }
.chat-list { flex: 1; min-height: 0; overflow: auto; padding: 3px 6px 12px; }
.chat-row { display: flex; align-items: center; gap: 12px; min-height: 70px; padding: 10px 9px; border-radius: 13px; cursor: pointer; transition: background .15s; }
.chat-row:hover, .chat-row.active { background: var(--surface-3); }
.chat-copy { min-width: 0; flex: 1; }
.chat-line { display: flex; justify-content: space-between; gap: 10px; }
.chat-title { overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.chat-time, .chat-preview { color: var(--muted); font-size: 12px; }
.chat-preview { display: block; overflow: hidden; margin-top: 4px; text-overflow: ellipsis; white-space: nowrap; }
.avatar { display: grid; flex: 0 0 50px; place-items: center; width: 50px; height: 50px; border-radius: 50%; color: white; font-size: 16px; font-weight: 800; background: #3390ec; }
.avatar.small { flex-basis: 42px; width: 42px; height: 42px; font-size: 13px; }
.avatar.official { background: linear-gradient(135deg, #3390ec, #7b55ed); }
.avatar.violet { background: #7655d6; } .avatar.pink { background: #d94e91; } .avatar.red { background: #d95353; } .avatar.orange { background: #df8b36; } .avatar.green { background: #43a875; } .avatar.teal { background: #1b9a9a; } .avatar.cyan { background: #2499c5; } .avatar.indigo { background: #455fc4; } .avatar.graphite { background: #66727d; }
.badge { padding: 2px 7px; border-radius: 12px; background: var(--accent); color: white; font-size: 11px; }

.main { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: var(--bg); }
.chat-head { background: var(--surface); }
.chat-identity { display: flex; align-items: center; min-width: 0; flex: 1; gap: 11px; padding: 0; background: transparent; color: var(--text); text-align: left; }
.head-actions { display: flex; align-items: center; gap: 2px; }
.chat-head .back { display: none; }
.chat-head-copy { min-width: 0; flex: 1; }
.chat-head-title { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.chat-head-status { margin-top: 3px; color: var(--accent); font-size: 12px; }
.verified { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 4px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 10px; vertical-align: 1px; }
.pinned-bar { display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 6px 17px; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); text-align: left; }
.pinned-bar i { width: 3px; height: 34px; border-radius: 4px; background: var(--accent); }
.pinned-bar span { display: grid; min-width: 0; font-size: 12px; }
.pinned-bar b { color: var(--accent); }
.pinned-bar span:not(b) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-searchbar { display: none; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-searchbar.open { display: flex; }
.chat-searchbar > span { display: grid; color: var(--muted); }
.chat-searchbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.chat-searchbar input { min-width: 0; flex: 1; padding: 8px 4px; border: 0; outline: 0; background: transparent; color: var(--text); }
.messages { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 5px; overflow: auto; padding: 20px clamp(12px, 5vw, 90px); background-color: var(--bg); background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 18px 18px; }
.msg { position: relative; max-width: min(650px, 82%); align-self: flex-start; padding: 9px 11px 7px; border-radius: 14px 14px 14px 4px; background: var(--bubble); color: var(--text); box-shadow: 0 2px 4px #0002; white-space: pre-wrap; word-break: break-word; animation: pop .14s ease; }
.msg.out { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--bubble-out); }
.msg.service { align-self: center; border-radius: 12px; background: var(--surface-3); color: var(--muted); font-size: 12px; }
.msg-sender { margin-bottom: 3px; color: #e46c91; font-size: 12px; font-weight: 800; }
.msg-text { line-height: 1.38; }
.msg-meta { float: right; margin: 7px 0 0 13px; color: var(--muted); font-size: 10px; }
.msg-meta b { color: #53b6ff; font-weight: 800; letter-spacing: -2px; }
.reply-preview { display: grid; gap: 1px; margin: 0 0 6px; padding: 2px 0 2px 8px; border-left: 3px solid var(--accent); font-size: 12px; }
.reply-preview b { color: var(--accent); }
.reply-preview span { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.msg-more { display: none; position: absolute; top: 4px; right: 3px; width: 30px; height: 30px; place-items: center; border-radius: 50%; background: #0002; color: var(--muted); }
.msg:hover .msg-more { display: grid; }
.msg-more svg { width: 17px; height: 17px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 9px 14px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { flex: 1; max-height: 140px; padding: 10px 4px; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); line-height: 1.4; }
.composer-tool { display: grid; place-items: center; width: 38px; height: 42px; flex: 0 0 38px; border-radius: 50%; background: transparent; color: var(--muted); }
.composer-tool:hover { background: var(--surface-3); color: var(--accent); }
.composer-tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.send { display: grid; place-items: center; width: 43px; height: 43px; flex: 0 0 43px; border-radius: 50%; background: var(--accent-strong); color: white; font-size: 18px; }
.send.sending svg { animation: send-pulse .7s infinite alternate; }
@keyframes send-pulse { to { transform: translateX(4px); opacity: .55; } }
.empty { display: grid; flex: 1; place-items: center; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 5px; color: var(--text); font-size: 17px; }
.loading-state { display: flex; justify-content: center; gap: 5px; padding: 28px; }
.loading-state span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: dots 1s infinite ease-in-out; }
.loading-state span:nth-child(2) { animation-delay: .14s; } .loading-state span:nth-child(3) { animation-delay: .28s; }
@keyframes dots { 0%, 80%, 100% { transform: scale(.65); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }
.welcome-empty img { width: 86px; margin-bottom: 15px; filter: drop-shadow(0 12px 24px #3390ec38); }
.welcome-empty span { display: block; }
.settings { width: min(720px, 100%); margin: 0 auto; padding: 24px; overflow: auto; }
.settings h2 { margin: 0 0 18px; }
.panel { margin-bottom: 14px; padding: 18px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); }
.panel h3 { margin: 0 0 13px; }
.list-item { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item > span:first-child { flex: 1; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.tabs { display: flex; gap: 4px; margin: 0 0 14px; overflow-x: auto; }
.tab { padding: 9px 12px; border-radius: 9px; background: transparent; color: var(--muted); white-space: nowrap; }
.tab.active { background: var(--surface-3); color: var(--accent); font-weight: 750; }
.modal-back { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 18px; background: #0008; }
.modal { width: min(500px, 100%); max-height: min(680px, 90dvh); overflow: auto; padding: 22px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.profile-modal { text-align: center; }
.profile-modal .avatar { margin: 4px auto 12px; }
.action-list { display: grid; gap: 2px; margin-top: 16px; }
.action-list button { display: flex; justify-content: space-between; align-items: center; min-height: 46px; padding: 0 12px; border-radius: 10px; background: transparent; color: var(--text); text-align: left; }
.action-list button:hover { background: var(--surface-3); }
.action-list button span { color: var(--muted); font-size: 12px; }
.action-list .danger-action { color: var(--danger); }
.toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; z-index: 60; transform: translateX(-50%); padding: 11px 17px; border-radius: 11px; background: #243441; color: white; box-shadow: var(--shadow); animation: rise .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 9px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 720px) {
  body { overflow: hidden; }
  .auth { align-items: start; padding: max(22px, env(safe-area-inset-top)) 16px 24px; }
  .auth-card, .onboard { padding: 25px 19px; border-radius: 20px; }
  .shell { display: block; position: relative; }
  .sidebar, .main { position: absolute; inset: 0; width: 100%; height: 100%; transition: transform .22s ease; }
  .main { transform: translateX(100%); }
  .shell.open .sidebar { transform: translateX(-10%); }
  .shell.open .main { transform: translateX(0); }
  .chat-head { padding-top: max(9px, env(safe-area-inset-top)); }
  .chat-head .back { display: grid; }
  .messages { padding: 14px 10px; }
  .msg { max-width: 88%; }
  .msg-more { display: grid; opacity: .72; }
  .settings { padding: max(18px, env(safe-area-inset-top)) 14px 24px; }
}
