:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --panel: #fff;
  --text: #172033;
  --muted: #697386;
  --line: #dfe4ec;
  --primary: #5457df;
  --primary-dark: #4144bd;
  --danger: #c83d4d;
  --success: #17845b;
  --shadow: 0 12px 32px rgba(25, 34, 59, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: 30px; line-height: 1.15; }
h2 { font-size: 18px; }
.muted, small { color: var(--muted); }
.topbar { height: 66px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1120px)/2)); background: #fff; border-bottom: 1px solid var(--line); }
.brand { color: var(--text); font-size: 19px; font-weight: 800; letter-spacing: -.4px; }
.topbar nav { display: flex; align-items: center; gap: 22px; }
.topbar nav a, .link-button { color: var(--muted); font-weight: 600; }
.topbar nav a.active { color: var(--primary); }
.topbar form { margin: 0; }
.link-button { border: 0; padding: 0; background: none; cursor: pointer; }
.language-switch { display: inline-flex; align-items: center; }
.language-switch select { max-width: 155px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); padding: 7px 28px 7px 9px; font: 600 13px/1.2 inherit; cursor: pointer; }
.language-switch select:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 3px rgba(84,87,223,.12); }
.invite-form { display: flex; align-items: flex-end; gap: 10px; }
.invite-language { display: grid; flex: 0 0 auto; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 600; }
.invite-language select { min-width: 150px; border: 1px solid #cbd2df; border-radius: 9px; background: #fff; color: var(--text); padding: 10px 12px; font: inherit; cursor: pointer; }
.invite-language select:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 3px rgba(84,87,223,.12); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.container { width: min(100% - 32px, 1120px); margin: 38px auto 70px; }
.container.narrow { max-width: 720px; }
.container.wide { width: min(100% - 32px, 1380px); }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 24px; box-shadow: var(--shadow); }
.panel.compact { margin-bottom: 22px; }
.panel.compact h2 { margin-bottom: 14px; }
input, textarea { width: 100%; min-width: 0; border: 1px solid #cbd2df; border-radius: 9px; background: #fff; color: var(--text); padding: 11px 13px; font: inherit; outline: none; transition: border .15s, box-shadow .15s; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(84,87,223,.12); }
button, .button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--primary); border-radius: 9px; padding: 10px 16px; background: var(--primary); color: #fff; font: 600 14px/1.2 inherit; cursor: pointer; white-space: nowrap; }
button:hover, .button:hover { background: var(--primary-dark); }
button.outline, .button.outline { color: var(--primary); background: transparent; }
button.outline:hover, .button.outline:hover { background: #f0f0ff; }
button.danger { color: var(--danger); border-color: #e6aab1; }
button.danger:hover { background: #fff1f3; }
button.small { padding: 7px 10px; font-size: 12px; }
.inline-form { display: flex; align-items: center; gap: 10px; }
.inline-form.invite-form { align-items: flex-end; }
.inline-form.grow { flex: 1; }
.stack { display: grid; gap: 17px; }
.stack label { display: grid; gap: 7px; font-weight: 600; }
.alert { margin: 0 0 18px; padding: 12px 14px; border: 1px solid #efb1b8; border-radius: 9px; background: #fff0f2; color: #8e2935; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 15px; }
.chat-card { display: flex; align-items: center; justify-content: space-between; min-height: 115px; padding: 21px; border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); box-shadow: 0 5px 18px rgba(25,34,59,.04); transition: transform .15s, box-shadow .15s; }
.chat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.chat-card h3 { margin-bottom: 6px; }
.chat-card p { margin: 0; color: var(--muted); }
.chat-card span { color: var(--primary); }
.back { display: inline-block; margin-bottom: 18px; }
.chat-settings { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; }
.participant-list { display: grid; gap: 10px; }
.participant-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.participant-row small { display: block; margin-top: 3px; }
.participant-actions, .mini-form { display: flex; align-items: center; gap: 8px; }
.mini-form input { width: 170px; }
.empty { padding: 30px; border: 1px dashed #cbd2df; border-radius: 12px; color: var(--muted); text-align: center; }
.invite-panel { margin-top: 80px; text-align: center; }
.success-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 20px; border-radius: 50%; background: #e1f6ed; color: var(--success); font-size: 26px; font-weight: 800; }
.copy-row { display: flex; gap: 9px; margin: 24px 0; }
.live-label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.live-label i { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: #31b67d; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { background: #fafbfe; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
td small { display: block; white-space: normal; max-width: 250px; }
code { font-size: 13px; }
.badge { display: inline-block; margin-bottom: 4px; padding: 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.online { color: #0c704a; background: #dff7ed; }
.badge.active-session { color: #8a6411; background: #fff3cf; }
.badge.muted-badge { color: #687083; background: #edf0f5; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at top, #e8e9ff, var(--bg) 48%); }
.login-language { position: fixed; top: 20px; right: 20px; }
.login-card { width: min(100%, 390px); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 24px; border-radius: 12px; background: var(--primary); color: #fff; font-weight: 800; }
.chat-body { height: 100vh; height: 100dvh; overflow: hidden; background: #e9edf5; }
.chat-shell { height: 100%; min-height: 0; max-width: 900px; margin: auto; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; background: #fff; box-shadow: 0 0 40px rgba(25,34,59,.1); }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.chat-identity { min-width: 0; }
.chat-header h1 { margin: 0 0 3px; font-size: 21px; }
.chat-header p { margin: 0; color: var(--muted); }
.participant-presences { display: grid; gap: 2px; margin-top: 7px; }
.participant-presence { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; }
.participant-presence strong { overflow: hidden; max-width: 180px; text-overflow: ellipsis; white-space: nowrap; }
.presence-status { color: var(--muted); }
.presence-status.online { color: #0c704a; }
.presence-status.online::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #26ae77; }
.chat-header-actions { display: flex; align-items: center; gap: 16px; }
.connection-actions { display: inline-flex; align-items: center; gap: 7px; }
.notification-toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.notification-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.notification-toggle i { position: relative; width: 34px; height: 20px; border-radius: 20px; background: #aab1be; transition: background .15s; }
.notification-toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(25,34,59,.25); transition: transform .15s; }
.notification-toggle input:checked + i { background: var(--primary); }
.notification-toggle input:checked + i::after { transform: translateX(14px); }
.notification-toggle input:focus-visible + i { outline: 3px solid rgba(84,87,223,.25); outline-offset: 2px; }
.notification-toggle:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.connection { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.connection::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #aab1be; }
.connection.online::before { background: #26ae77; }
.connection.offline::before { background: #d64c5c; }
.settings-button { width: 30px; height: 30px; padding: 5px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.settings-button:hover { background: #eef0f6; color: var(--text); }
.settings-button:focus-visible { outline: 3px solid rgba(84,87,223,.25); outline-offset: 1px; }
.settings-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.settings-dialog { width: min(calc(100% - 32px), 520px); min-height: 220px; padding: 0; border: 0; border-radius: 16px; background: #fff; color: var(--text); box-shadow: 0 22px 70px rgba(25,34,59,.28); }
.settings-dialog::backdrop { background: rgba(23,32,51,.45); backdrop-filter: blur(2px); }
.settings-dialog-panel { min-height: 220px; }
.settings-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.settings-dialog h2 { margin: 0; font-size: 19px; }
.settings-close { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 26px; font-weight: 400; line-height: 1; }
.settings-close:hover { background: #eef0f6; color: var(--text); }
.settings-dialog-content { min-height: 150px; padding: 20px; }
.telegram-link { padding: 0; border: 0; background: none; color: #2563eb; text-decoration: underline; cursor: pointer; text-align: left; }
.telegram-link:disabled { opacity: .5; cursor: default; }
#telegram-launch { display: block; margin-top: 12px; }
#telegram-launch[hidden], #telegram-link[hidden], #telegram-unlink[hidden] { display: none; }
.messages { min-height: 0; overflow-y: auto; padding: 22px; background: #f7f8fc; }
.message { width: fit-content; max-width: min(75%, 620px); margin: 0 0 11px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 4px 14px 14px; background: #fff; box-shadow: 0 2px 6px rgba(25,34,59,.04); }
.message.mine { margin-left: auto; border-color: #cdcef8; border-radius: 14px 4px 14px 14px; background: #ececff; }
.message-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.message-meta strong { color: var(--primary); font-size: 13px; }
.message-meta time { color: var(--muted); font-size: 10px; }
.message-status { margin-left: auto; color: #8992a3; font-size: 13px; font-weight: 700; line-height: 1; letter-spacing: -3px; white-space: nowrap; }
.message-status.sent { letter-spacing: 0; }
.message-status.read { color: #4f71e8; }
.message-status.pending, .message-status.failed { letter-spacing: 0; }
.message-spinner { display: block; width: 13px; height: 13px; border: 2px solid #b8bfd0; border-top-color: var(--primary); border-radius: 50%; animation: message-spin .8s linear infinite; }
.message-retry { min-width: 0; padding: 0; border: 0; background: transparent; color: #d64c5c; font-size: 18px; font-weight: 800; line-height: 1; box-shadow: none; }
.message-retry:hover { background: transparent; color: #a52f3c; box-shadow: none; }
.message.failed { border-color: #e7aeb5; }
@keyframes message-spin { to { transform: rotate(360deg); } }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-translation { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
.message-translation small { display: block; margin-bottom: 2px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.chat-empty { margin-top: 20vh; }
.typing-indicator { min-height: 28px; padding: 6px 22px 4px; background: #fff; color: var(--muted); font-size: 13px; font-style: italic; }
.typing-indicator[hidden] { display: none; }
.composer { display: flex; gap: 10px; padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.composer textarea { resize: none; min-height: 43px; max-height: 120px; }
.chat-error { padding: 10px 18px; background: #fff0f2; color: #8e2935; text-align: center; }
@media (max-width: 760px) {
  .topbar { height: auto; min-height: 66px; padding: 10px 16px; gap: 12px; }
  .topbar nav { justify-content: flex-end; flex-wrap: wrap; gap: 10px 12px; }
  .topbar .language-switch { order: 2; }
  .topbar .language-switch select { max-width: 125px; }
  .participant-row, .chat-settings { align-items: stretch; flex-direction: column; }
  .participant-actions { align-items: stretch; flex-direction: column; }
  .participant-actions form, .participant-actions button, .mini-form input { width: 100%; }
  .invite-form, .inline-form.invite-form { align-items: stretch; flex-direction: column; }
  .invite-language, .invite-language select { width: 100%; }
  .mini-form { width: 100%; }
  .page-title { align-items: flex-start; flex-direction: column; }
  .message { max-width: 88%; }
  .chat-header { align-items: flex-start; }
  .chat-header-actions { align-items: flex-end; flex-direction: column; gap: 8px; }
  .chat-header-actions .language-switch select { max-width: 125px; }
}
