:root {
  --teal: #1b5f84; --teal-2: #2479a8; --navy: #0a1a2b; --navy-2: #10263d; --navy-3: #173352;
  --orange: #ff6b1f; --text: #e8eef4; --muted: #8fa3b8; --line: #21405f; --ok: #3ccf8e; --danger: #e5484d;
  --radius: 10px; --sb: 290px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--navy); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: #6cc4f2; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .pad { padding: 8px 14px; }
.splash { display: grid; place-items: center; height: 100vh; color: var(--muted); }
code { background: var(--navy-3); padding: 1px 5px; border-radius: 4px; }

/* buttons & inputs */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--navy-3); border-radius: 8px; padding: 8px 14px; cursor: pointer; margin: 4px 0; }
.btn:hover { border-color: var(--teal-2); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #1a0d05; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #ffb3b5; border-color: #6b2a2d; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 18px; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--navy-3); color: var(--text); }
input, select, textarea { background: var(--navy); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-2); box-shadow: 0 0 0 3px rgba(36,121,168,.25); }
label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
label input, label select { margin-top: 4px; color: var(--text); font-size: 15px; }
label.check { display: flex; gap: 8px; align-items: center; } label.check input { width: auto; margin: 0; }
.form-err { color: #ffb3b5; min-height: 1.2em; font-size: 13px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--teal) 0%, var(--navy) 60%); }
.auth-card { width: 100%; max-width: 380px; background: var(--navy-2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.auth-card h1 { margin: 8px 0 2px; font-size: 22px; }
.auth-card .btn.primary { width: 100%; padding: 11px; margin-top: 8px; }
.auth-logo { width: 56px; height: 56px; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: var(--sb); flex: none; background: var(--navy-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--navy); }
.sb-top { display: flex; align-items: center; gap: 10px; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--teal) -60%, var(--navy-2) 100%); }
.sb-logo { width: 34px; height: 34px; }
.sb-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sb-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { padding: 10px 12px 4px; }
.search input { padding: 7px 10px; font-size: 14px; }
.admin-btn { margin: 6px 12px 0; width: calc(100% - 24px); text-align: left; color: var(--orange); border-color: #5a3420; background: transparent; }
.sb-section { padding: 8px 0; }
.sb-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 4px 16px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.sb-section ul { list-style: none; margin: 0; padding: 0 6px; }
.ch-item { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; color: var(--muted); padding: 7px 10px; border-radius: 7px; cursor: pointer; text-align: left; }
.ch-item:hover { background: var(--navy-3); color: var(--text); }
.ch-item.active { background: var(--teal); color: #fff; }
.ch-item.unread { color: var(--text); font-weight: 650; }
.ch-icon { width: 18px; text-align: center; opacity: .8; font-size: 13px; flex: none; }
.ch-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--teal-2); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; line-height: 19px; }
.badge.mention { background: var(--orange); color: #1a0d05; }
.presence { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--muted); flex: none; margin: 0 4px; }
.presence.on { background: var(--ok); border-color: var(--ok); }
.sb-foot { margin-top: auto; padding: 10px 16px; }

.ch-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); min-height: 58px; background: var(--navy-2); }
.ch-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.ch-title strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; font-size: 28px; }

