:root {
  --side: #1d2b3a; --side-2: #26384b; --side-text: #c5d0dc; --side-muted: #8193a6;
  --accent: #e8742c; --accent-2: #f08540; --link: #1f6fbf;
  --bg: #ffffff; --bg-2: #f6f7f9; --line: #e3e7ec; --text: #1c232b; --muted: #6a7684;
  --hover: #f4f6f9; --mention: #fff4d6; --highlight: #fdf0d5; --danger: #c0392b; --ok: #1e9e6a;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --side: #141d27; --side-2: #1e2a37; --bg: #1a1f26; --bg-2: #222831; --line: #2e3640;
    --text: #e6e9ed; --muted: #95a1ae; --hover: #222a33; --mention: #4a3a12; --highlight: #3d3215; --link: #6aaef0;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--link); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* ---------- auth */
.auth { min-height: 100%; display: grid; place-items: center; background: var(--side); padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--bg); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.auth-logo img { width: 36px; height: 36px; }
.auth-card h1 { margin: 6px 0 0; font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.auth-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); font-weight: 400; font-size: 15px; }
.auth-card:not(.register) .reg { display: none; }
.link { background: none; border: 0; color: var(--link); padding: 4px; }

.btn { border: 1px solid var(--line); background: var(--bg); border-radius: var(--radius); padding: 8px 14px; font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; width: 26px; height: 26px; border-radius: 6px; font-size: 16px; line-height: 1; color: inherit; display: inline-grid; place-items: center; }
.icon-btn:hover { background: rgba(127,127,127,.18); }

/* ---------- layout */
.app { display: grid; grid-template-columns: 260px 1fr auto; height: 100vh; height: 100dvh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; }
.ws-head { text-align: left; background: none; border: 0; border-bottom: 1px solid rgba(255,255,255,.08); padding: 14px 16px; color: #fff; }
.ws-head:hover { background: var(--side-2); }
#wsName { display: block; font-weight: 800; font-size: 17px; }
.me-line { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--side-muted); }
.side-scroll { overflow-y: auto; flex: 1; padding: 10px 0; }
.side-section { margin-bottom: 14px; }
.side-title { display: flex; align-items: center; padding: 4px 10px 4px 16px; color: var(--side-muted); font-size: 13px; font-weight: 600; }
.side-title span { flex: 1; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li button { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 5px 16px; color: var(--side-text); text-align: left; border-radius: 0; }
.sidebar li button:hover { background: var(--side-2); }
.sidebar li.active button { background: var(--accent); color: #fff; }
.sidebar li.unread button { color: #fff; font-weight: 700; }
.sidebar li.muted button { opacity: .5; font-weight: 400; }
.sidebar li.muted .ch-name::after { content: " 🔕"; font-size: 11px; }
.notify-opts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.notify-opts label.check { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; cursor: pointer; align-items: flex-start; }
.notify-opts label.check:has(input:checked) { border-color: var(--accent); background: rgba(232,116,44,.07); }
.notify-opts small { display: block; color: var(--muted); }
.sidebar .ch-ico { width: 16px; text-align: center; opacity: .8; flex: none; }
.sidebar .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; padding: 1px 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--side-muted); flex: none; display: inline-block; }
.dot.on { background: var(--ok); border-color: var(--ok); }
.conn { font-size: 12px; padding: 6px 16px; color: #ffd38a; min-height: 0; }
.conn:empty { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; background: var(--bg); }
.chan-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 58px; }
.chan-title { flex: 1; min-width: 0; }
.chan-title h2 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; display: block; }
.topic:hover { color: var(--text); }
.pill { border: 1px solid var(--line); background: var(--bg); border-radius: 16px; padding: 4px 10px; font-size: 13px; white-space: nowrap; }
.pill:hover { background: var(--hover); }
.search input { width: 220px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--bg-2); }
.menu-btn { display: none; }

