/* =========================================================================
   שיחה — VOIP + Chat  ·  clean WhatsApp-style UI
   ========================================================================= */

:root {
  --bg:        #ffffff;   /* elevated surface: sidebar, chat panel, cards */
  --panel:     #f0f2f5;   /* headers, pills, incoming bubbles */
  --panel-2:   #f2f4f7;   /* page ground behind cards */
  --chat-bg:   #efeae2;
  --input:     #ffffff;   /* form fields */
  --text:      #111b21;
  --text-dim:  #667781;
  --border:    #d7dde0;
  --hover:     #f5f6f6;
  --active:    #eef0f2;
  --accent:    #00a884;
  --accent-ink:#ffffff;
  --bubble-out:#d9fdd3;
  --bubble-in: #ffffff;
  --danger:    #ea4335;
  --unread:    #25d366;
  --shadow:    0 2px 10px rgba(11,20,26,.10);
  --shadow-sm: 0 1px 2px rgba(11,20,26,.10);
  --header-h:  60px;
}

:root[data-theme="dark"] {
  --bg:        #111b21;
  --panel:     #202c33;
  --panel-2:   #0b141a;
  --chat-bg:   #0b141a;
  --input:     #2a3942;
  --text:      #e9edef;
  --text-dim:  #9fb0bb;
  --border:    #2f3d47;
  --hover:     #202c33;
  --active:    #2a3942;
  --accent:    #00a884;
  --bubble-out:#005c4b;
  --bubble-in: #202c33;
  --danger:    #f15c6d;
  --shadow:    0 6px 20px rgba(0,0,0,.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#111b21; --panel:#202c33; --panel-2:#0b141a; --chat-bg:#0b141a;
    --input:#2a3942; --text:#e9edef; --text-dim:#9fb0bb; --border:#2f3d47;
    --hover:#202c33; --active:#2a3942; --bubble-out:#005c4b; --bubble-in:#202c33;
    --danger:#f15c6d; --shadow:0 6px 20px rgba(0,0,0,.5); --shadow-sm:0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The [hidden] attribute must always win over class-level `display` rules
   (.main, .call-overlay, .call-controls … all set display, which otherwise
   overrides the UA [hidden] style and leaves "hidden" elements visible). */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               "Noto Sans Hebrew", Arial, sans-serif;
  background: var(--panel-2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input  { font: inherit; }

svg { width: 100%; height: 100%; display: block; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-logo svg, .chat-empty svg, .ic-phone { fill: currentColor; stroke: none; }

#app { height: 100dvh; }

/* ---------- Avatars ---------- */
.avatar {
  --sz: 40px;
  width: var(--sz); height: var(--sz);
  min-width: var(--sz);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; text-transform: uppercase;
  font-size: calc(var(--sz) * .4);
  user-select: none;
  background: #64748b;
}
.avatar.xl { --sz: 116px; font-size: 44px; box-shadow: var(--shadow); }

/* =========================================================================
   Login
   ========================================================================= */
.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(0,168,132,.16), transparent 60%),
    var(--panel-2);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-logo {
  width: 64px; height: 64px; margin: 0 auto 14px;
  color: var(--accent);
}
.brand h1 { font-size: 26px; letter-spacing: .5px; }
.brand p { color: var(--text-dim); font-size: 14px; margin-top: 6px; }

#loginForm { margin-top: 26px; display: grid; gap: 12px; }
#loginForm input {
  width: 100%; padding: 13px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--input); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
#loginForm input::placeholder { color: var(--text-dim); }
#loginForm input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,168,132,.2); }
#loginForm button {
  padding: 13px 16px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; transition: filter .15s;
}
#loginForm button:hover { filter: brightness(1.05); }
#loginForm button:disabled { opacity: .6; cursor: default; }
.login-error { color: var(--danger); font-size: 13px; line-height: 1.5; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--text-dim); }

/* =========================================================================
   Main layout
   ========================================================================= */
.main { display: flex; height: 100dvh; overflow: hidden;
        max-width: 1600px; margin-inline: auto;
        background: var(--bg); position: relative; }

