/* ── Variables ─────────────────────────────────────────────── */

@font-face {
  font-family: 'NHaasGroteskTXPro';
  src: url('assets/fonts/NHaasGroteskTXPro-65Md.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --padding-s:      4px;
  --padding-m:      calc(var(--padding-s) * 2);

  --speed-s:        .4s;
  --speed-l:        .8s;

  --color-black:    #000;
  --color-white:    #fff;
  --color-white-10: rgba(100,100,100,.30);

  --radius-s:       8px;
  --radius-m:       calc(var(--radius-s) * 2);

  --font: 'NHaasGroteskTXPro', Helvetica, Arial, sans-serif;
  --fontsize-m:     14px;
  --fontsize-l:     24px;
  --fontweight:     400;

  /* One label row = a text line plus its own padding (+ a little buffer
     for line-height). A video tile must fit the name overlay (top),
     a padding-m gap, and the status overlay (bottom), with a padding-m
     inset at top and bottom. */
  --label-row:       calc(var(--fontsize-m) + var(--padding-m) * 2 + var(--padding-s));
  --tile-min-height: calc(var(--label-row) * 2 + var(--padding-m) * 3);
}


/* ── Reset ─────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font: inherit;
  color: var(--color-white);
}

body {
  font-family: var(--font);
  font-weight: var(--fontweight-m);
  font-size: var(--fontsize-m);
  background: var(--color-black);
  color: var(--color-white);
  height: 100vh;
  height: 100dvh;                            /* respect mobile browser bars */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Keep UI clear of the iPhone notch/island and home indicator */
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);
  font-variant-ligatures: none;              /* Ligaturen aus */
  font-feature-settings: "liga" 0, "clig" 0, "dlig" 0;
}


/* ── Utility ───────────────────────────────────────────────── */

.padding-s {
  padding: var(--padding-s);
}

.padding-m {
  padding: var(--padding-m);
}

.padding-bottom-0 {
    padding-bottom:0px;
}

.padding-top-0 {
    padding-top:0px;
}

.padding-left-0 {
    padding-left:0px;
}

.padding-right-0 {
    padding-right:0px;
}

.gap-s {
  gap: var(--padding-s);
}

.gap-m {
  gap: var(--padding-m);
}

.radius-s {
  border-radius: var(--radius-s);
}

.radius-m {
  border-radius: var(--radius-m);
}

.background-10 {
  background: var(--color-white-10);
}

.blur-m {
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Reusable "bubble" tag/badge — bundles the padding-m / background-10 / radius-s
   trio repeated across the header, footer, status badges and name labels.
   Combine with .blur-m for the translucent overlay badges. */
.bubble {
  padding: var(--padding-m);
  background: var(--color-white-10);
  border-radius: var(--radius-s);
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  align-items: center;
}

.opacity-50 {
  opacity: .5;
}

.text-center {
  text-align: center;
}

.cursor-pointer {
  cursor: pointer;
}

.width-full {
  width: 100%;
}

.btn {
  border: none;
  cursor: pointer;
  appearance: none;
  font-family: var(--font);
  font-size: inherit;
  color: var(--color-white);
}

/* Only on devices with a real pointer — avoids the white hover state
   sticking after a tap on touchscreens. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    background: var(--color-white) !important;
    color: var(--color-black);
    opacity: 1 !important;
  }
}


/* ── Join screen ───────────────────────────────────────────── */

#join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.join-room-display {
  font-size: var(--fontsize-l);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.join-fields {
  max-width: 320px;
}

.field-input {
  border: none;
  outline: none;
}

.field-input::placeholder {
  color: rgba(255,255,255,.5);
}

.field-row {
  display: flex;
}

.field-row .field-input {
  flex: 1;
}

.gen-btn {
  white-space: nowrap;
  flex-shrink: 0;
}


/* ── Waiting screen ────────────────────────────────────────── */

#waiting-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}


/* ── Call screen ───────────────────────────────────────────── */

#call-screen {
  display: none;
  flex: 1;
  min-height: 0;
}

#topbar, #topbar > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  width:100%;
}

/* Outside a call (join & waiting): only the B1B2 tag shows, and the bar has
   no background of its own. The slash + room id and the Arrange/Leave buttons
   appear only once in a call. */
#topbar-actions,
#topbar-room {
  display: none;
}

body.in-call #topbar-actions,
body.in-call #topbar-room {
  display: flex;
}

