:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #17202c;
  --muted: #657386;
  --line: #d9e1ea;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --blue: #2563eb;
  --red: #b42318;
  --amber: #a15c07;
  --green: #0f8a5f;
  --stage: #10151d;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 13px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

button.secondary {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
}

button.secondary:hover {
  background: #eef3f8;
}

button.danger {
  background: var(--red);
}

a,
.link-button {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
}

.link-button {
  height: auto;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
}

.link-button:hover {
  background: transparent;
  text-decoration: underline;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(880px, 100%);
  display: grid;
  gap: 18px;
}

.auth-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}

.auth-panel {
  width: 100%;
  display: grid;
  align-content: start;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 14px 35px rgba(23, 32, 44, .08);
}

.auth-panel-primary {
  border-color: rgba(15, 118, 110, .45);
  box-shadow: 0 14px 35px rgba(15, 118, 110, .11);
}

.auth-panel h1 {
  margin: 12px 0 0;
  font-size: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 800;
}

.brand span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  letter-spacing: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.legal-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.legal-note a {
  font-weight: 700;
}

@media (max-width: 760px) {
  .auth-options {
    grid-template-columns: 1fr;
  }
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.app.viewer-only {
  grid-template-columns: minmax(0, 1fr);
}

aside {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  border-right: 1px solid var(--line);
  padding: 18px;
  background: var(--panel);
}

.device-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.device-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.device-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfdff;
  color: var(--ink);
  text-align: left;
}

.device-card.active {
  border-color: rgba(15, 118, 110, .6);
  box-shadow: inset 3px 0 0 var(--brand);
}

.device-card.offline {
  opacity: .72;
}

.device-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.device-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  align-self: start;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.online {
  background: #e6f7ef;
  color: var(--green);
}

.side-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 13px;
}

main {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: rgba(255, 255, 255, .94);
}

.topbar-heading {
  min-width: 0;
}

.menu-toggle {
  display: none;
}

.menu-toggle span {
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.secondary-action {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 13px;
  background: #f8fafc;
  color: var(--ink);
}

.secondary-action:hover {
  background: #eef3f8;
  text-decoration: none;
}

.top-actions select {
  width: clamp(240px, 26vw, 340px);
  max-width: 100%;
}

.viewer-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 14px;
  background: var(--stage);
}

#screenCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border: 1px solid rgba(255, 255, 255, .12);
  background: #05080d;
  outline: none;
}

#screenCanvas:focus {
  border-color: rgba(56, 189, 248, .85);
}

.empty-state {
  position: absolute;
  display: grid;
  gap: 6px;
  place-items: center;
  color: #cbd5e1;
  text-align: center;
}

.empty-state strong {
  color: #fff;
}

.statusbar {
  display: flex;
  gap: 18px;
  border-top: 1px solid var(--line);
  padding: 8px 18px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-dialog {
  width: min(900px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 32px));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}

.file-dialog[open] {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
}

.file-dialog::backdrop {
  background: rgba(15, 23, 42, .55);
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 18px 20px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.file-toolbar {
  display: grid;
  grid-template-columns: minmax(150px, 220px) auto auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 14px 20px 8px;
}

.file-toolbar #dialogSendFilesBtn {
  justify-self: end;
}