.msgs { flex: 1; overflow-y: auto; padding: 8px 0 12px; }
.load-more { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }
.intro { padding: 24px 20px 12px; }
.intro h3 { margin: 0 0 4px; font-size: 22px; }
.day { display: flex; align-items: center; gap: 10px; margin: 14px 20px 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.new-line { display: flex; align-items: center; gap: 8px; margin: 6px 20px; color: var(--danger); font-size: 12px; font-weight: 700; }
.new-line::before { content: ""; flex: 1; border-top: 1px solid var(--danger); }

.msg { position: relative; display: grid; grid-template-columns: 40px 1fr; column-gap: 10px; padding: 4px 20px; }
.msg:hover { background: var(--hover); }
.msg.cont { padding-top: 1px; padding-bottom: 1px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg.cont .meta { display: none; }
.msg .ctime { visibility: hidden; color: var(--muted); font-size: 11px; text-align: right; padding-top: 3px; }
.msg.cont:hover .ctime { visibility: visible; }
.msg.flash { animation: flash 2.5s ease-out; }
.msg.mentioned { background: var(--mention); }
@keyframes flash { from { background: var(--highlight); } to { background: transparent; } }
.avatar { width: 36px; height: 36px; border-radius: 8px; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; user-select: none; }
.avatar.sm { width: 22px; height: 22px; border-radius: 5px; font-size: 10px; }
.meta { display: flex; align-items: baseline; gap: 8px; }
.meta .who { font-weight: 700; background: none; border: 0; padding: 0; }
.meta .who:hover { text-decoration: underline; }
.meta time, .edited { color: var(--muted); font-size: 12px; }
.body { overflow-wrap: anywhere; white-space: normal; }
.body.deleted { color: var(--muted); font-style: italic; }
.body pre { background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; overflow-x: auto; margin: 4px 0; white-space: pre-wrap; }
.body code { background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 13px; color: #c7254e; }
.body pre code { border: 0; padding: 0; color: inherit; background: none; }
.mention { background: rgba(31,111,191,.12); color: var(--link); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.mention.me { background: rgba(232,116,44,.2); color: var(--accent); }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.att-img img { max-width: 360px; max-height: 260px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.att-file { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; text-decoration: none; color: var(--text); max-width: 320px; }
.att-file:hover { background: var(--hover); }
.att-file .ext { width: 34px; height: 34px; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 800; flex: none; }
.att-file .fn { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file small { color: var(--muted); }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { border: 1px solid var(--line); background: var(--bg-2); border-radius: 12px; padding: 0 8px; font-size: 13px; height: 24px; }
.react.mine { border-color: var(--link); background: rgba(31,111,191,.1); }
.react.add { opacity: .7; }
.thread-sum { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; border: 1px solid transparent; background: none; padding: 2px 6px 2px 2px; border-radius: 6px; color: var(--link); font-weight: 600; font-size: 13px; }
.thread-sum:hover { border-color: var(--line); background: var(--bg); }
.thread-sum .avatar.sm + .avatar.sm { margin-left: -4px; }
.thread-sum small { color: var(--muted); font-weight: 400; }
.tools { position: absolute; right: 16px; top: -14px; display: none; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.msg:hover .tools { display: flex; }
.tools button { background: none; border: 0; padding: 4px 8px; font-size: 15px; }
.tools button:hover { background: var(--hover); }
.edit-box textarea { width: 100%; border: 1px solid var(--link); border-radius: 6px; padding: 6px 8px; resize: vertical; background: var(--bg); }
.edit-box .row { display: flex; gap: 6px; margin-top: 4px; }

.typing { height: 20px; padding: 0 20px; font-size: 12px; color: var(--muted); }
.join-bar { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--bg-2); display: flex; align-items: center; justify-content: center; gap: 12px; }
.composer { padding: 0 16px 16px; }
.composer .box { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.composer .box:focus-within { border-color: #9aa8b6; box-shadow: 0 0 0 2px rgba(31,111,191,.12); }
.composer textarea { width: 100%; border: 0; resize: none; padding: 10px 12px 4px; min-height: 42px; max-height: 240px; outline: none; background: transparent; display: block; }
.composer .bar { display: flex; align-items: center; gap: 4px; padding: 4px 6px; }
.composer .bar .sp { flex: 1; }
.composer .hint { font-size: 11px; color: var(--muted); margin-right: 6px; }
.send { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 5px 12px; font-weight: 700; }
.send:disabled { background: var(--line); color: var(--muted); }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg-2); border-radius: 6px; padding: 3px 4px 3px 8px; font-size: 13px; max-width: 240px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.uploading { opacity: .6; }
.drop-hint { position: absolute; inset: 8px; border: 3px dashed var(--accent); border-radius: 14px; background: rgba(232,116,44,.08); display: grid; place-items: center; font-size: 20px; font-weight: 700; color: var(--accent); pointer-events: none; }

.panel { width: 400px; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 58px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.panel .replies-sep { margin: 8px 20px; color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.panel .replies-sep::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.result { cursor: pointer; }
.result .where { font-size: 12px; color: var(--muted); padding: 0 20px; margin-top: 8px; }
mark { background: var(--highlight); color: inherit; border-radius: 2px; }

/* ---------- modal */
.modal { position: fixed; inset: 0; background: rgba(10,16,24,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--bg); border-radius: 12px; width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h2 { margin: 0 0 14px; font-size: 20px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.modal-card label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.modal-card input[type=text], .modal-card input[type=password], .modal-card input:not([type]), .modal-card textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); font-weight: 400; font-size: 15px; }
.modal-card .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.list { list-style: none; margin: 0 0 8px; padding: 0; max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li .grow small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { background: var(--hover); }
.list .dot { border-color: var(--muted); }
.filter { width: 100%; margin-bottom: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c232b; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 14px; }
.emoji-pop, .mention-pop { position: fixed; z-index: 40; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.emoji-pop { display: flex; padding: 4px; }
.emoji-pop button { background: none; border: 0; font-size: 20px; padding: 4px 6px; border-radius: 6px; }
.emoji-pop button:hover { background: var(--hover); }
.mention-pop { min-width: 220px; max-height: 240px; overflow-y: auto; padding: 4px; }
.mention-pop button { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 6px 8px; border-radius: 6px; text-align: left; }
.mention-pop button.sel, .mention-pop button:hover { background: var(--hover); }
.mention-pop small { color: var(--muted); }

/* ---------- mobil */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .app.side-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-grid; }
  .panel { position: fixed; inset: 0; width: auto; z-index: 25; }
  .search input { width: 120px; }
  #membersBtn { display: none; }
  #notifyBtn { padding: 4px 8px; }
  .msg { padding: 4px 12px; }
  .tools { right: 8px; }
  .att-img img { max-width: 100%; }
}
