:root {
  --bg: #eae6df; --panel: #ffffff; --panel-2: #f0f2f5; --line: #e2e2e2; --text: #111b21; --muted: #667781;
  --accent: #0f7b6c; --accent-2: #00a884; --in: #ffffff; --out: #d9fdd3; --chat-bg: #efeae2; --hover: #f5f6f6; --sel: #e9edef;
  --danger: #c0392b; --badge: #25d366; --shadow: 0 1px 0.5px rgba(11, 20, 26, .13);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b141a; --panel: #111b21; --panel-2: #202c33; --line: #222d34; --text: #e9edef; --muted: #8696a0;
    --accent: #00a884; --accent-2: #00a884; --in: #202c33; --out: #005c4b; --chat-bg: #0b141a; --hover: #202c33; --sel: #2a3942;
    --danger: #ef6b5b; --badge: #00a884; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, "Segoe UI", Arial, sans-serif; overflow: hidden; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; }

/* כניסה */
.login { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); width: 100%; max-width: 380px; border-radius: 14px; padding: 28px 24px; text-align: center; box-shadow: var(--shadow); }
.login-icon { width: 64px; height: 64px; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 10px 0 4px; }
.login-card label { display: block; text-align: right; margin: 18px 0 6px; color: var(--muted); font-size: 13.5px; }
.login-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 18px; letter-spacing: 1px; text-align: center; }
.login-card input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.primary { width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; }
.primary:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent-2); margin-top: 10px; }