/* "Website" link: shown on join & waiting, hidden once in a call. */
#website-btn {
  text-decoration: none;
}

body.in-call #website-btn {
  display: none;
}

body:not(.in-call) #topbar > div {
  background: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Footer buzzword tags — mirrors the top bar: shown on join & waiting,
   hidden once in a call. Tags wrap and stay centered on narrow screens. */
#footer {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  width: 100%;
}

#footer-tags {
  flex-wrap: wrap;
  justify-content: center;
}

body.in-call #footer {
  display: none;
}


/* ── Grid stage ────────────────────────────────────────────── */

#grid-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}


/* ── Grid tiles ────────────────────────────────────────────── */

.grid-tile {
  position: absolute;
  border-radius: var(--radius-m);
  overflow: hidden;
  background: var(--color-white-10);
  cursor: grab;
  user-select: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.grid-tile.dragging {
  opacity: .8;
  cursor: grabbing;
}

/* Fit the name (top) + status (bottom) overlays with a padding-m gap */
.grid-tile[data-kind="cam"],
.grid-tile[data-kind="screen"] {
  min-height: var(--tile-min-height);
}

.tile-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.grid-tile video {
  width: 100%;
  height: 100%;
  display: block;
  opacity:0.9;
}

.grid-tile[data-kind="cam"] video {
  object-fit: cover;
}

.grid-tile[data-kind="screen"] video {
  object-fit: contain;
}

#local-video {
  transform: scaleX(-1);
}

.grid-tile.cam-off video {
  display: none;
}

.video-label {
  position: absolute;
  top: var(--padding-m);
  left: var(--padding-m);
  right: var(--padding-m);
}

.video-status {
  position: absolute;
  bottom: var(--padding-m);
  left: var(--padding-m);
  right: var(--padding-m);
}

/* Active-speaker indicator: while this tile's participant is talking, their
   name label flips to a solid white "header" with black text. Voice activity
   is detected in voice.js, which toggles .speaking on the tile. */
.video-label .bubble {
  transition: background var(--speed-s), color var(--speed-s);
}

.grid-tile.speaking .video-label .bubble {
  background: var(--color-white);
  color: var(--color-black);
}


/* ── Resize handles (8 directions) ─────────────────────────── */

.tile-resize-n, .tile-resize-s,
.tile-resize-e, .tile-resize-w,
.tile-resize-ne, .tile-resize-nw,
.tile-resize-se, .tile-resize-sw {
  position: absolute;
  z-index: 10;
}

.tile-resize-n {
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  cursor: n-resize;
}

.tile-resize-s {
  bottom: 0;
  left: 0;
  right: 0;
  height: 8px;
  cursor: s-resize;
}

.tile-resize-e {
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  cursor: e-resize;
}

.tile-resize-w {
  top: 0;
  left: 0;
  bottom: 0;
  width: 8px;
  cursor: w-resize;
}

.tile-resize-ne,
.tile-resize-nw,
.tile-resize-se,
.tile-resize-sw {
  width: 12px;
  height: 12px;
  z-index: 11;
}

.tile-resize-ne {
  top: 0;
  right: 0;
  cursor: ne-resize;
}

.tile-resize-nw {
  top: 0;
  left: 0;
  cursor: nw-resize;
}

.tile-resize-se {
  bottom: 0;
  right: 0;
  cursor: se-resize;
}

.tile-resize-sw {
  bottom: 0;
  left: 0;
  cursor: sw-resize;
}


/* ── Resize handle hover indicators ────────────────────────── */

.tile-resize-e::after, .tile-resize-w::after,
.tile-resize-n::after, .tile-resize-s::after {
  content: '';
  position: absolute;
  border-radius: var(--radius-s);
  background: rgba(255,255,255,0);
  transition: background var(--speed-s);
}

.tile-resize-e::after, .tile-resize-w::after {
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
}

.tile-resize-e::after {
  right: 8px;
}

.tile-resize-w::after {
  left: 8px;
}

.tile-resize-n::after, .tile-resize-s::after {
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 4px;
}

.tile-resize-n::after {
  top: 8px;
}

.tile-resize-s::after {
  bottom: 8px;
}

.tile-resize-e:hover::after, .tile-resize-w:hover::after,
.tile-resize-n:hover::after, .tile-resize-s:hover::after {
  background: rgba(255,255,255,.5);
}

