/* Nodz chat client */
html, body.app { height: 100%; }
body.app { overflow: hidden; font-size: 1rem; }
[hidden] { display: none !important; }
.noscript { padding: 2rem; text-align: center; }

/* Welcome */
.welcome {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem;
  background: radial-gradient(900px 500px at 50% 0%, #1b3a2e 0%, transparent 65%), var(--bg);
  overflow-y: auto;
}
.welcome-card {
  width: min(460px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: clamp(1.25rem, 4vw, 2rem); box-shadow: var(--shadow);
}
.welcome-brand img { width: 150px; margin: 0 auto 0.75rem; }
.welcome-art { width: 100%; max-width: 280px; margin: 0 auto 0.5rem; border-radius: 14px; }
.welcome-card h1 { font-size: 1.7rem; text-align: center; margin-bottom: 1rem; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 999px; padding: 4px; margin-bottom: 1.2rem; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: 0.9rem;
  padding: 0.55rem 0.4rem; border-radius: 999px; cursor: pointer; min-height: 40px;
}
.tabs button[aria-selected=true] { background: var(--lime); color: var(--lime-ink); }
.join-form .field { margin-bottom: 0.9rem; }
.join-form label, .dialog label { display: block; font-weight: 700; margin-bottom: 0.3rem; font-size: 0.95rem; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 2px solid var(--line); border-radius: var(--radius-small); padding: 0.65rem 0.8rem; min-height: 46px;
}
input:focus, textarea:focus { outline: none; border-color: var(--lime); }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--lime); flex: none; margin-top: 0.2rem; }
label.check { display: flex; gap: 0.6rem; align-items: flex-start; font-weight: 500; }
.hint { color: var(--muted); font-size: 0.88rem; margin: 0.35rem 0 0; }
.form-error { color: var(--danger); min-height: 1.4em; margin: 0.4rem 0 0.6rem; font-weight: 600; }
.join-form .button-large { width: 100%; }
.join-form[data-mode=guest] [data-for=account],
.join-form[data-mode=guest] [data-for=register],
.join-form[data-mode=guest] [data-for=login],
.join-form[data-mode=login] [data-for=guest],
.join-form[data-mode=login] [data-for=register],
.join-form[data-mode=register] [data-for=guest],
.join-form[data-mode=register] [data-for=login] { display: none; }
.transport-note { font-size: 0.85rem; color: var(--muted); margin-top: 1rem; text-align: center; }
.welcome-langs { margin-top: 1rem; display: flex; justify-content: center; }

/* Shell layout: sidebar | conversation | members */
.shell {
  height: 100dvh; display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 240px;
  background: var(--bg);
}
body.members-hidden .shell { grid-template-columns: 272px minmax(0, 1fr); }
body.members-hidden .members { display: none; }