.messages { flex: 1; overflow-y: auto; padding: 12px 0; overscroll-behavior: contain; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.load-more { display: block; margin: 0 auto 10px; }
.msg { position: relative; display: flex; gap: 10px; padding: 6px 16px; }
.msg.grouped { padding-top: 1px; }
.msg:hover { background: rgba(255,255,255,.03); }
.avatar { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; border-radius: 7px; }
.avatar-space { width: 36px; flex: none; }
.msg-main { min-width: 0; flex: 1; }
.msg-head { display: flex; gap: 8px; align-items: baseline; }
.body { word-wrap: break-word; overflow-wrap: anywhere; }
.body.deleted { color: var(--muted); font-style: italic; }
.mention { background: rgba(36,121,168,.3); color: #9fd6f5; border-radius: 4px; padding: 0 3px; }
.mention.me { background: rgba(255,107,31,.25); color: #ffb48a; }
.msg-actions { position: absolute; right: 12px; top: -6px; display: none; background: var(--navy-2); border: 1px solid var(--line); border-radius: 8px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions .icon-btn { width: 30px; height: 30px; font-size: 15px; }
.emoji-pop { position: absolute; right: 0; top: 34px; z-index: 5; background: var(--navy-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.emoji-pop button { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-pop button:hover { background: var(--navy-3); }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { background: var(--navy-3); border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; font-size: 13px; cursor: pointer; }
.react.mine { border-color: var(--orange); background: rgba(255,107,31,.12); }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att-img img { max-width: min(320px, 70vw); max-height: 240px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.att-file { background: var(--navy-3); padding: 8px 12px; border-radius: 8px; text-decoration: none; border: 1px solid var(--line); }
.edit-form textarea { margin: 4px 0; }
.typing { height: 20px; padding: 0 18px; font-size: 12.5px; color: var(--muted); font-style: italic; }
.composer { padding: 8px 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--navy-2); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; min-height: 40px; }
.composer .send { margin: 0; height: 40px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--navy-3); border-radius: 12px; padding: 2px 10px; font-size: 12.5px; margin-bottom: 6px; }

/* modals */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { width: 100%; max-width: 480px; max-height: 88vh; display: flex; flex-direction: column; background: var(--navy-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 80px rgba(0,0,0,.5); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 12px 16px 16px; overflow-y: auto; }
.modal-body > .btn { display: block; width: 100%; text-align: left; }
.list { list-style: none; padding: 0; margin: 8px 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.list.pick { max-height: 300px; overflow-y: auto; }
.pick-row { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--text); font-size: 14px; flex: 1; cursor: pointer; }
.pick-row input { width: auto; margin: 0; }
.results .result { display: block; cursor: pointer; }
.results .result:hover { background: var(--navy-3); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tab { background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--orange); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; align-items: center; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table tr.inactive { opacity: .55; }
.table td.actions { white-space: nowrap; }
.table td.actions .btn { margin: 2px; }
.table select { padding: 5px 8px; font-size: 13px; }
.secret-box { background: var(--navy); border: 1px dashed var(--orange); border-radius: 10px; padding: 12px; margin: 10px 0; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; margin-bottom: 6px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--teal); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { background: #7a2326; }

/* phones */
@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: 0; }
  .app.view-list .main { display: none; }
  .app.view-chat .sidebar { display: none; }
  .back { display: block; }
  .msg-actions { display: flex; position: static; background: none; border: 0; align-self: flex-start; opacity: .55; }
  .msg-actions .icon-btn { width: 28px; height: 28px; font-size: 14px; }
  .modal-bg { padding: 0; align-items: end; }
  .modal { max-height: 92vh; border-radius: 14px 14px 0 0; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom */
}

/* Notifications control (account menu) */
.notif-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.notif-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notif-status { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--navy-3); }
.notif-status.on { background: #1f7a4d; color: #fff; }
.notif-status.blocked { background: #8a2b2b; color: #fff; }
.notif-box p { margin: 0; }

/* sign-up approval */
.auth-alt { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.pending-box { text-align: center; }
.pending-box h2 { margin: 6px 0 8px; font-size: 20px; }
.pending-icon { font-size: 40px; }
.admin-btn .badge { margin-left: 8px; }
.tab .badge { margin-left: 6px; }
.pending-item { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.pending-who { flex: 1 1 260px; min-width: 0; }
.pending-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pending-actions select { width: auto; margin: 0; }
.empty-note { padding: 14px; border: 1px dashed var(--line); border-radius: 10px; text-align: center; color: var(--muted); }
.name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.name-row label { min-width: 0; }
