/* Nook — self-contained styles. No external fonts or assets. */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --text: #1a1c22;
  --muted: #6b7180;
  --border: #e2e4ea;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef0fe;
  --bubble-me: #4f46e5;
  --bubble-me-ink: #ffffff;
  --bubble-other: #eceef2;
  --bubble-other-ink: #1a1c22;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 22, 34, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f13;
    --panel: #17181f;
    --panel-2: #1e1f28;
    --text: #e8e9ee;
    --muted: #9195a3;
    --border: #2a2c37;
    --accent: #7c74ff;
    --accent-ink: #ffffff;
    --accent-soft: #23213a;
    --bubble-me: #6d64f2;
    --bubble-me-ink: #ffffff;
    --bubble-other: #23252f;
    --bubble-other-ink: #e8e9ee;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: var(--accent); }
button { font-family: inherit; }

/* ---------- Centered card layout (join / login) ---------- */
.center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}
.brand .logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
  flex: none;
}
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); font-size: 14px; margin: 4px 0 22px; text-align: center; }
.room-badge {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: fit-content; margin: 0 auto 18px;
  background: var(--accent-soft); color: var(--accent);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
}

/* ---------- Avatar picker (join page) ---------- */
.avatar-pick { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 4px 0 6px; }
.avatar-preview {
  width: 78px; height: 78px; border-radius: 50%;
  border: 2px dashed var(--border); background: var(--panel-2);
  display: grid; place-items: center; cursor: pointer; overflow: hidden;
  padding: 0; position: relative;
}
.avatar-preview:hover { border-color: var(--accent); }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: none; }
.avatar-preview.has-img { border-style: solid; }
.avatar-preview.has-img img { display: block; }
.avatar-preview.has-img .avatar-plus { display: none; }
.avatar-plus { font-size: 30px; color: var(--muted); line-height: 1; }
.avatar-cap { background: none; border: none; color: var(--muted); font-size: 12.5px; cursor: pointer; padding: 2px 6px; }
.avatar-cap:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Recent rooms (landing) ---------- */
.recent { margin-bottom: 8px; }
.recent-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.recent-item { display: flex; align-items: stretch; gap: 6px; margin-bottom: 8px; }
.recent-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; color: var(--text); font-family: inherit;
}
.recent-main:hover { border-color: var(--accent); }
.recent-text { display: flex; flex-direction: column; min-width: 0; }
.recent-room { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 12px; color: var(--muted); }
.recent-x {
  flex: none; width: 38px; border: 1px solid var(--border); background: var(--panel-2);
  border-radius: 10px; color: var(--muted); cursor: pointer; font-size: 13px;
}
.recent-x:hover { border-color: var(--danger); color: var(--danger); }
.recent-or { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 4px; }
.recent-or::before, .recent-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.recent-or span { padding: 0 10px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=password] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 12px 16px;
  margin-top: 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .02s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); width: auto; margin: 0; padding: 7px 12px; font-size: 13px; }