.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto; padding: 0.9rem 0.7rem;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.9rem; padding: 0 0.3rem; }
.sidebar-brand img { width: 88px; }
.me {
  background: var(--surface); border: 1px solid var(--line); color: var(--text); border-radius: 12px;
  padding: 0.35rem 0.7rem; text-align: right; cursor: pointer; font: inherit; max-width: 60%;
}
.me-nick { display: block; font-weight: 800; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-sub { display: block; color: var(--muted); font-size: 0.75rem; }
.sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-bottom: 0.6rem; }
.list-heading { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 1rem 0.4rem 0.3rem; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-item { display: flex; align-items: center; border-radius: 10px; }
.conv-item.active { background: var(--surface-2); }
.conv-item:hover { background: var(--surface); }
.conv-button {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.4rem; text-align: left;
  background: none; border: 0; color: var(--text); font: inherit; padding: 0.55rem 0.6rem; cursor: pointer; min-height: 40px;
}
.conv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv-item.has-error .conv-name { color: var(--muted); text-decoration: line-through; }
.conv-flag { font-size: 0.7rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 0.3rem; color: var(--muted); }
.unread { margin-left: auto; background: var(--surface-2); color: var(--text); border-radius: 999px; font-size: 0.75rem; font-weight: 800; padding: 0.05rem 0.45rem; }
.unread.mention { background: var(--orange); color: #1d0f05; }
.conv-close {
  background: none; border: 0; color: var(--muted); font-size: 1.15rem; width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; opacity: 0; flex: none;
}
.conv-item:hover .conv-close, .conv-close:focus-visible, .conv-item.active .conv-close { opacity: 1; }
.conv-close:hover { background: var(--surface-2); color: var(--text); }
.sidebar-empty { color: var(--muted); font-size: 0.85rem; padding: 0 0.5rem; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; display: flex; gap: 0.8rem; flex-wrap: wrap; font-size: 0.82rem; padding-left: 0.4rem; }
.sidebar-foot a { color: var(--muted); }

/* Conversation */
.conversation { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.conv-header {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem; min-height: 60px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.conv-title-wrap { min-width: 0; flex: 1; }
.conv-title { font-size: 1.15rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-topic { margin: 0; color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button {
  position: relative; display: inline-flex; align-items: center; gap: 0.3rem; justify-content: center;
  min-width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-size: 1.2rem; padding: 0 0.5rem;
}
.icon-button:hover { background: var(--surface-2); }
.icon-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-button .count { font-size: 0.8rem; font-weight: 700; }
.icon-button .badge { position: absolute; top: -4px; right: -4px; background: var(--orange); color: #1d0f05; font-size: 0.7rem; font-weight: 800; border-radius: 999px; padding: 0 0.35rem; }
.only-narrow { display: none; }

.enc-label {
  margin: 0; padding: 0.3rem 1rem; font-size: 0.8rem; color: var(--muted);
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.enc-label::before { content: "🔒 "; }
.enc-label[data-secure=false] { color: #f2d48a; }
.enc-label[data-secure=false]::before { content: "⚠ "; }

.status-bar {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; padding: 0.5rem 1rem;
  background: #3a2c12; color: #ffe2a8; font-size: 0.92rem; border-bottom: 1px solid #6b5420;
}
.room-error {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; padding: 0.6rem 1rem;
  background: #3a1f1c; color: #ffc8bf; border-bottom: 1px solid #7a3a33;
}

.messages {
  list-style: none; margin: 0; padding: 0.8rem 0; flex: 1; overflow-y: auto; overscroll-behavior: contain;
  min-height: 0;
}
.msg {
  display: grid; grid-template-columns: 3.6rem auto 1fr; column-gap: 0.6rem; align-items: baseline;
  padding: 0.2rem 1rem; line-height: 1.45;
}
.msg:hover { background: rgb(255 255 255 / 0.025); }
.msg time { color: #7f8b80; font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.msg .nick {
  background: none; border: 0; padding: 0; font: inherit; font-weight: 800; cursor: pointer; text-align: left;
  max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg .text { overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.msg-action .text { font-style: italic; }
.msg-notice .text { color: #c9d9b0; }
.msg.mention { background: rgb(242 121 43 / 0.12); box-shadow: inset 3px 0 0 var(--orange); }
.msg.system { grid-template-columns: 3.6rem 1fr; color: var(--muted); font-size: 0.88rem; }
.msg-error .sys-text { color: var(--danger); }
.msg-service .sys-text { color: #c9d9b0; }
.msg .delivery, .msg .link-button { grid-column: 3; font-size: 0.78rem; color: var(--muted); justify-self: start; }
.msg.status-pending .text { opacity: 0.65; }
.msg.status-unknown .delivery { color: #f2d48a; }
.msg.status-failed .delivery { color: var(--danger); }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--lime); cursor: pointer; text-decoration: underline; }
.empty-state { color: var(--muted); text-align: center; padding: 3rem 1rem; }
.history-control { text-align: center; padding: 0.5rem 1rem 0.8rem; color: var(--muted); font-size: 0.85rem; }
.unread-divider {
  display: flex; align-items: center; gap: 0.6rem; margin: 0.5rem 1rem;
  color: var(--orange); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
}
.unread-divider::before, .unread-divider::after { content: ""; flex: 1; border-top: 1px solid rgb(242 121 43 / 0.6); }
.sync-note { color: var(--muted); font-size: 0.78rem; padding: 0 0.5rem; margin: 1rem 0 0; }
.prefs { border-top: 1px solid var(--line); padding-top: 0.8rem; display: grid; gap: 0.5rem; }
.prefs h3 { font-size: 1rem; margin: 0; }
.prefs .hint { margin: 0; }
.jump-latest {
  position: absolute; right: 1.2rem; bottom: 5.5rem; border-radius: 999px; border: 0;
  background: var(--lime); color: var(--lime-ink); font: inherit; font-weight: 700; padding: 0.45rem 0.9rem; cursor: pointer; box-shadow: var(--shadow);
}

.composer {
  display: flex; gap: 0.5rem; align-items: flex-end; padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
}
.composer textarea { resize: none; max-height: 160px; line-height: 1.4; }
.composer .button { min-height: 46px; }

/* Members */
.members { background: var(--bg-2); border-left: 1px solid var(--line); overflow-y: auto; padding: 0.9rem 0.6rem; }
.members-head { display: flex; align-items: center; justify-content: space-between; padding: 0 0.4rem; }
.members h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0.4rem 0; }
.member-list { list-style: none; padding: 0; margin: 0; }
.member {
  width: 100%; display: flex; align-items: center; gap: 0.35rem; background: none; border: 0; color: var(--text);
  font: inherit; padding: 0.4rem 0.5rem; border-radius: 8px; cursor: pointer; text-align: left; min-height: 36px;
}
.member:hover { background: var(--surface); }
.member.away { opacity: 0.55; }
.member-rank { width: 1ch; color: var(--lime); font-weight: 800; }
.member-nick { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-verified { color: var(--lime); font-size: 0.8rem; }
.member-muted { margin-left: auto; font-size: 0.7rem; color: var(--muted); }

/* Dialogs */
.dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100% - 2rem)); box-shadow: var(--shadow); max-height: calc(100dvh - 2rem);
}
.dialog::backdrop { background: rgb(5 10 8 / 0.7); }
.dialog-body { padding: 1.4rem; display: grid; gap: 0.8rem; }
.dialog h2 { font-size: 1.3rem; margin: 0; }
.dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius-small); padding: 0.8rem; display: grid; gap: 0.6rem; }
.dialog legend { font-weight: 700; padding: 0 0.3rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.4rem; }
.inline-field { display: flex; gap: 0.5rem; }
.register-box { background: var(--bg-2); border-radius: var(--radius-small); padding: 0.8rem; }
.register-box p { margin: 0 0 0.5rem; }
.member-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.browse-list { list-style: none; padding: 0; margin: 0; max-height: 50dvh; overflow-y: auto; display: grid; gap: 0.4rem; }
.browse-item { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; background: var(--bg-2); border-radius: var(--radius-small); padding: 0.6rem 0.8rem; }
.browse-topic { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 0.8rem; }
.prefs-block { border-top: 1px solid var(--line); padding-top: 0.8rem; display: grid; gap: 0.4rem; }
.prefs-block summary { cursor: pointer; font-weight: 700; }
.prefs-block[open] summary { margin-bottom: 0.4rem; }
.report-btn {
  grid-column: 3; justify-self: start; background: none; border: 0; padding: 0; font: inherit; font-size: 0.75rem;
  color: var(--muted); cursor: pointer; text-decoration: underline; opacity: 0;
}
.msg:hover .report-btn, .report-btn:focus-visible { opacity: 1; }
@media (hover: none) { .report-btn { opacity: 0.7; } }
.report-excerpt {
  margin: 0; padding: 0.5rem 0.7rem; border-left: 3px solid var(--orange); background: var(--bg-2);
  border-radius: 0 var(--radius-small) var(--radius-small) 0; white-space: pre-wrap; overflow-wrap: anywhere;
}
.dialog-wide { width: min(760px, calc(100% - 2rem)); }
.mod-tabs { grid-template-columns: repeat(4, 1fr); }
.mod-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; max-height: 55dvh; overflow-y: auto; }
.mod-item { background: var(--bg-2); border-radius: var(--radius-small); padding: 0.7rem 0.8rem; display: grid; gap: 0.4rem; }
.mod-item p { margin: 0; }
.mod-item.resolved { opacity: 0.6; }
.mod-row { display: flex; justify-content: space-between; align-items: center; }
.mod-meta { color: var(--muted); font-size: 0.82rem; }
.dialog h3 { font-size: 1rem; margin: 0.6rem 0 0; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 700; }

/* Toasts */
.toasts { position: fixed; z-index: 50; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: 0.5rem; width: min(520px, calc(100% - 2rem)); }
.toast {
  display: flex; align-items: center; gap: 0.7rem; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.65rem 0.8rem; box-shadow: var(--shadow); font-size: 0.93rem;
}
.toast span { flex: 1; }
.toast-error { border-color: #7a3a33; background: #3a1f1c; }
.toast-success { border-color: #4a6a36; }
.toast-warning { border-color: #6b5420; background: #3a2c12; }
.toast-close { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.scrim { display: none; }

/* Medium screens: members become a drawer */
@media (max-width: 1100px) {
  .shell, body.members-hidden .shell { grid-template-columns: 260px minmax(0, 1fr); }
  .members {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(300px, 85vw); z-index: 30;
    transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.members-hidden .members { display: block; }
  .members.open { transform: none; }
  .members .only-narrow { display: inline-flex; }
  .scrim { display: block; position: fixed; inset: 0; background: rgb(5 10 8 / 0.6); z-index: 25; }
}

/* Phones: one primary view; rooms in a drawer */
@media (max-width: 760px) {
  .shell, body.members-hidden .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(310px, 88vw); z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .only-narrow { display: inline-flex; }
  .conv-header { padding: 0.5rem 0.6rem; gap: 0.4rem; }
  .msg { grid-template-columns: auto 1fr; padding: 0.25rem 0.75rem; }
  .msg time { grid-column: 1 / -1; font-size: 0.7rem; }
  .msg.system { grid-template-columns: 1fr; }
  .msg .delivery, .msg .link-button, .msg .report-btn { grid-column: 2; }
  .composer { padding: 0.5rem 0.6rem calc(0.5rem + env(safe-area-inset-bottom)); }
  .enc-label { padding: 0.25rem 0.75rem; }
  .conv-close { opacity: 1; }
  .welcome-art { max-width: 200px; }
}

.invite-links { border-top: 1px solid var(--line); padding-top: 0.6rem; display: grid; gap: 0.5rem; }
.invite-links select { width: auto; flex: 1; }
.inline-field input[readonly] { font-family: var(--mono); font-size: 0.85rem; }
.invite-banner { background: var(--surface-2); border-left: 3px solid var(--lime); padding: 0.6rem 0.8rem; border-radius: 0 var(--radius-small) var(--radius-small) 0; }
