/* ==================================================================
   קשר / app.css
   Dark, high-contrast operational palette. RTL is the only layout
   direction the app is built for.
   ================================================================== */

:root {
  --k-bg: #0b0d10;
  --k-bg-2: #0f1319;
  --k-panel: #141a22;
  --k-panel-2: #1a222c;
  --k-line: #232c38;
  --k-ink: #e9eef6;
  --k-mute: #8b97a8;
  --k-gold: #d4af37;
  --k-gold-soft: rgba(212, 175, 55, 0.14);
  --k-red: #ff453a;
  --k-green: #32d74b;
  --k-amber: #ffd60a;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);

  --topbar-h: 60px;
  --font: "Segoe UI", "Rubik", "Assistant", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  background: var(--k-bg);
  color: var(--k-ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  /* An off-canvas panel must never widen the document. */
  overflow-x: hidden;
}

body {
  font-size: 15px;
  line-height: 1.5;
}

.view { min-height: 100dvh; max-width: 100%; overflow-x: hidden; }
[hidden] { display: none !important; }

/* ------------------- standalone (installed PWA) ------------------- */
/* black-translucent hands us the status-bar strip on iOS, so the shell
   has to pad itself out of the notch instead of sitting under it. The
   class is set from app.js on a home-screen launch. */
html.is-standalone .topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
html.is-standalone .auth-wrap,
html.is-standalone .boot {
  padding-top: calc(24px + env(safe-area-inset-top));
}

/* ---------------------------- boot ---------------------------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, #151b24 0%, var(--k-bg) 70%);
  z-index: 90;
}
.boot-mark {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--k-gold);
}
.boot-sub { color: var(--k-mute); font-size: 13px; }

/* ---------------------------- auth ---------------------------- */

.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 24px;
  gap: 22px;
  background: radial-gradient(circle at 50% 0%, #161d27 0%, var(--k-bg) 60%);
}
.auth-brand { text-align: center; }
.brand-mark {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 8px;
  color: var(--k-gold);
}
.brand-tag { color: var(--k-mute); font-size: 13px; margin: 6px 0 0; }

.auth-card {
  width: min(420px, 92vw);
  background: var(--k-panel);
  border: 1px solid var(--k-line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}
.auth-card.center { text-align: center; }
.auth-card h1 { font-size: 20px; margin: 12px 0 8px; }

.tabs {
  display: flex;
  gap: 6px;
  background: var(--k-bg-2);
  border-radius: var(--r-md);
  padding: 4px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--k-mute);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-on { background: var(--k-gold-soft); color: var(--k-gold); }

.pane { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; font-size: 13px; color: var(--k-mute); }
.field > span { font-weight: 600; }
.field small { font-size: 11px; line-height: 1.4; color: #6f7c8d; }

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--k-line);
  background: var(--k-bg-2);
  color: var(--k-ink);
  font: inherit;
  text-align: right;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--k-gold);
  outline-offset: 1px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--k-mute);
  cursor: pointer;
}
.switch input { width: 18px; height: 18px; accent-color: var(--k-gold); }

.btn {
  padding: 12px 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--k-gold); color: #14100a; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: var(--k-line); color: var(--k-ink); }
.btn-ghost:hover { background: var(--k-panel-2); }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-danger { background: transparent; border-color: rgba(255, 69, 58, 0.5); color: var(--k-red); }

.msg { font-size: 13px; margin: 0; min-height: 18px; }
.msg.err { color: var(--k-red); }
.msg.ok { color: var(--k-green); }
.fineprint { font-size: 11px; color: #6f7c8d; margin: 0; line-height: 1.5; }
.muted { color: var(--k-mute); }
.pending-mark { font-size: 42px; }

/* ---------------------------- app ----------------------------- */

.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--k-panel);
  border-bottom: 1px solid var(--k-line);
  flex: 0 0 auto;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; font-size: 15px; }
.topbar-title small { display: block; font-size: 11px; color: var(--k-mute); }
.topbar-actions { display: flex; gap: 4px; align-items: center; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--k-ink);
  font-size: 17px;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--k-panel-2); }
