:root {
  --bg: #f2f3f5; --panel: #ffffff; --text: #1c1e21; --muted: #8a8d91; --border: #e3e5e8;
  --mine: #0b84ff; --mine-text: #fff; --theirs: #ffffff; --danger: #e5484d; --accent: #0b84ff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1012; --panel: #1b1c1f; --text: #e9eaec; --muted: #8b8e94; --border: #2a2c30;
          --mine: #0a72e0; --theirs: #232528; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; font-size: 16px; color: var(--text); }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.login p { margin: 0; color: var(--muted); text-align: center; font-size: 14px; }
.login input { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); outline: none; }
.login input:focus { border-color: var(--accent); }
.btn { padding: 13px 16px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .6; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.error { color: var(--danger); font-size: 14px; text-align: center; min-height: 18px; }

/* ---------- chat ---------- */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 820px; margin: 0 auto;
  background: var(--bg); }
header { display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); }
header .title { flex: 1; min-width: 0; }
header .title b { display: block; font-size: 17px; }
header .title small { color: var(--muted); font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 10px; display: grid; place-items: center; }
.iconbtn:active { background: var(--bg); }

#messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 4px 10px;
  border-radius: 999px; margin: 10px 0 6px; border: 1px solid var(--border); }
.msg { display: flex; flex-direction: column; max-width: 80%; align-self: flex-start; margin-top: 2px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.first { margin-top: 8px; }
.msg .name { font-size: 12px; font-weight: 600; margin: 0 0 2px 10px; }
.bubble { background: var(--theirs); border: 1px solid var(--border); padding: 8px 12px; border-radius: 18px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.35; font-size: 15.5px; }
.mine .bubble { background: var(--mine); color: var(--mine-text); border-color: transparent; }
.bubble img { display: block; max-width: 100%; width: 260px; max-height: 340px; object-fit: cover;
  border-radius: 12px; margin: -4px -8px 4px; width: calc(100% + 16px); min-width: 180px; cursor: zoom-in; background: var(--border); }
.bubble.only-img { padding: 4px; }
.bubble.only-img img { margin: 0; width: 260px; max-width: 100%; }
.time { font-size: 10.5px; color: var(--muted); margin: 2px 8px 0; }
.pending { opacity: .55; }
.ticks { letter-spacing: -3px; margin-left: 2px; font-weight: 700; }
.ticks.all { color: var(--accent); }
.seen { font-size: 11px; color: var(--muted); margin: 1px 8px 0; text-align: right; max-width: 260px; }
#typing { font-size: 12px; color: var(--muted); padding: 0 16px 4px; min-height: 18px; }
#loadMore { align-self: center; margin: 4px 0 8px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 42px; padding: 10px 14px; border-radius: 21px;
  border: 1px solid var(--border); background: var(--bg); outline: none; line-height: 1.3; }
.composer .send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex-shrink: 0; }
.composer .attach { width: 42px; height: 42px; flex-shrink: 0; }

.preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--border); }
.preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.preview span { flex: 1; font-size: 14px; color: var(--muted); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 50; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff;
  display: grid; place-items: center; z-index: 1; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.lb-close:active { background: rgba(255,255,255,.32); }

/* ---------- admin ---------- */
.admin { max-width: 860px; margin: 0 auto; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
.admin h1 { font-size: 22px; margin: 0; }
.admin .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input { flex: 1 1 140px; min-width: 0; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); outline: none; }
.user { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); }
.user:first-child { border-top: 0; }
.user .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.user .info { flex: 1 1 180px; min-width: 0; }
.user .info b { display: block; }
.user .info code { color: var(--muted); font-size: 13px; }
.user .info small { color: var(--muted); font-size: 12px; margin-left: 6px; }
.user .actions { display: flex; gap: 6px; }
.user form { flex-basis: 100%; }
.muted { color: var(--muted); font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

#notifBtn.on { color: var(--accent); }
#notifBtn.on .slash { display: none; }
