:root {
  color-scheme: light;
  --ink: #13241d;
  --muted: #6f7d76;
  --line: #dfe7e2;
  --paper: #f3f6f4;
  --card: #ffffff;
  --green: #176845;
  --green-dark: #102a21;
  --green-soft: #e4f2e9;
  --red: #b5473f;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 290px minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.profile-rail { position: relative; z-index: 10; display: flex; min-height: 0; flex-direction: column; padding: 22px 16px 18px; color: #eef8f2; background: linear-gradient(165deg, #102a21, #183d30 62%, #102c22); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 4px 20px; }
.brand-mark, .empty-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; color: #123426; background: #b7e1c7; font-size: 20px; font-weight: 900; box-shadow: 0 9px 28px rgba(0, 0, 0, .16); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -.02em; }
.brand small { color: #a8c6b5; font-size: 12px; }
.new-connection { width: 100%; min-height: 42px; border: 1px solid rgba(255, 255, 255, .16); border-radius: 12px; color: #f6fff9; background: rgba(255, 255, 255, .08); font-weight: 750; }
.new-connection:hover { background: rgba(255, 255, 255, .14); }
.rail-heading { display: flex; justify-content: space-between; margin: 24px 6px 8px; color: #94b2a2; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.profile-list, .pending-list { display: grid; gap: 6px; }
.profile-list { min-height: 0; overflow: auto; }
.profile-item { display: flex; min-width: 0; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: 13px; color: #dbe9e1; background: transparent; text-align: left; }
.profile-item:hover, .profile-item.active { color: #fff; background: rgba(255, 255, 255, .11); }
.profile-item.invalid { opacity: .65; }
.profile-avatar { display: grid; flex: 0 0 35px; place-items: center; height: 35px; border-radius: 12px; color: #183e2f; background: #d6eddf; font-weight: 900; }
.profile-copy { min-width: 0; }
.profile-copy strong, .profile-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy small { margin-top: 1px; color: #94b2a2; font-size: 11px; }
.pending-list { margin-top: 10px; }
.pending-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border: 1px dashed rgba(255, 255, 255, .2); border-radius: 12px; color: #d5e8dd; }
.pending-item strong, .pending-item small { display: block; }
.pending-item small { color: #9fbead; font-size: 11px; }
.pending-item button { border: 0; color: #bbd0c4; background: transparent; font-size: 19px; }
.storage-note { margin: auto 5px 0; padding-top: 18px; color: #88a797; font-size: 11px; line-height: 1.5; }

.chat-panel { display: grid; min-width: 0; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; background: radial-gradient(circle at 82% -10%, #e0eee5 0, transparent 28rem), #f7f9f8; }
.chat-header { display: flex; min-height: 76px; align-items: center; gap: 13px; padding: 13px 24px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .86); backdrop-filter: blur(16px); }
.chat-header h1, .chat-header p { margin: 0; }
.chat-header h1 { font-size: 18px; letter-spacing: -.02em; }
.chat-header p { margin-top: 2px; color: var(--muted); font-size: 12px; }
.chat-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.connection-state { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 99px; color: var(--muted); background: #edf1ef; font-size: 11px; font-weight: 800; }
.connection-state::before { width: 7px; height: 7px; border-radius: 50%; background: #87948d; content: ""; }
.connection-state.online { color: #12613e; background: #e2f3e8; }
.connection-state.online::before { background: #23a365; box-shadow: 0 0 0 3px rgba(35, 163, 101, .13); }
.connection-state.loading::before { background: #c78a25; }
.connection-state.offline { color: #9d3c36; background: #f9e8e5; }
.connection-state.offline::before { background: #c54d44; }
.danger-ghost, .mobile-profiles, .icon-button { border: 0; background: transparent; }
.danger-ghost { padding: 5px 8px; color: var(--red); font-size: 12px; font-weight: 750; }
.mobile-profiles { display: none; font-size: 20px; }
.empty-state { align-self: center; justify-self: center; max-width: 510px; padding: 32px; text-align: center; }
.empty-state .empty-mark { width: 58px; height: 58px; margin: 0 auto 18px; border-radius: 18px; font-size: 29px; }
.empty-state h2 { margin: 0 0 10px; font-size: clamp(24px, 4vw, 35px); letter-spacing: -.04em; }
.empty-state p { margin: 0 auto 22px; color: var(--muted); line-height: 1.75; }
.primary { min-height: 42px; padding: 0 18px; border: 0; border-radius: 12px; color: #fff; background: var(--green); font-weight: 800; box-shadow: 0 8px 20px rgba(23, 104, 69, .2); }
.primary:hover { background: #115a3b; }
.primary:disabled { cursor: not-allowed; opacity: .55; }
.wide { width: 100%; }

.message-list { min-height: 0; padding: 28px max(24px, calc((100% - 860px) / 2)); overflow: auto; }
.message { width: fit-content; max-width: min(760px, 88%); margin-bottom: 20px; }
.message.user { margin-left: auto; }
.message-label { margin: 0 7px 5px; color: var(--muted); font-size: 11px; font-weight: 800; }
.message.user .message-label { text-align: right; }
.message-text { padding: 13px 16px; border: 1px solid var(--line); border-radius: 17px 17px 17px 5px; background: var(--card); box-shadow: 0 5px 18px rgba(27, 48, 38, .05); line-height: 1.68; overflow-wrap: anywhere; white-space: pre-wrap; }
.message.user .message-text { border-color: #176845; border-radius: 17px 17px 5px 17px; color: #fff; background: var(--green); }
.message.error .message-text { border-color: #efc9c5; color: #8e352f; background: #fff0ee; }
.message-status { display: block; margin: 5px 8px 0; color: var(--muted); text-align: right; }
.message-image, .message-video { display: block; max-width: min(620px, 100%); max-height: 560px; margin-top: 10px; border-radius: 14px; object-fit: contain; background:#111; }
.messages-empty { display: grid; min-height: 45vh; place-items: center; color: var(--muted); text-align: center; }
.composer { display: flex; align-items: flex-end; gap: 10px; width: min(870px, calc(100% - 32px)); margin: 0 auto max(18px, env(safe-area-inset-bottom)); padding: 9px 9px 9px 16px; border: 1px solid #d5dfd9; border-radius: 18px; background: #fff; box-shadow: 0 12px 34px rgba(28, 55, 42, .12); }
.composer textarea { flex: 1; max-height: 180px; padding: 7px 0; border: 0; outline: 0; resize: none; background: transparent; line-height: 1.55; }
.send { display: grid; flex: 0 0 39px; place-items: center; height: 39px; border: 0; border-radius: 13px; color: #fff; background: var(--green); font-size: 22px; font-weight: 800; }
.send:disabled { opacity: .45; }

dialog { width: min(620px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 20px; color: var(--ink); box-shadow: 0 30px 90px rgba(12, 31, 23, .28); }
dialog::backdrop { background: rgba(12, 28, 21, .56); backdrop-filter: blur(4px); }
.connection-form { display: grid; gap: 16px; padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-head h2, .dialog-head p { margin: 0; }
.dialog-head h2 { font-size: 23px; letter-spacing: -.03em; }
.dialog-head p { margin-top: 4px; color: var(--muted); }
.icon-button { color: var(--muted); font-size: 27px; line-height: 1; }
.connection-form label { display: grid; gap: 6px; font-size: 12px; font-weight: 800; }
.connection-form input { width: 100%; min-height: 43px; padding: 0 12px; border: 1px solid #cfdbd4; border-radius: 11px; outline: 0; background: #fff; }
.connection-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 104, 69, .1); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.privacy-note { margin: -3px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.form-error { padding: 10px 12px; border-radius: 10px; color: #913c35; background: #fce9e6; }
.toast { position: fixed; z-index: 100; top: 18px; left: 50%; max-width: min(520px, calc(100% - 32px)); padding: 10px 15px; transform: translateX(-50%); border-radius: 11px; color: #fff; background: #273b32; box-shadow: 0 12px 34px rgba(0, 0, 0, .18); }
.toast.success { background: #176845; }
.toast.error { background: #a9433b; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .profile-rail { position: fixed; inset: 0 auto 0 0; width: min(88vw, 320px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 45px rgba(0, 0, 0, .2); }
  body.profiles-open .profile-rail { transform: translateX(0); }
  .mobile-profiles { display: block; }
  .chat-header { padding: 10px 14px; }
  .chat-header p { max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .connection-state { display: none; }
  .message-list { padding: 20px 14px; }
  .message { max-width: 92%; }
  .composer { width: calc(100% - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .form-grid { grid-template-columns: 1fr; }
  .connection-form { padding: 20px; }
}

/* Compact navigation, dialogs and message spacing on both viewport sizes. */
button{white-space:nowrap;flex-shrink:0}input,textarea{min-width:0;max-width:100%}
.profile-rail{padding:14px 12px}.brand{padding-bottom:12px}.rail-heading{margin-top:16px}.profile-item{padding:8px}
.profile-copy strong,.profile-copy small{white-space:normal;overflow-wrap:anywhere;overflow:visible;text-overflow:clip}
.chat-header{min-height:60px;padding:8px 16px;gap:8px;flex-wrap:wrap}.chat-header>div:not(.chat-actions){min-width:0;flex:1 1 150px}
.chat-header h1,.chat-header p{overflow-wrap:anywhere}.chat-actions{gap:6px;flex-wrap:wrap}.connection-state{white-space:nowrap}.connection-state::before{flex:none}
.message-list{padding:16px max(16px,calc((100% - 860px)/2))}.message{margin-bottom:12px}.message-text{padding:9px 12px}
.composer{padding:6px 6px 6px 12px;margin-bottom:max(10px,env(safe-area-inset-bottom))}.composer textarea{min-width:0}
.connection-form{padding:16px;gap:10px}.dialog-head{gap:10px}.dialog-head>div{min-width:0}.dialog-head h2{font-size:20px}
.form-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.empty-state{padding:20px}
@media(max-width:760px){.chat-header{padding:7px 10px}.chat-header p{max-width:none;white-space:normal;overflow:visible;text-overflow:clip}.message-list{padding:12px 10px}.connection-form{padding:14px}.form-grid{grid-template-columns:1fr}}