.icon-btn.send { color: var(--k-gold); }

.net-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--k-green);
  box-shadow: 0 0 8px var(--k-green);
  margin-inline-end: 6px;
}
.net-dot.off { background: var(--k-mute); box-shadow: none; }

/* The positioning context for the off-canvas drawer. `overflow: hidden`
   is what actually clips the closed panel instead of letting it push the
   document sideways. */
.app-body { flex: 1; display: flex; min-height: 0; position: relative; overflow: hidden; }

.drawer {
  width: 268px;
  flex: 0 0 auto;
  background: var(--k-bg-2);
  /* The seam faces the stage: inline-end is the left edge under RTL. */
  border-inline-end: 1px solid var(--k-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.drawer-head { padding: 14px; border-bottom: 1px solid var(--k-line); }
.me { display: flex; align-items: center; gap: 10px; }
.me strong { display: block; font-size: 14px; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-content: center;
  background: var(--k-gold-soft);
  color: var(--k-gold);
  font-weight: 800;
}
.role-badge {
  font-size: 11px;
  color: var(--k-gold);
  background: var(--k-gold-soft);
  padding: 1px 7px;
  border-radius: 999px;
}
.drawer-foot { padding: 12px; border-top: 1px solid var(--k-line); }

.channel-list { flex: 1; overflow-y: auto; padding: 10px; }
.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--k-line);
  border-radius: var(--r-md);
  background: var(--k-panel);
  color: var(--k-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: start;
}
.group-head.is-on, .sub-item.is-on {
  border-color: var(--k-gold);
  background: var(--k-gold-soft);
  color: var(--k-gold);
}
.sub-list { padding-inline-start: 14px; display: grid; gap: 4px; margin-top: 4px; }
.sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--k-mute);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: start;
  width: 100%;
}
.sub-item::before { content: "↳"; opacity: 0.6; }
.sub-item:hover { background: var(--k-panel); }
.lock-tag { margin-inline-start: auto; font-size: 10px; color: var(--k-mute); }
.empty-note { padding: 18px 12px; color: var(--k-mute); font-size: 13px; text-align: center; }

.scrim { display: none; }

/* --------------------------- stage ---------------------------- */

.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.timeline {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: min(78%, 520px);
  padding: 10px 13px;
  border-radius: 16px;
  background: var(--k-panel);
  border: 1px solid var(--k-line);
  align-self: flex-start;
  word-break: break-word;
}
.bubble.mine {
  align-self: flex-end;
  background: var(--k-gold-soft);
  border-color: rgba(212, 175, 55, 0.35);
}
.bubble .meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--k-mute);
  margin-bottom: 4px;
}
.bubble .who { color: var(--k-gold); font-weight: 700; }
.bubble.system {
  align-self: center;
  background: transparent;
  border: 0;
  color: var(--k-mute);
  font-size: 12px;
}

.voice-row { display: flex; align-items: center; gap: 10px; }
.voice-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--k-line);
  background: var(--k-bg-2);
  color: var(--k-gold);
  font-size: 15px;
  cursor: pointer;
  flex: 0 0 auto;
}
.voice-wave { display: flex; gap: 2px; align-items: flex-end; height: 22px; flex: 1; }
.voice-wave i {
  display: block;
  width: 3px;
  background: var(--k-gold);
  opacity: 0.55;
  border-radius: 2px;
}
.voice-dur { font-size: 11px; color: var(--k-mute); font-variant-numeric: tabular-nums; }

/* ----------------------------- PTT ---------------------------- */

