:root {
  color-scheme: light dark;
  --bg: light-dark(#f5f7fb, #10151d);
  --panel: light-dark(#ffffff, #18202b);
  --panel-soft: light-dark(#f7f9fc, #202a38);
  --text: light-dark(#182133, #edf3fb);
  --muted: light-dark(#6f7c91, #9eabbc);
  --line: light-dark(#e2e7ef, #2b3747);
  --primary: #5f8cff;
  --primary-soft: light-dark(#eaf0ff, #23385e);
  --danger: light-dark(#c43a43, #ff7c85);
  --success: light-dark(#138459, #4bd39b);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.login-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 360px); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 30px; box-shadow: 0 20px 60px light-dark(rgba(35,50,80,.12),rgba(0,0,0,.25)); }
.logo { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: var(--primary); color: white; font-weight: 700; margin: 0 auto; }
.logo.small { width: 31px; height: 31px; border-radius: 10px; margin: 0; font-size: 13px; }
.login-card h1 { margin: 14px 0 5px; text-align: center; font-size: 25px; }
.login-card p { margin: 0 0 23px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin: 13px 0; font-size: 13px; color: var(--muted); }
input, textarea { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 11px; outline: none; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent); }
.login-card input { width: 100%; padding: 11px 12px; margin-top: 6px; }
.primary, .send-button { border: 0; background: var(--primary); color: white; border-radius: 10px; font-weight: 650; }
.primary { width: 100%; padding: 11px 14px; margin-top: 7px; }
.primary.compact { width: auto; margin: 0; white-space: nowrap; }
.error { min-height: 18px; color: var(--danger); margin-top: 10px; font-size: 12px; }
.app-shell { height: 100dvh; min-height: 0; overflow: hidden; display: grid; grid-template-rows: 62px minmax(0,1fr); }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(15px); }
.brand { display: flex; align-items: center; gap: 10px; }
.zone-tabs { display: flex; gap: 4px; background: var(--panel-soft); padding: 4px; border-radius: 11px; }
.zone-tab { border: 0; color: var(--muted); background: transparent; padding: 8px 17px; border-radius: 8px; font-size: 13px; }
.zone-tab.active { color: var(--text); background: var(--panel); box-shadow: 0 1px 5px light-dark(rgba(20,30,50,.08),rgba(0,0,0,.25)); font-weight: 650; }
.account { justify-self: end; display: flex; align-items: center; gap: 11px; font-size: 12px; }
.text-button { border: 0; padding: 4px; background: transparent; color: var(--muted); }
.text-button:hover { color: var(--text); }
.chat-card { width: min(100%, 920px); min-height: 0; margin: 22px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; display: grid; grid-template-rows: auto auto minmax(0,1fr) auto; box-shadow: 0 18px 50px light-dark(rgba(35,50,80,.08),rgba(0,0,0,.2)); }
.chat-header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.chat-header { grid-row: 1; grid-column: 1; }
.chat-header h2 { font-size: 16px; margin: 0; }
.chat-header p { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.chat-header-actions { display: flex; align-items: center; gap: 10px; }
.connection { font-size: 11px; color: var(--muted); }
.connection.online { color: var(--success); }
.clear-zone-button { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: 8px; padding: 6px 9px; color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--panel)); font-size: 11px; }
.load-more { grid-row: 2; grid-column: 1; justify-self: center; border: 0; background: transparent; color: var(--primary); padding: 10px; font-size: 12px; }
.messages { grid-row: 3; grid-column: 1; min-height: 0; overflow-y: auto; padding: 18px 24px; display: flex; flex-direction: column; gap: 11px; }
.message { display: flex; align-items: flex-end; gap: 8px; max-width: 76%; }
.message.own { align-self: flex-end; flex-direction: row-reverse; }
.avatar { flex: 0 0 29px; height: 29px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 700; }
.message-body { min-width: 0; max-width: 100%; }
.file-message .message-body { width: 225px; max-width: calc(100vw - 100px); flex: 0 1 225px; }
.sender { color: var(--muted); font-size: 10px; margin: 0 5px 4px; }
.message.own .sender { text-align: right; }
.bubble { width: fit-content; max-width: 100%; padding: 9px 11px; border-radius: 10px; border-bottom-left-radius: 3px; background: var(--panel-soft); font-size: 13px; line-height: 1.48; overflow-wrap: anywhere; white-space: break-spaces; }
.bubble.copyable { cursor: copy; }
.bubble.copyable:active { filter: brightness(.94); }
.message.own .bubble { margin-left: auto; border-bottom-left-radius: 10px; border-bottom-right-radius: 3px; color: white; background: var(--primary); }
.bubble a { color: inherit; text-decoration: underline; }
.meta { color: var(--muted); font-size: 10px; margin: 4px 5px 0; }
.message.own .meta { text-align: right; }
.image-copy { display: block; max-width: min(280px, 100%); padding: 0; border: 0; color: inherit; background: transparent; cursor: copy; }
.message.own .image-copy, .message.own .file-card { margin-left: auto; }
.attachment-image { display: block; width: auto; height: auto; max-width: 100%; max-height: 220px; border-radius: 15px; object-fit: contain; background: color-mix(in srgb, var(--bg) 70%, transparent); }
.file-card { width: 100%; min-height: 88px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 15px 16px; border-radius: 16px 5px 16px 16px; color: var(--text); background: var(--primary-soft); text-decoration: none; }
.file-details { min-width: 0; display: grid; gap: 7px; }
.file-name { min-width: 0; display: flex; align-items: baseline; overflow: hidden; font-size: 13px; font-weight: 650; white-space: nowrap; }
.file-name-full, .file-name-head { min-width: 0; overflow: hidden; text-overflow: clip; }
.file-name-head { flex: 1 1 auto; }
.file-name-ellipsis, .file-name-tail { flex: 0 0 auto; }
.file-size { color: var(--muted); font-size: 11px; }
.file-extension { min-width: 50px; height: 34px; padding: 0 6px; display: grid; place-items: center; border: 2px solid var(--primary); border-radius: 7px; color: var(--primary); font-size: 14px; font-weight: 700; line-height: 1; }
.message-actions { opacity: 0; border: 0; color: var(--muted); background: transparent; padding: 4px; }
.message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; }
.empty-state { grid-row: 3; grid-column: 1; align-self: center; justify-self: center; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 5px; font-size: 12px; pointer-events: none; }
.empty-state strong { color: var(--text); font-size: 14px; }
.composer { grid-row: 4; grid-column: 1; align-self: end; border-top: 1px solid var(--line); padding: 10px 14px max(10px, env(safe-area-inset-bottom)); background: var(--panel); }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-button { flex: 0 0 39px; height: 39px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-soft); color: var(--muted); font-size: 21px; cursor: pointer; }
.composer textarea { flex: 1; resize: none; min-height: 39px; max-height: 120px; padding: 9px 11px; font-size: 16px; }
.send-button { min-height: 39px; padding: 0 15px; }
.compose-hint { min-height: 15px; padding: 5px 4px 0 47px; display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.upload-progress { display: flex; align-items: center; gap: 8px; margin: 8px 0 0 47px; color: var(--muted); font-size: 11px; }
.upload-progress progress { flex: 1; min-width: 0; height: 8px; accent-color: var(--primary); }
.upload-progress button { min-height: 32px; padding-inline: 8px; white-space: nowrap; }
.upload-preview { margin: 0 0 8px 47px; padding: 8px 10px; border-radius: 10px; background: var(--panel-soft); font-size: 12px; display: flex; justify-content: space-between; gap: 10px; }
.upload-preview button { border: 0; background: transparent; color: var(--danger); }
.dragging .chat-card { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: -5px; }
dialog { width: min(92vw, 620px); max-height: 84dvh; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 28px 80px rgba(0,0,0,.32); }
dialog::backdrop { background: rgba(10,15,25,.45); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.close-button { border: 0; background: transparent; color: var(--muted); font-size: 25px; }
.create-user { display: grid; grid-template-columns: 1fr 1.25fr auto; gap: 8px; margin-top: 20px; }
.create-user input { min-width: 0; padding: 9px 10px; }
.user-list { margin-top: 10px; border-top: 1px solid var(--line); }
.storage-summary { margin-top: 14px; padding: 13px 14px; border-radius: 11px; background: var(--panel-soft); }
.storage-summary > strong { font-size: 13px; }
.storage-summary-grid { margin-top: 10px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.storage-summary-grid span { min-width: 0; color: var(--muted); font-size: 10px; }
.storage-summary-grid b { display: block; margin-top: 4px; color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.user-row { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.user-row small { color: var(--muted); }
.user-actions { display: flex; gap: 6px; }
.user-actions button { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 8px; padding: 6px 8px; font-size: 11px; }
.user-actions button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.danger-zone strong { color: var(--danger); font-size: 13px; }
.danger-zone p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.danger-zone button { flex: 0 0 auto; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); color: var(--danger); border-radius: 9px; padding: 8px 10px; font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--panel); border-radius: 9px; padding: 9px 13px; opacity: 0; pointer-events: none; transition: .2s; font-size: 12px; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 700px) {
  .app-shell { grid-template-rows: 56px minmax(0,1fr); }
  .topbar { grid-template-columns: auto 1fr auto; gap: 7px; }
  .brand strong { display: none; }
  .zone-tabs { justify-self: center; }
  .zone-tab { padding: 7px 12px; }
  .account #username { display: none; }
  .chat-card { margin: 0; width: 100%; border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { padding: 12px 14px; }
  .messages { padding: 14px 12px; }
  .message { max-width: 91%; }
  .message-actions { opacity: 1; }
  .image-copy, .file-card { max-width: 100%; }
  .composer { padding-inline: 10px; }
  .compose-hint { padding-left: 45px; }
  .create-user { grid-template-columns: 1fr; }
  .storage-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .primary.compact { width: 100%; }
  .danger-zone { align-items: stretch; flex-direction: column; }
}