.remote-path {
  overflow: hidden;
  margin: 4px 20px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  background: #f8fafc;
  font-family: Consolas, monospace;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status {
  min-height: 25px;
  padding: 3px 20px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.remote-file-list {
  overflow: auto;
  border-top: 1px solid var(--line);
}

.remote-file-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 90px 175px 96px;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid #edf1f5;
  padding: 6px 20px;
  color: var(--muted);
  font-size: 12px;
}

.remote-file-row:hover {
  background: #f8fafc;
}

button.remote-file-name {
  overflow: hidden;
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.remote-file-name:hover {
  background: transparent;
  color: var(--blue);
}

button.compact {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.transfer-panel {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: 16px;
  width: min(390px, calc(100vw - 32px));
  max-height: min(440px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15, 23, 42, .22);
}

.transfer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 11px 13px;
}

.transfer-list {
  overflow: auto;
}

.transfer-row {
  display: grid;
  gap: 5px;
  border-bottom: 1px solid #edf1f5;
  padding: 10px 13px;
}

.transfer-row.failed .transfer-detail {
  color: var(--red);
}

.transfer-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transfer-detail {
  color: var(--muted);
  font-size: 11px;
}

.transfer-row progress {
  width: 100%;
  height: 7px;
  accent-color: var(--brand);
}

.drop-overlay {
  position: fixed;
  z-index: 100;
  inset: 18px;
  display: grid;
  place-items: center;
  border: 3px dashed #5eead4;
  border-radius: 18px;
  background: rgba(15, 118, 110, .9);
  color: #fff;
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

.toast {
  position: fixed;
  z-index: 110;
  left: 50%;
  bottom: 24px;
  max-width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 11px 15px;
  background: #17202c;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  font-size: 13px;
  font-weight: 700;
}

.toast.error {
  background: var(--red);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  aside {
    max-height: 44vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  main {
    min-height: 56vh;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px), (pointer: coarse) and (max-width: 900px) {
  .device-tools,
  .device-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    gap: 10px;
    padding: 12px 16px;
  }

  .topbar-heading {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .topbar-heading > div {
    min-width: 0;
  }

  .topbar-heading h1,
  .topbar-heading p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu-toggle {
    width: 44px;
    min-width: 44px;
    height: 40px;
    display: inline-grid;
    place-content: center;
    gap: 4px;
    padding: 0;
  }

  .top-actions {
    display: none;
  }

  .top-actions.menu-open {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions,
  .top-actions select,
  .top-actions button {
    width: 100%;
  }

  .statusbar {
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .file-dialog {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
  }

  .file-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .file-toolbar #dialogSendFilesBtn,
  .file-toolbar select {
    width: 100%;
    justify-self: stretch;
  }

  .remote-file-row {
    grid-template-columns: minmax(0, 1fr) 88px;
  }

  .remote-file-row > span {
    display: none;
  }
}

/* Home-screen and touch viewer */
.mobile-controls { display: none; }
.touch-control-icon { width: 22px; height: 22px; display: block; margin: auto; pointer-events: none; }
.touch-cursor { position: absolute; z-index: 3; width: 32px; height: 32px; border: 0; background: transparent; pointer-events: none; filter: drop-shadow(0 1px 1px #ffffff80); }
.touch-cursor[hidden] { display: none; }
.install-app { margin-top: 16px; }
@media (pointer: coarse), (max-width: 560px) {
  .app.viewer-only main { height: var(--viewer-height, 100dvh); min-height: 0; grid-template-rows: auto minmax(80px, 1fr) auto auto; }
  .viewer-stage { padding: 4px; min-height: 0; }
  #screenCanvas { touch-action: none; user-select: none; -webkit-user-select: none; }
  .mobile-controls { display: block; background: var(--panel); padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); max-height: min(45dvh, 360px); overflow: auto; }
  .touch-actions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .touch-actions button { flex-shrink: 0; min-height: 44px; }
  .touch-actions button[aria-pressed="true"] { color: white; background: var(--brand); }
  .touch-help { margin: 4px 0; font-size: 12px; color: var(--muted); }
  input, select { font-size: 16px; }
  .statusbar { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .toast { bottom: max(24px, env(safe-area-inset-bottom)); }
}
/* Compact touch controls; keep the remote surface usable above the native keyboard. */
.touch-panel[hidden], .touch-help[hidden], .touch-drag-notice[hidden] { display: none; }
.touch-drag-notice { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5; min-height: 44px; background: #9a3412; color: white; }
@media (pointer: coarse), (max-width: 560px) {
  .app.viewer-only main { grid-template-rows: auto minmax(60px, 1fr) auto; overflow: hidden; }
  .app.viewer-only { min-height: 0; height: var(--viewer-height, 100dvh); }
  .viewer-stage { touch-action: none; }
  .statusbar { display: none; }
  .topbar { padding: max(4px, env(safe-area-inset-top)) 10px 4px; gap: 4px; flex-wrap: wrap; }
  .topbar-heading { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; }
  .topbar-heading > div { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .topbar h1 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar #statusText { margin: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-toggle { display: inline-grid; width: 44px; min-width: 44px; height: 44px; place-content: center; gap: 4px; padding: 0; }
  .top-actions { display: none; }
  .top-actions.menu-open { display: grid; width: 100%; max-height: 50dvh; overflow: auto; }
  .mobile-controls { position: relative; padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); max-height: 55%; overflow: auto; }
  .touch-primary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .touch-primary button { min-width: 0; min-height: 44px; padding: 8px 3px; font-size: 13px; }
  .mobile-controls button { background: #f1f5f9; color: var(--ink); border: 1px solid var(--line); }
  .mobile-controls button[aria-pressed="true"], .touch-primary button[aria-expanded="true"] { background: var(--brand); color: white; }
  .touch-panel { padding-top: 8px; font-size: 13px; }
  .touch-panel p { margin: 6px 0; }
  .touch-panel summary { padding: 10px 0; cursor: pointer; }
  .touch-actions { flex-wrap: wrap; overflow: visible; align-items: center; }
  .touch-actions button { min-width: 44px; padding: 8px 10px; }
  #touchKeys .touch-actions { flex-wrap: nowrap; overflow-x: auto; }
  /* Keep a focusable input for the native keyboard without a visible typing box. */
  #touchTyping { position: absolute; width: 1px; height: 1px; min-width: 0; min-height: 0; padding: 0; margin: 0; border: 0; opacity: 0; pointer-events: none; font: 16px system-ui; resize: none; }
  .touch-help { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
  .touch-help button { flex-shrink: 0; min-height: 44px; }
}
@media (pointer: coarse) and (orientation: landscape) and (min-width: 561px) {
  .app.viewer-only main { grid-template-columns: minmax(0, 1fr) 86px; grid-template-rows: auto minmax(60px, 1fr); }
  .topbar { grid-column: 1 / -1; }
  .viewer-stage { grid-column: 1; grid-row: 2; }
  .mobile-controls { grid-column: 2; grid-row: 2; max-height: none; overflow: visible; }
  .touch-primary { grid-template-columns: 1fr; }
  .touch-panel, .touch-help { position: absolute; right: 100%; bottom: 0; width: min(360px, 65vw); max-height: 100%; overflow: auto; background: var(--panel); padding: 10px; z-index: 6; border: 1px solid var(--line); border-radius: 8px 0 0 8px; }
}
.touch-cursor, .touch-drag-notice { display: none; }
@media (pointer: coarse), (max-width: 560px) {
  .touch-cursor:not([hidden]), .touch-drag-notice:not([hidden]) { display: block; }
  .mobile-controls { max-height: min(55dvh, 420px); }
}
@media (pointer: coarse) and (orientation: landscape) and (min-width: 561px) {
  .mobile-controls { max-height: none; }
}
/* Account home for installed clients and visits without a host link. */
.device-browser[hidden] { display: none; }
.device-browser { padding: 24px; overflow: auto; background: #f5f7fb; min-height: 0; }
.device-browser-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.device-browser h2 { margin: 0; font-size: 24px; }
.device-browser-heading p, #deviceBrowserStatus { color: var(--muted); font-size: 14px; }
.device-search-label { display: block; margin: 18px 0 6px; font-weight: 600; }
#deviceSearch { width: 100%; min-height: 46px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: white; }
.host-group { margin: 16px 0; }
.host-group > summary { padding: 12px 0; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.host-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.host-card { display: grid; gap: 8px; padding: 18px; text-align: left; min-width: 0; background: white; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; overflow-wrap: anywhere; }
.host-card.host-online { background: #f0fdf4; border-color: #86cfa4; border-left: 5px solid #15803d; }
.host-card.host-offline { background: #eef1f5; border-color: #cbd5e1; border-left: 5px solid #94a3b8; color: #526174; }
.host-card:hover:not(:disabled) { background: #eaf6f4; border-color: var(--brand); }
.host-card:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.host-card:disabled { opacity: 1; cursor: default; }
.host-card-meta { font-size: 13px; color: var(--muted); }
.host-card-status { display: inline-flex; align-items: center; justify-self: start; gap: 7px; padding: 5px 10px; border-radius: 999px; background: #e2e8f0; color: #475569; font-size: 13px; font-weight: 700; }
.host-card-status::before { content: ""; width: 9px; height: 9px; flex-shrink: 0; border: 2px solid currentColor; border-radius: 50%; box-sizing: border-box; }
.host-card-status.online { background: #dcfce7; color: #166534; }
.host-card-status.online::before { background: currentColor; }
.browsing-devices .viewer-stage, .browsing-devices .mobile-controls, .browsing-devices .statusbar,
.browsing-devices #viewerMenu > :not(#logoutBtn):not(.install-app) { display: none; }
#deviceSelect { display: none; }
.app.viewer-only.browsing-devices main { height: var(--viewer-height, 100dvh); min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.browsing-devices .device-browser { grid-column: 1; grid-row: 2; }
@media (max-width: 560px) { .device-browser { padding: 18px 14px max(18px, env(safe-area-inset-bottom)); } }
.connect-by-id { margin: 20px 0; border: 1px solid var(--line); border-radius: 12px; background: white; }
.connect-by-id > summary { padding: 16px; font-weight: 700; cursor: pointer; }
.quick-connect-form { display: grid; gap: 10px; padding: 0 16px 12px; max-width: 480px; }
.quick-connect-form p { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.quick-connect-form input { min-width: 0; width: 100%; min-height: 44px; font: inherit; font-size: 16px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.quick-connect-form button { min-height: 44px; }
/* Keep the remote viewer anchored above the mobile software keyboard. */
html.remote-viewport, html.remote-viewport body { overflow: hidden; overscroll-behavior: none; }
.remote-viewport .app.viewer-only { position: fixed; top: var(--viewer-top, 0px); left: 0; right: 0; height: var(--viewer-height, 100dvh); min-height: 0; overflow: hidden; }
.remote-viewport .mobile-controls { max-height: calc(var(--viewer-height, 100dvh) * .55); overscroll-behavior: contain; }
@media (pointer: coarse) and (orientation: landscape) and (min-width: 561px) {
  .remote-viewport .mobile-controls { max-height: none; }
}