.btn.small { width: auto; margin: 0; padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.note { font-size: 12.5px; color: var(--muted); margin-top: 16px; text-align: center; }
.error { color: var(--danger); font-size: 13.5px; margin-top: 12px; min-height: 18px; }
.hidden { display: none !important; }

/* ---------- Chat layout ---------- */
.chat {
  display: flex; flex-direction: column;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.chat-header .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; flex: none;
}
.chat-title { flex: 1; min-width: 0; }
.chat-title .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.off { background: var(--muted); }

.iconbtn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 7px 10px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.iconbtn:hover { border-color: var(--accent); }

.me-btn {
  border: 1px solid var(--border); background: var(--panel-2);
  border-radius: 50%; padding: 2px; cursor: pointer; flex: none;
  width: 38px; height: 38px; display: grid; place-items: center;
}
.me-btn:hover { border-color: var(--accent); }
.me-btn .avatar { width: 30px; height: 30px; font-size: 13px; }

/* ---------- Modal (profile editor) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(0,0,0,.5);
  display: grid; place-items: center; padding: 24px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; width: 100%; max-width: 340px; text-align: center;
}
.modal-title { margin: 0 0 16px; font-size: 17px; }
.profile-av { width: 96px; height: 96px; margin: 0 auto 12px; }
.profile-av .avatar { width: 96px; height: 96px; font-size: 34px; }
.profile-name { font-weight: 600; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.modal-actions .btn { width: auto; margin: 0; }
.modal-card .btn.secondary { margin-top: 14px; }
.modal .error { text-align: center; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
}
.day-sep { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 8px; }

.msg-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; }
.msg-row.me { flex-direction: row-reverse; }
.msg-row.grouped { margin-top: 2px; }
.av-slot { width: 30px; flex: none; }
.av-slot .avatar { width: 30px; height: 30px; font-size: 13px; }
.msg { display: flex; flex-direction: column; max-width: 76%; }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 0 3px 4px; font-weight: 600; }
.bubble {
  padding: 9px 13px; border-radius: 16px;
  background: var(--bubble-other); color: var(--bubble-other-ink);
  border-top-left-radius: 5px;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
  font-size: 14.5px;
}
.msg .time { font-size: 11px; color: var(--muted); margin: 3px 0 0 4px; }

.msg.me { align-items: flex-end; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); border-top-left-radius: 16px; border-top-right-radius: 5px; }
.msg.me .time, .msg.me .who { margin-left: 0; margin-right: 4px; }

.sys { text-align: center; color: var(--muted); font-size: 12.5px; margin: 10px 0; }

.typing { min-height: 18px; padding: 0 20px 2px; font-size: 12.5px; color: var(--muted); font-style: italic; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 14px; border-top: 1px solid var(--border);
  background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel-2); color: var(--text);
  padding: 11px 14px; font-size: 15px; font-family: inherit;
  max-height: 140px; outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send {
  border: none; background: var(--accent); color: var(--accent-ink);
  border-radius: 12px; padding: 0 18px; height: 44px; font-weight: 600; font-size: 15px; cursor: pointer;
  flex: none;
}
.send:hover { filter: brightness(1.05); }
.send:disabled { opacity: .5; cursor: not-allowed; }

.attach {
  flex: none;
  width: 44px; height: 44px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
  border-radius: 12px; font-size: 22px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: border-color .15s, color .15s;
}
.attach:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Upload bar (staged file) ---------- */
.upload-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.up-thumb {
  width: 42px; height: 42px; border-radius: 8px; flex: none;
  background: var(--border) center/cover no-repeat;
  display: grid; place-items: center; font-size: 20px;
  overflow: hidden;
}
.up-info { flex: 1; min-width: 0; }
.up-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress .fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .15s; }

/* ---------- Media in messages ---------- */
.att-media { margin-bottom: 3px; }
.att-img {
  max-width: min(340px, 72vw); max-height: 380px;
  border-radius: 14px; display: block; cursor: zoom-in;
  background: var(--bubble-other); object-fit: cover;
}
.msg.me .att-img, .msg.me .att-video { margin-left: auto; }
.att-video {
  max-width: min(360px, 78vw); max-height: 420px;
  border-radius: 14px; display: block; background: #000;
}
.att-file {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--bubble-other); color: var(--bubble-other-ink);
  padding: 10px 14px; border-radius: 14px; text-decoration: none; font-size: 14px;
}
.msg.me .att-file { background: var(--bubble-me); color: var(--bubble-me-ink); }
.att-file-ic { font-size: 18px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.85);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 94vh; border-radius: 10px; box-shadow: 0 10px 50px rgba(0,0,0,.5); }

/* ---------- Presence popover ---------- */
.people {
  position: absolute; right: 12px; top: 58px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  min-width: 200px; max-width: 260px; padding: 10px; z-index: 20;
}
.people h4 { margin: 4px 6px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.people ul { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.people li { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 8px; font-size: 14px; }
.people li:hover { background: var(--panel-2); }
.avatar { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ---------- Admin ---------- */
.admin-wrap { max-width: 820px; margin: 0 auto; padding: 24px 18px 60px; }
.admin-top { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.admin-top .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; flex: none;
}
.admin-top h1 { font-size: 20px; margin: 0; flex: 1; }
.newroom { display: flex; gap: 10px; margin-bottom: 22px; }
.newroom input { margin: 0; }
.newroom .btn { margin: 0; width: auto; padding: 12px 18px; white-space: nowrap; }

.room {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.room .row1 { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.room .rname { font-weight: 700; font-size: 16px; flex: 1; display: flex; align-items: center; gap: 8px; }
.lock-badge {
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px;
}
.room .meta { font-size: 12.5px; color: var(--muted); }
.linkbox {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; margin: 8px 0;
}
.linkbox code { flex: 1; font-size: 13px; overflow-x: auto; white-space: nowrap; color: var(--text); }
.room .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  .chat { border-left: none; border-right: none; }
  .msg { max-width: 86%; }
  .newroom { flex-direction: column; }
  .newroom .btn { width: 100%; }
}
