:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #172033;
  --muted: #6b7a90;
  --accent: #229ed9;
  --accent-hover: #1588bf;
  --accent-soft: #e8f5fc;
  --incoming: #ffffff;
  --outgoing: #dff2ff;
  --danger: #c73b3b;
  --danger-bg: #fff2f2;
  --ok: #2da56a;
  --warning: #b7791f;
  --shadow: 0 8px 28px rgba(31, 48, 73, .08);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif; color: var(--text); background: var(--bg); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-shell { height: 100vh; display: grid; grid-template-columns: 245px 360px minmax(420px, 1fr); overflow: hidden; background: var(--bg); }
.accounts-panel, .dialogs-panel, .chat-panel { min-height: 0; }
.accounts-panel { background: var(--panel); border-right: 1px solid var(--border); padding: 14px; display: flex; flex-direction: column; }
.brand-row { display: flex; gap: 10px; align-items: center; padding: 6px 4px 18px; }
.brand-row strong { display: block; font-size: 15px; color: var(--text); }
.brand-mark { width: 54px; height: 54px; border-radius: 16px; background: linear-gradient(135deg, #2aabee, #5d77ff); color: #fff; display: grid; place-items: center; font-weight: 800; box-shadow: 0 12px 28px rgba(42, 171, 238, .24); }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 13px; }
.accounts-list { overflow: auto; flex: 1; margin-top: 4px; }
.account-row { display: flex; align-items: stretch; gap: 4px; margin-bottom: 2px; }
.account-item { width: 100%; border: 0; background: transparent; color: var(--text); display: flex; align-items: center; gap: 9px; padding: 10px; border-radius: 10px; text-align: left; }
.account-row .account-item { flex: 1; width: auto; min-width: 0; }
.account-item:hover, .account-item.active { background: var(--accent-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; flex: none; }
.dot.online { background: var(--ok); }
.dot.error { background: #e05454; }
.dot.all { background: var(--accent); }
.dot.disabled { background: #9aa7b5; box-shadow: 0 0 0 2px #eef2f6; }
.account-text { min-width: 0; flex: 1; }
.account-text strong { font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-text small { color: var(--muted); }
.account-menu { flex: none; width: 30px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.account-menu:hover { background: #edf3f8; color: var(--text); }
.secondary, .primary, .danger { border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-hover); }
.secondary { background: #f7fafc; border-color: var(--border); color: var(--text); }
.secondary:hover { background: #eef4f8; }
.danger { border-color: #efcaca; color: var(--danger); background: var(--danger-bg); }
.danger:hover { background: #ffe6e6; }
.primary:disabled, .secondary:disabled, .danger:disabled { opacity: .55; cursor: not-allowed; }
.wide { width: 100%; }
.panel-footer { padding-top: 12px; }
.link-button { border: 0; background: transparent; color: var(--muted); padding: 6px; }
.link-button:hover { color: var(--text); }
.dialogs-panel { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.dialogs-header { padding: 16px 14px 12px; border-bottom: 1px solid var(--border); }
.dialogs-header h2 { margin: 0 0 12px; font-size: 19px; }
.search { width: 100%; background: #f8fafc; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none; }
.search:focus { border-color: #73bfe5; box-shadow: 0 0 0 3px rgba(42,171,238,.10); }
.dialogs-list { overflow: auto; flex: 1; }
.dialog { display: block; width: 100%; border: 0; border-bottom: 1px solid #edf1f5; background: transparent; color: var(--text); padding: 13px 14px; text-align: left; }
.dialog:hover, .dialog.active { background: #f0f8fd; }
.dialog-top { display: flex; align-items: center; gap: 8px; }
.dialog-name { font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-time { font-size: 11px; color: var(--muted); }
.dialog-bottom { display: flex; gap: 8px; margin-top: 5px; align-items: center; }
.dialog-snippet { flex: 1; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; min-width: 20px; height: 20px; border-radius: 12px; padding: 0 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.account-badge { flex: none; margin-left: auto; box-shadow: 0 0 0 2px #fff; }
#all-accounts .account-text { display: flex; align-items: center; }
.line-label { font-size: 10px; color: #318bb7; margin-top: 5px; }
.chat-panel { background: #f5f8fb; position: relative; }
.chat-empty { height: 100%; display: grid; place-content: center; text-align: center; padding: 40px; color: var(--muted); }
.chat-empty h2 { color: var(--text); margin: 8px; }
.chat-empty p { max-width: 420px; }
.empty-icon { width: 58px; height: 58px; border-radius: 18px; background: #e7f4fb; display: grid; place-items: center; margin: auto; font-size: 25px; color: var(--accent); }
.chat-view { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.chat-header { padding: 14px 18px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.96); }
.chat-header h2 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); font-size: 12px; margin-top: 3px; }
.messages { overflow: auto; padding: 20px 5%; display: flex; flex-direction: column; gap: 8px; background: radial-gradient(circle at 20% 20%, rgba(42,171,238,.06), transparent 34%), #f5f8fb; }
.message { max-width: 72%; padding: 9px 12px; border: 1px solid rgba(203,213,225,.75); border-radius: 13px; box-shadow: 0 1px 3px rgba(31,48,73,.07); }
.message.incoming { align-self: flex-start; background: var(--incoming); border-bottom-left-radius: 4px; }
.message.outgoing { align-self: flex-end; background: var(--outgoing); border-color: #bde2f6; border-bottom-right-radius: 4px; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.38; }
.message-time { font-size: 10px; color: #718096; text-align: right; margin-top: 4px; }
.media-pill { display: inline-block; font-size: 11px; color: #236b91; background: rgba(42,171,238,.10); border-radius: 7px; padding: 3px 7px; margin-bottom: 5px; }
.composer { padding: 10px 14px 12px; background: #fff; border-top: 1px solid var(--border); }
.composer-row { display: grid; grid-template-columns: auto 1fr auto; gap: 9px; align-items: end; }
.composer textarea { resize: none; max-height: 120px; min-height: 42px; background: #f8fafc; color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; outline: none; }
.composer textarea:focus { border-color: #73bfe5; box-shadow: 0 0 0 3px rgba(42,171,238,.10); }
.attach-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 12px; background: #f8fafc; color: #39708c; font-size: 24px; line-height: 1; cursor: pointer; user-select: none; }
.attach-button:hover { background: #edf7fc; border-color: #b9dceb; }
.composer-hint { color: #94a3b8; font-size: 10px; margin: 6px 0 0 51px; }
.file-preview { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 9px 51px; }
.file-chip { max-width: 280px; min-width: 180px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: #f8fbfd; border-radius: 11px; padding: 7px 8px; }
.file-icon { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: #e7f4fb; color: var(--accent); }
.file-chip-text { min-width: 0; flex: 1; }
.file-chip-text strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip-text small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.file-remove { flex: none; width: 25px; height: 25px; border: 0; border-radius: 7px; background: transparent; color: #7b8ba0; font-size: 19px; line-height: 1; }
.file-remove:hover { background: #e9eef3; color: var(--text); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.modal { position: fixed; inset: 0; background: rgba(23,32,51,.35); display: grid; place-items: center; padding: 20px; z-index: 50; backdrop-filter: blur(2px); }
.modal-card { width: min(460px,100%); background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 24px; position: relative; box-shadow: 0 25px 80px rgba(31,48,73,.22); }
.modal-close { position: absolute; right: 12px; top: 10px; border: 0; background: transparent; color: var(--muted); font-size: 28px; }
.modal h2 { margin-top: 0; }
.modal input { width: 100%; background: #f8fafc; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 11px; margin: 8px 0 14px; }
.modal input:disabled { opacity: .72; cursor: not-allowed; }
.qr-image { display: block; width: 280px; height: 280px; max-width: 100%; margin: 14px auto; background: white; border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.qr-help { color: var(--muted); font-size: 13px; line-height: 1.5; text-align: center; }
.status-line { text-align: center; margin: 10px 0; color: #317ca2; }
.error-text { color: #c04444; min-height: 20px; margin-top: 10px; font-size: 13px; }
.toast { position: fixed; right: 18px; bottom: 18px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 12px 15px; box-shadow: var(--shadow); z-index: 100; }
.login-body { display: grid; place-items: center; background: radial-gradient(circle at 50% 20%, rgba(42,171,238,.10), transparent 36%), #f4f7fb; }
.login-card { width: min(380px,calc(100% - 32px)); background: #fff; border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: 0 26px 70px rgba(31,48,73,.12); }
.login-card .brand-mark { margin-bottom: 18px; }
.login-card h1 { margin: 0; }
.login-card p { color: var(--muted); margin: 7px 0 22px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input { width: 100%; margin: 7px 0 14px; background: #f8fafc; border: 1px solid var(--border); color: var(--text); padding: 12px; border-radius: 10px; outline: none; }
.account-actions { display: grid; gap: 10px; margin-top: 14px; }
.account-actions hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.action-note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 0 0 6px; }
.warning-note { color: var(--warning); }
.danger-box { border: 1px solid #efcaca; background: var(--danger-bg); border-radius: 12px; padding: 13px; margin: 12px 0 16px; }
.danger-box p { color: #9d5555; font-size: 12px; line-height: 1.45; margin: 7px 0 0; }
.confirm-label { display: block; color: var(--muted); font-size: 12px; margin-top: 8px; }
@media(max-width:900px){.app-shell{grid-template-columns:200px 310px 1fr}.accounts-panel{padding:10px}.brand-row strong{font-size:13px}}