.tile-resize-ne::after, .tile-resize-nw::after,
.tile-resize-se::after, .tile-resize-sw::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0);
  transition: background var(--speed-s);
}

.tile-resize-ne::after {
  top: 12px;
  right: 12px;
}

.tile-resize-nw::after {
  top: 12px;
  left: 12px;
}

.tile-resize-se::after {
  bottom: 12px;
  right: 12px;
}

.tile-resize-sw::after {
  bottom: 12px;
  left: 12px;
}

.tile-resize-ne:hover::after, .tile-resize-nw:hover::after,
.tile-resize-se:hover::after, .tile-resize-sw:hover::after {
  background: rgba(255,255,255,.5);
}


/* ── Knocker overlay ───────────────────────────────────────── */

#knocker-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--padding-m);
  pointer-events: none;
  z-index: 100;
}

.knocker-tile {
  width: 320px;
  background: var(--color-white-10);
  border-radius: var(--radius-m);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: var(--padding-m);
  padding: var(--padding-m);
}


/* ── Chat tile ─────────────────────────────────────────────── */

#chat-tile {
  cursor: default;
  min-height:200px;
}

.sidebar-tabs {
  flex-shrink: 0;
  cursor: grab;
}

.sidebar-tabs:active {
  cursor: grabbing;
}

.stab {
  flex: 1;
}

.stab.active {
  opacity: 1;
}

.pane {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pane.visible {
  display: flex;
}


/* ── Controls ──────────────────────────────────────────────── */

#controls, #controls > div {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width:100%;
}

.ctrl {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ctrl.active,
.ctrl:not(.muted) {
 opacity:1;
}

/* Screen-share is the inverse of mic/sound/cam: it's OFF by default, so the
   button stays greyed out until you're actually sharing (gets .active). The
   #id beats the generic .ctrl:not(.muted) opacity:1 rule above. */
#screen-btn:not(.active) {
 opacity: .5;
}

#leave-btn {
 background: rgba(255, 0, 0, 0.3);
}


/* ── Chat ──────────────────────────────────────────────────── */

#chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* The chat tile is a .grid-tile (user-select: none) — re-enable selection
     here so messages can be highlighted/copied. Dragging the tile is bound to
     the tab bar only, so this doesn't interfere with moving the tile. */
  user-select: text;
  -webkit-user-select: text;
  cursor: auto;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: var(--padding-s);
}

.msg-sender {
  opacity: .5;
  padding-left: var(--padding-m);
  padding-right: var(--padding-m);
}

.msg-text {
  max-width: 80%;
  align-self: flex-start;
  overflow-wrap: anywhere;       /* long URLs wrap instead of overflowing */
}

.msg-text a {
  color: inherit;
  text-decoration: underline;
}

.msg.own {
  align-items: flex-end;
}

.msg.own .msg-text {
  background: rgba(100,100,100,.30);
  align-self: flex-end;
}

.msg-system {
  padding-left: var(--padding-m);
  padding-right: var(--padding-m);
}

#chat-input-area {
  display: flex;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
}

#chat-input::placeholder {
  color: rgba(255,255,255,.5);
}

.send-btn {
  flex-shrink: 0;
}


/* ── People ────────────────────────────────────────────────── */

#people-pane {
  overflow-y: auto;
  min-height: 0;
}

.person {
  justify-content: space-between;
}

.person-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: var(--padding-m);
}

.status-icon {
  white-space: nowrap;
}

/* ── Mobile ────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .grid-tile {
    cursor: default;
  }

  .tile-resize-n, .tile-resize-s,
  .tile-resize-e, .tile-resize-w,
  .tile-resize-ne, .tile-resize-nw,
  .tile-resize-se, .tile-resize-sw {
    display: none;
  }

  /* Join screen fills the width on mobile */
  #join-screen {
    padding-left:  var(--padding-m);
    padding-right: var(--padding-m);
  }

  #join-screen .join-room-display,
  #join-screen .join-fields {
    max-width: none;
  }

  /* Let mobileLayout fully control the chat height (35% of stage) */
  #chat-tile {
    min-height: 0;
  }

  /* Arrange is desktop-only — mobile is always auto-layout */
  #arrange-btn {
    display: none;
  }

  /* Screen share is desktop-only */
  #screen-btn {
    display: none;
  }

  /* Inputs at 16px stop iOS Safari from auto-zooming on focus */
  input {
    font-size: 16px;
  }
}