.ptt-zone {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 10px 16px 4px;
  border-top: 1px solid var(--k-line);
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.25));
}
.ptt-status { font-size: 12px; color: var(--k-mute); min-height: 18px; font-weight: 600; }
.ptt-hint { font-size: 11px; color: #6f7c8d; }

.ptt {
  position: relative;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.ptt-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--k-line);
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.ptt-core {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  display: grid;
  place-content: center;
  gap: 4px;
  background: radial-gradient(circle at 50% 35%, var(--k-panel-2), var(--k-panel));
  border: 1px solid var(--k-line);
  color: var(--k-ink);
  transition: background 0.18s ease, color 0.18s ease;
}
.ptt-icon { font-size: 34px; }
.ptt-label { font-size: 13px; font-weight: 700; }

.ptt[data-state="requesting"] .ptt-ring {
  border-color: var(--k-amber);
  box-shadow: 0 0 0 6px rgba(255, 214, 10, 0.12);
  animation: pulse 0.9s ease-in-out infinite;
}
.ptt[data-state="transmitting"] .ptt-ring {
  border-color: var(--k-red);
  box-shadow: 0 0 0 10px rgba(255, 69, 58, 0.16), 0 0 34px rgba(255, 69, 58, 0.5);
}
.ptt[data-state="transmitting"] .ptt-core {
  background: radial-gradient(circle at 50% 35%, #52140f, #2a0b09);
  color: #ffd9d6;
}
.ptt[data-state="receiving"] .ptt-ring {
  border-color: var(--k-green);
  box-shadow: 0 0 0 10px rgba(50, 215, 75, 0.14), 0 0 34px rgba(50, 215, 75, 0.45);
  animation: pulse 1.4s ease-in-out infinite;
}
.ptt[data-state="receiving"] .ptt-core {
  background: radial-gradient(circle at 50% 35%, #0f3d1b, #082111);
  color: #d6ffe0;
}
.ptt[data-state="blocked"] .ptt-ring { border-color: var(--k-mute); }
.ptt[data-state="blocked"] .ptt-core { color: var(--k-mute); }
.ptt[disabled] { opacity: 0.45; cursor: not-allowed; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}
@media (prefers-reduced-motion: reduce) {
  .ptt-ring { animation: none !important; }
}

/* -------------------------- composer -------------------------- */

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--k-line);
  background: var(--k-panel);
}
.composer input { flex: 1; }

/* --------------------------- sheets --------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  background: var(--k-bg);
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--k-line);
  background: var(--k-panel);
}
.sheet-head h1 { font-size: 17px; margin: 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 22px; align-content: start; }

.block {
  background: var(--k-panel);
  border: 1px solid var(--k-line);
  border-radius: var(--r-lg);
  padding: 16px;
  display: grid;
  gap: 12px;
}
.block h2 {
  font-size: 14px;
  margin: 0;
  color: var(--k-gold);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  background: var(--k-gold-soft);
  color: var(--k-gold);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11px;
}

.rows { display: grid; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--k-line);
  border-radius: var(--r-md);
  background: var(--k-bg-2);
  flex-wrap: wrap;
}
.row-sub { margin-inline-start: 18px; }
.row .grow { flex: 1; min-width: 120px; }
.row strong { display: block; font-size: 14px; }
.row small { color: var(--k-mute); font-size: 11px; }
.row .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

/* ------------------- super admin command centre ------------------- */
/* Only ever rendered for an active מנהל-על — see ui/super-admin.js.  */

.crown-btn { color: var(--k-gold); font-size: 17px; }
.super .sheet-head {
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.16), var(--k-panel));
  border-bottom-color: rgba(212, 175, 55, 0.35);
}
.super .sheet-head h1 { color: var(--k-gold); }
.super .sheet-head .crown { margin-inline-start: auto; color: var(--k-gold); font-size: 18px; }

.block-alert { border-color: var(--k-line); }
.super.has-pending .block-alert {
  border-color: rgba(255, 214, 10, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 214, 10, 0.12) inset;
}
.super.has-pending .block-alert h2 { color: var(--k-amber); }
.super.has-pending .block-alert .pill { background: rgba(255, 214, 10, 0.16); color: var(--k-amber); }
.row-pending { border-color: rgba(255, 214, 10, 0.35); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
}
.stat {
  background: var(--k-bg-2);
  border: 1px solid var(--k-line);
  border-radius: var(--r-md);
  padding: 10px;
  display: grid;
  gap: 2px;
  text-align: center;
}
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--k-mute); line-height: 1.3; }
.stat.ok b { color: var(--k-green); }
.stat.warn b { color: var(--k-amber); }
.stat.bad b { color: var(--k-red); }

.tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--k-line);
  color: var(--k-mute);
  white-space: nowrap;
}
.tag-ok { border-color: rgba(50, 215, 75, 0.4); color: var(--k-green); }
.tag-warn { border-color: rgba(255, 214, 10, 0.45); color: var(--k-amber); }

.role-super_admin strong { color: var(--k-gold); }

.seg { display: flex; gap: 6px; background: var(--k-bg-2); border-radius: var(--r-md); padding: 4px; }
.seg-item {
  flex: 1;
  padding: 10px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--k-mute);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.seg-item.is-on { background: var(--k-gold-soft); color: var(--k-gold); }

.fingerprint {
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 11px;
  color: var(--k-mute);
  background: var(--k-bg-2);
  border: 1px dashed var(--k-line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  direction: ltr;
  text-align: left;
  word-break: break-all;
}

/* ------------------------ invite links ------------------------ */

/* The minted link, shown in full: clipboard access is refused often
   enough (insecure context, embedded webview) that "copied!" cannot be
   the only way a Super Admin gets the URL out of the app. */
.invite-out {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--k-bg-2);
  border: 1px dashed var(--k-gold);
  border-radius: var(--r-sm);
  padding: 10px;
}
.invite-url {
  flex: 1;
  min-width: 180px;
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 11px;
  color: var(--k-gold);
  direction: ltr;
  text-align: left;
  word-break: break-all;
  user-select: all;
}

.invite-code {
  font-family: ui-monospace, "Consolas", monospace;
  letter-spacing: 0.06em;
  direction: ltr;
  text-align: left;
  user-select: all;
}
.invite-row.is-active { border-color: rgba(212, 175, 55, 0.35); }
/* A spent link is history, not a control — read it, do not reach for it. */
.invite-row:not(.is-active) { opacity: 0.62; }

.invite-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--k-bg-2);
  border: 1px solid var(--k-line);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.invite-banner strong { display: block; font-size: 15px; color: var(--k-gold); }
.invite-banner small { display: block; font-size: 11px; color: var(--k-mute); margin-top: 2px; }
.invite-badge {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  background: var(--k-gold-soft);
  color: var(--k-gold);
  font-size: 18px;
}

.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn[disabled]:hover { background: transparent; filter: none; }

/* ---------------------------- toast --------------------------- */

.toast {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom));
  inset-inline: 0;
  margin-inline: auto;
  width: fit-content;
  max-width: 88vw;
  background: var(--k-panel-2);
  border: 1px solid var(--k-line);
  color: var(--k-ink);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 80;
}
.toast.err { border-color: rgba(255, 69, 58, 0.6); color: #ffb9b4; }
.toast.ok { border-color: rgba(50, 215, 75, 0.5); color: #b9ffcb; }

/* --------------------------- mobile --------------------------- */

@media (max-width: 780px) {
  /* Off-canvas panel. It is anchored to the *inline-start* edge — the
     right-hand side under RTL — because that is the side it occupies in
     the desktop flex row, and because `transform` is physical: a panel
     pinned to the left edge and pushed by translateX(100%) slides INTO
     the viewport rather than out of it. That mismatch was the overflow. */
  .drawer {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(268px, 84vw);
    z-index: 30;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
    /* Closed panels are inert: no focus targets, no stray taps. The
       visibility flip is delayed by the slide so the exit still animates. */
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.24s ease, visibility 0s linear 0.24s;
  }
  html[dir="rtl"] .drawer { transform: translateX(100%); }
  .drawer.is-open {
    transform: translateX(0) !important;
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.24s ease, visibility 0s linear 0s;
  }
  .scrim {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 20;
    animation: scrim-in 0.24s ease;
  }
  .ptt { width: 150px; height: 150px; }
  .timeline { padding: 12px; }
}

@keyframes scrim-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Respect the platform setting — the panel still opens, it just arrives. */
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer.is-open { transition: none; }
  .scrim { animation: none; }
}

@media (max-height: 680px) {
  .ptt { width: 118px; height: 118px; }
  .ptt-icon { font-size: 26px; }
  .ptt-hint { display: none; }
}
