/* --- Mobile & Responsive Layout --- */
.mobile-top {
  display: none;
}

.side-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.side-close-btn {
  display: none;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  place-items: center;
}

.mobile-inspect-bar {
  display: none;
}

.side-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(11, 34, 51, 0.58);
  backdrop-filter: blur(3px);
}

/* --- Virtual Trackpad Cursor & Mobile Mouse Bar --- */
#remote-stage {
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#remote-view {
  transform-origin: center center;
  will-change: transform;
}

.virtual-cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 30;
  width: 28px;
  height: 28px;
  pointer-events: none;
  transform-origin: 4px 3px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.65));
}

.virtual-cursor[hidden] {
  display: none;
}

.virtual-cursor-spot {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #2ef2e6;
  opacity: 0;
  transform: scale(0.4);
  pointer-events: none;
}

.virtual-cursor.clicking .virtual-cursor-spot {
  animation: cursor-ripple 280ms ease-out;
}

@keyframes cursor-ripple {
  0% {
    opacity: 0.95;
    transform: scale(0.4);
  }
  100% {
    opacity: 0;
    transform: scale(1.9);
  }
}

.mobile-mouse-pad {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(14, 40, 56, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.mobile-mouse-pad[hidden] {
  display: none;
}

.mouse-pad-btn {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f7fa;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.mouse-pad-btn:active {
  background: #1c8f8c;
  border-color: #2ef2e6;
  color: #fff;
}

@media (max-width: 980px) {
  body:has(.console) {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }

  .mobile-top {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #0e2838;
    color: #f4f7fa;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .mobile-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-quick-btn {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.22);
    color: #fff;
    padding: 5px 10px;
    text-decoration: none;
  }

  .mobile-menu-btn {
    border: 1px solid rgba(255, 255, 255, 0.24);
    background: #173044;
    color: #fff;
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
  }

  .side {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    z-index: 100;
    width: min(290px, 84vw);
    min-height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    transform: translateX(105%);
    transition: transform 220ms ease;
    box-shadow: -12px 0 36px rgba(11, 34, 51, 0.45);
  }

  body.side-open {
    overflow: hidden;
  }

  body.side-open .side {
    transform: translateX(0);
  }

  .side-close-btn {
    display: grid;
  }

  .app-shell {
    flex-direction: column;
    min-height: calc(100dvh - 57px);
  }

  .console {
    display: block;
    position: relative;
  }

  .list-pane {
    min-height: calc(100dvh - 57px);
    border-inline: 0;
  }

  .inspect {
    display: none;
    position: fixed;
    inset: 57px 0 0 0;
    z-index: 70;
    background: #f7fafb;
    overflow-y: auto;
    padding: 12px 14px 32px;
  }

  body.inspect-open {
    overflow: hidden;
  }

  body.inspect-open .inspect {
    display: block;
  }

  .mobile-inspect-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-inspect-bar .chip-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
}

@media (max-width: 680px) {
  h1 {
    font-size: 22px;
  }

  .top {
    padding: 10px 12px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand small {
    font-size: 11px;
  }

  .gate {
    width: calc(100% - 20px);
    margin: 16px auto 28px;
    border-radius: 18px;
    grid-template-columns: 1fr;
  }

  .gate-side {
    padding: 20px 18px;
  }

  .gate-side h1 {
    font-size: 22px;
  }

  .gate .form {
    padding: 20px 16px;
  }

  .join-code-input {
    font-size: 22px;
    letter-spacing: 5px;
    padding: 10px 12px;
  }

  .list-head {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .list-head h1 {
    flex: 1 0 100%;
    font-size: 16px;
  }

  .list-head .tool {
    flex: 1 1 auto;
    justify-content: center;
    padding: 8px 10px;
    font-size: 13px;
  }

  .list-head .find {
    width: 100%;
    order: 3;
  }

  .machine {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
  }

  .machine-services {
    flex-wrap: wrap;
  }

  /* Compact connection indicator on mobile so machine names never get squished */
  .conn {
    min-width: auto;
    gap: 6px;
  }

  .conn-ico,
  .conn-screen,
  .conn-line {
    display: none;
  }

  .conn-track {
    width: auto;
    height: auto;
  }

  .conn-label {
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef3f6;
    font-size: 11px;
  }

  .conn.st-online .conn-label {
    background: #e7f6ef;
    color: var(--up);
  }

  .conn.st-offline .conn-label {
    background: #fdecee;
    color: var(--down);
  }

  .live-tools {
    flex-wrap: wrap;
  }

  .chip-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .page {
    width: calc(100% - 20px);
    margin: 16px auto 32px;
  }

  .panel {
    padding: 14px;
    border-radius: 14px;
  }

  .modal,
  .modal-wide,
  .modal-remote {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    border-radius: 16px;
  }

  .modal-sheet {
    max-height: 90dvh;
    padding: 10px;
  }

  .log-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .log-filters {
    flex-wrap: wrap;
  }

  .log-table-wrap {
    height: 58dvh;
  }

  .remote-bar {
    padding: 6px 8px;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .remote-bar .session-row {
    flex-wrap: nowrap;
    flex: none;
  }

  .remote-bar .session-chip {
    white-space: nowrap;
    flex: none;
    padding: 6px 10px;
  }

  .remote-bar .quality-label span {
    display: none;
  }

  body.remote-window {
    height: 100dvh;
  }

  .stage-fill {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: none;
  }

  .stage-fill.stage-zoomed {
    place-items: start;
    touch-action: pan-x pan-y;
  }

  .stage-fill.stage-zoomed canvas {
    max-width: none;
    max-height: none;
  }

  /* Responsive Users & Groups tables on phones */
  .users-table th:nth-child(4),
  .users-table td:nth-child(4),
  .users-table th:nth-child(5),
  .users-table td:nth-child(5) {
    display: none;
  }

  .users-table th,
  .users-table td {
    padding: 10px 6px;
    font-size: 13px;
  }

  .user-actions {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* --- AnyDesk-style mobile remote: immersive layout, keys bar, chrome --- */
body.remote-window {
  /* Reclaim the whole phone screen and respect the notch/home-indicator. */
  height: 100svh;
  height: 100dvh;
  overscroll-behavior: none;
  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);
  box-sizing: border-box;
}

body.remote-window.ios-fullscreen {
  /* iOS Safari has no Fullscreen API on iPhone; this is the CSS fallback. */
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
}

body.remote-window.chrome-hidden .remote-bar,
body.remote-window.chrome-hidden .remote-keys-bar,
body.remote-window.chrome-hidden .remote-clip {
  display: none;
}

.remote-keys-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #0d1c2c;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.remote-keys-bar[hidden] {
  display: none;
}

.remote-keys-bar::-webkit-scrollbar {
  display: none;
}

.key-chip {
  flex: none;
  min-width: 42px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #eef4f8;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.key-chip:active {
  background: #1c8f8c;
  border-color: #2ef2e6;
}

.key-chip.armed {
  background: #1c8f8c;
  border-color: #2ef2e6;
  color: #fff;
  box-shadow: 0 0 0 2px rgba(46, 242, 230, 0.4);
}

.remote-chrome-toggle {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  inset-inline-start: calc(8px + env(safe-area-inset-left));
  z-index: 45;
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(13, 28, 44, 0.82);
  color: #eef4f8;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

@media (max-width: 980px) {
  body.remote-window.chrome-hidden .remote-chrome-toggle {
    display: inline-flex;
  }

  .remote-kbd-btn.on,
  #remote-keys-btn.on {
    background: #173044;
    color: #fff;
  }
}

/* Landscape phones: trim vertical chrome so the view gets the height. */
@media (max-width: 980px) and (orientation: landscape) {
  body.remote-window .remote-bar {
    padding: 4px 8px;
  }

  .remote-keys-bar {
    padding: 4px 8px;
  }

  .key-chip {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 13px;
  }

  .mobile-mouse-pad {
    bottom: 8px;
  }
}

/* --- PWA install hint --- */
.pwa-install-hint {
  position: fixed;
  z-index: 80;
  inset-inline: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  max-width: 520px;
  margin-inline: auto;
  padding: 12px 14px;
  background: #0b2233;
  color: #f4f7fa;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(11, 34, 51, 0.35);
}

.pwa-install-hint p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
}

.pwa-install-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.pwa-install-btn {
  border: 0;
  background: #0d7f78;
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.pwa-install-btn:hover {
  background: #15968e;
}

.pwa-install-dismiss {
  border: 0;
  background: transparent;
  color: #9eb0be;
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.pwa-install-dismiss:hover {
  color: #f4f7fa;
}


/* --- Mobile remote toolbar: icon-only chips, no horizontal scroll --- */
@media (max-width: 980px) {
  /* Hide every chip's text label; keep the icon and a monitor's number.
     The title / aria-label still carries the full label as a tooltip. */
  .remote-bar .session-chip.with-ico > span:not(.chip-num) {
    display: none;
  }

  .remote-bar {
    gap: 4px;
    padding: 6px;
  }

  .remote-bar .session-chip.with-ico {
    /* >=44px tap target (Apple HIG) so taps register on a phone. */
    min-height: 44px;
    min-width: 44px;
    padding: 5px 9px;
    gap: 2px;
    justify-content: center;
  }

  .remote-bar .session-chip:not(.with-ico) {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .remote-chrome-toggle,
  .mouse-pad-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .remote-toast-close {
    min-height: 40px;
    min-width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .remote-bar .chip-num {
    font-size: 11px;
    margin-inline-start: 1px;
  }

  .remote-bar .chip-badge {
    font-size: 11px;
    font-weight: 700;
    margin-inline-start: 1px;
  }

  /* Quality: one cycling button instead of three text chips. */
  .remote-bar #remote-quality [data-quality],
  .remote-bar #remote-quality .quality-label {
    display: none;
  }

  .remote-bar #remote-quality .quality-cycle {
    display: inline-flex;
  }

  /* Desktop-only ScreenConnect chrome stays out of the compact phone bar. */
  .remote-menu-toggle,
  .remote-bar-sep,
  .remote-site-name,
  .remote-live-user,
  .menu-caret,
  .remote-status-dot {
    display: none !important;
  }

  .remote-bar-inner,
  .remote-bar-group,
  .remote-menu,
  .remote-menu-panel {
    display: contents;
  }

  .remote-status-dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e6b33a;
    box-shadow: 0 0 0 3px rgba(230, 179, 58, 0.22);
  }

  .remote-status-dot[data-state="live"] {
    background: #2ee6a8;
    box-shadow: 0 0 0 3px rgba(46, 230, 168, 0.22);
  }

  .remote-status-dot[data-state="down"] {
    background: #e85b5b;
    box-shadow: 0 0 0 3px rgba(232, 91, 91, 0.25);
  }

  /* Keep the short connection status on one line, never a tall column. */
  .remote-title {
    max-width: 38vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .remote-toast {
    font-size: 13px;
  }

  /* Remote frame: centre it (no dead space at the top) and let the trackpad
     transform size it for fit/fill + pan. */
  .stage-fill:not(.stage-zoomed) {
    place-items: center;
    overflow: hidden;
  }

  .stage-fill canvas {
    max-width: none;
    max-height: none;
  }
}