/* מבנה */
.app { display: grid; grid-template-columns: minmax(300px, 30%) 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; max-width: 1600px; margin: 0 auto; background: var(--panel); overflow: hidden; }
.side { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--panel); }
.side-head, .conv-head { height: 60px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--panel-2); }
.side-head { justify-content: space-between; }
.me { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.me span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-icon { width: 34px; height: 34px; }
.head-actions { display: flex; align-items: center; gap: 6px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--badge); }
.conn.off { background: var(--danger); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 20px; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--hover); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 8px 14px; border: 0; border-radius: 8px; background: var(--panel-2); }
.search input:focus { outline: 1px solid var(--accent-2); }
.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.chat:hover { background: var(--hover); }
.chat.sel { background: var(--sel); }
.avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; color: #fff; }
.conv-head .avatar { width: 40px; height: 40px; font-size: 15px; }
.chat-body { flex: 1; min-width: 0; }
.chat-top, .chat-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 12px; color: var(--muted); flex: none; }
.chat.unread .chat-time { color: var(--badge); }
.chat-prev { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--badge); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 6px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.main { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--chat-bg); }
.placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
.ph-icon { width: 90px; height: 90px; opacity: .85; margin-bottom: 12px; }
.conv { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-title { min-width: 0; }
.conv-title > div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub:empty { display: none; }
.back { display: none; }

.msgs { flex: 1; overflow-y: auto; padding: 12px 6% 8px; display: flex; flex-direction: column; }
#msgs-list { display: flex; flex-direction: column; gap: 2px; }
.more { align-self: center; margin: 6px 0 12px; padding: 6px 14px; border: 0; border-radius: 14px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); }
.day { align-self: center; margin: 10px 0 6px; padding: 4px 12px; border-radius: 8px; background: var(--panel); color: var(--muted); font-size: 12.5px; box-shadow: var(--shadow); }
.b { position: relative; max-width: min(65%, 560px); padding: 6px 9px 6px; border-radius: 8px; box-shadow: var(--shadow); margin: 1px 0; word-wrap: break-word; overflow-wrap: anywhere; }
.b.in { align-self: flex-start; background: var(--in); border-top-right-radius: 0; }
.b.out { align-self: flex-end; background: var(--out); border-top-left-radius: 0; }
.b.cont { border-radius: 8px; margin-top: 0; }
.sender { font-size: 12.5px; font-weight: 600; color: var(--accent-2); margin-bottom: 2px; }
.txt { white-space: pre-wrap; unicode-bidi: plaintext; }
.txt a { color: #027eb5; }
.meta { float: left; margin: 6px 10px 0 0; font-size: 11px; color: var(--muted); white-space: nowrap; line-height: 1; position: relative; top: 4px; }
.meta .tick { color: var(--muted); }
.deleted .txt { font-style: italic; color: var(--muted); }
.quote { border-right: 4px solid var(--accent-2); background: rgba(0, 0, 0, .05); border-radius: 6px; padding: 4px 8px; margin-bottom: 4px; font-size: 13px; color: var(--muted); max-height: 3.2em; overflow: hidden; }
.react { position: absolute; bottom: -12px; left: 8px; background: var(--panel); border-radius: 12px; padding: 0 6px; font-size: 14px; box-shadow: var(--shadow); }
.b.has-react { margin-bottom: 12px; }
.media { display: block; position: relative; margin: -2px -5px 4px; border-radius: 6px; overflow: hidden; cursor: pointer; background: rgba(0, 0, 0, .08); min-width: 200px; min-height: 120px; }
.media img, .media video { display: block; width: 100%; max-width: 340px; max-height: 360px; object-fit: cover; }
.media .play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 42px; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .5); }
.media .label { position: absolute; bottom: 6px; right: 8px; color: #fff; font-size: 12px; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.media.noimg { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.sticker img { width: 150px; height: 150px; object-fit: contain; }
.b.sticker-b { background: none; box-shadow: none; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: -2px -3px 4px; border-radius: 6px; background: rgba(0, 0, 0, .05); color: inherit; text-decoration: none; min-width: 220px; }
.doc .ico { font-size: 28px; }
.doc .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
audio { width: 260px; max-width: 100%; height: 40px; display: block; margin: 2px 0 4px; }
.loc { color: inherit; }
.poll li { margin: 2px 0; }
.note { color: var(--muted); font-style: italic; }
.reply-btn { position: absolute; top: 2px; left: 2px; display: none; background: var(--panel); border: 0; border-radius: 50%; width: 26px; height: 26px; color: var(--muted); font-size: 14px; box-shadow: var(--shadow); }
.b:hover .reply-btn { display: block; }

.reply-bar { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: var(--panel-2); border-top: 1px solid var(--line); }
.reply-bar > div { flex: 1; border-right: 4px solid var(--accent-2); padding: 4px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-note { flex: none; text-align: center; padding: 12px; background: var(--panel-2); color: var(--muted); font-size: 13.5px; }
.compose { flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; background: var(--panel-2); }
.compose textarea { flex: 1; resize: none; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--panel); max-height: 140px; line-height: 1.4; unicode-bidi: plaintext; }
.compose textarea:focus { outline: none; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 18px; transform: scaleX(-1); flex: none; }
.send:disabled { opacity: .5; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 15; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal h1 { font-size: 20px; margin: 0 0 6px; }
.login-card .small { margin-top: 14px; }
.admin-card { background: var(--panel); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 14px; padding: 18px 20px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; }
.admin-head h1 { font-size: 20px; margin: 0; }
.admin-list { list-style: none; margin: 12px 0; padding: 0; }
.admin-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.admin-row.off { opacity: .6; }
.admin-row .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.admin-row .who { font-weight: 600; }
.admin-row .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.admin-row .acts button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 5px 10px; font-size: 13px; }
.admin-row .acts button.danger { color: var(--danger); }
.admin-add { border-top: 1px solid var(--line); padding-top: 12px; }
.admin-add h2 { font-size: 16px; margin: 0 0 4px; }
.admin-add input[type=tel], .admin-add input[type=text] { width: 100%; margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.chk { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--panel-2); color: var(--muted); }
.pill.on { color: var(--badge); }
.pill.bad { color: var(--danger); }
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 10; display: flex; align-items: center; justify-content: center; }
.viewer #viewer-close { position: absolute; top: 12px; left: 12px; color: #fff; font-size: 26px; }
.viewer img, .viewer video { max-width: 96vw; max-height: 90vh; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #323232; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }

/* טלפון: מסך אחד בכל פעם */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { border: 0; }
  .app.in-chat .side { display: none; }
  .app:not(.in-chat) .main { display: none; }
  .back { display: inline-flex; }
  .msgs { padding: 10px 10px 6px; }
  .b { max-width: 85%; }
  .media img, .media video { max-width: 100%; }
}
