:root {
  color-scheme: light dark;
  --bg: #f4f5f7; --panel: #ffffff; --side: #1f2a37; --side-text: #e5e9ef; --side-hover: #2c3a4b;
  --text: #1c2430; --muted: #66707e; --line: #dde1e7; --accent: #0b6bcb; --accent-text: #ffffff;
  --mine: #dbeafe; --other: #ffffff; --error: #b42318; --alert: #f59e0b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171e; --panel: #1a2029; --side: #0d1218; --side-hover: #1d2631;
    --text: #e6e9ee; --muted: #98a2b0; --line: #2b3440; --accent: #4d9fec; --accent-text: #08131f;
    --mine: #17365a; --other: #222a35; --error: #ff8a7a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }

.login { width: min(360px, calc(100% - 32px)); margin: 12vh auto 0; padding: 28px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; color: var(--muted); }
.login label { display: grid; gap: 4px; font-weight: 600; }
.login input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font-weight: 400; }
.login button, #send { padding: 9px 16px; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-text);
  font-weight: 600; cursor: pointer; }
.login .error { color: var(--error); min-height: 20px; }

.app { display: grid; grid-template-columns: 240px 1fr; height: 100%; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; }
.me { padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-bottom: 1px solid #ffffff1f; }
.link { background: none; border: 0; color: inherit; opacity: .75; text-decoration: underline; cursor: pointer; font-size: 12px; }
#convs { list-style: none; margin: 0; padding: 8px; overflow: auto; }
.devices { margin-top: auto; padding: 12px 14px; display: grid; justify-items: start; gap: 6px; border-top: 1px solid #ffffff1f; }
.devices p { margin: 4px 0 0; font-size: 12px; overflow-wrap: anywhere; }
.devices strong { display: block; font-size: 18px; letter-spacing: 1px; user-select: all; }
.conv { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 0; border-radius: 6px;
  background: none; color: inherit; text-align: left; cursor: pointer; }
.conv:hover { background: var(--side-hover); }
.conv.active { background: var(--side-hover); font-weight: 600; }
.conv .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7686; flex: none; }
.dot.on { background: #34d17a; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--alert); color: #1b1200;
  font-size: 12px; font-weight: 700; text-align: center; }

.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat header { padding: 13px 18px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 16px; font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; padding: 2px 10px; color: var(--muted); font-size: 12px; }
.msg { max-width: min(680px, 85%); align-self: flex-start; padding: 7px 11px; background: var(--other);
  border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.meta { font-size: 12px; color: var(--muted); }
.meta strong { color: var(--text); }
.body { white-space: pre-wrap; }
.body a { color: var(--accent); }
.msg img { display: block; max-width: 100%; max-height: 320px; margin-top: 6px; border-radius: 6px; }
.file { display: inline-flex; gap: 6px; margin-top: 6px; color: var(--accent); text-decoration: none; font-weight: 600; }
.file small { color: var(--muted); font-weight: 400; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; overflow-y: hidden; padding: 8px 10px; max-height: 160px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); }
.icon { width: 38px; height: 38px; border: 0; border-radius: 6px; background: none; font-size: 20px; cursor: pointer; }
.icon:hover { background: var(--bg); }
.emoji-panel { display: grid; grid-template-columns: repeat(auto-fill, 38px); gap: 2px; max-height: 190px; overflow: auto;
  padding: 8px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.emoji-panel button { width: 38px; height: 36px; border: 0; border-radius: 6px; background: none; font-size: 20px; cursor: pointer; }
.emoji-panel button:hover { background: var(--bg); }
.upload-status { padding: 6px 18px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); }
.upload-status.error { color: var(--error); }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; background: #0b6bcbd9; color: #fff;
  font-size: 22px; font-weight: 600; pointer-events: none; }

@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { max-height: 34vh; }
}
