/* JMAR Talk — dark theme (JMAR navy #0D2443 / gold #D4AF37, temi #0b1020 family)
 * External stylesheet on purpose: CSP is default-src 'self' without 'unsafe-inline'. */
:root {
  --bg: #0b1020;
  --panel: #111a31;
  --panel-2: #0e1628;
  --border: #1f2a44;
  --navy: #0D2443;
  --gold: #D4AF37;
  --gold-soft: #e7d491;
  --text: #e5e7eb;
  --muted: #8fa0bf;
  --faint: #64748b;
  --danger: #f87171;
  --ok: #34d399;
  --bubble: #141f3a;
  --bubble-own: #1b3055;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}
[x-cloak] { display: none !important; }
/* no-JS fallback: operator identification (see index.html <noscript>) */
.noscript-note {
  max-width: 560px; margin: 12vh auto 0; padding: 28px 24px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  color: var(--muted); font-size: .88rem; line-height: 1.7;
}
.noscript-note h1 { font-size: 1.05rem; color: var(--text); margin: 0 0 12px; }
.noscript-note strong { color: var(--gold-soft); }
.noscript-note p { margin: 0 0 10px; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea, select {
  font: inherit; color: var(--text); color-scheme: dark;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; outline: none; max-width: 100%;
}
input:focus, textarea:focus { border-color: var(--gold); }
a { color: #93b4e8; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #26324d; border-radius: 4px; }
.muted { color: var(--muted); }
.hidden-input { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 10px; padding: 10px 16px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--border); min-height: 42px;
}
.btn:hover { background: #182342; }
.btn.gold { background: var(--gold); color: #0b1020; border-color: var(--gold); }
.btn.gold:hover { background: #e0bf55; }
.btn.gold:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: #7f1d1d; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px; font-size: 1.05rem;
  color: var(--muted); border: 1px solid transparent;
}
.icon-btn:hover { background: #182342; color: var(--text); }
.mini-btn {
  font-size: .78rem; padding: 3px 9px; border-radius: 7px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.mini-btn:hover { color: var(--text); background: #182342; }
.mini-btn.gold { background: var(--gold); color: #0b1020; border-color: var(--gold); font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  font-size: .7rem; font-weight: 700;
}
.badge.gold { background: var(--gold); color: #0b1020; }
.icon-btn .badge { position: absolute; top: -4px; right: -6px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 28px 20px;
  background: radial-gradient(1000px 600px at 50% -10%, #14335f 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .5);
}
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 14px; border-radius: 17px;
  background: linear-gradient(135deg, #14335f, var(--navy));
  border: 1.5px solid rgba(212, 175, 55, .55);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-weight: 700; font-size: 1.7rem; letter-spacing: 1px;
}
.login-title { text-align: center; font-size: 1.3rem; font-weight: 700; margin: 0 0 2px; }
.login-sub { text-align: center; color: var(--muted); font-size: .8rem; margin: 0 0 16px; letter-spacing: .04em; }
.login-note {
  margin: 0 0 6px; padding: 10px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: .76rem; line-height: 1.6;
}
.login-note strong { color: var(--gold-soft); font-weight: 600; }
.login-card label { display: block; font-size: .82rem; color: var(--muted); margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 11px 12px; }
.login-err { color: var(--danger); font-size: .85rem; margin: 12px 0 0; min-height: 1.2em; }
.login-btn { width: 100%; margin-top: 18px; }
.login-footer {
  width: 100%; max-width: 380px; text-align: center;
  color: var(--faint); font-size: .74rem; line-height: 1.65;
}
.login-footer p { margin: 0 0 5px; }
.login-footer-org { color: var(--muted); font-weight: 600; font-size: .78rem; }
.login-footer-desc { color: var(--faint); }
.login-footer-links a { color: #93b4e8; text-decoration: none; }
.login-footer-links a:hover { text-decoration: underline; }
.login-footer-copy { margin-top: 8px; color: #4a5674; font-size: .7rem; }

/* ---------- app layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 300px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--panel-2); border-right: 1px solid var(--border);
}
.thread { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
@media (max-width: 767px) {
  .sidebar { width: 100%; border-right: none; }
  .thread { display: none; }
  .app.show-thread .sidebar { display: none; }
  .app.show-thread .thread { display: flex; }
}

/* ---------- sidebar ---------- */
.side-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 10px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #10254a, var(--panel-2));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; overflow: hidden; }
.brand-name { white-space: nowrap; }
.brand-logo {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #14335f, var(--navy));
  border: 1px solid rgba(212, 175, 55, .55);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-weight: 700; font-size: .95rem;
}
.brand-name { font-weight: 700; line-height: 1.2; }
.brand-sub { font-size: .62rem; color: var(--muted); letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-actions { display: flex; gap: 2px; flex-shrink: 0; }
.offline-banner {
  background: #7f1d1d; color: #fecaca; font-size: .78rem; text-align: center; padding: 5px 8px;
}
.room-list { flex: 1; overflow-y: auto; padding: 6px; }
.room-sec {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 6px; font-size: .72rem; color: var(--faint); letter-spacing: .08em;
}
.sec-btns { display: flex; gap: 6px; }
.room-item {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 9px 8px; border-radius: 10px; min-height: 56px;
}
.room-item:hover { background: #14203c; }
.room-item.active { background: #182b52; }
.room-avatar {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 11px;
  background: #1b2b4e; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem; color: var(--gold-soft);
}
.room-avatar.dm { border-radius: 50%; }
.room-mid { flex: 1; min-width: 0; }
.room-name {
  display: block; font-weight: 600; font-size: .92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-last {
  display: block; font-size: .78rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-right { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.room-time { font-size: .68rem; color: var(--faint); }
.side-foot {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.foot-name { flex: 1; min-width: 0; font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- avatars ---------- */
.avatar {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #0b1020;
}
.avatar.sm { width: 26px; height: 26px; font-size: .7rem; }

/* ---------- thread ---------- */
.thread-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--faint); gap: 10px; padding: 24px; text-align: center;
}
.thread-empty .big { font-size: 2.4rem; }
.thread-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); background: var(--panel-2); min-height: 56px;
}
.thread-title { flex: 1; min-width: 0; }
.thread-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-members-line {
  font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back-btn { display: none; }
@media (max-width: 767px) { .back-btn { display: inline-flex; } }

.msg-list { flex: 1; overflow-y: auto; padding: 14px 12px 8px; }
.load-older { display: block; margin: 0 auto 10px; }
.jump-latest {
  display: block; margin: 0 auto 10px; background: var(--gold); color: #0b1020;
  font-weight: 700; font-size: .82rem; padding: 6px 14px; border-radius: 999px;
}
.date-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; }
.date-sep::before, .date-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.date-sep span { font-size: .74rem; color: var(--faint); }

.msg-row { display: flex; gap: 9px; padding: 3px 0; align-items: flex-start; }
.msg-row.own { flex-direction: row-reverse; }
.msg-row.own .avatar { display: none; }
.msg-main { max-width: min(78%, 640px); min-width: 0; display: flex; flex-direction: column; }
.msg-row.own .msg-main { align-items: flex-end; }
.msg-meta { display: flex; align-items: baseline; gap: 7px; font-size: .72rem; padding: 0 2px; }
.msg-row.own .msg-meta { flex-direction: row-reverse; }
.msg-name { font-weight: 700; color: var(--gold-soft); }
.msg-row.own .msg-name { display: none; }
.msg-time { color: var(--faint); }
.msg-edited { color: var(--faint); }
.bm-flag { color: var(--gold); }
.bubble-wrap { display: flex; align-items: flex-end; gap: 4px; max-width: 100%; min-width: 0; }
.msg-row.own .bubble-wrap { flex-direction: row-reverse; }
.bubble {
  background: var(--bubble); border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px; padding: 8px 12px; min-width: 0; max-width: 100%;
  overflow-wrap: anywhere;
}
.msg-row.own .bubble { background: var(--bubble-own); border-color: #2b4370; border-radius: 14px 4px 14px 14px; }
.msg-row.flash .bubble { box-shadow: 0 0 0 2px var(--gold); transition: box-shadow .2s; }
.msg-body { white-space: pre-wrap; }
.msg-body.deleted { color: var(--faint); font-style: italic; font-size: .85rem; }
.msg-body a { overflow-wrap: anywhere; }
.mention {
  color: var(--gold); font-weight: 600; background: rgba(212, 175, 55, .12);
  border-radius: 5px; padding: 0 3px;
}
.msg-more {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 7px; color: var(--faint);
  opacity: 0; font-size: .95rem; line-height: 1;
}
.msg-row:hover .msg-more { opacity: 1; }
.msg-more:hover { background: #182342; color: var(--text); }
@media (pointer: coarse) { .msg-more { opacity: .55; } }

.reply-quote {
  display: block; width: 100%; max-width: 100%; min-width: 0; overflow: hidden; text-align: left; margin: 0 0 6px;
  border-left: 3px solid var(--gold); background: rgba(212, 175, 55, .06);
  border-radius: 0 8px 8px 0; padding: 4px 8px; font-size: .78rem;
}
.reply-quote-name { display: block; color: var(--gold-soft); font-weight: 700; }
.reply-quote-text { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.attach { margin-top: 6px; }
.attach-img {
  max-width: 100%; max-height: 280px; border-radius: 10px; display: block; cursor: zoom-in;
  border: 1px solid var(--border); background: #070b16;
}
.file-card {
  display: flex; align-items: center; gap: 9px; text-decoration: none;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; color: var(--text); max-width: 320px;
}
.file-card:hover { border-color: var(--gold); }
.file-ic { font-size: 1.3rem; }
.file-name { flex: 1; min-width: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: .72rem; color: var(--faint); flex-shrink: 0; }

.react-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding: 0 2px; }
.msg-row.own .react-row { justify-content: flex-end; }
.react-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 8px; font-size: .82rem;
}
.react-chip.mine { border-color: var(--gold); background: rgba(212, 175, 55, .12); }
.react-chip.add { color: var(--faint); }
.react-chip:hover { border-color: var(--gold); }
.react-n { font-size: .72rem; color: var(--muted); }

.edit-box textarea { width: 100%; min-width: 220px; resize: vertical; }
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }

/* ---------- composer ---------- */
.composer { border-top: 1px solid var(--border); background: var(--panel-2); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); position: relative; }
.reply-bar, .file-bar {
  display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 5px 9px; margin-bottom: 6px;
}
.reply-bar b, .file-bar b { color: var(--gold-soft); }
.bar-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-x { color: var(--faint); font-size: .95rem; padding: 0 4px; }
.bar-x:hover { color: var(--danger); }
.composer-row { display: flex; align-items: flex-end; gap: 7px; }
.composer-ta {
  flex: 1; resize: none; min-height: 42px; max-height: 140px; padding: 10px 12px;
  border-radius: 12px; line-height: 1.45;
}
.send-btn {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 12px;
  background: var(--gold); color: #0b1020; font-size: 1.1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .35; cursor: default; }
.attach-btn {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 12px; font-size: 1.15rem;
  color: var(--muted); border: 1px solid var(--border); background: var(--panel);
  display: flex; align-items: center; justify-content: center;
}
.attach-btn:hover { color: var(--text); }
.composer-hint { font-size: .68rem; color: var(--faint); padding: 4px 4px 0; }

.mention-pop {
  position: absolute; bottom: 100%; left: 10px; right: 10px; max-width: 340px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .45); overflow: hidden; margin-bottom: 4px; z-index: 30;
}
.mention-item { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 8px 12px; }
.mention-item.sel, .mention-item:hover { background: #182b52; }
.mention-item .u { font-weight: 600; }
.mention-item .d { font-size: .76rem; color: var(--muted); }

/* ---------- modals / sheets ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(4, 8, 18, .72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 460px; max-height: min(86dvh, 720px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  display: flex; flex-direction: column; box-shadow: 0 20px 70px rgba(0, 0, 0, .6);
}
.modal.wide { max-width: 560px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.02rem; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-body h3 { font-size: .82rem; color: var(--muted); margin: 16px 0 8px; letter-spacing: .05em; }
.modal-body h3:first-child { margin-top: 0; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(4, 8, 18, .6);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 768px) { .sheet-backdrop { align-items: center; } }
.sheet {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px 16px 0 0; padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
@media (min-width: 768px) { .sheet { border-radius: 16px; padding-bottom: 8px; } }
.sheet button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 10px; font-size: .95rem;
}
.sheet button:hover { background: #182b52; }
.sheet button.danger { color: var(--danger); }
.sheet-title { font-size: .74rem; color: var(--faint); padding: 6px 14px 2px; }

.emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
.emoji-grid button {
  width: 46px; height: 46px; font-size: 1.4rem; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--border); padding: 0;
}
.emoji-grid button:hover { border-color: var(--gold); }
.emoji-custom { display: flex; gap: 8px; padding: 4px 12px 12px; }
.emoji-custom input { flex: 1; width: 60px; }

/* ---------- lists in modals ---------- */
.pick-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px;
}
.pick-item:hover { background: #182b52; }
.pick-item .nm { font-weight: 600; }
.pick-item .un { font-size: .76rem; color: var(--muted); }
.chk { display: flex; align-items: center; gap: 8px; padding: 7px 4px; font-size: .92rem; cursor: pointer; }
.chk input { width: 17px; height: 17px; accent-color: var(--gold); }

.result-item {
  display: block; width: 100%; text-align: left; padding: 10px 11px;
  border: 1px solid var(--border); border-radius: 11px; margin-bottom: 8px; background: var(--panel-2);
}
.result-item:hover { border-color: var(--gold); }
.result-top { display: flex; gap: 8px; align-items: baseline; font-size: .74rem; color: var(--muted); margin-bottom: 3px; flex-wrap: wrap; }
.result-room { color: var(--gold-soft); font-weight: 700; }
.result-text { font-size: .88rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input { flex: 1; }

/* ---------- admin ---------- */
.admin-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.pw-row { display: flex; gap: 6px; align-items: center; }
.pw-row input { flex: 1; min-width: 0; }
.admin-user {
  display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); align-items: flex-start;
}
.admin-user.inactive { opacity: .55; }
.admin-user-mid { flex: 1; min-width: 0; }
.admin-user-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.tag {
  display: inline-block; font-size: .64rem; padding: 1px 7px; border-radius: 999px;
  background: rgba(212, 175, 55, .15); color: var(--gold); font-weight: 700; vertical-align: 1px;
}
.tag.off { background: #7f1d1d33; color: var(--danger); }

/* ---------- settings ---------- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.switch-row small { color: var(--muted); }
.switch-row input { width: 20px; height: 20px; accent-color: var(--gold); flex-shrink: 0; }
.settings-me { display: flex; align-items: center; gap: 10px; padding: 6px 4px 14px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(2, 4, 10, .9);
  display: flex; align-items: center; justify-content: center; padding: 18px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 360px); }
.toast {
  background: #182342; border: 1px solid var(--border); border-left: 3px solid var(--gold);
  color: var(--text); border-radius: 10px; padding: 9px 13px; font-size: .85rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.error { border-left-color: var(--danger); }

.spin {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--gold);
  animation: spin .8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
