/* Monochrome by default; optional gradients and layouts are device-local. */
:root, html[data-theme="light"] {
  color-scheme: light;
  --accent: #171717; --accent-hover: #353535; --accent-light: #eeeeee;
  --surface: #ffffff; --surface-hover: #f5f5f5; --surface-active: #ededed;
  --bg: #f8f8f8; --text: #202020; --text-secondary: #626262; --muted: #737373;
  --line: #e7e7e7; --own-bubble: #eaeaea; --own-bubble-border: #e0e0e0;
  --other-bubble: #fff; --other-bubble-border: #e7e7e7; --reply-bg: #dedede;
  --dialog-backdrop: #00000066; --card-shadow: 0 2px 3px #00000004;
  --scrollbar-thumb: #cccccc; --scrollbar-thumb-hover: #aaaaaa;
  --highlight-bg: #d0d0d0; --highlight-shadow: #00000015; --art-paper: #dedede;
  --button-bg: #181818; --button-fg: #ffffff; --avatar-bg: #e7e7e7; --avatar-fg: #555555;
  --message-size: 14px; --radius: 12px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --accent: #ededed; --accent-hover: #ffffff; --accent-light: #272727;
  --surface: #111111; --surface-hover: #1c1c1c; --surface-active: #252525;
  --bg: #0b0b0b; --text: #ededed; --text-secondary: #b0b0b0; --muted: #929292;
  --line: #292929; --own-bubble: #2b2b2b; --own-bubble-border: #363636;
  --other-bubble: #181818; --other-bubble-border: #282828; --reply-bg: #373737;
  --dialog-backdrop: #000000b3; --card-shadow: 0 2px 3px #0000000c;
  --scrollbar-thumb: #3d3d3d; --scrollbar-thumb-hover: #5c5c5c;
  --highlight-bg: #474747; --highlight-shadow: #ffffff18; --art-paper: #292929;
  --button-bg: #eeeeee; --button-fg: #111111; --avatar-bg: #2a2a2a; --avatar-fg: #c4c4c4;
}
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: var(--text); background: var(--bg); -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; border: 0; }
button { cursor: pointer; background: none; color: inherit; transition: background .18s, color .18s, transform .18s; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input:focus, textarea:focus { outline: none; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }
.app { display: flex; height: 100vh; height: 100dvh; max-width: 1800px; margin: auto; background: var(--surface); overflow: hidden; }
aside { width: 364px; flex-shrink: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--surface); min-height: 0; }
.brand { display: flex; align-items: center; padding: 30px 26px 24px; gap: 11px; }
.logo, .dialog-logo { background: var(--button-bg); color: var(--button-fg); width: 41px; height: 41px; display: grid; place-items: center; border-radius: 14px 14px 14px 4px; flex-shrink: 0; }
.brand strong { font-size: 26px; line-height: 1; font-weight: 750; letter-spacing: -1.2px; display: block; }
.brand span { display: block; font-size: 10px; color: var(--muted); margin-top: 6px; letter-spacing: .1px; }
.brand .brand-period { display: inline; font-size: inherit; color: var(--accent); margin: 0; }
.icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--text-secondary); flex-shrink: 0; }
.icon:hover, .icon-btn:hover { background: var(--surface-hover); color: var(--accent); }
.brand .icon { margin-left: auto; border: 1px solid var(--line); }
.sidebar-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 17px 26px 23px; gap: 8px; }
.eyebrow { font-size: 9px; line-height: 1.5; letter-spacing: 1.8px; font-weight: 650; color: var(--muted); }
.sidebar-heading h1 { font-size: 27px; font-weight: 650; letter-spacing: -.9px; margin: 5px 0 0; line-height: 1.2; }
.chat-count { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-light); border-radius: 7px; padding: 3px 6px; margin-left: 9px; vertical-align: middle; letter-spacing: 0; }
.chat-count:empty { display: none; }
.telegram-label { font-size: 10px; color: var(--muted); padding-bottom: 5px; white-space: nowrap; }
.search { margin: 0 22px 17px; background: var(--bg); border: 1px solid transparent; border-radius: 11px; display: flex; align-items: center; padding: 0 13px; gap: 10px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.search-icon { color: var(--muted); flex-shrink: 0; }
.search input { width: 100%; min-width: 0; padding: 13px 0; background: transparent; font-size: 13px; color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.filters { display: flex; gap: 3px; padding: 0 22px 17px; border-bottom: 1px solid var(--line); }
.filters button { flex: 1; font-size: 12px; font-weight: 550; padding: 9px 6px; border-radius: 8px; color: var(--text-secondary); }
.filters button:hover { background: var(--surface-hover); }
.filters button.active { background: var(--accent-light); color: var(--accent); }
.section-label { display: flex; align-items: center; justify-content: space-between; padding: 13px 26px 5px; font-size: 9px; letter-spacing: 1.4px; font-weight: 600; color: var(--muted); }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: var(--muted); flex-shrink: 0; }
.chat-list { overflow-y: auto; overscroll-behavior: contain; flex: 1; padding: 3px 12px 16px; min-height: 0; }
.chat-row { display: flex; align-items: center; width: 100%; min-height: 80px; padding: 14px 12px; text-align: left; gap: 12px; border-radius: 12px; margin: 3px 0; position: relative; }
.chat-row:hover { background: var(--surface-hover); }
.chat-row.selected { background: var(--surface-active); }
.chat-row.selected::before { content: ''; position: absolute; left: 0; top: 26px; bottom: 26px; width: 3px; background: var(--accent); border-radius: 4px; }
.avatar { width: 46px; height: 46px; display: grid; place-items: center; flex-shrink: 0; border-radius: 16px; font-size: 14px; font-weight: 600; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-copy { min-width: 0; flex: 1; }
.row-top { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.row-top strong { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.row-top time { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.chat-copy p { font-size: 12px; color: var(--text-secondary); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; margin: 6px 0 0; line-height: 1.5; }
.sender-prefix { font-weight: 550; color: var(--text); margin-right: 3px; }
.badge { border-radius: 7px; background: var(--button-bg); color: var(--button-fg); font-size: 10px; font-weight: 650; min-width: 19px; padding: 3px 5px; text-align: center; }
aside footer { border-top: 1px solid var(--line); padding: 18px 26px; padding-bottom: max(18px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 10px; display: flex; align-items: center; gap: 8px; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.offline .dot { background: var(--muted); }
main { flex: 1; min-width: 0; min-height: 0; background: var(--bg); display: flex; flex-direction: column; }
.welcome { height: 100%; display: flex; flex-direction: column; padding: 32px 42px 25px; }
.welcome-topline { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 9px; letter-spacing: 1.5px; }
.welcome-topline span:last-child { letter-spacing: .2px; }
.welcome-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.welcome-art { position: relative; width: 240px; height: 200px; margin-bottom: 27px; }
.art-orbit { position: absolute; inset: 0 18px; border: 1px solid var(--line); border-radius: 50%; transform: rotate(-22deg); }
.art-note { position: absolute; width: 104px; height: 116px; border-radius: 16px; display: flex; flex-direction: column; justify-content: center; padding: 23px; }
.art-note-back { background: var(--art-paper); left: 35px; top: 31px; transform: rotate(-14deg); gap: 11px; }
.art-note-back span { height: 4px; width: 48px; border-radius: 4px; background: #88888866; }
.art-note-back span:last-child { width: 28px; }
.art-note-front { display: grid; place-items: center; background: var(--button-bg); color: var(--button-fg); left: 104px; top: 61px; transform: rotate(12deg); box-shadow: 0 12px 24px #00000010; border-bottom-left-radius: 4px; }
.art-spark { position: absolute; top: 13px; right: 33px; font-size: 35px; color: var(--accent); }
.art-dot { position: absolute; bottom: 17px; left: 27px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.welcome h1 { font-size: clamp(32px, 3.5vw, 50px); font-weight: 550; letter-spacing: -2px; line-height: 1.16; margin: 17px 0 16px; }
.welcome h1 em { font-family: Georgia, 'Times New Roman', serif; font-weight: 400; color: var(--accent); }
.welcome p { font-size: 13px; color: var(--text-secondary); line-height: 1.85; margin: 0; }
.welcome-hint { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text-secondary); margin-top: 28px; border: 1px solid var(--line); border-radius: 30px; padding: 10px 17px; }
.welcome-hint span { color: var(--accent); font-size: 18px; }
.welcome-bottom { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--muted); }
.welcome-bottom-note { margin-left: auto; }
#chatView { height: 100%; min-height: 0; display: flex; flex-direction: column; }
.chat-header { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 21px 32px; gap: 13px; }
.chat-heading { min-width: 0; flex: 1; }
.chat-header h2 { font-size: 16px; font-weight: 650; margin: 0 0 4px; letter-spacing: -.3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-header span { font-size: 11px; color: var(--muted); }
.chat-header .avatar { width: 42px; height: 42px; border-radius: 14px; }
.chat-header > a { margin-left: auto; border: 1px solid var(--line); }
#back { display: grid; width: 32px; }
.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 22px clamp(18px, 4vw, 64px); }
.older { display: block; margin: 0 auto 20px; color: var(--text-secondary); font-size: 11px; font-weight: 550; padding: 9px 17px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.older:hover { color: var(--accent); border-color: var(--accent); }
.date-separator { text-align: center; font-size: 10px; font-weight: 550; color: var(--muted); margin: 23px 0; display: flex; align-items: center; justify-content: center; gap: 16px; }
.date-separator::before, .date-separator::after { content: ''; width: 40px; height: 1px; background: var(--line); }
.message { display: flex; gap: 10px; margin: 18px 0; align-items: flex-start; }
.message.grouped-first { margin-top: 18px; margin-bottom: 3px; }
.message.grouped-middle { margin: 3px 0; }
.message.grouped-last { margin-top: 3px; margin-bottom: 18px; }
.message > .avatar { width: 30px; height: 30px; border-radius: 11px; font-size: 10px; margin-top: 22px; }
.avatar-spacer { width: 30px; flex-shrink: 0; }
.message-body { max-width: min(82%, 600px); min-width: 100px; }
.message-author { font-size: 10px; font-weight: 600; color: var(--text-secondary); margin: 0 0 6px 3px; }
.bubble { position: relative; background: var(--other-bubble); border: 1px solid var(--other-bubble-border); border-radius: 15px 15px 15px 4px; padding: 11px 14px 8px; font-size: var(--message-size); line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; box-shadow: var(--card-shadow); }
.message.own { flex-direction: row-reverse; }
.message.own > .avatar, .message.own > .avatar-spacer { display: none; }
.own .bubble { background: var(--own-bubble); border-color: var(--own-bubble-border); border-radius: 15px 15px 4px 15px; }
.message.grouped-first .bubble { border-bottom-left-radius: 6px; }
.message.grouped-middle .bubble { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.message.grouped-last .bubble { border-top-left-radius: 6px; }
.message.own.grouped-first .bubble { border-bottom-left-radius: 15px; border-bottom-right-radius: 6px; }
.message.own.grouped-middle .bubble { border-top-left-radius: 15px; border-bottom-left-radius: 15px; border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.message.own.grouped-last .bubble { border-top-left-radius: 15px; border-top-right-radius: 6px; }
.message.highlighted .bubble { animation: highlight-pulse .8s ease-out; }
@keyframes highlight-pulse { 0%, 55% { background-color: var(--highlight-bg); box-shadow: 0 0 0 4px var(--highlight-shadow); } }
.reply-quote { background: var(--accent-light); border-left: 2px solid var(--accent); padding: 8px 11px; border-radius: 3px 9px 9px 3px; margin-bottom: 9px; font-size: 12px; cursor: pointer; }
.own .reply-quote { background: var(--reply-bg); }
.reply-quote:hover { opacity: .85; }
.reply-quote strong { color: var(--accent); display: block; font-size: 11px; font-weight: 600; margin-bottom: 2px; }
.reply-quote span { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; word-break: break-word; }
.link-attachment { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--accent-light); border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; font-size: 12px; text-decoration: none !important; white-space: normal; }
.link-attachment:hover, .attachment:hover { border-color: var(--accent); }
.link-attachment span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-attachment .ext-icon { opacity: .7; flex-shrink: 0; }
.attachment { display: block; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; font-size: 12px; background: var(--surface); white-space: normal; text-decoration: none !important; }
.message-meta { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 12px; font-size: 10px; color: var(--text-secondary); margin-top: 6px; user-select: none; }
.reply-button { font-size: 10px; font-weight: 550; color: var(--accent); padding: 3px 0; }
.reply-button:hover { text-decoration: underline; text-underline-offset: 3px; }
.message-media { display: grid; gap: 5px; margin-top: 8px; border-radius: 9px; overflow: hidden; }
.message-media.single { display: block; max-width: 440px; }
.message-media.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 500px; }
.message-media.grid-multi { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 500px; }
.message-image-link { display: block; overflow: hidden; border-radius: 9px; background: var(--accent-light); cursor: zoom-in; }
.message-image-link:hover { opacity: .92; }
.message-image { display: block; width: 100%; height: auto; max-height: 380px; object-fit: cover; }
.message-media.single .message-image { max-height: 420px; object-fit: contain; }
.message-media.grid-2 .message-image, .message-media.grid-multi .message-image { height: 150px; object-fit: cover; }
.reply-bar { padding: 10px 14px; margin: 0 32px; background: var(--surface-active); border-left: 2px solid var(--accent); display: flex; align-items: center; gap: 12px; border-radius: 4px 10px 10px 4px; }
.reply-bar div { flex: 1; min-width: 0; }
.reply-bar b { font-size: 11px; color: var(--accent); display: block; font-weight: 600; }
.reply-bar span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; margin-top: 3px; color: var(--text-secondary); }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 10px 12px 10px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; margin: 12px 32px 0; box-shadow: 0 4px 16px #00000004; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; background: transparent; color: var(--text); font-size: 14px; line-height: 1.5; padding: 9px 0; }
.send { width: 40px; height: 40px; border-radius: 12px; background: var(--button-bg); color: var(--button-fg); display: grid; place-items: center; flex-shrink: 0; }
.send:hover { background: var(--accent-hover); transform: translateY(-1px); }
.send:active { transform: scale(.96); }
.composer-note { display: flex; justify-content: space-between; gap: 8px; font-size: 9px; color: var(--muted); padding: 10px 36px max(18px, env(safe-area-inset-bottom)); }
.keyboard-hint > span { margin: 0 5px; }
.placeholder { padding: 40px 20px; color: var(--text-secondary); font-size: 13px; line-height: 1.8; text-align: center; }
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 24px; width: 430px; max-width: calc(100% - 32px); max-height: calc(100dvh - 32px); padding: 32px; box-shadow: 0 24px 90px #00000030; }
dialog::backdrop { background: var(--dialog-backdrop); backdrop-filter: blur(6px); }
dialog h2 { font-size: 25px; font-weight: 600; letter-spacing: -.8px; margin: 8px 0 16px; }
dialog p { color: var(--text-secondary); font-size: 13px; line-height: 1.8; margin: 6px 0; overflow-wrap: anywhere; }
.dialog-logo { width: 50px; height: 50px; margin-bottom: 25px; }
.dialog-eyebrow { margin-bottom: 8px; }
.settings-group { margin: 24px 0; padding-bottom: 23px; border-bottom: 1px solid var(--line); }
.settings-label { font-size: 10px; font-weight: 600; letter-spacing: .8px; color: var(--muted); }
.theme-picker { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.theme-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 11px; padding: 15px 5px; border-radius: 9px; font-size: 11px; font-weight: 550; color: var(--text-secondary); }
.theme-btn svg { width: 21px; height: 21px; }
.theme-btn:hover { color: var(--accent); }
.theme-btn.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 5px #00000010; }
dialog label { display: block; font-size: 11px; color: var(--text-secondary); margin: 19px 0 9px; }
dialog input { display: block; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 13px 14px; color: var(--text); background: var(--bg); }
dialog input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.primary, .secondary, .danger { width: 100%; min-height: 46px; padding: 12px; border-radius: 10px; font-size: 13px; margin-top: 11px; font-weight: 550; display: flex; align-items: center; justify-content: center; }
.primary { background: var(--button-bg); color: var(--button-fg); }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface-hover); color: var(--text); }
.danger { background: #88888810; color: var(--text-secondary); }
[data-theme="dark"] .danger, [data-theme="dark"] .error { color: var(--text-secondary); }
.danger:hover { background: #88888820; }
dialog small { display: block; margin-top: 22px; font-size: 10px; line-height: 1.8; color: var(--muted); }
.error { font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin-top: 12px; }
#toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 30px); width: max-content; background: #252525; color: #fff; padding: 13px 19px; border-radius: 12px; font-size: 12px; line-height: 1.6; box-shadow: 0 8px 24px #00000020; z-index: 30; }
.image-dialog { width: fit-content; border: 1px solid #ffffff20; border-radius: 16px; background: #111111f5; color: #fff; padding: 0; max-width: 94vw; max-height: 94dvh; overflow: hidden; }
.image-dialog::backdrop { background: #000000d9; }
.image-dialog-content { display: flex; flex-direction: column; max-width: 94vw; max-height: 94dvh; }
.image-dialog-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid #ffffff20; gap: 12px; }
.image-dialog-title { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.image-dialog-actions { display: flex; gap: 8px; }
.image-dialog-actions .icon-btn { color: #eeeeee; background: #ffffff10; width: 40px; height: 40px; }
.image-dialog-actions .icon-btn:hover { background: #ffffff20; }
.image-dialog-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; min-height: 0; }
.image-dialog-body img { max-width: 88vw; max-height: calc(88dvh - 80px); width: auto; height: auto; object-fit: contain; border-radius: 6px; }
@media (min-width: 701px) and (max-width: 1050px) {
  aside { width: 320px; }
  .brand, .sidebar-heading { padding-left: 22px; padding-right: 22px; }
  .telegram-label { display: none; }
  .welcome { padding: 28px; }
  .welcome-bottom-note { display: none; }
  .keyboard-hint { display: none; }
}
@media (max-height: 740px) and (min-width: 701px) {
  .welcome-art { transform: scale(.8); height: 170px; margin-bottom: 10px; }
  .welcome h1 { font-size: 36px; }
  .welcome-hint { margin-top: 18px; }
}
@media (max-width: 700px) {
  aside { width: 100%; border: 0; }
  .brand { padding: 21px 22px 18px; }
  .sidebar-heading { padding: 12px 24px 21px; }
  .sidebar-heading h1 { font-size: 30px; }
  .app:not(.chat-open) main { display: none; }
  .app.chat-open aside { display: none; }
  .app.chat-open main { display: flex; }
  .chat-row { min-height: 83px; }
  .row-top strong { font-size: 14px; }
  .chat-copy p { font-size: 13px; }
  .chat-header { padding: 12px; gap: 9px; padding-top: max(12px, env(safe-area-inset-top)); }
  .chat-header h2 { font-size: 14px; }
  .chat-header .avatar { width: 36px; height: 36px; border-radius: 12px; }
  .chat-header .icon { width: 36px; height: 36px; }
  .chat-header > a { border: 0; }
  .messages { padding: 10px 12px 16px; }
  .message { gap: 7px; }
  .message-body { max-width: calc(100% - 37px); }
  .own .message-body { max-width: 88%; }
  .bubble { font-size: var(--message-size); padding: 9px 11px 7px; }
  .composer { margin: 8px 10px 0; padding: 7px 8px 7px 13px; border-radius: 15px; }
  .composer textarea { font-size: 16px; padding: 8px 0; }
  .composer-note { padding: 7px 17px max(10px, env(safe-area-inset-bottom)); font-size: 9px; }
  .keyboard-hint { display: none; }
  .reply-bar { margin: 0 10px; }
  .reply-button { min-height: 28px; padding: 3px 2px; }
  dialog { padding: 26px; border-radius: 22px; }
  dialog input { font-size: 16px; }
  .search input { font-size: 16px; }
  .image-dialog { padding: 0; }
  .image-dialog-body { padding: 6px; }
}
@media (max-width: 350px) {
  .telegram-label { display: none; }
  .brand { padding: 18px; }
  .sidebar-heading { padding: 12px 20px 18px; }
  .theme-btn { font-size: 10px; }
  dialog { padding: 22px; }
  .image-dialog { padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Personalization and quiet, automatic synchronization */
.brand { padding: 26px 24px; }
.brand strong { font-size: 25px; }
.logo, .dialog-logo { border-radius: var(--radius); }
.avatar { background: var(--avatar-bg); color: var(--avatar-fg); }
.chat-row, .search, .composer, .send, .primary, .secondary, .danger { border-radius: var(--radius); }
.filters { touch-action: pan-y; user-select: none; }
.filters button { min-height: 40px; }
.filters .dragging, .order-row.dragging { opacity: .45; }
.drop-target { outline: 2px dashed var(--muted); outline-offset: -2px; }
.auto-label { font-size: 10px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.welcome h1 em { font-family: inherit; font-style: normal; color: var(--muted); font-weight: 450; }
.welcome-art .art-note-front { border-radius: 22px; }
.welcome-art .art-note-back { border-radius: 22px; }
.welcome-art .art-spark { color: var(--text-secondary); }
.welcome-topline { letter-spacing: .8px; }
html[data-preset="soft"] { --radius: 22px; }
html[data-preset="soft"] .bubble { border-radius: 22px; }
html[data-preset="soft"] .avatar { border-radius: 50%; }
html[data-preset="compact"] { --radius: 7px; }
html[data-preset="compact"] .chat-row { min-height: 60px; padding-top: 8px; padding-bottom: 8px; }
html[data-preset="compact"] .chat-row .avatar { width: 36px; height: 36px; border-radius: 10px; }
html[data-preset="compact"] .message:not(.grouped) { margin: 11px 0; }
html[data-preset="compact"] .bubble { padding: 7px 11px; }
html[data-preset="compact"] .brand { padding-top: 19px; padding-bottom: 19px; }
html[data-tabs="bottom"] .filters { order: 2; border-top: 1px solid var(--line); border-bottom: 0; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
html[data-tabs="bottom"] aside footer { padding-bottom: 12px; padding-top: 12px; }
html[data-send="left"] .composer { flex-direction: row-reverse; padding-left: 10px; padding-right: 16px; }
html[data-avatars="false"] .message > .avatar, html[data-avatars="false"] .avatar-spacer { display: none; }
html[data-avatars="false"] .message-body { max-width: 88%; }
html[data-gradient="true"] .send, html[data-gradient="true"] .primary, html[data-gradient="true"] .own .bubble, html[data-gradient="true"] .preview-outgoing { background: var(--custom-gradient); color: #fff; border-color: #ffffff1a; }
html[data-gradient="true"] .own .bubble .message-meta, html[data-gradient="true"] .own .bubble .reply-button, html[data-gradient="true"] .own .bubble a { color: #eeeeee; }
html[data-gradient="true"] .own .reply-quote { background: #ffffff12; border-color: #ffffff99; }
html[data-gradient="true"] .own .reply-quote strong, html[data-gradient="true"] .own .reply-quote span { color: #eeeeee; }
html[data-gradient="true"] .own .attachment, html[data-gradient="true"] .own .link-attachment { background: #ffffff12; }
#settingsDialog { padding: 0; width: 470px; overflow: hidden; }
#settingsDialog[open] { display: flex; flex-direction: column; max-height: min(840px, calc(100dvh - 32px)); }
.settings-header { display: flex; align-items: center; justify-content: space-between; padding: 25px 26px 15px; flex-shrink: 0; }
.settings-header h2 { margin-bottom: 0; font-size: 27px; }
.settings-header .icon { border: 1px solid var(--line); font-size: 16px; }
.settings-tabs { display: flex; gap: 4px; padding: 0 22px 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.settings-tabs button { flex: 1; border-radius: 9px; font-size: 12px; padding: 11px 7px; color: var(--muted); }
.settings-tabs button.active { background: var(--accent-light); color: var(--text); }
.settings-pane { overflow-y: auto; overscroll-behavior: contain; padding: 0 26px 24px; min-height: 0; }
.settings-pane .settings-group { margin: 20px 0; padding-bottom: 20px; }
.settings-label { font-size: 11px; letter-spacing: 0; }
.theme-btn { font-size: 11px; }
.preset-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset-card { display: flex; flex-direction: column; align-items: center; gap: 9px; padding: 11px 7px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); font-size: 11px; }
.preset-card.active { border-color: var(--text-secondary); color: var(--text); background: var(--surface-hover); }
.preset-sketch { display: block; width: 100%; height: 48px; position: relative; background: var(--bg); border-radius: 6px; }
.preset-sketch::before, .preset-sketch::after { content: ''; position: absolute; height: 12px; width: 52%; background: var(--muted); opacity: .45; border-radius: 3px; left: 9px; top: 9px; }
.preset-sketch::after { top: 27px; left: auto; right: 9px; width: 40%; opacity: .8; }
.soft-sketch::before, .soft-sketch::after { border-radius: 9px; }
.compact-sketch::before { height: 7px; box-shadow: 0 10px 0 var(--muted); }
.compact-sketch::after { top: 30px; height: 7px; }
.setting-line { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 16px; }
.setting-line label { margin: 0; font-size: 13px; color: var(--text); }
.setting-line p { font-size: 11px; margin-top: 4px; }
input.switch { appearance: none; display: inline-block; width: 38px; height: 23px; min-width: 38px; padding: 0; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: 20px; position: relative; cursor: pointer; }
input.switch::before { content: ''; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
input.switch:checked { background: var(--button-bg); border-color: var(--button-bg); }
input.switch:checked::before { background: var(--button-fg); transform: translateX(15px); }
input.switch:disabled { opacity: .35; cursor: default; }
input.switch:focus-visible { outline: 2px solid var(--muted); outline-offset: 3px; }
.gradient-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.gradient-presets button { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; font-size: 11px; }
.color-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-pair input { height: 39px; padding: 4px; margin-top: 8px; cursor: pointer; }
.settings-pane input[type="range"] { padding: 0; height: 22px; accent-color: var(--text); border: 0; background: transparent; cursor: pointer; }
.settings-pane output { float: right; color: var(--text); }
.appearance-preview { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; margin-top: 20px; padding: 14px; display: flex; flex-direction: column; gap: 10px; font-size: 11px; }
.preview-incoming { align-self: flex-start; background: var(--other-bubble); padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.preview-outgoing { align-self: flex-end; background: var(--own-bubble); padding: 9px 12px; border-radius: var(--radius); max-width: 90%; line-height: 1.7; }
.preview-outgoing span { display: block; font-size: 9px; text-align: right; opacity: .7; }
.settings-footnote, .setting-help { font-size: 11px !important; color: var(--muted); line-height: 1.7; }
.settings-footnote { text-align: center; margin-top: 14px !important; }
.tab-order { display: flex; flex-direction: column; gap: 8px; margin-top: 15px; }
.order-row { display: flex; align-items: center; padding: 7px 10px 7px 3px; gap: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.order-row > span { flex: 1; font-size: 13px; }
.drag-handle { touch-action: none; cursor: grab; width: 34px; height: 36px; font-size: 23px; color: var(--muted); }
.order-step { width: 28px; height: 32px; border-radius: 7px; background: var(--surface-hover); }
.settings-pane select { width: 100%; color: var(--text); background: var(--surface-hover); font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.sync-info { display: flex; gap: 10px; align-items: baseline; padding: 3px 0 24px; }
.sync-info strong { font-size: 13px; font-weight: 550; }
.sync-info p { font-size: 12px; }
@media (max-width: 700px) {
  .brand { padding: 21px 22px; }
  .brand strong { font-size: 26px; }
  #settingsDialog { max-width: calc(100% - 20px); border-radius: 20px; }
  .settings-header { padding: 22px 20px 15px; }
  .settings-pane { padding: 0 20px 22px; }
  .settings-tabs { padding-left: 16px; padding-right: 16px; }
  .settings-pane select { font-size: 16px; }
  .settings-header h2 { font-size: 25px; }
}

/* Chat Header Clickable Info & Dialog */
.chat-header-info {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: -4px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
  color: inherit;
  transition: background .15s ease, opacity .15s ease;
}
.chat-header-info:hover {
  background: var(--surface-hover);
}
.chat-header-info:active {
  opacity: .75;
}
.chat-info-chevron {
  color: var(--muted);
  flex-shrink: 0;
  margin-left: 2px;
  opacity: .5;
  transition: transform .15s ease, opacity .15s ease;
}
.chat-header-info:hover .chat-info-chevron {
  opacity: .9;
  transform: translateX(2px);
}

.chat-info-dialog {
  padding: 0;
  width: 480px;
  max-width: calc(100% - 24px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px #00000055;
}
.chat-info-dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: min(820px, calc(100dvh - 32px));
}
.chat-info-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
}
.chat-info-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 10px;
  flex-shrink: 0;
}
.chat-info-top .icon {
  border: 1px solid var(--line);
  width: 32px;
  height: 32px;
}
.chat-info-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 10px 24px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.info-hero-avatar {
  width: 68px !important;
  height: 68px !important;
  border-radius: 22px !important;
  font-size: 24px !important;
  margin-bottom: 12px;
  box-shadow: 0 8px 24px #00000022;
}
.info-hero-title {
  font-size: 20px;
  font-weight: 650;
  margin: 0 0 5px;
  letter-spacing: -.3px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-hero-subtitle {
  font-size: 12px;
  color: var(--muted);
}
.chat-info-search-box {
  position: relative;
  padding: 12px 20px 8px;
  flex-shrink: 0;
}
.chat-info-search-box input {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface-hover);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px 9px 34px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
}
.chat-info-search-box input:focus {
  border-color: var(--text-secondary);
}
.chat-info-search-box .search-icon {
  position: absolute;
  left: 31px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.chat-info-section-title {
  padding: 6px 24px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .6px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.chat-members-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 20px;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .12s ease;
  user-select: none;
}
.member-item:hover {
  background: var(--surface-hover);
}
.member-item:active {
  opacity: .75;
}
.member-avatar {
  width: 38px !important;
  height: 38px !important;
  border-radius: 12px !important;
  font-size: 13px !important;
  flex-shrink: 0;
}
.member-info {
  min-width: 0;
  flex: 1;
}
.member-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.member-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-title {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.role-badge {
  font-size: 9.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: .2px;
  flex-shrink: 0;
  line-height: 1.3;
}
.role-badge.owner {
  background: rgba(36, 129, 204, 0.16);
  color: var(--tg-theme-link-color, #2481cc);
  border: 1px solid rgba(36, 129, 204, 0.3);
}
.role-badge.admin {
  background: rgba(139, 92, 246, 0.16);
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.28);
}
.role-badge.curator {
  background: rgba(245, 158, 11, 0.16);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.28);
}
.role-badge.teacher {
  background: rgba(16, 185, 129, 0.16);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.28);
}
.role-badge.tutor {
  background: rgba(14, 165, 233, 0.16);
  color: #0284c7;
  border: 1px solid rgba(14, 165, 233, 0.28);
}
.role-badge.starosta {
  background: rgba(99, 102, 241, 0.16);
  color: #6366f1;
  border: 1px solid rgba(99, 102, 241, 0.28);
}

[data-theme="dark"] .role-badge.owner,
body.dark .role-badge.owner {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
}
[data-theme="dark"] .role-badge.admin,
body.dark .role-badge.admin {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.35);
}
[data-theme="dark"] .role-badge.curator,
body.dark .role-badge.curator {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.35);
}
[data-theme="dark"] .role-badge.teacher,
body.dark .role-badge.teacher {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.35);
}
[data-theme="dark"] .role-badge.tutor,
body.dark .role-badge.tutor {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
}
[data-theme="dark"] .role-badge.starosta,
body.dark .role-badge.starosta {
  color: #818cf8;
  border-color: rgba(129, 140, 248, 0.35);
}

/* Member profile drawer / detail overlay */
.member-profile-overlay {
  position: absolute;
  inset: 0;
  background: var(--surface);
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: slideInProfile .2s cubic-bezier(.16,1,.3,1);
}
@keyframes slideInProfile {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.member-profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 24px;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}
.member-profile-back {
  align-self: flex-start;
  border: 1px solid var(--line);
  margin-bottom: 8px;
}
.profile-big-avatar {
  width: 80px !important;
  height: 80px !important;
  border-radius: 26px !important;
  font-size: 28px !important;
  margin-bottom: 14px;
  box-shadow: 0 10px 30px #00000022;
}
.profile-name {
  font-size: 19px;
  font-weight: 650;
  margin: 0 0 4px;
}
.profile-nick {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.profile-role-badge {
  margin-bottom: 16px;
}
.profile-title-box {
  width: 100%;
  background: var(--surface-hover);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: left;
  margin-bottom: 20px;
}
.profile-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}
.profile-title-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
  word-break: break-word;
}
.profile-actions {
  width: 100%;
  margin-top: auto;
  padding-top: 16px;
}
.profile-write-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 13px;
  border-radius: 12px;
}