.net-banner {
  position: absolute; inset-inline: 0; top: 0; z-index: 60;
  background: #b23c17; color: #fff; text-align: center;
  font-size: 13px; padding: 6px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 34%; min-width: 300px; max-width: 460px;
  display: flex; flex-direction: column;
  border-inline-end: 1px solid var(--border);
  background: var(--bg);
}
.sidebar-head {
  height: var(--header-h); min-height: var(--header-h);
  padding-inline: 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel);
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me .avatar { --sz: 38px; }
.me-name { font-weight: 600; font-size: 15px; white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; }
.sidebar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--active); }

.search {
  padding: 8px 12px; background: var(--bg);
  position: relative;
}
.search-ic {
  position: absolute; inset-inline-start: 24px; top: 50%;
  width: 16px; height: 16px; transform: translateY(-50%);
  color: var(--text-dim);
}
.search input {
  width: 100%; padding: 9px 14px 9px 40px;
  border: 0; border-radius: 10px;
  background: var(--input); color: var(--text);
  outline: none;
}
.search input::placeholder { color: var(--text-dim); }
[dir="rtl"] .search input { padding: 9px 40px 9px 14px; }

/* ---------- Online-now strip ---------- */
.online-bar {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 10px 0 12px;
}
.online-bar-head {
  display: flex; align-items: center; gap: 7px;
  padding: 0 16px 8px;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .4px;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--unread);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, .25);
}
.online-count {
  margin-inline-start: auto;
  background: var(--panel); color: var(--text-dim);
  border-radius: 9px; min-width: 20px; height: 18px; padding: 0 6px;
  display: grid; place-items: center; font-size: 11px;
}
.online-list {
  list-style: none; display: flex; flex-direction: column;
  max-height: 40vh; overflow-y: auto;
}
.online-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; cursor: pointer;
  transition: background .12s;
}
.online-row:hover { background: var(--hover); }
.online-row .avatar {
  --sz: 42px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--unread);
}
.online-row .or-name {
  flex: 1; min-width: 0; font-weight: 600; font-size: 14.5px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.or-call {
  width: 38px; height: 38px; min-width: 38px;
  border-radius: 50%; display: grid; place-items: center;
  color: var(--accent);
  background: rgba(0, 168, 132, .12);
  transition: background .15s, transform .1s;
}
.or-call:hover { background: var(--accent); color: #fff; }
.or-call:active { transform: scale(.92); }
.or-call svg { width: 19px; height: 19px; }
.or-call .ic-fill { fill: currentColor; stroke: none; }
.or-kick {
  width: 32px; height: 32px; min-width: 32px;
  border-radius: 50%; display: grid; place-items: center;
  color: var(--danger);
  background: rgba(234, 67, 53, .1);
  transition: background .15s, transform .1s;
}
.or-kick:hover { background: var(--danger); color: #fff; }
.or-kick:active { transform: scale(.92); }
.or-kick svg { width: 15px; height: 15px; }
.online-empty { padding: 6px 16px 2px; font-size: 12.5px; color: var(--text-dim); }

/* ---------- Conference selection ---------- */
.conf-toggle {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.conf-toggle svg { width: 17px; height: 17px; }
.conf-toggle:hover { background: var(--hover); color: var(--text); }
.conf-toggle.active { background: var(--accent); color: #fff; }
.conference-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px 10px; font-size: 13px; color: var(--text-dim);
}
.conference-bar #conferenceCount { flex: 1; }
.conf-action {
  padding: 7px 14px; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  transition: opacity .15s;
}
.conf-action:disabled { opacity: .45; cursor: default; }
.conf-cancel { padding: 7px 10px; color: var(--text-dim); font-size: 13px; }
.online-row.selectable { cursor: pointer; }
.select-check {
  width: 22px; height: 22px; min-width: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--bg);
  display: none; place-items: center; color: #fff;
  transition: background .12s, border-color .12s;
}
.select-check svg { width: 13px; height: 13px; }
.online-bar.selecting .select-check { display: grid; }
.online-bar.selecting .or-call { display: none; }
.online-row.checked .select-check { background: var(--accent); border-color: var(--accent); }

.chat-list { list-style: none; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item.selected { background: var(--active); }
.chat-item .avatar { --sz: 46px; }
.ci-body { flex: 1; min-width: 0; }
.ci-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ci-name { font-weight: 600; font-size: 15px; white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.ci-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.ci-preview { font-size: 13px; color: var(--text-dim); white-space: nowrap;
              overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ci-badge {
  background: var(--unread); color: #04101a;
  font-size: 11px; font-weight: 700;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; display: grid; place-items: center;
}
.presence-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--unread); flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg);
}
.presence-dot.off { background: #9aa6ac; }

.sidebar-hint { padding: 24px; text-align: center; color: var(--text-dim);
                font-size: 13px; line-height: 1.7; }

/* ---------- Chat panel ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0;
        background: var(--chat-bg); position: relative; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  color: var(--text-dim);
}
.chat-empty svg { width: 72px; height: 72px; opacity: .35; }

.chat-open { display: flex; flex-direction: column; height: 100%; }

.chat-head {
  height: var(--header-h); min-height: var(--header-h);
  padding-inline: 10px 8px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
}
.chat-head .avatar { --sz: 40px; }
.chat-head .back { display: none; }
.peer-meta { flex: 1; min-width: 0; }
.peer-name { display: block; font-weight: 600; font-size: 15px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { display: block; font-size: 12px; color: var(--text-dim); }
.peer-status.live { color: var(--accent); }
.chat-head-actions { display: flex; gap: 2px; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 14px clamp(12px, 6vw, 90px);
  display: flex; flex-direction: column; gap: 3px;
  background-image:
    radial-gradient(circle at 25% 15%, rgba(0,0,0,.02) 0 2px, transparent 2px),
    radial-gradient(circle at 75% 65%, rgba(0,0,0,.02) 0 2px, transparent 2px);
  background-size: 42px 42px;
}
:root[data-theme="dark"] .messages { background-image:
  radial-gradient(circle at 25% 15%, rgba(255,255,255,.02) 0 2px, transparent 2px),
  radial-gradient(circle at 75% 65%, rgba(255,255,255,.02) 0 2px, transparent 2px); }

.day-sep { align-self: center; margin: 10px 0;
           background: var(--panel); color: var(--text-dim);
           font-size: 12px; padding: 5px 12px; border-radius: 8px;
           box-shadow: var(--shadow-sm); }

.bubble {
  max-width: min(75%, 560px);
  padding: 7px 10px 8px;
  border-radius: 10px;
  font-size: 14.5px; line-height: 1.4;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.bubble.in  { align-self: flex-start; background: var(--bubble-in);
              border-start-start-radius: 3px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out);
              border-start-end-radius: 3px; }
.bubble + .bubble.same { margin-top: -1px; }
.bubble .meta {
  float: inline-end; margin-inline-start: 10px; margin-top: 6px;
  font-size: 10.5px; color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 3px; line-height: 1;
}
.bubble .tick { width: 15px; height: 12px; }
.bubble .tick.read { color: #53bdeb; }

.call-note {
  align-self: center; margin: 8px 0;
  background: var(--panel); color: var(--text-dim);
  font-size: 12.5px; padding: 6px 12px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: var(--shadow-sm);
}
.call-note svg { width: 14px; height: 14px; }
.call-note.missed { color: var(--danger); }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
}
.composer input {
  flex: 1; padding: 11px 16px;
  border: 0; border-radius: 20px;
  background: var(--input); color: var(--text);
  outline: none;
}
.composer input::placeholder { color: var(--text-dim); }
.send {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff;
  transition: transform .1s, filter .15s;
}
.send svg { width: 20px; height: 20px; margin-inline-start: 2px; }
.send:hover { filter: brightness(1.05); }
.send:active { transform: scale(.94); }

/* ---------- Emoji picker ---------- */
.emoji-wrap { position: relative; }
#emojiBtn.active { background: var(--active); color: var(--text); }
.emoji-picker {
  position: absolute; bottom: calc(100% + 10px); inset-inline-start: 0;
  width: 300px; max-height: 260px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px; z-index: 10;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.emoji-picker button {
  font-size: 21px; line-height: 1; padding: 6px 0;
  border-radius: 8px; text-align: center;
}
.emoji-picker button:hover { background: var(--hover); }

/* =========================================================================
   Call overlay
   ========================================================================= */
.call-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #0b141a;
  color: #e9edef;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: max(48px, env(safe-area-inset-top)) 24px max(40px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.local-video { display: none; }
/* Off-screen but never display:none, so autoplaying audio for voice-only
   calls keeps playing on browsers that pause media inside display:none
   ancestors (notably some mobile WebKit builds). */
.audio-sinks { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.call-tiles {
  position: absolute; inset: 0; display: none;
  gap: 2px; background: #000;
}
.call-overlay.video .call-tiles { display: grid; }
.call-tiles.n1 { grid-template-columns: 1fr; }
.call-tiles.n2 { grid-template-columns: 1fr 1fr; }
.call-tiles.n3, .call-tiles.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.call-tiles.n5plus { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.call-tile { position: relative; background: #14202a; overflow: hidden; }
.call-tile video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.call-tile.connecting::after {
  content: 'מתחבר…'; position: absolute; inset: 0;
  display: grid; place-items: center; color: #cdd6db; font-size: 13px;
}
.call-tile.cam-off video { opacity: .12; }
.call-tile .tile-label {
  position: absolute; inset-inline-start: 8px; bottom: 8px; z-index: 1;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px;
  padding: 3px 9px; border-radius: 7px; display: flex; align-items: center; gap: 5px;
}
.call-tile .tile-badge { width: 13px; height: 13px; color: var(--danger); }

.local-video {
  position: absolute; inset-block-start: 20px; inset-inline-end: 20px;
  width: 108px; aspect-ratio: 3/4; object-fit: cover;
  border-radius: 12px; border: 2px solid rgba(255,255,255,.25);
  z-index: 2; background: #222;
}
.call-overlay.video .local-video:not([hidden]) { display: block; }

.call-info {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  margin-top: 6vh; text-align: center;
  transition: opacity .3s;
}
.call-overlay.video .call-info {
  margin-top: 0; background: linear-gradient(rgba(0,0,0,.45), transparent);
  position: absolute; inset-inline: 0; top: 0; padding: 40px 0 30px;
}
.call-overlay.connected.video .call-info { padding: 16px 0 24px; }
.call-overlay.connected.video .call-info h2 { font-size: 16px; }
.call-overlay.connected.video .call-info p { font-size: 12px; }
.call-info h2 { font-size: 24px; font-weight: 600; }
.call-info p { font-size: 15px; color: #cdd6db; letter-spacing: .3px; }
.call-roster { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; max-width: 320px; }
.call-roster .avatar { --sz: 90px; font-size: 34px; box-shadow: var(--shadow); }
.call-overlay.connected .call-roster .avatar { --sz: 40px; font-size: 16px; }
.call-roster.many .avatar { --sz: 56px; font-size: 22px; }
.roster-avatar { position: relative; display: inline-block; }
.roster-badge {
  position: absolute; bottom: -1px; inset-inline-end: -1px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); border: 2px solid #0b141a;
  display: grid; place-items: center; color: #fff;
}
.roster-badge svg { width: 8px; height: 8px; }

.call-controls, .call-incoming {
  position: relative; z-index: 2;
  display: flex; gap: 26px; align-items: center;
}
.call-overlay.video .call-controls {
  position: absolute; inset-inline: 0; bottom: max(40px, env(safe-area-inset-bottom));
}
.call-btn {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,.16);
  color: #fff;
  transition: transform .12s, background .15s;
}
.call-btn svg { width: 28px; height: 28px; }
.call-btn:active { transform: scale(.92); }
.call-btn.active { background: #fff; color: #0b141a; }
.call-btn.accept  { background: #00a884; }
.call-btn.decline, .call-btn.hangup { background: var(--danger); }
.ic-phone-end { transform: rotate(135deg); }

@keyframes ring-pulse {
  0%,100% { transform: scale(1); }
  50%     { transform: scale(1.06); }
}
.call-btn.accept, .call-incoming .call-btn.decline { animation: ring-pulse 1.2s ease-in-out infinite; }

/* =========================================================================
   Mobile
   ========================================================================= */
@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 0; max-width: none;
             border-inline-end: 0; }
  .chat {
    position: absolute; inset: 0; z-index: 20;
    transform: translateX(0);
    transition: transform .22s ease;
  }
  [dir="rtl"] .chat { transform: translateX(-100%); }
  [dir="ltr"] .chat { transform: translateX(100%); }
  body.chat-open .chat { transform: translateX(0); }
  .chat-head .back { display: grid; }
  .messages { padding-inline: 10px; }
  .bubble { max-width: 82%; }
}
