:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #20242d;
  --border: #2b303b;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --toolbar-h: 48px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0 0 .4em; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
p { margin: .4em 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.version { text-align: center; margin-top: 10px; }
.error { color: #fca5a5; background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35); padding: .5em .75em; border-radius: 8px; }
[hidden] { display: none !important; }

/* ---------- dashboard ---------- */
.page { min-height: 100vh; min-height: 100dvh; padding-top: var(--sat); padding-bottom: var(--sab); }
.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; }
label { font-size: .9rem; color: var(--muted); margin-top: 8px; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.btn {
  font: inherit; font-weight: 600; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; cursor: pointer;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #3a4150; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { color: #fecaca; border-color: rgba(239, 68, 68, .5); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn.big { min-height: 52px; font-size: 1.05rem; margin-top: 14px; text-decoration: none; }
.home-card { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row .btn { flex: 1 1 auto; }
.status-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; font-size: .92rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-right: 4px; vertical-align: middle; }
.dot.good { background: var(--ok); }
.dot.bad { background: var(--danger); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: .88em; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border);
  border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- viewer ---------- */
body.viewer {
  background: #000; overflow: hidden; position: fixed; inset: 0;
  height: 100vh; height: 100dvh;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
/* The canvas renders at the remote resolution and is scaled to fit the
   screen area (rdp.js fitCanvas), letterboxed on a black background. */
.rdp-wrap {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0; background: #000;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.rdp-screen { outline: none; }

/* Control bar: small, centred at the top, floating over the remote desktop
   (which always gets the whole window). Hidden, it leaves a small tab. */
.toolbar {
  position: fixed; top: var(--sat); left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 1px; padding: 2px 5px;
  max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none;
  background: rgba(24, 27, 34, .88); border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 10px 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  opacity: .9; transition: opacity .15s;
}
.toolbar:hover { opacity: 1; }
.toolbar::-webkit-scrollbar { display: none; }
.tb {
  flex: 0 0 auto; width: 28px; height: 28px; border: 0; background: transparent; color: var(--text);
  border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.tb.txt { width: auto; padding: 0 7px; font: inherit; font-size: .72rem; font-weight: 600; }
.tb svg { width: 16px; height: 16px; }
.tb:hover { background: var(--panel-2); }
.tb.danger { color: #fca5a5; }
.tb-sep { flex: 0 0 auto; width: 1px; height: 16px; margin: 0 3px; background: var(--border); }
.tb-title { display: none; }
.pill {
  position: fixed; top: var(--sat); left: 50%; transform: translateX(-50%); z-index: 20;
  width: 46px; height: 14px; padding: 0; border-radius: 0 0 8px 8px; border: 1px solid var(--border); border-top: 0;
  background: rgba(24, 27, 34, .85); color: var(--text); display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: .55; transition: opacity .15s, height .15s;
}
.pill:hover { opacity: 1; height: 18px; }
.pill svg { width: 12px; height: 12px; }

.status { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .65); padding: 20px; }
.status-card { max-width: 360px; width: 100%; text-align: center; }
.status-card p { margin: 12px 0; word-break: break-word; }
.status-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.toast {
  position: absolute; left: 50%; bottom: calc(40px + var(--sab)); transform: translateX(-50%); z-index: 40;
  background: rgba(24, 27, 34, .95); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: .9rem; max-width: 90vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dlg { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 0; width: min(92vw, 420px); }
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg form { padding: 18px; }
.dlg label { display: block; }
.dlg-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.dlg-actions .btn { flex: 1 1 auto; }
